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); } }
void HandleOnBleDidConnectEvent() { searchBleDevicesButton.GetComponent <Button>().enabled = true; byte[] resetSignal = new byte[] { 0xfe, 0xfe, 0xfe }; BLEController.SendData(resetSignal); }
void HandleSearchBLEDevicesEvent() { DidStartPeripheralScanEvent?.Invoke(); ShowActivityIndicatorEvent?.Invoke(); searchBleDevicesButton.GetComponent <Button>().enabled = false; BLEController.ScanForPeripherals(); infoMessage.GetComponent <Text>().text = "Scanning for devices..."; }
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); } }
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"); } }
void HandleSearchBLEDevicesEvent() { if (DidStartPeripheralScanEvent != null) { DidStartPeripheralScanEvent(); } if (ShowActivityIndicatorEvent != null) { ShowActivityIndicatorEvent(); } searchBleDevicesButton.GetComponent <Button>().enabled = false; BLEController.ScanForPeripherals(); }
void HandleDisconnectButtonEvent() { BLEController.Disconnect(); }
IEnumerator SendUpdateDataCommand(int delay) { yield return(new WaitForSeconds(delay)); BLEController.SendData(updateDataCommand); }
public void StopMeteoUpdates() { BLEController.SendData(stopCommand); }
void HandleConnectionEstablishedEvent() { isTrasmissionActive = true; BLEController.SendData(resetCommand); }
public void StopRobot() { isTrasmissionActive = false; BLEController.SendData(resetCommand); }
IEnumerator SendLastCommandAfterDelay(int delay) { yield return(new WaitForSeconds(delay)); BLEController.SendData(lastCommand); }