예제 #1
0
        private void Init()
        {
            _bluetoothService         = new BluetoothService();
            devicesComBox.ItemsSource = _bluetoothService.GetDevices();

            aBtn.Click += async(s, e) => await DoAsync(Actions.A);

            bBtn.Click += async(s, e) => await DoAsync(Actions.B);

            cBtn.Click += async(s, e) => await DoAsync(Actions.C);

            dBtn.Click += async(s, e) => await DoAsync(Actions.D);

            startBtn.Click += async(s, e) => await DoAsync(Actions.Start);

            selectBtn.Click += async(s, e) => await DoAsync(Actions.Select);

            upBtn.Click += async(s, e) => await MoveAsync(Directions.Up);

            downBtn.Click += async(s, e) => await MoveAsync(Directions.Down);

            leftBtn.Click += async(s, e) => await MoveAsync(Directions.Left);

            rightBtn.Click += async(s, e) => await MoveAsync(Directions.Right);

            connectBtn.Click += async(s, e) =>
            {
                var port = devicesComBox.SelectedValue as string;
                if (port != null)
                {
                    if (!_bluetoothService.IsConnected)
                    {
                        connectBtn.IsEnabled = false;
                        connectBtn.Content   = "Disconnect";
                        await _bluetoothService.ConnectAsync(port);

                        connectBtn.IsEnabled = true;
                    }
                    else
                    {
                        connectBtn.IsEnabled = false;
                        connectBtn.Content   = "Connect";
                        _bluetoothService.Disconnect();
                        connectBtn.IsEnabled = true;
                    }
                }
            };

            refreshBtn.Click += (s, e) =>
            {
                devicesComBox.ItemsSource = _bluetoothService.GetDevices();
            };
        }
예제 #2
0
 public override void Disconnect(bool rememberDevice = true)
 {
     BluetoothService.Disconnect(rememberDevice);
 }