Beispiel #1
0
    void Start()
    {
        try{
            x        = "";
            BTHelper = BluetoothHelper.GetInstance("HC-05");
            BTHelper.setLengthBasedStream();
            BTHelper.OnConnected += OnBluetoothConnected;             //OnBluetoothConnected is a function defined later on

            BTHelper.OnDataReceived += () => {
                //this is called when you receive data FROM your arduino
                string receivedData;
                receivedData = BTHelper.Read();                 // returns a string
                //since you are sending an array, convert the string to array :
                char[] data = receivedData.ToCharArray();

                //do Whatever you want
            };

            BTHelper.OnDataReceived += () => {
                try{
                    string xx   = BTHelper.Read();
                    char[] data = xx.ToCharArray();

                    if (data.Length != 3)
                    {
                        return;
                    }

                    int i = 0;
                    if (data[0] != 'S')
                    {
                        return;
                    }
                    if (data[1] == 'E')
                    {
                        i = 1;
                    }
                    if (data[2] > 7)
                    {
                        return;
                    }

                    spheres[data[2] - 2].GetComponent <Renderer>().material = materials[i];
                }catch (Exception ex)
                {
                    x += ex.Message;
                }
            };
        }catch (Exception ex) {
            Debug.Log(ex);
            x = ex.ToString();
        }
    }
 //Asynchronous method to receive messages
 void OnMessageReceived()
 {
     StartCoroutine(blinkSphere());
     received_message = bluetoothHelper.Read();
     text.text        = received_message;
     Debug.Log(received_message);
 }
Beispiel #3
0
 // Update is called once per frame
 void Update()
 {
     if (helper.Available)
     {
         string msg = helper.Read();
     }
 }
Beispiel #4
0
    //Asynchronous method to receive messages
    void OnMessageReceived()
    {
        //StartCoroutine(blinkSphere());
        received_message = bluetoothHelper.Read();
        Debug.Log(received_message);
        // Debug.Log(received_message);

        char sp = '/';

        string[] strings = received_message.Split(sp);

        float[] nums = new float[3];

        for (int i = 1; i < strings.Length; i++)
        {
            float.TryParse(strings[i], out nums[i - 1]);
        }

        if (strings[0] == "T")
        {
            isTouched = true;
        }
        else
        {
            isTouched = false;
        }
        if (setFirst == null)
        {
            setFirst = new Vector3(nums[0], nums[1], nums[2]);
        }

        Con.rotation = Quaternion.Euler(new Vector3(nums[0] - setFirst.x, nums[1] - setFirst.y, nums[2] - setFirst.z));
    }
Beispiel #5
0
 void FixedUpdate()
 {
     if (helper.Available)
     {
         msg = helper.Read();
     }
 }
    private void OnBluetoothDataReceived()
    {
        string json = m_Helper.Read();

        ShowText($"{json}\nLeft: {Packet.leftBrake}\tSteer: {Packet.steerAngle}\tRight: {Packet.rightBrake}");

        Packet = JsonUtility.FromJson <ArduinoPacket>(json);
    }
Beispiel #7
0
 //Asynchronous method to receive messages
 void OnMessageReceived()
 {
     //StartCoroutine(blinkSphere());
     received_message = bluetoothHelper.Read();
     text.text        = received_message;
     Debug.Log(System.DateTime.Now.Second);
     //Debug.Log(received_message);
 }
Beispiel #8
0
 //Asynchronous method to receive messages
 void OnMessageReceived(BluetoothHelper helper)
 {
     //StartCoroutine(blinkSphere());
     received_message = helper.Read();
     Debug.Log(received_message);
     text.text = received_message;
     // Debug.Log(received_message);
 }
Beispiel #9
0
    //Asyncrone Methode des Dtaneempfangens
    void OnMessageReceived()
    {
        char[] data = bluetoothHelper.Read().ToCharArray();
        for (int i = 0; i < data.Length / 2; i++)
        {
            buffer[0]     = (byte)data[2 * i];
            buffer[1]     = (byte)data[2 * i + 1];
            sensordata[i] = BitConverter.ToUInt16(buffer, 0);
            Debug.Log(debugfilter + "Sensor[ " + i + " ] " + sensordata[i]);
        }


        k1_Bew = sensordata[0];
        r1_Bew = sensordata[1];
        m1_Bew = sensordata[2];
        z1_Bew = sensordata[3];
        z2_Bew = sensordata[4];
        d1_Bew = sensordata[5];
        x_Bew  = sensordata[6];
        y_Bew  = sensordata[7];
        z_Bew  = sensordata[8];



        for (int i = 0; i <= 5; i++)
        {
            setauf(i); // Auf Wert (Max Wert) setzen
            setzu(i);  // Zu Wert (Min Wert) setzen
            pro(i);    //Prozente der Öffnung der Hand bekommen
        }


        // Faust - Greifen
        if (proz[0] <= 30 && proz[1] <= 30 && proz[4] <= 30)
        {
            greif = true;
        }
        else
        {
            greif = false;
        }



        //Zeigen - Laufen
        //if (proz[0] >= 60 && proz[1] >= 60 && proz[2] >= 60 && proz[3] >= 60 && proz[4] <= 40)
        //   { lauf = true;}
        // else
        //  {lauf = false;

        // }


        //Dubug Hilfen
        mytext2.text = auf[3].ToString() + zu[3].ToString();
        mytext3.text = proz[3].ToString();
        mytext.text  = proz[3].ToString() + "=" + sensordata[3].ToString() + "*" + (100f / (auf[3] - zu[3])).ToString();
    }
Beispiel #10
0
    // Update is called once per frame
    void Update()
    {
        if (btManager.connectBT == true)
        {
            //Read from bluetooth
            helper = btManager.GetBluetoothHelper();
            outMsg = helper.Read();

            ParseMsg();
        }
    }
Beispiel #11
0
    /// <summary>
    /// //////////////////////////////  아두이노에서 시리얼 입력을 받았을 때 문자열 분석  //////////////////////
    /// </summary>
    /// <param name="helper"></param>
    void OnMessageReceived(BluetoothHelper helper)
    {
        received_message = helper.Read();
        LogWrite(received_message);
        if (received_message.Contains("Sensor"))
        {
            tempText.GetComponentInChildren <Text>().text = int.Parse(received_message.Substring(6, 3)) + " ℃";

            LogWrite("센서값");
        }
    }
Beispiel #12
0
    void OnMessageReceived()
    {
        received_message = bluetoothHelper.Read();

        if (received_message == null)
        {
            return;
        }

        AddStringToBuffer(received_message);
        carDivice.UpdateInfo(received_message);
        ppManager.CheckEOP(received_message);
    }
Beispiel #13
0
    private void BluetoothHelper_OnDataReceived()
    {
        awatingMsg = false;

        string aux = bluetoothHelper.Read();

        Debug.Log(" Received: " + aux);

        BLE_dataReceived.UpdateText(aux);

        // send the next message only when the previous message response is received.
        SendNext();
    }
Beispiel #14
0
    //Asynchronous method to receive messages
    void OnMessageReceived()
    {
        received_message = bluetoothHelper.Read();
        Debug.Log(received_message);

        if (received_message.Contains("on"))
        {
            Txt_Door.text = "Door is close";
            onDoorClose.Invoke();
        }

        if (received_message.Contains("off"))
        {
            Txt_Door.text = "Door is open";
            onDoorOpen.Invoke();
        }
    }
    //Asynchronous method to receive messages
    void OnMessageReceived()
    {
        received_message = bluetoothHelper.Read();
        Debug.Log(received_message);

        if (received_message.Contains("on"))
        {
            Txt_Door.text = "Door is close";
            onDoorClose.Invoke();
            GameObject.Find("Coin Creator").GetComponent <Spawner>().spawn();                      //메시지가 on이면 어떻게할지
        }

        if (received_message.Contains("off"))
        {
            Txt_Door.text = "Door is open";
            onDoorOpen.Invoke();
        }
    }
Beispiel #16
0
    /// <summary>
    /// This method is called every frame and makes this device wait for available data.
    /// </summary>
    public void ReceiveData()
    {
        if (bt.Available)
        {
            string   msg  = bt.Read();
            string[] data = msg.Split(';');

            // extract values from received string
            float temperature = (float)System.Convert.ToDouble(data[0].Replace("temp;", ""));
            float humidity    = (float)System.Convert.ToDouble(data[1].Replace("hum;", ""));
            float voltage     = (float)System.Convert.ToDouble(data[2].Replace("volt;", ""));

            // get current time
            System.DateTime now = System.DateTime.Now; // temporarily

            // add values to their corresponding statistics
            UIManager.GetInstance().GetTemperatureStatistics().AddPoint(now, temperature);
            UIManager.GetInstance().GetHumidityStatistics().AddPoint(now, humidity);
            UIManager.GetInstance().GetVoltageStatistics().AddPoint(now, voltage);
        }
    }
Beispiel #17
0
    public void OnMessageReceived()
    {
        //   Debug.Log("It's received_message!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
        received_message = bluetoothHelper.Read();
        // Debug.Log($"BT_Debug : {received_message}");
        //    ? write(received_message);

        if (received_message.Contains("ON"))
        {
            isWet = true;
            Debug.Log("true");
        }
        else if (received_message.Contains("OFF"))
        {
            isWet = false;
            Debug.Log("false");
        }
        else
        {
            Debug.Log("Error");
        }
        Debug.Log($"GameMGRIsWet? : {isWet}");
    }
Beispiel #18
0
 void OnMessageReceived(BluetoothHelper helper)
 {
     payload  = helper.Read();
     payloada = payload.Split(';');
     Debug.Log(payload);
 }
Beispiel #19
0
 void OnMessageReceived(BluetoothHelper helper)
 {
     received_message = helper.Read();
     Debug.Log(received_message);
     write("Received : " + received_message);
 }
Beispiel #20
0
 void OnDataReceived()
 {
     data += "\n<" + helper.Read();
 }
Beispiel #21
0
    //Asynchronous method to receive messages
    void OnMessageReceived()
    {
        char[] data = bluetoothHelper.Read().ToCharArray();
        for (int i = 0; i < data.Length / 2; i++)
        {
            buffer[0]      = (byte)data [2 * i];
            buffer[1]      = (byte)data [2 * i + 1];
            sensordata [i] = BitConverter.ToUInt16(buffer, 0);
            Debug.Log(debugfilter + "Sensor[ " + i + " ] " + sensordata[i]);
        }
        k1_Bew = sensordata[0];
        r1_Bew = sensordata[1];
        m1_Bew = sensordata[2];
        z1_Bew = sensordata[3];
        d1_Bew = sensordata[4];
        x_Bew  = sensordata[5];
        y_Bew  = sensordata[6];
        z_Bew  = sensordata[7];

        mytext3.text = x_Bew.ToString();

        flex [0] = k1_Bew;
        flex [1] = r1_Bew;
        flex [2] = m1_Bew;
        flex [3] = z1_Bew;
        flex [4] = d1_Bew;

        for (int m = 0; m <= 4; m++)
        {
            setmin(m);
            setmax(m);
            mom [m] = ((((float)flex[m] - (float)min[m]) / ((float)max[m] - (float)min[m]))) * 100000f;
        }

        gegriffen = true;
        for (int j = 0; j <= 4; j++)
        {
            if (mom [j] > 33000)
            {
                greif [j] = true;
            }
            else if (j != 3)
            {
                greif [j] = false;
            }
        }
        greif[3] = true;
        if ((mom [0] > 35000) && (mom [1] > 35000) && (mom [2] > 35000) && (mom [3] < 28000) && (mom [4] > 35000))
        {
            gezeigt   = true;
            gegriffen = true;
        }
        else
        {
            gezeigt = false;
            for (int k = 0; k <= 4; k++)
            {
                if (greif [k] == false)
                {
                    gegriffen = false;
                }
            }
        }



        /*	mytext4.text = flex [0].ToString () + " " + flex [1].ToString () + " " + flex [2].ToString () + " " + flex [3].ToString () + " " + flex [4].ToString ();
         * mytext.text = mom [0].ToString () + " " + mom [1].ToString () + " " + mom [2].ToString () + " " + mom [3].ToString () + " " + mom [4].ToString ();
         * mytext5.text = max [0].ToString () + " " + max [1].ToString () + " " + max [2].ToString () + " " + max [3].ToString () + " " + max [4].ToString ();
         * mytext6.text = min [0].ToString () + " " + min [1].ToString () + " " + min [2].ToString () + " " + min [3].ToString () + " " + min [4].ToString ();
         * if (gegriffen == true) {
         *      mytext2.text = "true";
         * } else {
         *      mytext2.text = "false";
         * }*/



        mytext2.text = gezeigt.ToString();
    }
Beispiel #22
0
 void OnDataReceived(BluetoothHelper helper)
 {
     data += "\n<" + helper.Read();
 }