예제 #1
0
 public void Disconnect()
 {
     if (BtConnector.isConnected())
     {
         BtConnector.close();
     }
 }
예제 #2
0
    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);
    }
예제 #3
0
    void OnGUI()
    {
        GUIStyle style = GUI.skin.GetStyle("label");

        style.fontSize = 20;

        if (!BtConnector.isConnected() && 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();
            }
        }



        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"))
        {
            BtConnector.sendString(messageToMC);
        }


        if (GUI.Button(new Rect(Screen.width * 0.9f, 0, Screen.width * 0.1f, Screen.height * 0.1f), "Close Connection"))
        {
            BtConnector.close();
        }

        GUI.Label(new Rect(0, 0, Screen.width * 0.9f, Screen.height * 0.1f), "From Plugin : " + controlData);
    }
    void OnGUI()
    {
        GUI.Label(new Rect(0, 0, Screen.width * 0.15f, Screen.height * 0.1f), "Module Name ");

        stringToEdit = GUI.TextField(new Rect(Screen.width * 0.15f, 0, Screen.width * 0.8f, Screen.height * 0.1f), stringToEdit);
        GUI.Label(new Rect(0, Screen.height * 0.2f, Screen.width, Screen.height * 0.1f), "Arduino Says : " + ByteArrayToString(buffer));
        GUI.Label(new Rect(0, Screen.height * 0.3f, Screen.width, Screen.height * 0.1f), "from PlugIn : " + BtConnector.readControlData());

        if (GUI.Button(new Rect(0, Screen.height * 0.4f, Screen.width, Screen.height * 0.1f), "Connect"))
        {
            if (!BtConnector.isBluetoothEnabled())
            {
                BtConnector.askEnableBluetooth();
            }
            else
            {
                BtConnector.connect();
            }
        }


        ///the hidden code here let you connect directly without askin the user
        /// if you want to use it, make sure to hide the code from line 23 to lin 33

        /*
         * if( GUILayout.Button ("Connect")){
         *
         *      startConnection = true;
         *
         * }
         *
         * if(GUI.Button(new Rect(0,Screen.height*0.4f,Screen.width,Screen.height*0.1f), "Connect"))
         * {
         *      if (!BtConnector.isBluetoothEnabled ()){
         *              BtConnector.enableBluetooth();
         *
         *      } else {
         *
         *              BtConnector.connect();
         *
         *              startConnection = false;
         *
         *      }
         *
         * }
         */
        /////////////
        if (GUI.Button(new Rect(0, Screen.height * 0.6f, Screen.width, Screen.height * 0.1f), "sendChar"))
        {
            if (BtConnector.isConnected())
            {
                BtConnector.sendChar('h');
                BtConnector.sendChar('e');
                BtConnector.sendChar('l');
                BtConnector.sendChar('l');
                BtConnector.sendChar('o');
                BtConnector.sendChar('\n');                 //because we are going to read it using .readLine() which reads lines.
            }
        }
        if (GUI.Button(new Rect(0, Screen.height * 0.5f, Screen.width, Screen.height * 0.1f), "sendString"))
        {
            if (BtConnector.isConnected())
            {
                BtConnector.sendString("Hii");
                BtConnector.sendString("you can do this");
            }
        }



        if (GUI.Button(new Rect(0, Screen.height * 0.7f, Screen.width, Screen.height * 0.1f), "Close"))
        {
            BtConnector.close();
        }

        if (GUI.Button(new Rect(0, Screen.height * 0.8f, Screen.width, Screen.height * 0.1f), "readData"))
        {
            //fromArduino = BtConnector.readLine();
            buffer = BtConnector.readBuffer();
        }
        if (GUI.Button(new Rect(0, Screen.height * 0.9f, Screen.width, Screen.height * 0.1f), "change ModuleName"))
        {
            BtConnector.moduleName(stringToEdit);
        }
    }
예제 #5
0
    void OnGUI()
    {
        GUI.Label(new Rect(0, 0, Screen.width * 0.15f, Screen.height * 0.1f), "Module Name ");

        stringToEdit = GUI.TextField(new Rect(Screen.width * 0.15f, 0, Screen.width * 0.8f, Screen.height * 0.1f), stringToEdit);
        GUI.Label(new Rect(0, Screen.height * 0.2f, Screen.width, Screen.height * 0.1f), "Arduino Says : " + fromArduino);
        GUI.Label(new Rect(0, Screen.height * 0.3f, Screen.width, Screen.height * 0.1f), "from PlugIn : " + BtConnector.readControlData());

        if (GUI.Button(new Rect(0, Screen.height * 0.4f, Screen.width, Screen.height * 0.1f), "Connect"))
        {
            if (!BtConnector.isBluetoothEnabled())
            {
                BtConnector.askEnableBluetooth();
            }
            else
            {
                BtConnector.moduleName(stringToEdit);                         //incase User Changed the Bluetooth Name
                BtConnector.connect();
            }
        }


        ///the hidden code here let you connect directly without askin the user
        /// if you want to use it, make sure to hide the code from line 23 to lin 33

        /*
         * if( GUILayout.Button ("Connect")){
         *
         *      startConnection = true;
         *
         * }
         *
         * if(GUI.Button(new Rect(0,Screen.height*0.4f,Screen.width,Screen.height*0.1f), "Connect"))
         * {
         *      if (!BtConnector.isBluetoothEnabled ()){
         *              BtConnector.enableBluetooth();
         *
         *      } else {
         *
         *              BtConnector.connect();
         *
         *              startConnection = false;
         *
         *      }
         *
         * }
         */
        /////////////
        if (GUI.Button(new Rect(0, Screen.height * 0.6f, Screen.width, Screen.height * 0.1f), "sendChar"))
        {
            if (BtConnector.isConnected())
            {
                BtConnector.sendChar('h');
                BtConnector.sendChar('e');
                BtConnector.sendChar('l');
                BtConnector.sendChar('l');
                BtConnector.sendChar('o');
                BtConnector.sendChar('\n');                 //because we are going to read it using .readLine() which reads lines.

                //don't call the send method multiple times unless you really need to, because it will kill performance.
            }
        }
        if (GUI.Button(new Rect(0, Screen.height * 0.5f, Screen.width, Screen.height * 0.1f), "sendString"))
        {
            if (BtConnector.isConnected())
            {
                BtConnector.sendString("Hii");
                BtConnector.sendString("you can do this");
                //BtConnector.sendBytes(new byte[] {55,55,55,10});

                //don't call the send method multiple times unless you really need to, because it will kill performance.
            }
        }



        if (GUI.Button(new Rect(0, Screen.height * 0.7f, Screen.width, Screen.height * 0.1f), "Close"))
        {
            BtConnector.close();
        }

        if (GUI.Button(new Rect(0, Screen.height * 0.8f, Screen.width, Screen.height * 0.1f), "readData"))
        {
            if (BtConnector.available())
            {
                fromArduino = BtConnector.readLine();
            }
        }
        if (GUI.Button(new Rect(0, Screen.height * 0.9f, Screen.width, Screen.height * 0.1f), "change ModuleName"))
        {
            BtConnector.moduleName(stringToEdit);
        }
    }