Пример #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="reading"></param>
        private async Task SetActiveFromReadingAsync(ProximitySensorReading reading)
        {
            if (reading != null)
            {
                if (this.ObjectDetected)
                {
                    await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                    {
                        var isActive = reading.IsDetected;

                        if (isActive)
                        {
                            if (reading.DistanceInMillimeters.HasValue)
                            {
                                isActive = (reading.DistanceInMillimeters >= this.MinimumDistanceInMillimeters);
                            }
                        }

                        SetActive(isActive);
                    });
                }
                else
                {
                    await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                    {
                        SetActive(!reading.IsDetected);
                    });
                }
            }
        }
        /// <summary>
        /// This is the event handler for ReadingChanged events.
        /// </summary>
        /// <param name="sender">The proximity sensor that sent the reading change</param>
        /// <param name="e"></param>
        async private void ReadingChanged(ProximitySensor sender, ProximitySensorReadingChangedEventArgs e)
        {
            await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                ProximitySensorReading reading = e.Reading;
                if (null != reading)
                {
                    ScenarioOutput_DetectionState.Text = reading.IsDetected ? "Detected" : "Not detected";
                    ScenarioOutput_Timestamp.Text      = reading.Timestamp.ToString("u");

                    // Show the detection distance, if available
                    if (null != reading.DistanceInMillimeters)
                    {
                        ScenarioOutput_DetectionDistance.Text = reading.DistanceInMillimeters.ToString();
                    }
                }
            });
        }
        /// <summary>
        /// This is the click handler for the 'GetData' button.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ScenarioGetData(object sender, RoutedEventArgs e)
        {
            if (null != sensor)
            {
                ProximitySensorReading reading = sensor.GetCurrentReading();
                if (null != reading)
                {
                    ScenarioOutput_DetectionState.Text = reading.IsDetected ? "Detected" : "Not detected";
                    ScenarioOutput_Timestamp.Text      = reading.Timestamp.ToString("u");

                    // Show the detection distance, if available
                    if (null != reading.DistanceInMillimeters)
                    {
                        ScenarioOutput_DetectionDistance.Text = reading.DistanceInMillimeters.ToString();
                    }
                }
            }
            else
            {
                rootPage.NotifyUser("No proximity sensor found", NotifyType.ErrorMessage);
            }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="reading"></param>
        private async Task SetActiveFromReadingAsync(ProximitySensorReading reading)
        {
            if (reading != null)
            {
                if (this.ObjectDetected)
                {
                    await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                    {
                        var isActive = reading.IsDetected;

                        if (isActive)
                        {
                            if (reading.DistanceInMillimeters.HasValue)
                            {
                                isActive = (reading.DistanceInMillimeters >= this.MinimumDistanceInMillimeters);
                            }
                        }

                        SetActive(isActive);
                    });
                }
                else
                {
                    await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                    {
                        SetActive(!reading.IsDetected);
                    });
                }
            }
        }