コード例 #1
0
    void HandleDidReceiveDataEvent(byte[] data, int numOfBytes)
    {
        Debug.Log("AppControllerBehavior: HandleOnBleDidReceiveDataEvent: size: " + numOfBytes);

        if (numOfBytes == 1 && data[0] == 0xfe)
        {
            Debug.Log("Command correctly received. Can send next command.");
            if (currentCommandIndex >= listOfCommands.Length)
            {
                currentCommandIndex = 0;
            }
            lastCommand          = listOfCommands[currentCommandIndex];
            currentCommandIndex += 1;
            //send last command in 3 seconds!
            if (isTrasmissionActive)
            {
                transmissionCoroutine = StartCoroutine(SendLastCommandAfterDelay(3));
            }
        }
        else if (isTrasmissionActive && numOfBytes == 1 && data[0] == 0xdf)
        {
            Debug.Log("There was an error sending the command. Retry to send last command.");
            BLEController.SendData(lastCommand);
        }
    }
コード例 #2
0
    void HandleOnBleDidConnectEvent()
    {
        searchBleDevicesButton.GetComponent <Button>().enabled = true;

        byte[] resetSignal = new byte[] { 0xfe, 0xfe, 0xfe };

        BLEController.SendData(resetSignal);
    }
コード例 #3
0
    void HandleSearchBLEDevicesEvent()
    {
        DidStartPeripheralScanEvent?.Invoke();
        ShowActivityIndicatorEvent?.Invoke();

        searchBleDevicesButton.GetComponent <Button>().enabled = false;

        BLEController.ScanForPeripherals();
        infoMessage.GetComponent <Text>().text = "Scanning for devices...";
    }
コード例 #4
0
    void HandleBleDevicesListButtonConnectEvent(int buttonIndex)
    {
        Debug.Log("AppControllerBehavior: HandleBleDevicesListButtonConnectEvent: Calling connect peripheral at index: " + buttonIndex);
        bool success = BLEController.ConnectPeripheralAtIndex(buttonIndex);

        if (!success)
        {
            HandleOnBleDidConnectEvent("Error invoking ConnectPeripheralAtIndex " + buttonIndex);
        }
    }
コード例 #5
0
    void HandleBleDevicesListButtonConnectEvent(int buttonIndex)
    {
        Debug.Log("AppControllerBehavior: HandleBleDevicesListButtonConnectEvent: Calling connect peripheral at index");
        bool result = BLEController.ConnectPeripheralAtIndex(buttonIndex);

        if (result)
        {
            Debug.Log("AppControllerBehavior: HandleBleDevicesListButtonConnectEvent: Call is success");
        }
        else
        {
            Debug.Log("AppControllerBehavior: HandleBleDevicesListButtonConnectEvent: Call did fail");
        }
    }
コード例 #6
0
    void HandleSearchBLEDevicesEvent()
    {
        if (DidStartPeripheralScanEvent != null)
        {
            DidStartPeripheralScanEvent();
        }

        if (ShowActivityIndicatorEvent != null)
        {
            ShowActivityIndicatorEvent();
        }

        searchBleDevicesButton.GetComponent <Button>().enabled = false;

        BLEController.ScanForPeripherals();
    }
コード例 #7
0
 void HandleDisconnectButtonEvent()
 {
     BLEController.Disconnect();
 }
コード例 #8
0
    IEnumerator SendUpdateDataCommand(int delay)
    {
        yield return(new WaitForSeconds(delay));

        BLEController.SendData(updateDataCommand);
    }
コード例 #9
0
 public void StopMeteoUpdates()
 {
     BLEController.SendData(stopCommand);
 }
コード例 #10
0
 void HandleConnectionEstablishedEvent()
 {
     isTrasmissionActive = true;
     BLEController.SendData(resetCommand);
 }
コード例 #11
0
 public void StopRobot()
 {
     isTrasmissionActive = false;
     BLEController.SendData(resetCommand);
 }
コード例 #12
0
    IEnumerator SendLastCommandAfterDelay(int delay)
    {
        yield return(new WaitForSeconds(delay));

        BLEController.SendData(lastCommand);
    }