Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -399,3 +399,4 @@ FodyWeavers.xsd

**/.DS_Store
.vscode/launch.json
.vscode/
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ Public project samples for Meadow and Meadow.Foundation. Click on any of the pro
<img src="Design/wildernesslabs-meadow-project-samples-rover-leds.png" alt="iot, dotnet, meadow, rover, led"/><br/>
Meadow Rover Part 1: Motor Control with directional LEDs</br>
<a href="https://www.hackster.io/wilderness-labs/meadow-rover-part-1-motor-control-with-directional-leds-85107d">Hackster</a> |
<a href="Source/Meadow F7 Feather/MeadowRoverLeds/">Source Code</a>
<a href="Source/Meadow F7 Feather/Rover/MeadowRoverLeds">Source Code</a>
</td>
<td>
<img src="Design/wildernesslabs-meadow-project-samples-obstacle-radar.png" alt="iot, dotnet, meadow, sensors, displays, graphics"/><br/>
Expand Down
22 changes: 13 additions & 9 deletions Source/Azure/ProjectLab_AzureIoTHub/Controllers/MainController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public async Task Initialize()

await InitializeIoTHub();

hardware.EnvironmentalSensor.Updated += EnvironmentalSensorUpdated;
hardware.BarometricPressureSensor.Updated += BarometricPressureSensor_Updated;
}

private async Task InitializeIoTHub()
Expand Down Expand Up @@ -101,23 +101,27 @@ private async Task SendDataToIoTHub((Temperature? Temperature, RelativeHumidity?
}
}

private async void EnvironmentalSensorUpdated(object sender, IChangeResult<(Temperature? Temperature, RelativeHumidity? Humidity, Pressure? Pressure, Resistance? GasResistance)> e)
private async void BarometricPressureSensor_Updated(object sender, IChangeResult<Pressure> e)
{
hardware.RgbPwmLed.StartBlink(Color.Orange);
await hardware.RgbPwmLed.StartBlink(Color.Orange);

var t = await hardware.TemperatureSensor.Read();
var h = await hardware.HumiditySensor.Read();
var p = hardware.BarometricPressureSensor.Pressure.Value;

displayController.UpdateAtmosphericConditions(
temperature: e.New.Temperature.Value.Celsius,
pressure: e.New.Pressure.Value.Millibar,
humidity: e.New.Humidity.Value.Percent);
temperature: t.Celsius,
pressure: p.Millibar,
humidity: h.Percent);

await SendDataToIoTHub(e.New);
await SendDataToIoTHub((t, h, p, null));

hardware.RgbPwmLed.StartBlink(Color.Green);
await hardware.RgbPwmLed.StartBlink(Color.Green);
}

public async Task Run()
{
hardware.EnvironmentalSensor.StartUpdating(TimeSpan.FromSeconds(15));
hardware.BarometricPressureSensor.StartUpdating(TimeSpan.FromSeconds(15));

while (true)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
using Meadow.Foundation.Sensors.Atmospheric;
using Meadow.Peripherals.Displays;
using Meadow.Peripherals.Displays;
using Meadow.Peripherals.Leds;
using Meadow.Peripherals.Sensors;
using Meadow.Peripherals.Sensors.Atmospheric;

namespace ProjectLab_AzureIoTHub.Hardware;

internal interface IMeadowAzureIoTHubHardware
{
public IPixelDisplay Display { get; }

public Bme68x EnvironmentalSensor { get; }
public ITemperatureSensor TemperatureSensor { get; set; }

public IBarometricPressureSensor BarometricPressureSensor { get; set; }

public IHumiditySensor HumiditySensor { get; set; }

public IRgbPwmLed RgbPwmLed { get; }

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using Meadow.Devices;
using Meadow.Foundation.Sensors.Atmospheric;
using Meadow.Peripherals.Displays;
using Meadow.Peripherals.Leds;
using Meadow.Peripherals.Sensors;
using Meadow.Peripherals.Sensors.Atmospheric;

namespace ProjectLab_AzureIoTHub.Hardware;

Expand All @@ -11,7 +12,11 @@ internal class MeadowAzureIoTHubHardware : IMeadowAzureIoTHubHardware

public IPixelDisplay Display { get; set; }

public Bme68x EnvironmentalSensor { get; set; }
public ITemperatureSensor TemperatureSensor { get; set; }

public IBarometricPressureSensor BarometricPressureSensor { get; set; }

public IHumiditySensor HumiditySensor { get; set; }

public IRgbPwmLed RgbPwmLed { get; set; }

Expand All @@ -26,6 +31,8 @@ public void Initialize()

RgbPwmLed = ProjLab.RgbLed;

EnvironmentalSensor = (ProjLab as ProjectLabHardwareBase).AtmosphericSensor;
TemperatureSensor = ProjLab.TemperatureSensor;
BarometricPressureSensor = ProjLab.BarometricPressureSensor;
HumiditySensor = ProjLab.HumiditySensor;
}
}
2 changes: 1 addition & 1 deletion Source/Meadow F7/IO/AnalogInputPort/MeadowApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace AnalogInputPort;

public class MeadowApp : App<F7FeatherV2>
{
IObservableAnalogInputPort analogIn;
private IObservableAnalogInputPort analogIn;

public override Task Initialize()
{
Expand Down
17 changes: 4 additions & 13 deletions Source/Meadow.Cloud/FeatherF7_OTA/MeadowApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Meadow.Foundation.Leds;
using Meadow.Peripherals.Leds;
using Meadow.Update;
using System.Threading;
using System.Threading.Tasks;

namespace FeatherF7_OTA;
Expand Down Expand Up @@ -50,8 +51,6 @@ public override Task Initialize()

var updateService = Resolver.UpdateService;

updateService.ClearUpdates(); // uncomment to clear persisted info

updateService.StateChanged += OnUpdateStateChanged;

updateService.RetrieveProgress += OnUpdateProgress;
Expand All @@ -72,33 +71,25 @@ private void OnUpdateStateChanged(object sender, UpdateState e)
Resolver.Log.Info($"UpdateState {e}");
}

private void OnUpdateProgress(IUpdateService updateService, UpdateInfo info)
private void OnUpdateProgress(IUpdateService updateService, UpdateInfo info, CancellationTokenSource token)
{
short percentage = (short)(((double)info.DownloadProgress / info.FileSize) * 100);

Resolver.Log.Info($"Downloading... {percentage}%");
}

private async void OnUpdateAvailable(IUpdateService updateService, UpdateInfo info)
private async void OnUpdateAvailable(IUpdateService updateService, UpdateInfo info, CancellationTokenSource token)
{
Resolver.Log.Info($"Update available!");

_ = onboardLed.StartBlink(Color.Magenta);

await Task.Delay(5000);

updateService.RetrieveUpdate(info);
}

private async void OnUpdateRetrieved(IUpdateService updateService, UpdateInfo info)
private async void OnUpdateRetrieved(IUpdateService updateService, UpdateInfo info, CancellationTokenSource token)
{
Resolver.Log.Info($"Update retrieved!");

_ = onboardLed.StartBlink(Color.Cyan);

await Task.Delay(5000);

updateService.ApplyUpdate(info);
}

private void OnCloudStateChanged(object sender, CloudConnectionState e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,35 +16,28 @@ public class MainController
public MainController()
{
Resolver.MeadowCloudService.ConnectionStateChanged += OnConnectionStateChanged;

Resolver.UpdateService.UpdateRetrieved += OnUpdateRetrieved;
Resolver.UpdateService.UpdateAvailable += OnUpdateAvailable;
Resolver.UpdateService.RetrieveProgress += OnRetrieveProgress;
Resolver.UpdateService.UpdateSuccess += OnUpdateSuccess;
Resolver.UpdateService.UpdateFailure += OnUpdateFailure;
Resolver.UpdateService.UpdateRetrieved += OnUpdateRetrieved;

commandController = new CommandController(Resolver.CommandService);
telemetryController = new TelemetryController(Resolver.MeadowCloudService);
controlTimer = new Timer(ControlTimerProc);
}

private void OnUpdateFailure(Meadow.Update.IUpdateService updateService, Meadow.Update.UpdateInfo info, CancellationTokenSource cancel)
{
Resolver.Log.Error($"Update Failure: {info.ID} - {info.Version} - {info.Detail}");
}

private void OnUpdateSuccess(Meadow.Update.IUpdateService updateService, Meadow.Update.UpdateInfo info, CancellationTokenSource cancel)
private void OnUpdateRetrieved(Meadow.Update.IUpdateService updateService, Meadow.Update.UpdateInfo info, CancellationTokenSource token)
{
Resolver.Log.Info($"Update Success: {info.ID} - {info.Version}");
Resolver.Log.Info($"Update {info.ID} retrieved");
}

private void OnRetrieveProgress(Meadow.Update.IUpdateService updateService, Meadow.Update.UpdateInfo info, CancellationTokenSource cancel)
private void OnRetrieveProgress(Meadow.Update.IUpdateService updateService, Meadow.Update.UpdateInfo info, CancellationTokenSource token)
{
Resolver.Log.Info($"Update Retrieve Progress: {info.ID} - {info.Version} - {info.DownloadProgress}%");
Resolver.Log.Info($"{info.ID} retrieved {info.DownloadProgress}");
}

private void OnUpdateRetrieved(Meadow.Update.IUpdateService updateService, Meadow.Update.UpdateInfo info, CancellationTokenSource cancel)
private void OnUpdateAvailable(Meadow.Update.IUpdateService updateService, Meadow.Update.UpdateInfo info, CancellationTokenSource token)
{
Resolver.Log.Info($"Update Retrieved: {info.ID} - {info.Version}");
Resolver.Log.Info($"An update is available: {info.ID}");
}

private void OnConnectionStateChanged(object sender, CloudConnectionState e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ private void LoadSplashLayout()
var image = Image.LoadFromResource("ProjectLab_ApiClient.Resources.img_meadow.bmp");
var displayImage = new Picture(0, 0, displayScreen.Width, displayScreen.Height, image)
{
BackgroundColor = Meadow.Color.FromHex("14607F"),
BackgroundColor = Color.FromHex("14607F"),
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ private void LoadSplashLayout()
var image = Image.LoadFromResource("ProjectLab_Command.Resources.img_meadow.bmp");
var displayImage = new Picture(0, 0, displayScreen.Width, displayScreen.Height, image)
{
BackgroundColor = Meadow.Color.FromHex("#B35E2C"),
BackgroundColor = Color.FromHex("#B35E2C"),
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center,
};
Expand Down
15 changes: 4 additions & 11 deletions Source/Meadow.Cloud/ProjectLab_OTA/Controllers/MainController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Meadow.Hardware;
using Meadow.Update;
using ProjectLab_OTA.Hardware;
using System.Threading;
using System.Threading.Tasks;

namespace ProjectLab_OTA.Controllers;
Expand Down Expand Up @@ -29,8 +30,6 @@ public Task Run()
{
var updateService = Resolver.UpdateService;

updateService.ClearUpdates(); // uncomment to clear persisted info

updateService.StateChanged += OnUpdateStateChanged;

updateService.RetrieveProgress += OnUpdateProgress;
Expand All @@ -51,29 +50,23 @@ private void OnUpdateStateChanged(object sender, UpdateState e)
displayController.UpdateStatus($"{FormatStatusMessage(e)}");
}

private void OnUpdateProgress(IUpdateService updateService, UpdateInfo info)
private void OnUpdateProgress(IUpdateService updateService, UpdateInfo info, CancellationTokenSource token)
{
short percentage = (short)(((double)info.DownloadProgress / info.FileSize) * 100);

displayController.UpdateDownloadProgress(percentage);
}

private async void OnUpdateAvailable(IUpdateService updateService, UpdateInfo info)
private async void OnUpdateAvailable(IUpdateService updateService, UpdateInfo info, CancellationTokenSource token)
{
_ = hardware.RgbPwmLed.StartBlink(Color.Magenta);
displayController.UpdateStatus("Update available!");

await Task.Delay(5000);
updateService.RetrieveUpdate(info);
}

private async void OnUpdateRetrieved(IUpdateService updateService, UpdateInfo info)
private async void OnUpdateRetrieved(IUpdateService updateService, UpdateInfo info, CancellationTokenSource token)
{
_ = hardware.RgbPwmLed.StartBlink(Color.Cyan);
displayController.UpdateStatus("Update retrieved!");

await Task.Delay(5000);
updateService.ApplyUpdate(info);
}

private void OnCloudStateChanged(object sender, CloudConnectionState e)
Expand Down
24 changes: 12 additions & 12 deletions Source/Modbus/MeadowModbusServer/MeadowApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ public override Task Initialize()

BuildScreen();

(projectLab as ProjectLabHardwareBase).AtmosphericSensor.Updated += OnEnvironmentalSensorUpdated;
(projectLab as ProjectLabHardwareBase).AtmosphericSensor.StartUpdating();
projectLab.BarometricPressureSensor.Updated += BarometricPressureSensor_Updated;
projectLab.BarometricPressureSensor.StartUpdating();

var wifi = Hardware.ComputeModule.NetworkAdapters.Primary<IWiFiNetworkAdapter>();

Expand Down Expand Up @@ -129,25 +129,25 @@ private void ShowNetworkAddress(IPAddress address)
addressLabel.Text = address.ToString();
}

private void OnEnvironmentalSensorUpdated(object sender, IChangeResult<(Temperature? Temperature, RelativeHumidity? Humidity, Pressure? Pressure, Resistance? GasResistance)> e)
private void BarometricPressureSensor_Updated(object sender, IChangeResult<Pressure> e)
{
var d = new Dictionary<string, float>();

// we lose some numeric accuracy here, but 64-bits is much higher precision than the sensor
if (e.New.Temperature != null)
if (Hardware.TemperatureSensor != null)
{
registers.SetRegisters(RegisterBank.Registers.Temperature, (float)e.New.Temperature.Value.Celsius);
d.Add("Temp", (float)e.New.Temperature.Value.Celsius);
registers.SetRegisters(RegisterBank.Registers.Temperature, (float)Hardware.TemperatureSensor.Read().Result.Celsius);
d.Add("Temp", (float)Hardware.TemperatureSensor.Read().Result.Celsius);
}
if (e.New.Humidity != null)
if (Hardware.HumiditySensor != null)
{
registers.SetRegisters(RegisterBank.Registers.Humidity, (float)e.New.Humidity.Value.Percent);
d.Add("Hum", (float)e.New.Humidity.Value.Percent);
registers.SetRegisters(RegisterBank.Registers.Humidity, (float)Hardware.HumiditySensor.Humidity.Value.Percent);
d.Add("Hum", (float)Hardware.HumiditySensor.Humidity.Value.Percent);
}
if (e.New.Pressure != null)
if (Hardware.BarometricPressureSensor != null)
{
registers.SetRegisters(RegisterBank.Registers.AirPressure, (float)e.New.Pressure.Value.Pascal);
d.Add("Pres", (float)e.New.Pressure.Value.Pascal);
registers.SetRegisters(RegisterBank.Registers.AirPressure, (float)Hardware.BarometricPressureSensor.Pressure.Value.Pascal);
d.Add("Pres", (float)Hardware.BarometricPressureSensor.Pressure.Value.Pascal);
}

ShowTelemetry(d);
Expand Down
20 changes: 20 additions & 0 deletions Source/MultiPlatform/MeadowBlazor/Components/App.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<base href="/" />
<link rel="stylesheet" href="bootstrap/bootstrap.min.css" />
<link rel="stylesheet" href="app.css" />
<link rel="stylesheet" href="MeadowBlazor.styles.css" />
<link rel="icon" type="image/png" href="favicon.png" />
<HeadOutlet />
</head>

<body>
<Routes />
<script src="_framework/blazor.web.js"></script>
</body>

</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
@inherits LayoutComponentBase

<div class="page">
<div class="sidebar">
<NavMenu />
</div>

<main>
<div class="top-row px-4">
<a href="https://learn.microsoft.com/aspnet/core/" target="_blank">About</a>
</div>

<article class="content px-4">
@Body
</article>
</main>
</div>

<div id="blazor-error-ui">
An unhandled error has occurred.
<a href="" class="reload">Reload</a>
<a class="dismiss">🗙</a>
</div>
Loading
Loading