예제 #1
0
    void Update()
    {
        if (BtConnector.isConnected())
        {
            if (BtConnector.available())                                      //check if there's an available data

            {
                messageFromMC = BtConnector.readLine();                                 //hold the data in messageFromMC
                //cause BtConnector.read () will delete the buffer

                if (messageFromMC.Length > 0)                                                  // recheck if there's an available data
                //this check is more important than BtConnector.available ()
                //actually you could delete BtConnector.available () with no effect.

                {
                    messages.Add(messageFromMC);                                                             //add the string to the list

                    if (labelHeight * messages.Count >= (height - labelHeight))
                    {
                        scrollPosition.y += labelHeight;                                                                        //it will slide the ScrollView down
                    }
                    //if the whole screen filled with messages

                    if (labelHeight * messages.Count >= height * 2)
                    {
                        messages.RemoveAt(0);                                                                         //when the ScrollView filled ,delet old messages
                    }
                }
            }
        }

        //read control data from the Module.
        controlData = BtConnector.readControlData();
    }
예제 #2
0
    void update()
    {
        string temp = BtConnector.readLine();

        if (temp.Length > 0)
        {
            BT = temp;
        }

        if (BT.Length >= 2)
        {
            joystickxy[0] = BT[0] - 48;             // -48 used to convert char to int

            joystickxy[1] = BT[1] - 48;
        }         // do whatever you want with these data

        //// now lets try to convert these values into something
        /// similar to Input.GetAxis()
        Vector2 tempVector = new Vector2(joystickxy [0], joystickxy [1]);

        curAccess = Vector3.Lerp(curAccess, tempVector - new Vector2(4, 4), Time.deltaTime / 0.5f);


        float VerticalAxis   = Mathf.Clamp(curAccess.y, -1, 1);
        float HorizantalAxis = Mathf.Clamp(curAccess.x, -1, 1);


        //now these two variables are from -1 to 1
        // to increase resolution you need to increase
        // joystick reading scale
    }
예제 #3
0
    void Update()
    {
        arduinotext = BtConnector.readLine();

        if (PhotonNetwork.connected && PhotonNetwork.isMasterClient && flag)
        {
            roundtime          -= Time.smoothDeltaTime;
            roundtimetext.text  = roundtime.ToString("N0");
            roundtimetextR.text = roundtimetext.text;
            ViewRoundTime(roundtime.ToString("N0"));
            if (roundtime < 0.0f)
            {
                ViewScore();
                PhotonNetwork.DestroyAll();
                flag = false;
            }
        }
    }
예제 #4
0
 void OnGUI()
 {
     GUI.TextArea(new Rect(Screen.width - 500, 0, 500, 100), BtConnector.readControlData());
     GUI.TextArea(new Rect(Screen.width - 500, 100, 500, 100), BtConnector.readLine());
     GUI.TextArea(new Rect(Screen.width - 500, 200, 500, 100), BtConnector.read());
 }
예제 #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.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();
        }
        if (GUI.Button(new Rect(0, Screen.height * 0.9f, Screen.width, Screen.height * 0.1f), "change ModuleName"))
        {
            BtConnector.moduleName(stringToEdit);
        }
    }
예제 #6
0
    void Update()
    {
        // Display current status of Bluetooth module
        statusText.text = BtConnector.readControlData();

        // If already connected
        if (BtConnector.isConnected())
        {
            objectReceiver.ActivateSensor(true);
            // Send PING
            if (!waitResponse)
            {
                BtConnector.sendString("PING");
                waitResponse = true;
            }

            // Check for PONG (non-blocking)
            if (BtConnector.available())
            {
                string response = BtConnector.readLine();
                if (response.Length > 0)
                {
                    waitResponse = false;
                    if (response[0] == ' ')
                    {
                        // string to tell us whether or not to activate the stasis
                        activateText.text = activateStasis;
                        powerupText.text  = response.Substring(3);
                        activateStasis    = response.Substring(1, 1);
                        powerUpString     = response.Substring(3);
                        if (activateStasis[0] == '1')
                        {
                            objectReceiver.FireCharge();
                        }
                        objectReceiver.PowerUp(float.Parse(powerUpString));
                    }
                    else if (response == "PONG BUTTON ON")
                    {
                        bluetoothText.text = "Button On!";
                    }
                    else if (response == "PONG BUTTON OFF")
                    {
                        bluetoothText.text = "...";
                    }
                    else
                    {
                        bluetoothText.text = response;
                    }
                }
            }
            else
            {
                bluetoothText.text = "Not Available";
            }
        }
        else
        {
            bluetoothText.text = "Not Connected";
            //BtConnector.connect();
        }
    }