예제 #1
0
        private Task UpdateLeds(ApplicationSensorReading sensorReading)
        {
            if (!_runningLedTest)
            {
                // ***
                // *** Green is "all clear"
                // ***
                bool allClear = !sensorReading.IsCritical && !sensorReading.IsAboveUpperThreshold && !sensorReading.IsBelowLowerThreshold;
                this.GreenPin.Write(allClear ? GpioPinValue.Low : GpioPinValue.High);

                // ***
                // *** Red is > upper threshold temperature
                // ***
                this.RedPin.Write(sensorReading.IsAboveUpperThreshold ? GpioPinValue.Low : GpioPinValue.High);

                // ***
                // *** Blue is < upper threshold temperature
                // ***
                this.BluePin.Write(sensorReading.IsBelowLowerThreshold ? GpioPinValue.Low : GpioPinValue.High);

                // ***
                // *** Yellow is >= critical temperature
                // ***
                this.YellowPin.Write(sensorReading.IsCritical ? GpioPinValue.Low : GpioPinValue.High);

                // ***
                // *** Cache the last sensor reading
                // ***
                _previousSensorReading = sensorReading;
            }

            return(Task.FromResult(0));
        }
 protected async Task OnTemperatureAlertChangedEvent()
 {
     try
     {
         if (this.TemperatureRepository != null)
         {
             this.EventAggregator.GetEvent <Events.TemperatureChangedEvent>().Publish(new TemperatureChangedEventArgs()
             {
                 SensorReading = ApplicationSensorReading.FromIApplicationSensorReading(await this.TemperatureRepository.GetSensorReading())
             });
         }
     }
     catch (Exception ex)
     {
         this.EventAggregator.GetEvent <Events.DebugEvent>().Publish(new DebugEventArgs(ex));
     }
 }
예제 #3
0
        private async Task SendSensorReading(bool force)
        {
            try
            {
                IApplicationSensorReading sensorReading = await this.GetSensorReading();

                // ***
                // *** Add the temperature thresholds
                // ***
                sensorReading.CriticalThreshold = this.Device.CriticalTemperatureThreshold;
                sensorReading.LowerThreshold    = this.Device.LowerTemperatureThreshold;
                sensorReading.UpperThreshold    = this.Device.UpperTemperatureThreshold;

                // ***
                // *** Only send the event when the reading has changed
                // ***
                if (force ||
                    _previousReading == null ||
                    _previousReading.Temperature != sensorReading.Temperature ||
                    _previousReading.IsCritical != sensorReading.IsCritical ||
                    _previousReading.IsAboveUpperThreshold != sensorReading.IsAboveUpperThreshold ||
                    _previousReading.IsBelowLowerThreshold != sensorReading.IsBelowLowerThreshold ||
                    _previousReading.CriticalThreshold != sensorReading.CriticalThreshold ||
                    _previousReading.LowerThreshold != sensorReading.LowerThreshold ||
                    _previousReading.UpperThreshold != sensorReading.UpperThreshold)
                {
                    this.EventAggregator.GetEvent <Events.TemperatureChangedEvent>().Publish(new TemperatureChangedEventArgs()
                    {
                        SensorReading = ApplicationSensorReading.FromIApplicationSensorReading(sensorReading)
                    });
                    _previousReading = sensorReading;
                }
            }
            catch (Exception ex)
            {
                this.EventAggregator.GetEvent <Events.DebugEvent>().Publish(new DebugEventArgs(ex));
            }
        }