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(); }
private async void CurrentOnSuspending(object sender, SuspendingEventArgs suspendingEventArgs) { if (HrDevice != null) { await HrDevice.Close(); } }