예제 #1
0
 private void Awake()
 {
     if (this.debugOutput)
     {
         Debug.Log("BluetoothLE.Awake called");
     }
     if (BluetoothLE.created)
     {
         UnityEngine.Object.Destroy(base.gameObject);
     }
     else
     {
         UnityEngine.Object.DontDestroyOnLoad(this);
         BluetoothLE.bluetoothDeviceScript = BluetoothLEHardwareInterface.Initialize(true, false, new Action(this.Initialized), new Action <string>(this.Error));
         if (null != BluetoothLE.bluetoothDeviceScript)
         {
             UnityEngine.Object.DontDestroyOnLoad(BluetoothLE.bluetoothDeviceScript);
             BluetoothLE.bluetoothDeviceScript.DisconnectedPeripheralAction = new Action <string>(this.disconnectedPeripheralAction);
         }
         BluetoothLE.created = true;
         if (this.debugOutput)
         {
             Debug.Log("BluetoothLE.Awake initialized");
         }
         BluetoothLE.instance = this;
     }
     Array.Clear(this.status, 0, (int)this.status.Length);
     Array.Clear(this.config, 0, (int)this.config.Length);
     Array.Clear(this.mapping, 0, (int)this.mapping.Length);
 }
예제 #2
0
    private void Update()
    {
        BluetoothLE bluetoothLE = this;

        bluetoothLE.frames = bluetoothLE.frames + 1;
        float _realtimeSinceStartup = Time.realtimeSinceStartup;

        if (BluetoothLE.connectState && _realtimeSinceStartup > this.lastInterval + this.updateInterval)
        {
            if (this.interleave % 10 == 1)
            {
                this.SendCommand(1, false);
            }
            else if (BluetoothLE.updateState && this.interleave % 2 == 0)
            {
                if (!BluetoothLE.writeState)
                {
                    this.getServoPos(false);
                }
                else
                {
                    this.setServoPos(false);
                }
            }
            else if (!BluetoothLE.motorState || this.interleave % 10 != 5)
            {
                this.executeQueue();
            }
            else
            {
                this.setMotorValues();
            }
            BluetoothLE bluetoothLE1 = this;
            int         num          = bluetoothLE1.interleave + 1;
            int         num1         = num;
            bluetoothLE1.interleave = num;
            if (num1 >= 20)
            {
                this.interleave = 0;
            }
            this.frames       = 0;
            this.lastInterval = _realtimeSinceStartup;
        }
        if (this.connectDataCallback != null && !BluetoothLE.connecting && !BluetoothLE.connectDataState && 0 <= this.connectedDevice && this.connectedDevice < this.uuids.Count && this.config0flag && this.config1flag && this.config2flag && this.config3flag && this.nameflag)
        {
            BluetoothLE.connectDataState = true;
            this.connectDataCallback(this.uuids[this.connectedDevice]);
        }
    }
예제 #3
0
    public void SubResult(string msg, byte[] data)
    {
        StringBuilder stringBuilder = new StringBuilder();

        if ((int)data.Length > 0)
        {
            stringBuilder.Append(string.Concat(msg, ": (", data[0].ToString("X"), ") "));
        }
        for (int i = 1; i <= 8 && i < (int)data.Length; i++)
        {
            stringBuilder.Append(string.Concat(data[i].ToString("X"), " "));
        }
        if (this.debugOutput)
        {
            Debug.Log(string.Concat("*** SubResult: ", stringBuilder.ToString()));
        }
        byte num = data[0];

        this.status = new byte[16];
        switch (num)
        {
        case 1:
        {
            for (int j = 0; j < 16; j++)
            {
                this.status[j] = data[j + 1];
            }

            if (this.debugOutput)
            {
                Debug.Log(string.Concat(new object[] { "STATUS DATA: ", this.status[0], ",", this.status[1], ",", this.status[2], ",", this.status[3], ",", this.status[4], ",", this.status[5], ",", this.status[6], ",", this.status[7], ",", this.status[8], ",", this.status[9], ",", this.status[10], ",", this.status[11], ",", this.status[12], ",", this.status[13], ",", this.status[14], ",", this.status[15] }));
            }
            if (this.status[15] == 5 || this.status[15] == 6)
            {
                if (this.jDebug)
                {
                    Debug.Log("ERROR FOUND");
                }
                this.CheckForConfigError();
            }
            this.config0flag = true;
            this.updateRobotType();
            if (this.status[15] == 4)
            {
                if (this.jDebug)
                {
                    Debug.Log("SWITCH FOUND ");
                }

                /*if (!TutorialManager.ACTIVE)
                 * {
                 *  this.robotType = this.status[0];
                 *  Debug.Log(string.Concat("new robot type: ", this.robotType));
                 *  ScanManager scanManager = Object.FindObjectOfType<ScanManager>();
                 *  if (scanManager != null)
                 *  {
                 *      scanManager.UpdateRobotInfo();
                 *      scanManager.UpdateRobotPageInfo();
                 *  }
                 *  GameObject gameObject = GameObject.Find("DroneWarningDialog");
                 *  if (gameObject != null && gameObject.get_activeSelf())
                 *  {
                 *      gameObject.GetComponent<ConnectToDroneMeccDialog>().ConnectToMecc();
                 *  }
                 *  GameObject gameObject1 = GameObject.Find("AppVersionDialog");
                 *  if (gameObject1 != null && gameObject1.get_activeSelf() && scanManager != null)
                 *  {
                 *      if (this.jDebug)
                 *      {
                 *          Debug.Log("app version active");
                 *      }
                 *      scanManager.ReprocessFirmwareCheck();
                 *  }
                 *  this.requestStatus();
                 * }*/
            }
            if (this.status[15] != 0)
            {
                if (this.jDebug)
                {
                    Debug.Log(string.Concat("ERROR FOUND : ", this.status[15]));
                }
                if (this.jDebug)
                {
                    Debug.Log(string.Concat("behavior running : "));
                }
            }
            this.updateMeccaButtons();
            break;
        }

        case 2:
        {
            for (int k = 0; k < 16; k++)
            {
                this.config[k] = data[k + 1];
            }
            this.config1flag = true;
            if (this.debugOutput)
            {
                Debug.LogWarning(string.Concat(new object[] { "Config1: ", data[1], ",", data[2], ",", data[3], ",", data[4], " | ", data[5], ",", data[6], ",", data[7], ",", data[8], " | ", data[9], ",", data[10], ",", data[11], ",", data[12], " | ", data[13], ",", data[14], ",", data[15], ",", data[16] }));
            }
            if (this.m_checkingForConfigError)
            {
                this.m_checkingForConfigError = false;
                //Error
            }
            this.m_checkingForStatus = false;
            break;
        }

        case 3:
        {
            for (int l = 0; l < 16; l++)
            {
                this.config[l + 16] = data[l + 1];
            }
            this.config2flag = true;
            if (this.debugOutput)
            {
                Debug.LogWarning(string.Concat(new object[] { "Config2: ", data[1], ",", data[2], ",", data[3], ",", data[4], " | ", data[5], ",", data[6], ",", data[7], ",", data[8], " | ", data[9], ",", data[10], ",", data[11], ",", data[12], " | ", data[13], ",", data[14], ",", data[15], ",", data[16] }));
            }
            break;
        }

        case 7:
        {
            this.meccaName = string.Empty;
            for (int m = 1; m <= 16 && data[m] >= 32 && data[1] <= 126; m++)
            {
                BluetoothLE bluetoothLE = this;
                bluetoothLE.meccaName = string.Concat(bluetoothLE.meccaName, (char)data[m]);
            }
            this.nameflag = true;
            break;
        }

        case 9:
        {
            for (int n = 0; n < 8; n++)
            {
                this.actualPos[n] = data[n + 1];
            }
            if (this.getServoPosCallback != null)
            {
                this.getServoPosCallback();
            }
            break;
        }

        default:
        {
            switch (num)
            {
            case 26:
            {
                base.CancelInvoke("timeOut");
                base.CancelInvoke("SendPIN");
                BluetoothLE.connecting = false;
                if (data[1] != 0 || data[2] != 1 || data[3] != 255)
                {
                    if (this.debugOutput)
                    {
                        Debug.Log(string.Concat(new object[] { "MB_SendPinNumber returned: ", data[1], ", ", data[2], ", ", data[3], ", ", data[4] }));
                    }
                    BluetoothLE.connectState = true;
                    this.Completed();
                }
                else
                {
                    BluetoothLE.connectState = false;
                    this.Disconnect();
                }
                break;
            }

            case 29:
            {
                this.timeDate     = string.Format("{0}{1}:{2}{3}{4} onMB_GetServoMapping {5}/{6}/{7}{8}{9}{10}", new object[] { (data[1] != 0 ? data[1].ToString() : string.Empty), data[2].ToString(), data[3].ToString(), data[4].ToString(), (data[5] != 0 ? "pm" : "am"), data[7].ToString(), data[8].ToString(), data[9].ToString(), data[10].ToString(), data[11].ToString(), data[12].ToString() });
                this.timeDateflag = true;
                break;
            }

            default:
            {
                if (num == 15)
                {
                    if (this.getLEDColorCallback != null)
                    {
                        Color color = this.getColor((int)data[3], (int)data[4]);
                        this.getLEDColorCallback(color);
                    }
                }
                else if (num != 19)
                {
                    if (num == 32)
                    {
                        for (int o = 0; o < 16; o++)
                        {
                            this.mapping[o] = data[o + 1];
                        }
                        this.config3flag = true;
                        if (this.debugOutput)
                        {
                            Debug.LogWarning(string.Concat(new object[] { "Mapping: ", data[1], ",", data[2], ",", data[3], ",", data[4], " | ", data[5], ",", data[6], ",", data[7], ",", data[8], " | ", data[9], ",", data[10], ",", data[11], ",", data[12], " | ", data[13], ",", data[14], ",", data[15], ",", data[16] }));
                        }
                    }
                }
                else if (this.getLIMInfoCallback != null)
                {
                    byte num1 = data[1];
                    if (this.jDebug)
                    {
                        Debug.Log(string.Concat("GET LIM INFO: ", num1));
                    }
                    byte   num2     = data[2];
                    char[] chrArray = new char[16];
                    for (int p = 0; p < 15; p++)
                    {
                        chrArray[p] = (char)data[p + 3];
                    }
                    chrArray[15] = '\0';
                    if (this.jDebug)
                    {
                        Debug.Log(string.Concat("LIM NAME: ", new string(chrArray)));
                    }
                    float single = (float)Convert.ToInt32(num2);
                    if (this.jDebug)
                    {
                        Debug.Log(string.Concat(new object[] { "LIM CONVERTED DURATION: ", single, " : ", num2 }));
                    }
                    this.getLIMInfoCallback(num1, single, new string(chrArray));
                }
                break;
            }
            }
            break;
        }
        }
        if (this.resultsCallback != null)
        {
            this.resultsCallback(data);
        }
    }
예제 #4
0
 public override void Connect()
 {
     bluetoothLE = new BluetoothLE();
     ShowDevices();
 }