/// <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);
                });
            }
        }
示例#2
0
        /// <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);
                });
            }
        }