Ejemplo n.º 1
0
        private async Task ConnectingToDeviceAsync()
        {
            try
            {
                IsBusy = true;

                await _bluetoothService.ConnectAsync(_mMContext.Device);

                if (_mMContext.Device.State == Plugin.BLE.Abstractions.DeviceState.Connected)
                {
                    IsSuccessConnection = true;
                    CanExecuteNextBtn   = true;
                    _navigation.NextPage <WiFiSetupNetworkPage>();
                }
                else
                {
                    IsNotSuccessConnection = true;
                }
            }
            catch (DeviceConnectionException e)
            {
                //todo add display info
                // ... could not connect to device
                IsNotSuccessConnection = true;
            }
            catch (Exception ex)
            {
                //generic
                IsNotSuccessConnection = true;
            }
            finally
            {
                IsBusy = false;
            }
        }
Ejemplo n.º 2
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();
            };
        }