Skip to content

Commit

Permalink
API fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianstevens committed Jun 19, 2024
1 parent 99494d9 commit 01dfd40
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 15 deletions.
35 changes: 23 additions & 12 deletions Source/GnssTracker_Demo/Controllers/DisplayController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Meadow.Peripherals.Displays;
using Meadow.Peripherals.Sensors.Location.Gnss;
using Meadow.Units;
using System;

namespace GnssTracker_Demo.Controllers;

Expand Down Expand Up @@ -196,22 +197,32 @@ public void UpdateDisplay(
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}\"";
var geo = new GeoLocation(locationInfo?.Position?.Latitude ?? 0, locationInfo?.Position?.Longitude ?? 0);

string lat = ConvertToDMS(geo.Latitude);
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}\"";
string lon = ConvertToDMS(geo.Longitude);
longitudeLabel.Text = lon;

displayScreen.EndUpdate();
}

public string ConvertToDMS(double decimalDegrees)
{
bool isNegative = decimalDegrees < 0;
decimalDegrees = Math.Abs(decimalDegrees);

int degrees = (int)decimalDegrees;

double fractionalPart = decimalDegrees - degrees;
double totalMinutes = fractionalPart * 60;
int minutes = (int)totalMinutes;

double seconds = (totalMinutes - minutes) * 60;

string dms = $"{degrees}° {minutes}' {seconds:F2}\"";

return isNegative ? "-" + dms : dms;
}
}
6 changes: 3 additions & 3 deletions Source/GnssTracker_Demo/MeadowApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ private void SolarVoltageUpdated(object sender, IChangeResult<Voltage> e)

private void GnssRmcReceived(object sender, GnssPositionInfo e)
{
if (e.Valid)
if (e.IsValid)
{
ReportGNSSPosition(e);
lastGNSSPosition = e;
Expand All @@ -156,7 +156,7 @@ private void GnssRmcReceived(object sender, GnssPositionInfo e)

private void GnssGllReceived(object sender, GnssPositionInfo e)
{
if (e.Valid)
if (e.IsValid)
{
ReportGNSSPosition(e);
lastGNSSPosition = e;
Expand All @@ -165,7 +165,7 @@ private void GnssGllReceived(object sender, GnssPositionInfo e)

private void ReportGNSSPosition(GnssPositionInfo e)
{
if (e.Valid)
if (e.IsValid)
{
if (DateTime.UtcNow - lastGNSSPositionReportTime >= GNSSPositionReportInterval)
{
Expand Down

0 comments on commit 01dfd40

Please sign in to comment.