/// <summary> /// Invoked when the device watcher finds a matching custom sensor device /// </summary> /// <param name="watcher">device watcher</param> /// <param name="customSensorDevice">device information for the custom sensor that was found</param> public async void OnCustomSensorAdded(DeviceWatcher watcher, DeviceInformation customSensorDevice) { try { customSensor = await CustomSensor.FromIdAsync(customSensorDevice.Id); if (customSensor != null) { CustomSensorReading reading = customSensor.GetCurrentReading(); if (!reading.Properties.ContainsKey(CO2LevelKey)) { rootPage.NotifyUser("The found custom sensor doesn't provide CO2 reading", NotifyType.ErrorMessage); customSensor = null; } } else { rootPage.NotifyUser("No custom sensor found", NotifyType.ErrorMessage); } } catch (Exception e) { await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { rootPage.NotifyUser("The user may have denied access to the custom sensor. Error: " + e.Message, NotifyType.ErrorMessage); }); } }
/// <summary> /// This is the dispatcher callback. /// </summary> /// <param name="sender"></param> /// <param name="args"></param> private void GetCO2Level(object sender, RoutedEventArgs e) { if (customSensor != null) { CustomSensorReading reading = customSensor.GetCurrentReading(); string CO2LevelString = String.Format("{0,5:0.00}", reading.Properties[CO2LevelKey]); ScenarioOutputCO2Level.Text = CO2LevelString; } else { rootPage.NotifyUser("No custom sensor found", NotifyType.ErrorMessage); } }
/// <summary> /// Invoked when the device watcher finds a matching custom sensor device /// </summary> /// <param name="watcher">device watcher</param> /// <param name="customSensorDevice">device information for the custom sensor that was found</param> public async void OnCustomSensorAdded(DeviceWatcher watcher, DeviceInformation customSensorDevice) { try { customSensor = await CustomSensor.FromIdAsync(customSensorDevice.Id); if (customSensor != null) { CustomSensorReading reading = customSensor.GetCurrentReading(); if (!reading.Properties.ContainsKey(CO2LevelKey)) { rootPage.NotifyUser("The found custom sensor doesn't provide CO2 reading", NotifyType.ErrorMessage); customSensor = null; } else { // Select a report interval that is both suitable for the purposes of the app and supported by the sensor. // This value will be used later to activate the sensor. // In the case below, we defined a 200ms report interval as being suitable for the purpose of this app. UInt32 minReportInterval = customSensor.MinimumReportInterval; desiredReportInterval = minReportInterval > 200 ? minReportInterval : 200; } } else { rootPage.NotifyUser("No custom sensor found", NotifyType.ErrorMessage); } } catch (Exception e) { await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { rootPage.NotifyUser("The user may have denied access to the custom sensor. Error: " + e.Message, NotifyType.ErrorMessage); }); } }
/// <summary> /// Invoked when the device watcher finds a matching custom sensor device /// </summary> /// <param name="watcher">device watcher</param> /// <param name="customSensorDevice">device information for the custom sensor that was found</param> public async void OnCustomSensorAdded(DeviceWatcher watcher, DeviceInformation customSensorDevice) { try { customSensor = await CustomSensor.FromIdAsync(customSensorDevice.Id); if (customSensor != null) { CustomSensorReading reading = customSensor.GetCurrentReading(); if (!reading.Properties.ContainsKey(CO2LevelKey)) { rootPage.NotifyUser("The found custom sensor doesn't provide CO2 reading", NotifyType.ErrorMessage); customSensor = null; } else { // Select a report interval that is both suitable for the purposes of the app and supported by the sensor. // This value will be used later to activate the sensor. // In the case below, we defined a 200ms report interval as being suitable for the purpose of this app. UInt32 minReportInterval = customSensor.MinimumReportInterval; desiredReportInterval = minReportInterval > 200 ? minReportInterval : 200; } } else { rootPage.NotifyUser("No custom sensor found", NotifyType.ErrorMessage); } } catch(Exception e) { await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { rootPage.NotifyUser("The user may have denied access to the custom sensor. Error: " + e.Message, NotifyType.ErrorMessage); }); } }