Skip to content

Commit

Permalink
Merge pull request #28 from WildernessLabs/update-microlayout
Browse files Browse the repository at this point in the history
Update Samples with Navigation
  • Loading branch information
jorgedevs authored Sep 26, 2023
2 parents f0dc3bc + 180ec97 commit d66b5b3
Show file tree
Hide file tree
Showing 4 changed files with 166 additions and 192 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using Meadow.Foundation.Graphics;
using Meadow.Foundation.Graphics.MicroLayout;
using Meadow.Logging;
using System;

namespace GnssTracker_SQLite_Demo.Controllers
{
Expand All @@ -14,10 +13,13 @@ public class DisplayController
protected Logger Log { get => Resolver.Log; }
protected DisplayScreen DisplayScreen { get; set; }

protected Font12x20 largeFont { get; set; }
protected Font4x8 smallFont { get; set; }
protected AbsoluteLayout SplashLayout { get; set; }
protected AbsoluteLayout DataLayout { get; set; }

protected Label TempLabel { get; set; }
protected Font12x20 LargeFont { get; set; }
protected Font4x8 SmallFont { get; set; }

protected Label TemperatureLabel { get; set; }
protected Label HumidityLabel { get; set; }
protected Label PressureLabel { get; set; }
protected Label LatitudeLabel { get; set; }
Expand All @@ -26,116 +28,104 @@ public class DisplayController

public DisplayController(IGraphicsDisplay display)
{
largeFont = new Font12x20();
smallFont = new Font4x8();
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");
SplashLayout = new AbsoluteLayout(DisplayScreen, 0, 0, DisplayScreen.Width, DisplayScreen.Height);

var image = Image.LoadFromResource("GnssTracker_SQLite_Demo.gnss_tracker.bmp");
var displayImage = new Picture(0, 0, 250, 122, image)
{
BackColor = Color.FromHex("#23ABE3"),
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center,
};

DisplayScreen.Controls.Add(displayImage);
}
SplashLayout.Controls.Add(displayImage);

public void LoadDataScreen()
{
try
DataLayout = new AbsoluteLayout(DisplayScreen, 0, 0, DisplayScreen.Width, DisplayScreen.Height);

var box = new Box(0, 0, DisplayScreen.Width, DisplayScreen.Height)
{
DisplayScreen.Controls.Clear();

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

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

TempLabel = new Label(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 Label(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 Label(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 Label(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 Label(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 Label(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)
ForeColor = Color.White,
Filled = true
};
var frame = new Box(5, 5, 240, 112)
{
ForeColor = Color.Black,
Filled = false
};
TemperatureLabel = new Label(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 Label(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 Label(10, 50, DisplayScreen.Width - 20, LargeFont.Height)
{
Log?.Error($"err while rendering: {e.Message}");
}
Text = $"Pressure: 0.00atm",
TextColor = Color.Black,
BackColor = Color.White,
Font = LargeFont,
VerticalAlignment = VerticalAlignment.Center,
HorizontalAlignment = HorizontalAlignment.Left
};
LatitudeLabel = new Label(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 Label(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 Label(222, 113, 20, 8)
{
Text = $"{counter.ToString("D4")}",
TextColor = Color.Black,
BackColor = Color.White,
Font = SmallFont,
VerticalAlignment = VerticalAlignment.Center,
HorizontalAlignment = HorizontalAlignment.Center
};

DataLayout.Controls.Add(box, frame, TemperatureLabel, HumidityLabel, PressureLabel, LatitudeLabel, LongitudeLabel, CounterLabel);

DisplayScreen.Controls.Add(SplashLayout, DataLayout);

DataLayout.Visible = false;
}

public void UpdateDisplay(AtmosphericModel conditions, LocationModel locationInfo)
{
TempLabel.Text = $"Temp: {conditions.Temperature?.Celsius:n2}°C";
SplashLayout.Visible = false;
DataLayout.Visible = true;

TemperatureLabel.Text = $"Temp: {conditions.Temperature?.Celsius:n2}°C";
HumidityLabel.Text = $"Humidity: {conditions.RelativeHumidity?.Percent:n2}%";
PressureLabel.Text = $"Pressure: {conditions.Pressure?.StandardAtmosphere:n2}atm";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ public async Task Initialize(IGnssTrackerHardware gnssTracker)
if (gnssTracker.Display is { } display)
{
DisplayController = new DisplayController(display);
DisplayController.ShowSplashScreen();
await Task.Delay(TimeSpan.FromSeconds(20));
}

Expand All @@ -47,8 +46,6 @@ public async Task Initialize(IGnssTrackerHardware gnssTracker)

public void Start()
{
DisplayController.LoadDataScreen();

if (GnssTracker.AtmosphericSensor is { } bme)
{
bme.Updated += AtmosphericSensorUpdated;
Expand Down
Loading

0 comments on commit d66b5b3

Please sign in to comment.