コード例 #1
0
        private async void BtnConnect_Click(object sender, RoutedEventArgs e)
        {
            d("Button CONNECT clicked.");
            HrDevice = await BleHeartRate.FirstOrDefault();

            if (HrDevice == null)
            {
                d("I was not able to find any HR device!");
                return;
            }

            d("Found device: " + HrDevice.Name + " IsConnected=" + HrDevice.IsConnected);
            // we should always monitor the connection status
            HrDevice.DeviceConnectionStatusChanged -= HrDeviceOnDeviceConnectionStatusChanged;
            HrDevice.DeviceConnectionStatusChanged += HrDeviceOnDeviceConnectionStatusChanged;

            // we can create value parser and listen for parsed values of given characteristic
            HrParser.ConnectWithCharacteristic(HrDevice.HeartRate.HeartRateMeasurement);
            HrParser.ValueChanged -= HrParserOnValueChanged;
            HrParser.ValueChanged += HrParserOnValueChanged;

            // connect also battery level parser to proper characteristic
            BatteryParser.ConnectWithCharacteristic(HrDevice.BatteryService.BatteryLevel);

            // we can monitor raw data notified by BLE device for specific characteristic
            HrDevice.HeartRate.HeartRateMeasurement.ValueChanged -= HeartRateMeasurementOnValueChanged;
            HrDevice.HeartRate.HeartRateMeasurement.ValueChanged += HeartRateMeasurementOnValueChanged;

            // we could force propagation of event with connection status change, to run the callback for initial status
            HrDevice.NotifyConnectionStatus();
        }
コード例 #2
0
        private async void BtnStart_Click(object sender, RoutedEventArgs e)
        {
            d("Button START clicked.");
            await HrParser.EnableNotifications();

            d("Notification enabled");
        }
コード例 #3
0
        private async void BtnStop_Click(object sender, RoutedEventArgs e)
        {
            d("Button STOP clicked.");
            await HrParser.DisableNotifications();

            d("Notification disabled.");
            TxtHr.Text = "--";
        }