Exemple #1
0
        private async void UnpairButton_Click(object sender, RoutedEventArgs e)
        {
            DeviceInformationDisplay deviceInfoDisp = resultsListView.SelectedItem as DeviceInformationDisplay;

            Debug.WriteLine("Unpair");

            UnpairButton.IsEnabled = false;
            SensorList.IsEnabled   = false;
            InitButton.IsEnabled   = false;
            EnableButton.IsEnabled = false;

            EnableIOButton.IsEnabled  = false;
            DisableIOButton.IsEnabled = false;
            AllOffIOButton.IsEnabled  = false;
            BUZZButton.IsEnabled      = false;
            LED1Button.IsEnabled      = false;
            LED2Button.IsEnabled      = false;
            DeviceInfoConnected       = null;

            Debug.WriteLine("Disable Sensors");
            for (int i = 0; i < CC2650SensorTag.NUM_SENSORS; i++)
            {
                if (CC2650SensorTag.ServiceList[i] != null)
                {
                    //await disableSensor(i);
                    await CC2650SensorTag.SensorsCharacteristicsList[i].DisableNotify();
                }
            }

            Debug.WriteLine("UnpairAsync");
            try
            {
                DeviceUnpairingResult dupr = await deviceInfoDisp.DeviceInformation.Pairing.UnpairAsync();

                string unpairResult = $"Unpairing result = {dupr.Status}";
                Debug.WriteLine(unpairResult);
                UserOut.Text = unpairResult;
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Unpair exception = " + ex.Message);
            }

            for (int i = 0; i < CC2650SensorTag.ServiceList.Length; i++)
            {
                CC2650SensorTag.ServiceList[i] = null;
            }

            UpdatePairingButtons();
            StartWatcher();
        }
Exemple #2
0
        private Task StopBLEWatcherAsync(DeviceInformationDisplay deviceInfoDisp)
        {
            return(Task.Run(async() =>
            {
                Debug.WriteLine("Disable Sensors");
                foreach (var sensor in _serviceList)
                {
                    await disableSensor(sensor.Key);
                }
                lock (_serviceList)
                {
                    _serviceList.Clear();
                }
                lock (_notifyList)
                {
                    _notifyList.Clear();
                }

                // stop BLE watcher
                if (null != blewatcher)
                {
                    // Unregister all event handlers but stopped,
                    // stop the watcher and wait it is stopped.
                    blewatcher.Added -= OnBLEAdded;
                    blewatcher.Updated -= OnBLEUpdated;
                    blewatcher.Removed -= OnBLERemoved;
                    blewatcher.Stop();
                    if (blewatcherStopped.WaitOne(TimeSpan.FromMinutes(BLEWATCHER_STOP_TIMEOUT)))
                    {
                        Debug.WriteLine($"BLE watcher {blewatcher.Status.ToString()}");
                        blewatcher.Stopped -= OnBLEStopped;
                        blewatcher = null;
                    }
                    else
                    {
                        Debug.WriteLine($"CANNOT stop BLE watcher - timeout expired - BLE status: {blewatcher.Status.ToString()}");
                    }
                }

                Debug.WriteLine("UnpairAsync");
                DeviceUnpairingResult dupr = await deviceInfoDisp.DeviceInformation.Pairing.UnpairAsync();
                string unpairResult = $"Unpairing result = {dupr.Status}";
                Debug.WriteLine(unpairResult);

                await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                {
                    UserOut.Text = unpairResult;
                });
            }));
        }
Exemple #3
0
        // ---------------------------------------------------
        //             Pairing Process Handlers and Functions -- Begin
        // ---------------------------------------------------

        private async void PairButton_Click(object sender, RoutedEventArgs e)
        {
            DeviceInformationDisplay deviceInfoDisp = resultsListView.SelectedItem as DeviceInformationDisplay;

            if (deviceInfoDisp != null)
            {
                PairButton.IsEnabled = false;
                bool paired = true;
                if (deviceInfoDisp.IsPaired != true)
                {
                    paired = false;
                    DevicePairingKinds           ceremoniesSelected = DevicePairingKinds.ConfirmOnly | DevicePairingKinds.DisplayPin | DevicePairingKinds.ProvidePin | DevicePairingKinds.ConfirmPinMatch;
                    DevicePairingProtectionLevel protectionLevel    = DevicePairingProtectionLevel.Default;

                    // Specify custom pairing with all ceremony types and protection level EncryptionAndAuthentication
                    DeviceInformationCustomPairing customPairing = deviceInfoDisp.DeviceInformation.Pairing.Custom;

                    customPairing.PairingRequested += PairingRequestedHandler;
                    DevicePairingResult result = await customPairing.PairAsync(ceremoniesSelected, protectionLevel);

                    customPairing.PairingRequested -= PairingRequestedHandler;

                    if (result.Status == DevicePairingResultStatus.Paired)
                    {
                        paired = true;
                    }
                    else
                    {
                        UserOut.Text = "Pairing Failed " + result.Status.ToString();
                    }
                }

                if (paired)
                {
                    // device is paired, set up the sensor Tag
                    UserOut.Text = "Setting up SensorTag";

                    DeviceInfoConnected = deviceInfoDisp;

                    //Start watcher for Bluetooth LE Services
                    StartBLEWatcher();
                }
                UpdatePairingButtons();
            }
        }
Exemple #4
0
        private async void UnpairButton_Click(object sender, RoutedEventArgs e)
        {
            DeviceInformationDisplay deviceInfoDisp = resultsListView.SelectedItem as DeviceInformationDisplay;

            Debug.WriteLine("Unpair");

            UnpairButton.IsEnabled  = false;
            SensorList.IsEnabled    = false;
            EnableButton.IsEnabled  = false;
            DisableButton.IsEnabled = false;
            DeviceInfoConnected     = null;

            await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async() =>
            {
                await StopBLEWatcherAsync(deviceInfoDisp);
            });

            UpdatePairingButtons();
        }
Exemple #5
0
        private async void UnpairButton_Click(object sender, RoutedEventArgs e)
        {
            DeviceInformationDisplay deviceInfoDisp = resultsListView.SelectedItem as DeviceInformationDisplay;

            Debug.WriteLine("Unpair");

            UnpairButton.IsEnabled  = false;
            SensorList.IsEnabled    = false;
            EnableButton.IsEnabled  = false;
            DisableButton.IsEnabled = false;
            DeviceInfoConnected     = null;

            Debug.WriteLine("Disable Sensors");
            for (int i = 0; i < NUM_SENSORS; i++)
            {
                if (serviceList[i] != null)
                {
                    await disableSensor(i);
                }
            }

            Debug.WriteLine("UnpairAsync");
            try
            {
                DeviceUnpairingResult dupr = await deviceInfoDisp.DeviceInformation.Pairing.UnpairAsync();

                string unpairResult = $"Unpairing result = {dupr.Status}";
                Debug.WriteLine(unpairResult);
                UserOut.Text = unpairResult;
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Unpair exception = " + ex.Message);
            }

            for (int i = 0; i < NUM_SENSORS; i++)
            {
                serviceList[i] = null;
            }

            UpdatePairingButtons();
        }