From c594db0265d2a892d5453a2334d7acca9e15a4d5 Mon Sep 17 00:00:00 2001 From: Jorge Ramirez Date: Tue, 28 May 2024 11:01:38 -0700 Subject: [PATCH] Minor fix for demo app --- .../Controllers/DisplayController.cs | 433 +++++++++--------- Source/GnssTracker_Demo/MeadowApp.cs | 353 +++++++------- 2 files changed, 392 insertions(+), 394 deletions(-) diff --git a/Source/GnssTracker_Demo/Controllers/DisplayController.cs b/Source/GnssTracker_Demo/Controllers/DisplayController.cs index 2d7cf34..a9a0382 100644 --- a/Source/GnssTracker_Demo/Controllers/DisplayController.cs +++ b/Source/GnssTracker_Demo/Controllers/DisplayController.cs @@ -1,218 +1,217 @@ -using Meadow; -using Meadow.Foundation.Graphics; -using Meadow.Foundation.Graphics.MicroLayout; -using Meadow.Peripherals.Displays; -using Meadow.Peripherals.Sensors.Location.Gnss; -using Meadow.Units; - -namespace GnssTracker_Demo.Controllers -{ - public class DisplayController - { - private readonly int marginX = 8; - private readonly int offsetY = 5; - - private readonly Font8x12 largeFont = new Font8x12(); - - private readonly DisplayScreen displayScreen; - private readonly AbsoluteLayout dataLayout; - - private readonly Label solarVoltageLabel; - private readonly Label temperatureLabel; - private readonly Label humidityLabel; - private readonly Label pressureLabel; - private readonly Label co2LevelsLabel; - private readonly Label latitudeLabel; - private readonly Label longitudeLabel; - private readonly Label batteryVoltageLabel; - - public DisplayController(IPixelDisplay display) - { - displayScreen = new DisplayScreen(display, RotationType._90Degrees); - - displayScreen.BeginUpdate(); - - dataLayout = new AbsoluteLayout(displayScreen, 0, 0, displayScreen.Width, displayScreen.Height) - { - BackgroundColor = Color.White - }; - - dataLayout.Controls.Add(new Box(0, 0 + offsetY, displayScreen.Width, 15) - { - ForeColor = Color.Red, - IsFilled = true - }); - - dataLayout.Controls.Add(new Label(marginX, 3 + offsetY, displayScreen.Width, largeFont.Height) - { - Text = $"BATTERY VOLTAGE:", - TextColor = Color.White, - Font = largeFont - }); - batteryVoltageLabel = new Label(0, 3 + offsetY, displayScreen.Width - marginX, largeFont.Height) - { - Text = $"0.00 V", - TextColor = Color.White, - Font = largeFont, - HorizontalAlignment = HorizontalAlignment.Right - }; - dataLayout.Controls.Add(batteryVoltageLabel); - - dataLayout.Controls.Add(new Label(marginX, 18 + offsetY, displayScreen.Width, largeFont.Height) - { - Text = $"SOLAR VOLTAGE:", - TextColor = Color.Black, - Font = largeFont - }); - solarVoltageLabel = new Label(0, 18 + offsetY, displayScreen.Width - marginX, largeFont.Height) - { - Text = $"0.00 V", - TextColor = Color.Black, - Font = largeFont, - HorizontalAlignment = HorizontalAlignment.Right, - }; - dataLayout.Controls.Add(solarVoltageLabel); - - dataLayout.Controls.Add(new Label(marginX, 33 + offsetY, displayScreen.Width / 2, largeFont.Height) - { - Text = $"TEMPERATURE:", - TextColor = Color.Black, - Font = largeFont - }); - temperatureLabel = new Label(0, 33 + offsetY, displayScreen.Width - marginX, largeFont.Height) - { - Text = $"0.0 C", - TextColor = Color.Black, - Font = largeFont, - HorizontalAlignment = HorizontalAlignment.Right, - }; - dataLayout.Controls.Add(temperatureLabel); - - dataLayout.Controls.Add(new Label(marginX, 48 + offsetY, displayScreen.Width, largeFont.Height) - { - Text = $"HUMIDITY:", - TextColor = Color.Black, - Font = largeFont - }); - humidityLabel = new Label(0, 48 + offsetY, displayScreen.Width - marginX, largeFont.Height) - { - Text = $"0.0 %", - TextColor = Color.Black, - Font = largeFont, - HorizontalAlignment = HorizontalAlignment.Right, - }; - dataLayout.Controls.Add(humidityLabel); - - dataLayout.Controls.Add(new Label(marginX, 63 + offsetY, displayScreen.Width, largeFont.Height) - { - Text = $"PRESSURE:", - TextColor = Color.Black, - Font = largeFont - }); - pressureLabel = new Label(0, 63 + offsetY, displayScreen.Width - marginX, largeFont.Height) - { - Text = $"0.0 ATM", - TextColor = Color.Black, - Font = largeFont, - HorizontalAlignment = HorizontalAlignment.Right, - }; - dataLayout.Controls.Add(pressureLabel); - - dataLayout.Controls.Add(new Label(marginX, 78 + offsetY, displayScreen.Width, largeFont.Height) - { - Text = $"CO2 LEVELS:", - TextColor = Color.Black, - Font = largeFont - }); - co2LevelsLabel = new Label(0, 78 + offsetY, displayScreen.Width - marginX, largeFont.Height) - { - Text = $"0.0 PPM", - TextColor = Color.Black, - Font = largeFont, - HorizontalAlignment = HorizontalAlignment.Right, - }; - dataLayout.Controls.Add(co2LevelsLabel); - - dataLayout.Controls.Add(new Box(0, 90 + offsetY, displayScreen.Width, 32) - { - ForeColor = Color.Red, - IsFilled = true - }); - - dataLayout.Controls.Add(new Label(marginX, 94 + offsetY, displayScreen.Width, largeFont.Height) - { - Text = $"LATITUDE:", - TextColor = Color.White, - Font = largeFont - }); - latitudeLabel = new Label(0, 94 + offsetY, displayScreen.Width - marginX, largeFont.Height) - { - Text = $"00 00' 0.0\"", - TextColor = Color.White, - Font = largeFont, - HorizontalAlignment = HorizontalAlignment.Right, - }; - dataLayout.Controls.Add(latitudeLabel); - - dataLayout.Controls.Add(new Label(marginX, 109 + offsetY, displayScreen.Width, largeFont.Height) - { - Text = $"LONGITUDE:", - TextColor = Color.White, - Font = largeFont - }); - longitudeLabel = new Label(0, 109 + offsetY, displayScreen.Width - marginX, largeFont.Height) - { - Text = $"00 00' 0.0\"", - TextColor = Color.White, - Font = largeFont, - HorizontalAlignment = HorizontalAlignment.Right, - }; - dataLayout.Controls.Add(longitudeLabel); - - displayScreen.Controls.Add(dataLayout); - - displayScreen.EndUpdate(); - } - - public void UpdateDisplay( - Voltage? BatteryVoltage, - Voltage? SolarVoltage, - Temperature? Temperature, - RelativeHumidity? Humidity, - Pressure? Pressure, - Concentration? Concentration, - GnssPositionInfo locationInfo) - { - displayScreen.BeginUpdate(); - - batteryVoltageLabel.Text = $"{BatteryVoltage?.Volts:N2} V"; - solarVoltageLabel.Text = $"{SolarVoltage?.Volts:N2} V"; - temperatureLabel.Text = $"{Temperature?.Celsius:N1} C"; - humidityLabel.Text = $"{Humidity?.Percent:N1} %"; - pressureLabel.Text = $"{Pressure?.StandardAtmosphere:N1} ATM"; - - if (Concentration != null) - { - co2LevelsLabel.Text = $"{Concentration?.PartsPerMillion:N1} PPM"; - } - - string lat = locationInfo == null - ? $"00 00' 0.00\"" - : $"" + - $"{locationInfo?.Position?.Latitude?.Degrees:N2} " + - $"{locationInfo?.Position?.Latitude?.Minutes:N2}'" + - $"{locationInfo?.Position?.Latitude?.Seconds:N2}\""; - latitudeLabel.Text = lat; - - string lon = locationInfo == null - ? $"00 00' 0.00\"" - : $"" + - $"{locationInfo?.Position?.Longitude?.Degrees:N2} " + - $"{locationInfo?.Position?.Longitude?.Minutes:N2}'" + - $"{locationInfo?.Position?.Longitude?.Seconds:N2}\""; - longitudeLabel.Text = lon; - - displayScreen.EndUpdate(); - } - } +using Meadow; +using Meadow.Foundation.Graphics; +using Meadow.Foundation.Graphics.MicroLayout; +using Meadow.Peripherals.Displays; +using Meadow.Peripherals.Sensors.Location.Gnss; +using Meadow.Units; + +namespace GnssTracker_Demo.Controllers; + +public class DisplayController +{ + private readonly int marginX = 8; + private readonly int offsetY = 5; + + private readonly Font8x12 largeFont = new Font8x12(); + + private readonly DisplayScreen displayScreen; + private readonly AbsoluteLayout dataLayout; + + private readonly Label solarVoltageLabel; + private readonly Label temperatureLabel; + private readonly Label humidityLabel; + private readonly Label pressureLabel; + private readonly Label co2LevelsLabel; + private readonly Label latitudeLabel; + private readonly Label longitudeLabel; + private readonly Label batteryVoltageLabel; + + public DisplayController(IPixelDisplay display) + { + displayScreen = new DisplayScreen(display, RotationType._90Degrees); + + displayScreen.BeginUpdate(); + + dataLayout = new AbsoluteLayout(0, 0, displayScreen.Width, displayScreen.Height) + { + BackgroundColor = Color.White + }; + + dataLayout.Controls.Add(new Box(0, 0 + offsetY, displayScreen.Width, 15) + { + ForeColor = Color.Red, + IsFilled = true + }); + + dataLayout.Controls.Add(new Label(marginX, 3 + offsetY, displayScreen.Width, largeFont.Height) + { + Text = $"BATTERY VOLTAGE:", + TextColor = Color.White, + Font = largeFont + }); + batteryVoltageLabel = new Label(0, 3 + offsetY, displayScreen.Width - marginX, largeFont.Height) + { + Text = $"0.00 V", + TextColor = Color.White, + Font = largeFont, + HorizontalAlignment = HorizontalAlignment.Right + }; + dataLayout.Controls.Add(batteryVoltageLabel); + + dataLayout.Controls.Add(new Label(marginX, 18 + offsetY, displayScreen.Width, largeFont.Height) + { + Text = $"SOLAR VOLTAGE:", + TextColor = Color.Black, + Font = largeFont + }); + solarVoltageLabel = new Label(0, 18 + offsetY, displayScreen.Width - marginX, largeFont.Height) + { + Text = $"0.00 V", + TextColor = Color.Black, + Font = largeFont, + HorizontalAlignment = HorizontalAlignment.Right, + }; + dataLayout.Controls.Add(solarVoltageLabel); + + dataLayout.Controls.Add(new Label(marginX, 33 + offsetY, displayScreen.Width / 2, largeFont.Height) + { + Text = $"TEMPERATURE:", + TextColor = Color.Black, + Font = largeFont + }); + temperatureLabel = new Label(0, 33 + offsetY, displayScreen.Width - marginX, largeFont.Height) + { + Text = $"0.0 C", + TextColor = Color.Black, + Font = largeFont, + HorizontalAlignment = HorizontalAlignment.Right, + }; + dataLayout.Controls.Add(temperatureLabel); + + dataLayout.Controls.Add(new Label(marginX, 48 + offsetY, displayScreen.Width, largeFont.Height) + { + Text = $"HUMIDITY:", + TextColor = Color.Black, + Font = largeFont + }); + humidityLabel = new Label(0, 48 + offsetY, displayScreen.Width - marginX, largeFont.Height) + { + Text = $"0.0 %", + TextColor = Color.Black, + Font = largeFont, + HorizontalAlignment = HorizontalAlignment.Right, + }; + dataLayout.Controls.Add(humidityLabel); + + dataLayout.Controls.Add(new Label(marginX, 63 + offsetY, displayScreen.Width, largeFont.Height) + { + Text = $"PRESSURE:", + TextColor = Color.Black, + Font = largeFont + }); + pressureLabel = new Label(0, 63 + offsetY, displayScreen.Width - marginX, largeFont.Height) + { + Text = $"0.0 ATM", + TextColor = Color.Black, + Font = largeFont, + HorizontalAlignment = HorizontalAlignment.Right, + }; + dataLayout.Controls.Add(pressureLabel); + + dataLayout.Controls.Add(new Label(marginX, 78 + offsetY, displayScreen.Width, largeFont.Height) + { + Text = $"CO2 LEVELS:", + TextColor = Color.Black, + Font = largeFont + }); + co2LevelsLabel = new Label(0, 78 + offsetY, displayScreen.Width - marginX, largeFont.Height) + { + Text = $"0.0 PPM", + TextColor = Color.Black, + Font = largeFont, + HorizontalAlignment = HorizontalAlignment.Right, + }; + dataLayout.Controls.Add(co2LevelsLabel); + + dataLayout.Controls.Add(new Box(0, 90 + offsetY, displayScreen.Width, 32) + { + ForeColor = Color.Red, + IsFilled = true + }); + + dataLayout.Controls.Add(new Label(marginX, 94 + offsetY, displayScreen.Width, largeFont.Height) + { + Text = $"LATITUDE:", + TextColor = Color.White, + Font = largeFont + }); + latitudeLabel = new Label(0, 94 + offsetY, displayScreen.Width - marginX, largeFont.Height) + { + Text = $"00 00' 0.0\"", + TextColor = Color.White, + Font = largeFont, + HorizontalAlignment = HorizontalAlignment.Right, + }; + dataLayout.Controls.Add(latitudeLabel); + + dataLayout.Controls.Add(new Label(marginX, 109 + offsetY, displayScreen.Width, largeFont.Height) + { + Text = $"LONGITUDE:", + TextColor = Color.White, + Font = largeFont + }); + longitudeLabel = new Label(0, 109 + offsetY, displayScreen.Width - marginX, largeFont.Height) + { + Text = $"00 00' 0.0\"", + TextColor = Color.White, + Font = largeFont, + HorizontalAlignment = HorizontalAlignment.Right, + }; + dataLayout.Controls.Add(longitudeLabel); + + displayScreen.Controls.Add(dataLayout); + + displayScreen.EndUpdate(); + } + + public void UpdateDisplay( + Voltage? BatteryVoltage, + Voltage? SolarVoltage, + Temperature? Temperature, + RelativeHumidity? Humidity, + Pressure? Pressure, + Concentration? Concentration, + GnssPositionInfo? locationInfo) + { + displayScreen.BeginUpdate(); + + batteryVoltageLabel.Text = $"{BatteryVoltage?.Volts:N2} V"; + solarVoltageLabel.Text = $"{SolarVoltage?.Volts:N2} V"; + temperatureLabel.Text = $"{Temperature?.Celsius:N1} C"; + humidityLabel.Text = $"{Humidity?.Percent:N1} %"; + pressureLabel.Text = $"{Pressure?.StandardAtmosphere:N1} ATM"; + + if (Concentration != null) + { + co2LevelsLabel.Text = $"{Concentration?.PartsPerMillion:N1} PPM"; + } + + string lat = locationInfo == null + ? $"00 00' 0.00\"" + : $"" + + $"{locationInfo?.Position?.Latitude?.Degrees:N2} " + + $"{locationInfo?.Position?.Latitude?.Minutes:N2}'" + + $"{locationInfo?.Position?.Latitude?.Seconds:N2}\""; + latitudeLabel.Text = lat; + + string lon = locationInfo == null + ? $"00 00' 0.00\"" + : $"" + + $"{locationInfo?.Position?.Longitude?.Degrees:N2} " + + $"{locationInfo?.Position?.Longitude?.Minutes:N2}'" + + $"{locationInfo?.Position?.Longitude?.Seconds:N2}\""; + longitudeLabel.Text = lon; + + displayScreen.EndUpdate(); + } } \ No newline at end of file diff --git a/Source/GnssTracker_Demo/MeadowApp.cs b/Source/GnssTracker_Demo/MeadowApp.cs index 1ea1327..9b70b68 100644 --- a/Source/GnssTracker_Demo/MeadowApp.cs +++ b/Source/GnssTracker_Demo/MeadowApp.cs @@ -6,245 +6,244 @@ using System; using System.Threading.Tasks; -namespace GnssTracker_Demo -{ - public class MeadowApp : App - { - GnssPositionInfo lastGNSSPosition; - Voltage? solarVoltage = new Voltage(0); - Voltage? batteryVoltage = new Voltage(0); - DateTime lastGNSSPositionReportTime = DateTime.MinValue; - - protected DisplayController displayController { get; set; } - - protected IGnssTrackerHardware gnssTracker { get; set; } - - readonly TimeSpan GNSSPositionReportInterval = TimeSpan.FromMinutes(5); - - readonly TimeSpan sensorUpdateInterval = TimeSpan.FromMinutes(5); - - public override Task Initialize() - { - Resolver.Log.Info("Initialize hardware..."); - - gnssTracker = GnssTracker.Create(); +namespace GnssTracker_Demo; - if (gnssTracker.TemperatureSensor is { } temperatureSensor) - { - temperatureSensor.Updated += TemperatureSensorUpdated; - } - - if (gnssTracker.HumiditySensor is { } humiditySensor) - { - humiditySensor.Updated += HumiditySensorUpdated; - } - - if (gnssTracker.BarometricPressureSensor is { } barometer) - { - barometer.Updated += BarometerUpdated; - } - - if (gnssTracker.GasResistanceSensor is { } gasResistanceSensor) - { - gasResistanceSensor.Updated += GasResistanceSensorUpdated; - } - - if (gnssTracker.CO2ConcentrationSensor is { } cO2ConcentrationSensor) - { - cO2ConcentrationSensor.Updated += CO2ConcentrationSensorUpdated; - } - - if (gnssTracker.Gyroscope is { } gyroscope) - { - gyroscope.Updated += GyroscopeUpdated; - } +public class MeadowApp : App +{ + GnssPositionInfo lastGNSSPosition; + Voltage? solarVoltage = new Voltage(0); + Voltage? batteryVoltage = new Voltage(0); + DateTime lastGNSSPositionReportTime = DateTime.MinValue; - if (gnssTracker.Accelerometer is { } accelerometer) - { - accelerometer.Updated += AccelerometerUpdated; ; - } + protected DisplayController displayController { get; set; } - if (gnssTracker.BatteryVoltageInput is { } batteryvoltage) - { - batteryvoltage.Updated += BatteryVoltageUpdated; - } + protected IGnssTrackerHardware gnssTracker { get; set; } - if (gnssTracker.SolarVoltageInput is { } solarVoltage) - { - solarVoltage.Updated += SolarVoltageUpdated; - } + readonly TimeSpan GNSSPositionReportInterval = TimeSpan.FromMinutes(5); - if (gnssTracker.Gnss is { } gnss) - { - gnss.RmcReceived += GnssRmcReceived; - gnss.GllReceived += GnssGllReceived; - } + readonly TimeSpan sensorUpdateInterval = TimeSpan.FromMinutes(5); - if (gnssTracker.Display is { } display) - { - displayController = new DisplayController(display); - } + public override Task Initialize() + { + Resolver.Log.Info("Initialize hardware..."); - if (gnssTracker.OnboardRgbLed is { } onboardRgbLed) - { - onboardRgbLed.StartPulse(Color.Magenta); - } + gnssTracker = GnssTracker.Create(); - Resolver.Log.Info("Initialization complete"); + if (gnssTracker.TemperatureSensor is { } temperatureSensor) + { + temperatureSensor.Updated += TemperatureSensorUpdated; + } - return Task.CompletedTask; + if (gnssTracker.HumiditySensor is { } humiditySensor) + { + humiditySensor.Updated += HumiditySensorUpdated; } - private void TemperatureSensorUpdated(object sender, IChangeResult e) + if (gnssTracker.BarometricPressureSensor is { } barometer) { - Resolver.Log.Info($"TEMPERATURE: {e.New.Celsius:N1}C"); + barometer.Updated += BarometerUpdated; } - private void HumiditySensorUpdated(object sender, IChangeResult e) + if (gnssTracker.GasResistanceSensor is { } gasResistanceSensor) { - Resolver.Log.Info($"HUMIDITY: {e.New.Percent:N1}%"); + gasResistanceSensor.Updated += GasResistanceSensorUpdated; } - private void BarometerUpdated(object sender, IChangeResult e) + if (gnssTracker.CO2ConcentrationSensor is { } cO2ConcentrationSensor) { - Resolver.Log.Info($"PRESSURE: {e.New.Millibar:N1}mbar"); + cO2ConcentrationSensor.Updated += CO2ConcentrationSensorUpdated; } - private void GasResistanceSensorUpdated(object sender, IChangeResult e) + if (gnssTracker.Gyroscope is { } gyroscope) { - Resolver.Log.Info($"RESISTANCE: {e.New.Megaohms:N1}MΩ"); + gyroscope.Updated += GyroscopeUpdated; } - private void CO2ConcentrationSensorUpdated(object sender, IChangeResult e) + if (gnssTracker.Accelerometer is { } accelerometer) { - Resolver.Log.Info($"CO2 CONCENTRATION: {e.New.PartsPerMillion:N1}ppm"); + accelerometer.Updated += AccelerometerUpdated; ; } - private void GyroscopeUpdated(object sender, IChangeResult e) + if (gnssTracker.BatteryVoltageInput is { } batteryvoltage) { - Resolver.Log.Info($"GYROSCOPE: X:{e.New.X.DegreesPerSecond:N1}°/s, Y:{e.New.Y.DegreesPerSecond:N1}°/s, Z:{e.New.Z.DegreesPerSecond:N1}°/s"); + batteryvoltage.Updated += BatteryVoltageUpdated; } - private void AccelerometerUpdated(object sender, IChangeResult e) + if (gnssTracker.SolarVoltageInput is { } solarVoltage) { - Resolver.Log.Info($"ACCELEROMETER: X:{e.New.X.Gravity:N1}g, Y:{e.New.Y.Gravity:N1}g, Z:{e.New.Z.Gravity:N1}g"); + solarVoltage.Updated += SolarVoltageUpdated; } - private void BatteryVoltageUpdated(object sender, IChangeResult e) + if (gnssTracker.Gnss is { } gnss) { - // Note: Battery Voltage input has a voltage divider, check schematics to learn more - batteryVoltage = e.New * 1.60; - Resolver.Log.Info($"BATTERY VOLTAGE: {batteryVoltage:N2} volts"); + gnss.RmcReceived += GnssRmcReceived; + gnss.GllReceived += GnssGllReceived; } - private void SolarVoltageUpdated(object sender, IChangeResult e) + if (gnssTracker.Display is { } display) { - // Note: Solar Voltage input has a voltage divider, check schematics to learn more - solarVoltage = e.New * 1.40; - Resolver.Log.Info($"SOLAR VOLTAGE: {solarVoltage:N2} volts"); + displayController = new DisplayController(display); + } + if (gnssTracker.OnboardRgbLed is { } onboardRgbLed) + { + onboardRgbLed.StartPulse(Color.Magenta); } - private void GnssRmcReceived(object sender, GnssPositionInfo e) + Resolver.Log.Info("Initialization complete"); + + return Task.CompletedTask; + } + + private void TemperatureSensorUpdated(object sender, IChangeResult e) + { + Resolver.Log.Info($"TEMPERATURE: {e.New.Celsius:N1}C"); + } + + private void HumiditySensorUpdated(object sender, IChangeResult e) + { + Resolver.Log.Info($"HUMIDITY: {e.New.Percent:N1}%"); + } + + private void BarometerUpdated(object sender, IChangeResult e) + { + Resolver.Log.Info($"PRESSURE: {e.New.Millibar:N1}mbar"); + } + + private void GasResistanceSensorUpdated(object sender, IChangeResult e) + { + Resolver.Log.Info($"RESISTANCE: {e.New.Megaohms:N1}MΩ"); + } + + private void CO2ConcentrationSensorUpdated(object sender, IChangeResult e) + { + Resolver.Log.Info($"CO2 CONCENTRATION: {e.New.PartsPerMillion:N1}ppm"); + } + + private void GyroscopeUpdated(object sender, IChangeResult e) + { + Resolver.Log.Info($"GYROSCOPE: X:{e.New.X.DegreesPerSecond:N1}°/s, Y:{e.New.Y.DegreesPerSecond:N1}°/s, Z:{e.New.Z.DegreesPerSecond:N1}°/s"); + } + + private void AccelerometerUpdated(object sender, IChangeResult e) + { + Resolver.Log.Info($"ACCELEROMETER: X:{e.New.X.Gravity:N1}g, Y:{e.New.Y.Gravity:N1}g, Z:{e.New.Z.Gravity:N1}g"); + } + + private void BatteryVoltageUpdated(object sender, IChangeResult e) + { + // Note: Battery Voltage input has a voltage divider, check schematics to learn more + batteryVoltage = e.New * 1.60; + Resolver.Log.Info($"BATTERY VOLTAGE: {batteryVoltage:N2} volts"); + } + + private void SolarVoltageUpdated(object sender, IChangeResult e) + { + // Note: Solar Voltage input has a voltage divider, check schematics to learn more + solarVoltage = e.New * 1.40; + Resolver.Log.Info($"SOLAR VOLTAGE: {solarVoltage:N2} volts"); + + } + + private void GnssRmcReceived(object sender, GnssPositionInfo e) + { + if (e.Valid) { - if (e.Valid) - { - ReportGNSSPosition(e); - lastGNSSPosition = e; - } + ReportGNSSPosition(e); + lastGNSSPosition = e; } + } - private void GnssGllReceived(object sender, GnssPositionInfo e) + private void GnssGllReceived(object sender, GnssPositionInfo e) + { + if (e.Valid) { - if (e.Valid) - { - ReportGNSSPosition(e); - lastGNSSPosition = e; - } + ReportGNSSPosition(e); + lastGNSSPosition = e; } + } - private void ReportGNSSPosition(GnssPositionInfo e) + private void ReportGNSSPosition(GnssPositionInfo e) + { + if (e.Valid) { - if (e.Valid) + if (DateTime.UtcNow - lastGNSSPositionReportTime >= GNSSPositionReportInterval) { - if (DateTime.UtcNow - lastGNSSPositionReportTime >= GNSSPositionReportInterval) - { - Resolver.Log.Info($"GNSS POSITION: LAT: [{e.Position.Latitude}], LONG: [{e.Position.Longitude}]"); + Resolver.Log.Info($"GNSS POSITION: LAT: [{e.Position.Latitude}], LONG: [{e.Position.Longitude}]"); - lastGNSSPositionReportTime = DateTime.UtcNow; - } + lastGNSSPositionReportTime = DateTime.UtcNow; } } + } - public override async Task Run() - { - Resolver.Log.Info("Run..."); + public override async Task Run() + { + Resolver.Log.Info("Run..."); - if (gnssTracker.TemperatureSensor is { } temperatureSensor) - { - temperatureSensor.StartUpdating(sensorUpdateInterval); - } + if (gnssTracker.TemperatureSensor is { } temperatureSensor) + { + temperatureSensor.StartUpdating(sensorUpdateInterval); + } - if (gnssTracker.HumiditySensor is { } humiditySensor) - { - humiditySensor.StartUpdating(sensorUpdateInterval); - } + if (gnssTracker.HumiditySensor is { } humiditySensor) + { + humiditySensor.StartUpdating(sensorUpdateInterval); + } - if (gnssTracker.BarometricPressureSensor is { } barometer) - { - barometer.StartUpdating(sensorUpdateInterval); - } + if (gnssTracker.BarometricPressureSensor is { } barometer) + { + barometer.StartUpdating(sensorUpdateInterval); + } - if (gnssTracker.GasResistanceSensor is { } gasResistanceSensor) - { - gasResistanceSensor.StartUpdating(sensorUpdateInterval); - } + if (gnssTracker.GasResistanceSensor is { } gasResistanceSensor) + { + gasResistanceSensor.StartUpdating(sensorUpdateInterval); + } - if (gnssTracker.CO2ConcentrationSensor is { } cO2ConcentrationSensor) - { - cO2ConcentrationSensor.StartUpdating(sensorUpdateInterval); - } + if (gnssTracker.CO2ConcentrationSensor is { } cO2ConcentrationSensor) + { + cO2ConcentrationSensor.StartUpdating(sensorUpdateInterval); + } - if (gnssTracker.Gyroscope is { } gyroscope) - { - gyroscope.StartUpdating(sensorUpdateInterval); - } + if (gnssTracker.Gyroscope is { } gyroscope) + { + gyroscope.StartUpdating(sensorUpdateInterval); + } - if (gnssTracker.Accelerometer is { } accelerometer) - { - accelerometer.StartUpdating(sensorUpdateInterval); - } + if (gnssTracker.Accelerometer is { } accelerometer) + { + accelerometer.StartUpdating(sensorUpdateInterval); + } - if (gnssTracker.BatteryVoltageInput is { } batteryVoltageInput) - { - batteryVoltageInput.StartUpdating(sensorUpdateInterval); - } + if (gnssTracker.BatteryVoltageInput is { } batteryVoltageInput) + { + batteryVoltageInput.StartUpdating(sensorUpdateInterval); + } - if (gnssTracker.SolarVoltageInput is { } solarVoltageInput) - { - solarVoltageInput.StartUpdating(sensorUpdateInterval); - } + if (gnssTracker.SolarVoltageInput is { } solarVoltageInput) + { + solarVoltageInput.StartUpdating(sensorUpdateInterval); + } - if (gnssTracker.Gnss is { } gnss) - { - //TODO: This should be set with an interval, no? - gnss.StartUpdating(); - } + if (gnssTracker.Gnss is { } gnss) + { + //TODO: This should be set with an interval, no? + gnss.StartUpdating(); + } - while (true) - { - Resolver.Log.Info("=================================================="); - - displayController.UpdateDisplay( - batteryVoltage, - solarVoltage, - gnssTracker.TemperatureSensor.Temperature, - gnssTracker.HumiditySensor.Humidity, - gnssTracker.BarometricPressureSensor.Pressure, - gnssTracker.CO2ConcentrationSensor?.CO2Concentration ?? null, - lastGNSSPosition); - await Task.Delay(sensorUpdateInterval); - } + while (true) + { + Resolver.Log.Info("=================================================="); + + displayController.UpdateDisplay( + batteryVoltage, + solarVoltage, + gnssTracker.TemperatureSensor.Temperature, + gnssTracker.HumiditySensor.Humidity, + gnssTracker.BarometricPressureSensor.Pressure, + gnssTracker.CO2ConcentrationSensor?.CO2Concentration ?? null, + lastGNSSPosition); + await Task.Delay(sensorUpdateInterval); } } } \ No newline at end of file