void HandleBlueTooth() { //input UFOneAPI.AddData(BtConnector.readBuffer()); //output BtConnector.sendBytes(UFOneAPI.GetRawCommand()); UFOneAPI.Update(); }
void OnGUI() { GUIStyle style = GUI.skin.GetStyle("label"); style.fontSize = 20; if (!connected && GUI.Button(gRect, "Connect")) //the Connect button will disappear when connecttion done // and appear again if it disconnected { if (!BtConnector.isBluetoothEnabled()) { BtConnector.askEnableBluetooth(); } else { BtConnector.connect(); } } connected = BtConnector.isConnected(); //check connection status scrollPosition = GUI.BeginScrollView(new Rect(0, height * 0.1f, Screen.width, height), scrollPosition, new Rect(0, 0, Screen.width, height * 2)); for (int i = 0; i < messages.Count; i++) //display the List of messages { GUI.Label(new Rect(0, labelHeight * i, Screen.width, labelHeight), messages[i]); } GUI.EndScrollView(); messageToMC = GUI.TextField(new Rect(0, Screen.height * 0.9f, Screen.width * 0.9f, Screen.height * 0.1f), messageToMC); if (GUI.Button(new Rect(Screen.width * 0.9f, Screen.height * 0.9f, Screen.width * 0.1f, Screen.height * 0.1f), "Send")) { byte[] bytes = System.Text.Encoding.UTF8.GetBytes(messageToMC + '\n'.ToString()); //convert string to array of bytes and add a new line BtConnector.sendBytes(bytes); } if (GUI.Button(new Rect(Screen.width * 0.9f, 0, Screen.width * 0.1f, Screen.height * 0.1f), "Close Connection")) { BtConnector.close(); connected = false; } GUI.Label(new Rect(0, 0, Screen.width * 0.9f, Screen.height * 0.1f), "From Plugin : " + controlData); }
void Update() { UFoneInterface.AddData(BtConnector.readBuffer()); UFoneInterface.Update(); Debug.Log("Picked:" + BtConnector.isDevicePicked + ":" + BtConnector.getPickedDeviceName()); //if(BtConnector.isConnected()) //UFoneInterface.SetRawRC(1400,1410,1420,1000,1950,1500,1500,1501); //SendData byte[] dataToSend = UFoneInterface.GetRawCommand(); if (dataToSend.Length > 0) { BtConnector.sendBytes(dataToSend); Debug.Log("sendBytes:" + byteToIntStr(dataToSend)); } //GetData }