Example #1
0
        private async void TempSensor_ReadingChanged(IAnalogSensor sender, AnalogSensorReadingChangedEventArgs args)
        {
            var reading = args.Reading.Value;

            tempVals.Add(((9 / 5) * (reading / 10)) + 32);
            tempVals.RemoveAt(0);
            double temp = tempVals.Average();

            #region comment this out if running headless.
            await Dispatcher.RunIdleAsync((s) =>
            {
                // Value
                TemperatureProgress.Text = "Temperature: " + temp.ToString() + "deg F";

                // Color
                if (temp < 40)
                {
                    TemperatureProgress.Foreground = new SolidColorBrush(Colors.LightBlue);
                }
                else if (temp < 80)
                {
                    TemperatureProgress.Foreground = new SolidColorBrush(Colors.Yellow);
                }
                else
                {
                    TemperatureProgress.Foreground = new SolidColorBrush(Colors.Red);
                }
            });

            #endregion comment this out if running headless.
        }
Example #2
0
        private async void LightSensor_ReadingChanged(IAnalogSensor sender, AnalogSensorReadingChangedEventArgs args)
        {
            // Invert
            var reading = 1 - args.Reading.Ratio;

            // Update UI
            await Dispatcher.RunIdleAsync((s) =>
            {
                // Value
                LightProgress.Value = reading;

                // Color
                if (reading < .25)
                {
                    LightProgress.Foreground = new SolidColorBrush(Colors.Red);
                }
                else if (reading < .75)
                {
                    LightProgress.Foreground = new SolidColorBrush(Colors.Yellow);
                }
                else
                {
                    LightProgress.Foreground = new SolidColorBrush(Colors.Green);
                }
            });
        }
Example #3
0
        private void AnalogSensor_ReadingChanged(IAnalogSensor sender, AnalogSensorReadingChangedEventArgs args)
        {
            // Get reading
            var r = args.Reading;

            currentReading = args.Reading.Ratio - ambientThreshold;
            maxReading     = Math.Max(maxReading, currentReading);

            var t = Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() =>
            {
                if (currentState == States.Cooldown)
                {
                    CurrentValueProg.Value = currentReading;
                }
                else
                {
                    CurrentValueProg.Value = maxReading;
                }
                PercentBlock.Text = string.Format("{0:N0}%", maxReading * 100);
                await TestAndUpdateStateAsync();
            });

            // Print
            Debug.WriteLine(string.Format("Value: {0}  Ratio: {1}", r.Value, r.Ratio));
        }
        private async void LightSensor_ReadingChanged(IAnalogSensor sender, AnalogSensorReadingChangedEventArgs args)
        {
            // Invert
            var reading = 1 - args.Reading.Ratio;

            // Update UI
            await Dispatcher.RunIdleAsync((s) =>
            {
                // Value
                LightProgress.Value = reading;

                // Color
                if (reading < .25)
                {
                    LightProgress.Foreground = new SolidColorBrush(Colors.Red);
                }
                else if (reading < .75 )
                {
                    LightProgress.Foreground = new SolidColorBrush(Colors.Yellow);
                }
                else
                {
                    LightProgress.Foreground = new SolidColorBrush(Colors.Green);
                }
            });

        }
Example #5
0
        private void AnalogSensor_ReadingChanged(IAnalogSensor sender, AnalogSensorReadingChangedEventArgs args)
        {
            // Get reading
            var r = args.Reading;

            // Store for reporting
            lastAnalog = r.Ratio;

            // Print
            Debug.WriteLine(string.Format("Value: {0}  Ratio: {1}", r.Value, r.Ratio));
        }
Example #6
0
        /// <summary>
        /// Event Handler for Light Sensor Reading Changed.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        private async void LightSensor_ReadingChanged(IAnalogSensor sender, AnalogSensorReadingChangedEventArgs args)
        {
            //Read the ratio, which is readvalue/maxvalue
            var reading = args.Reading.Ratio;

            //Add reading to end of list
            lightVals.Add(reading * 100);
            //remove first reading.  Constant size of list is 10.
            lightVals.RemoveAt(0);
            //Smooth the reading out by averaging all 10
            //this is average light value across 5 seconds
            //Note: You occasionally get bad values, hence the smoothing.
            var avg = lightVals.Average();

            // Update UI
            #region comment this out if running headless.
            await Dispatcher.RunIdleAsync((s) =>
            {
                // Value
                LightProgress.Text = "Light: " + avg.ToString() + "%";

                // Color
                if (avg < 25)
                {
                    LightProgress.Foreground = new SolidColorBrush(Colors.OrangeRed);
                }
                else if (avg < 75)
                {
                    LightProgress.Foreground = new SolidColorBrush(Colors.Yellow);
                }
                else
                {
                    LightProgress.Foreground = new SolidColorBrush(Colors.Green);
                }
            });

            #endregion comment this out if running headless.
        }
Example #7
0
 private void Sensor_ReadingChanged(IAnalogSensor sender, AnalogSensorReadingChangedEventArgs args)
 {
     // Perform update, existing reading
     Update(args.Reading);
 }