private void BtnConnectClick(object sender, EventArgs e) { if (_connectWorker.IsBusy || _discoverWorker.IsBusy) { return; } if (_connector.Connected) { _connector.Disconnect(); btnConnect.Text = "Connect"; SetControlState(false); btnRefresh.Enabled = true; lsbCommands.Items.Clear(); } else { _connectWorker.RunWorkerAsync(lsbCommands.SelectedItem); btnRefresh.Enabled = false; btnConnect.Enabled = false; statusLabel.Text = "Connecting to device..."; } }
/// <summary> /// Tries the disconnection with the tamabin. /// </summary> /// <returns>The disconnect message.</returns> public string TryDisconnect() { if (bluetoothConnector.Connected()) { bluetoothConnector.Disconnect(); return(DISCONNECTED); } return(NOT_CONNECTED); }
IEnumerator PushAnchorPositions() { BluetoothConnector.Disconnect(); yield return(new WaitUntil(() => BluetoothConnector.currentState() == BluetoothConnector.States.Disconnected)); BluetoothConnector.Reset(); foreach (string anchorName in AnchorNames) { Debug.Log("pushing anchor " + anchorName); BluetoothBytes positionBytes = BluetoothBytes.MakeFromLocation((int)anchorPositions[anchorName][0], (int)anchorPositions[anchorName][1], (int)anchorPositions[anchorName][2], 100); Debug.Log("would push " + positionBytes.ToHex()); byte[] anchorPositionBytes = positionBytes.ToBytes(); BluetoothConnector.InitializeAction(anchorName, ServiceUUID, WriteCharacteristic, BluetoothConnector.States.Write, bytesToWrite: anchorPositionBytes); BluetoothConnector.StartProcess(); yield return(new WaitUntil(() => BluetoothConnector.actionSuccessful())); BluetoothConnector.Disconnect(); yield return(new WaitUntil(() => BluetoothConnector.currentState() == BluetoothConnector.States.Disconnected)); BluetoothConnector.Reset(); } }