Example #1
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);
    }
    double height;                                                                                //

    //---------------------------------------------------INITIALIZATION---------------------------------------------------------------
    void Start()
    {
        t          = Time.time;                                                                   // record start time
        timebuffer = Time.time;
        if (!BtConnector.isBluetoothEnabled())                                                    // if phone's bluetooth is disabled
        {
            BtConnector.askEnableBluetooth();
        }                                                                                         // prompt user to enable it
        BtConnector.moduleName(mcID);                                                             // tell bt connecter the name of the bt module we are going to connect to
        BtConnector.connect();                                                                    // connect phone to bt module
        droneh        = "0"; dronef = "0"; droner = "0"; dronel = "0";                            // set all controls initially to zero
        lookAngleZero = Cardboard.SDK.HeadPose.Orientation.eulerAngles.y;                         // set phone reference position
        height        = 0;                                                                        // set initial height to zero
    }
Example #3
0
    public void Connect()
    {
        if (!BtConnector.isBluetoothEnabled())
        {
            BtConnector.askEnableBluetooth();
        }
        else
        {
            _lastNameEnteredToConnect = deviceNameInput.text;
            BtConnector.moduleName(deviceNameInput.text); //incase User Changed the Bluetooth Name
            int result = BtConnector.connect();
        }

        connected = BtConnector.isConnected();//check connection status
    }
Example #4
0
    void OnGUI()
    {
        GUI.Label(new Rect(0, 0, Screen.width * 0.15f, Screen.height * 0.1f), "Module Name ");


        if (BtConnector.isConnected())
        {
            if (GUI.Button(new Rect(0, Screen.height * 0.5f, Screen.width, Screen.height * 0.1f), "RequestIMU"))
            {
                UFoneInterface.RequestIMU();
            }
            if (GUI.Button(new Rect(0, Screen.height * 0.6f, Screen.width, Screen.height * 0.1f), "RequestRC"))
            {
                UFoneInterface.RequestRC();
            }

            if (GUI.Button(new Rect(0, Screen.height * 0.7f, Screen.width, Screen.height * 0.1f), "ARM"))
            {
                UFoneInterface.SetRawRC(1400, 1410, 1420, 1000, 1950, 1500, 1500, 1501);
            }

            if (GUI.Button(new Rect(0, Screen.height * 0.8f, Screen.width, Screen.height * 0.1f), "DisArm"))
            {
                UFoneInterface.SetRawRC(1400, 1410, 1420, 1000, 1050, 1500, 1500, 1500);
            }
        }
        else
        {
            if (GUI.Button(new Rect(0, Screen.height * 0.4f, Screen.width, Screen.height * 0.1f), "Try Connect"))
            {
                if (!BtConnector.isBluetoothEnabled())
                {
                    BtConnector.askEnableBluetooth();
                }
                else
                {
                    BtConnector.connect();
                }
            }

            if (GUI.Button(new Rect(0, Screen.height * 0.9f, Screen.width, Screen.height * 0.1f), "Show"))
            {
                BtConnector.showDevices();
            }
        }
    }
Example #5
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);
    }
Example #6
0
    void Start()
    {
        bluetoothText.text = "";

        // Initialize module and connect to paired Bluetooth device
        BtConnector.moduleName("HC-06");
        if (!BtConnector.isBluetoothEnabled())
        {
            BtConnector.askEnableBluetooth();
        }
        else
        {
            BtConnector.connect();
        }

        Assert.IsTrue(objectReceiver);
    }
Example #7
0
    public void Connect()
    {
        if (BtConnector.isDevicePicked)
        {
            if (!BtConnector.isBluetoothEnabled())
            {
                BtConnector.askEnableBluetooth();
            }
            else
            {
                string name = BtConnector.getPickedDeviceName();
                BtConnector.moduleName(name);
                BtConnector.connect();

                Debug.Log("try to connect " + name);
            }
        }
    }
Example #8
0
    void Start()
    {
        BtConnector.moduleMAC("20:15:07:02:69:59");

        if (!BtConnector.isBluetoothEnabled())
        {
            BtConnector.askEnableBluetooth();
        }
        else
        {
            BtConnector.moduleMAC("20:15:07:02:69:59");
            BtConnector.connect();
        }


        photonView = GetComponent <PhotonView> ();
        messages   = new Queue <string> (messageCount);

        PhotonNetwork.logLevel = PhotonLogLevel.Full;
        PhotonNetwork.ConnectUsingSettings("1.0");
        StartCoroutine("UpdateConnectionString");
    }
Example #9
0
    // Use this for initialization
    void Start()
    {
        UFOneAPI = new MultiWiiProtocol();
        BtConnector.askEnableBluetooth();

        UFOneAPI.DebugMessageEvent += (string log) =>
        {
            Debug.Log(log);
        };

        leftStick.ControllerMovedEvent += (position, stick) =>
        {
            int dif  = (RANGE_MAX - RANGE_MIN) / 2;
            int mean = (RANGE_MAX + RANGE_MIN) / 2;

            ROLL  = (ushort)(position.x * dif / 4 + mean);
            PITCH = (ushort)(position.y * dif / 4 + mean);

            Debug.Log("Left:" + position.x + ":" + position.y);
        };

        leftStick.FingerLiftedEvent += (CNAbstractController o) =>
        {
            ROLL  = _defaultRoll;
            PITCH = _defaultPitch;
        };

        rightStick.ControllerMovedEvent += (position, stick) =>
        {
            int dif  = (RANGE_MAX - RANGE_MIN) / 2;
            int mean = (RANGE_MAX + RANGE_MIN) / 2;

            YAW      = (ushort)(position.x * dif / 4 + mean);
            THROTTLE = (ushort)(position.y * dif + mean);

            Debug.Log("Right:" + position.x + ":" + position.y);
        };
    }
Example #10
0
 void OnGUI()
 {
     if (!Network.isClient && !Network.isServer)
     {
         if (GUI.Button(new Rect(100, 100, 250, 100), "Start Server"))
         {
             StartServer();
         }
         if (GUI.Button(new Rect(100, 250, 250, 100), "Refresh Hosts"))
         {
             RefreshHostList();
         }
         if (hostList != null)
         {
             for (int i = 0; i < hostList.Length; i++)
             {
                 if (GUI.Button(new Rect(400, 100 + (110 * i), 300, 100), hostList [i].gameName))
                 {
                     JoinServer(hostList [i]);
                 }
             }
         }
         if (GUI.Button(new Rect(400, 250, 250, 100), "Connect"))
         {
             if (!BtConnector.isBluetoothEnabled())
             {
                 BtConnector.askEnableBluetooth();
             }
             else
             {
                 BtConnector.connect();
             }
             BtConnector.stopListen();
         }
     }
 }
    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);
        }
    }
Example #12
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);
        }
    }