Exemple #1
0
    void Start()
    {
        DontDestroyOnLoad(this);
        Application.LoadLevel("menu");
        BtConnector.moduleName("HC-06");
        //MasterServer.ipAddress = "149.142.250.42";

        /*MasterServer.ipAddress = "169.232.80.18";
         * MasterServer.port = 23466;
         * Network.natFacilitatorIP = "169.232.80.18";
         * Network.natFacilitatorPort = 50005;*/
    }
    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
    }
    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
    }
Exemple #4
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);
    }
Exemple #5
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);
            }
        }
    }
Exemple #6
0
    void Start()
    {
        BtConnector.moduleName(stringToEdit);



        //BtConnector.sho

        UFoneInterface = new MultiWiiProtocol();
        UFoneInterface.DebugMessageEvent += (string log) =>
        {
            Debug.Log(log);
        };

        UFoneInterface.IMUResultEvent += (short accx, short accy, short accz, short gyrx, short gyry, short gyrz, short magx, short magy, short magz) =>
        {
            Debug.Log("IMU: accX=" + accx + " accY=" + accy + " accZ=" + accz + " gyrx=" + gyrx + " gyry=" + gyry + " gyrz=" + gyrz + " magx=" + magx + " magy=" + magy + " magz=" + magz);
        };

        UFoneInterface.RCResultEvent += (ushort Roll, ushort Pitch, ushort Yaw, ushort Throttle, ushort AUX1, ushort AUX2, ushort AUX3, ushort AUX4) =>
        {
            Debug.Log("RC: Roll=" + Roll + " PITCH=" + Pitch + " Yaw=" + Yaw + " Throttle=" + Throttle + " AUX1=" + AUX1 + " AUX2=" + AUX2 + " AUX3=" + AUX3 + " AUX4=" + AUX4);
        };
    }
    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);
        }
    }
 void Start()
 {
     //use one of the following two methods to change the default bluetooth module.
     //BtConnector.moduleMAC("00:13:12:09:55:17");
     BtConnector.moduleName("HC-06");
 }
Exemple #9
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);
        }
    }