Skip to content

Commit

Permalink
Merge pull request #23 from WildernessLabs/jorge-updates
Browse files Browse the repository at this point in the history
Update Samples
  • Loading branch information
adrianstevens authored Aug 25, 2023
2 parents 6d39c33 + d45ca18 commit 25d4921
Show file tree
Hide file tree
Showing 22 changed files with 625 additions and 196 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ The GNSS Sensor Tracker is an open-source, sensor-rich, GNSS/GPS tracking board
</tr>
<tr>
<td>
You can get a Gnss Sensor Tracker fully assembled from the <strong>Wilderness Labs store</strong>.
You can get a Gnss Sensor Tracker fully assembled from the <a href="https://store.wildernesslabs.co/collections/frontpage/products/gnss-sensor-tracker">Wilderness Labs store</a>.
</td>
<td>
It's also designed so that it can be assembled at home for the adventurous. All design files can be found in the <a href="Hardware/Design%20Files/">Hardware Design</a> folder.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Deploy",
"type": "meadow",
"request": "launch",
"preLaunchTask": "meadow: Build"
}
]
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using Meadow;
using GnssTracker_SQLite_Demo.Models.Data;
using GnssTracker_SQLite_Demo.Models.Logical;
using Meadow;
using Meadow.Logging;
using SQLite;
using System.IO;
using Meadow.Logging;
using GnssTracker_Demo.Models.Data;
using GnssTracker_Demo.Models.Logical;

namespace GnssTracker_Demo.Controllers
namespace GnssTracker_SQLite_Demo.Controllers
{
public static class DatabaseController
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
using GnssTracker_SQLite_Demo.Models.Logical;
using Meadow;
using Meadow.Foundation;
using Meadow.Foundation.Graphics;
using Meadow.Foundation.Graphics.MicroLayout;
using Meadow.Logging;
using System;

namespace GnssTracker_SQLite_Demo.Controllers
{
public class DisplayController
{
protected int counter = 0;
protected Logger Log { get => Resolver.Log; }
protected DisplayScreen DisplayScreen { get; set; }

protected Font12x20 largeFont { get; set; }
protected Font4x8 smallFont { get; set; }

protected DisplayLabel TempLabel { get; set; }
protected DisplayLabel HumidityLabel { get; set; }
protected DisplayLabel PressureLabel { get; set; }
protected DisplayLabel LatitudeLabel { get; set; }
protected DisplayLabel LongitudeLabel { get; set; }
protected DisplayLabel CounterLabel { get; set; }

public DisplayController(IGraphicsDisplay display)
{
largeFont = new Font12x20();
smallFont = new Font4x8();

DisplayScreen = new DisplayScreen(display, RotationType._270Degrees);
}

public void ShowSplashScreen()
{
var image = Image.LoadFromResource("GnssTracker_SQLite_Demo.gnss_tracker.bmp");

var displayImage = new DisplayImage(0, 0, 250, 122, image)
{
BackColor = Color.FromHex("#23ABE3"),
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center,
};

DisplayScreen.Controls.Add(displayImage);
}

public void LoadDataScreen()
{
try
{
DisplayScreen.Controls.Clear();

var box = new DisplayBox(0, 0, DisplayScreen.Width, DisplayScreen.Height)
{
ForeColor = Color.White,
Filled = true
};

var frame = new DisplayBox(5, 5, 240, 112)
{
ForeColor = Color.Black,
Filled = false
};

TempLabel = new DisplayLabel(10, 10, DisplayScreen.Width - 20, largeFont.Height)
{
Text = $"Temp: 0.00°C",
TextColor = Color.Black,
BackColor = Color.White,
Font = largeFont,
VerticalAlignment = VerticalAlignment.Center,
HorizontalAlignment = HorizontalAlignment.Left
};

HumidityLabel = new DisplayLabel(10, 30, DisplayScreen.Width - 20, largeFont.Height)
{
Text = $"Humidity: 0.00%",
TextColor = Color.Black,
BackColor = Color.White,
Font = largeFont,
VerticalAlignment = VerticalAlignment.Center,
HorizontalAlignment = HorizontalAlignment.Left
};

PressureLabel = new DisplayLabel(10, 50, DisplayScreen.Width - 20, largeFont.Height)
{
Text = $"Pressure: 0.00atm",
TextColor = Color.Black,
BackColor = Color.White,
Font = largeFont,
VerticalAlignment = VerticalAlignment.Center,
HorizontalAlignment = HorizontalAlignment.Left
};

LatitudeLabel = new DisplayLabel(10, 72, DisplayScreen.Width - 20, largeFont.Height)
{
Text = $"Lat: 0°0'0.0\"",
TextColor = Color.White,
BackColor = Color.Red,
Font = largeFont,
VerticalAlignment = VerticalAlignment.Center,
HorizontalAlignment = HorizontalAlignment.Left
};

LongitudeLabel = new DisplayLabel(10, 92, DisplayScreen.Width - 20, largeFont.Height)
{
Text = $"Lon: 0°0'0.0\"",
TextColor = Color.White,
BackColor = Color.Red,
Font = largeFont,
VerticalAlignment = VerticalAlignment.Center,
HorizontalAlignment = HorizontalAlignment.Left
};

counter++;
CounterLabel = new DisplayLabel(222, 113, 20, 8)
{
Text = $"{counter.ToString("D4")}",
TextColor = Color.Black,
BackColor = Color.White,
Font = smallFont,
VerticalAlignment = VerticalAlignment.Center,
HorizontalAlignment = HorizontalAlignment.Center
};

DisplayScreen.Controls.Add(box, frame, TempLabel, HumidityLabel, PressureLabel, LatitudeLabel, LongitudeLabel, CounterLabel);
}
catch (Exception e)
{
Log?.Error($"err while rendering: {e.Message}");
}
}

public void UpdateDisplay(AtmosphericModel conditions, LocationModel locationInfo)
{
TempLabel.Text = $"Temp: {conditions.Temperature?.Celsius:n2}°C";
HumidityLabel.Text = $"Humidity: {conditions.RelativeHumidity?.Percent:n2}%";
PressureLabel.Text = $"Pressure: {conditions.Pressure?.StandardAtmosphere:n2}atm";

string lat = locationInfo.PositionInformation == null
? $"Lat: 0°0'0.0\""
: $"Lat: " +
$"{locationInfo.PositionInformation?.Position?.Latitude?.Degrees}°" +
$"{locationInfo.PositionInformation?.Position?.Latitude?.Minutes:n2}'" +
$"{locationInfo.PositionInformation?.Position?.Latitude?.seconds}\"";
LatitudeLabel.Text = lat;

string lon = locationInfo.PositionInformation == null
? $"Lon: 0°0'0.0\""
: $"Lon: " +
$"{locationInfo.PositionInformation?.Position?.Longitude?.Degrees}°" +
$"{locationInfo.PositionInformation?.Position?.Longitude?.Minutes:n2}'" +
$"{locationInfo.PositionInformation?.Position?.Longitude?.seconds}\"";
LongitudeLabel.Text = lon;

counter++;
CounterLabel.Text = $"{counter.ToString("D4")}";
}
}
}
Original file line number Diff line number Diff line change
@@ -1,24 +1,16 @@
using Meadow;
using Meadow.Foundation.Sensors.Gnss;
using Meadow.Logging;
using Meadow.Peripherals.Sensors.Location.Gnss;
using System;

namespace GnssTracker_Demo.Controllers
namespace GnssTracker_SQLite_Demo.Controllers
{
/// <summary>
/// Responsible for initializing the GPS stuff and running all things GPS
/// </summary>
public static class GnssController
{
public static event EventHandler<GnssPositionInfo> GnssPositionInfoUpdated = delegate { };

private static Logger Log { get => Resolver.Log; }
private static NeoM8? GnssDevice { get; set; }

/// <summary>
/// Last Gnss Position
/// </summary>
public static GnssPositionInfo? LastGnssPositionInfo { get; private set; }

public static void Initialize(NeoM8 gnssDevice)
Expand Down Expand Up @@ -63,7 +55,7 @@ public static void Initialize(NeoM8 gnssDevice)
{
if (positionCourseAndTime.Valid)
{
Log.Debug($"GNSS - Position: LAT: [{positionCourseAndTime.Position.Latitude}], LON: [{positionCourseAndTime.Position.Longitude}]");
Resolver.Log.Debug($"GNSS - Position: LAT: [{positionCourseAndTime.Position.Latitude}], LON: [{positionCourseAndTime.Position.Longitude}]");
LastGnssPositionInfo = positionCourseAndTime;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
using GnssTracker_Demo.Models.Logical;
using GnssTracker_SQLite_Demo.Models.Logical;
using Meadow;
using Meadow.Logging;
using Meadow.Peripherals.Sensors.Location.Gnss;
using System;
using System.Threading.Tasks;
using WildernessLabs.Hardware.GnssTracker;

namespace GnssTracker_Demo.Controllers
namespace GnssTracker_SQLite_Demo.Controllers
{
/// <summary>
/// This is the main tracker application controller. It's responsible for
Expand All @@ -15,29 +16,40 @@ public class MainTrackerController
{
private TimeSpan UPDATE_INTERVAL = TimeSpan.FromMinutes(1);

protected IGnssTrackerHardware GnssTracker { get; set; }

protected Logger Log { get => Resolver.Log; }
protected IGnssTrackerHardware Hardware { get; set; }

protected AtmosphericModel? LastAtmosphericConditions { get; set; }

protected LocationModel? LastLocationInfo { get; set; }

public MainTrackerController(IGnssTrackerHardware hardware)
protected DisplayController DisplayController { get; set; }

public MainTrackerController() { }

public async Task Initialize(IGnssTrackerHardware gnssTracker)
{
Hardware = hardware;
GnssTracker = gnssTracker;

LastLocationInfo = new LocationModel();
LastAtmosphericConditions = new AtmosphericModel();

if (gnssTracker.Display is { } display)
{
DisplayController = new DisplayController(display);
DisplayController.ShowSplashScreen();
await Task.Delay(TimeSpan.FromSeconds(20));
}

GnssController.GnssPositionInfoUpdated += GnssPositionInfoUpdated;
}

/// <summary>
/// Starts updating all the things
/// </summary>
public void Start()
{
Hardware.OnboardLed.StartPulse();
DisplayController.LoadDataScreen();

if (Hardware.AtmosphericSensor is { } bme)
if (GnssTracker.AtmosphericSensor is { } bme)
{
bme.Updated += AtmosphericSensorUpdated;
bme.StartUpdating(UPDATE_INTERVAL);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<Project Sdk="Meadow.Sdk/1.1.0">
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<OutputType>Library</OutputType>
<AssemblyName>App</AssemblyName>
</PropertyGroup>
<ItemGroup>
<None Remove="gnss_tracker.bmp" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="gnss_tracker.bmp" />
</ItemGroup>
<ItemGroup>
<None Update="app.config.yaml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<PackageReference Include="SimpleJpegDecoder" Version="*" />
<PackageReference Include="sqlite-net-static" Version="1.8.116" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\..\Meadow.Foundation\Source\Meadow.Foundation.Libraries_and_Frameworks\Graphics.MicroLayout\Driver\Graphics.MicroLayout.csproj" />
<ProjectReference Include="..\..\GnssTracker\GnssTracker.csproj" />
</ItemGroup>
</Project>
46 changes: 46 additions & 0 deletions Source/Additional Samples/GnssTracker_SQLite_Demo/MeadowApp.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using GnssTracker_SQLite_Demo.Controllers;
using Meadow;
using Meadow.Devices;
using System;
using System.Threading.Tasks;
using WildernessLabs.Hardware.GnssTracker;

namespace GnssTracker_SQLite_Demo
{
public class MeadowApp : App<F7CoreComputeV2>
{
protected MainTrackerController MainController { get; set; }

public override async Task Initialize()
{
Resolver.Log.Info("Initialize hardware...");

var gnssTracker = GnssTracker.Create();

try
{
DatabaseController.ConfigureDatabase();
}
catch (Exception e)
{
Resolver.Log.Info($"Err bringing up database: {e.Message}");
}

//await Task.Delay(TimeSpan.FromSeconds(10));

GnssController.Initialize(gnssTracker.Gnss);

MainController = new MainTrackerController();
await MainController.Initialize(gnssTracker);
}

public override Task Run()
{
Resolver.Log.Info("Running");

MainController.Start();

return base.Run();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using SQLite;
using System;

namespace GnssTracker_Demo.Models.Data
namespace GnssTracker_SQLite_Demo.Models.Data
{
[Table("SensorReadings")]
public class SensorDataModel
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Meadow.Units;
using System;

namespace GnssTracker_Demo.Models.Logical
namespace GnssTracker_SQLite_Demo.Models.Logical
{
public class AtmosphericModel
{
Expand Down
Loading

0 comments on commit 25d4921

Please sign in to comment.