Exemplo n.º 1
0
    private void ReadFromArduino()
    {
        string response = ap.ReadFromArduino();

        if (response != null)
        {
            int type = 0;
            try { type = int.Parse(response.Split("," [0]) [0]); } catch { Debug.Log(response); }
            switch (type)
            {
            case (12):
                float.TryParse(response.Split("," [0]) [1], out x_angle [arduinoCounter]);
                float.TryParse(response.Split("," [0]) [2], out y_angle [arduinoCounter]);
                float.TryParse(response.Split("," [0]) [3], out z_angle [arduinoCounter]);
                float.TryParse(response.Split("," [0]) [4], out x_acc [arduinoCounter]);
                float.TryParse(response.Split("," [0]) [5], out y_acc [arduinoCounter]);
                float.TryParse(response.Split("," [0]) [6], out z_acc [arduinoCounter]);
                NormalizeAcceleration();
                //Debug.Log (response);
                //Debug.Log ("X: "+x_angle[arduinoCounter]+"\tY: "+y_angle[arduinoCounter]+"\tZ: "+z_angle[arduinoCounter]+"\txAcc: "+x_acc[arduinoCounter]+"\tyAcc: "+y_acc[arduinoCounter]+"\tzAcc: "+z_acc[arduinoCounter]);
                break;

            default:
                //Debug.Log (response);
                break;
            }
        }
    }
Exemplo n.º 2
0
    private void ReadFromArduino()
    {
        string response = ap.ReadFromArduino();

        if (response != null)
        {
            int type = 0;
            try { type = int.Parse(response.Split("," [0]) [0]); } catch { Debug.Log(response); }
            switch (type)
            {
            case (12):
                for (int i = 0; i < num_notes + num_variables; i++)
                {
                    float.TryParse(response.Split("," [0]) [i + 1], out data[i, buffer_pointer]);
                }



                if (buffer_pointer == buffer_dimension - 1)
                {
                    buffer_pointer = 0;
                    buffer_ready   = true;
                }
                else
                {
                    buffer_pointer += 1;
                }

                //Debug.Log (response);
                break;

            default:
                Debug.Log(response);
                break;
            }
        }
    }