Skip to content

Commit

Permalink
Merge pull request #67 from WildernessLabs/v1.9.0
Browse files Browse the repository at this point in the history
Release 1.9.0
  • Loading branch information
jorgedevs committed Feb 27, 2024
2 parents e3427e1 + a6894f8 commit 8edaeef
Show file tree
Hide file tree
Showing 12 changed files with 655 additions and 323 deletions.
Expand Up @@ -15,11 +15,11 @@
<EmbeddedResource Include="img_wifi_connecting.jpg" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Meadow.Foundation.Web.Maple.Server" Version="1.8.0.1" />
<PackageReference Include="Meadow.F7" Version="1.8.0.1" />
<PackageReference Include="Meadow.Foundation" Version="1.8.0.1" />
<PackageReference Include="Meadow.Foundation.Displays.TextDisplayMenu" Version="1.8.0.1" />
<PackageReference Include="Meadow.Foundation.Displays.TftSpi" Version="1.8.0.1" />
<PackageReference Include="Meadow.Foundation.Web.Maple.Server" Version="1.9.0" />
<PackageReference Include="Meadow.F7" Version="1.9.0" />
<PackageReference Include="Meadow.Foundation" Version="1.9.0" />
<PackageReference Include="Meadow.Foundation.Displays.TextDisplayMenu" Version="1.9.0" />
<PackageReference Include="Meadow.Foundation.Displays.TftSpi" Version="1.9.0" />
<PackageReference Include="SimpleJpegDecoder" Version="0.4.0" />
<PackageReference Include="sqlite-net-static" Version="1.8.116" />
<PackageReference Include="System.Text.Json" Version="*" />
Expand Down
Expand Up @@ -11,6 +11,7 @@
using System.Threading;
using System.Threading.Tasks;
using Meadow;
using Meadow.Peripherals.Displays;

namespace Clima_HackKit_Demo.Controller
{
Expand Down
Expand Up @@ -10,7 +10,7 @@
<LangVersion>9.0</LangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Meadow.Foundation.Web.Maple.Server" Version="1.8.0.1" />
<PackageReference Include="Meadow.Foundation.Web.Maple.Server" Version="1.9.0" />
<ProjectReference Include="..\..\Meadow.Clima\Meadow.Clima.csproj" />
<PackageReference Include="System.Text.Json" Version="*" />
<PackageReference Include="sqlite-net-static" Version="*" />
Expand Down
@@ -1,6 +1,6 @@
using Meadow.Devices;
using Clima_SQLite_Demo.Database;
using Clima_SQLite_Demo.Database;
using Clima_SQLite_Demo.Models;
using Meadow.Devices;
using System;
using System.Threading.Tasks;

Expand Down Expand Up @@ -68,19 +68,21 @@ void StopUpdating()

public async Task<ClimateReading> Read()
{
var bmeTask = clima.AtmosphericSensor?.Read();
var tempTask = clima.TemperatureSensor?.Read();
var pressureTask = clima.BarometricPressureSensor?.Read();
var humidityTask = clima.HumiditySensor?.Read();
var windVaneTask = clima.WindVane?.Read();
var anemometerTask = clima.Anemometer?.Read();
var rainFallTask = clima.RainGauge?.Read();

await Task.WhenAll(bmeTask, anemometerTask, windVaneTask, rainFallTask);
await Task.WhenAll(tempTask, humidityTask, pressureTask, anemometerTask, windVaneTask, rainFallTask);

var climate = new ClimateReading()
{
DateTime = DateTime.Now,
Temperature = bmeTask?.Result.Temperature,
Pressure = bmeTask?.Result.Pressure,
Humidity = bmeTask?.Result.Humidity,
Temperature = tempTask?.Result,
Pressure = pressureTask?.Result,
Humidity = humidityTask?.Result,
RainFall = rainFallTask?.Result,
WindDirection = windVaneTask?.Result.Compass16PointCardinalName,
WindSpeed = anemometerTask?.Result,
Expand Down
82 changes: 56 additions & 26 deletions Source/Clima_Demo/MeadowApp.cs
Expand Up @@ -19,18 +19,28 @@ public override Task Initialize()
Resolver.Log.Info("Initialize hardware...");

clima = Clima.Create();
clima.ColorLed.SetColor(Color.Red);
clima.RgbLed.SetColor(Color.Red);

Resolver.Log.Info($"Running on Clima Hardware {clima.RevisionString}");

if (clima.AtmosphericSensor is { } bme688)
if (clima.TemperatureSensor is { } temperatureSensor)
{
bme688.Updated += Bme688Updated;
temperatureSensor.Updated += TemperatureUpdated;
}

if (clima.EnvironmentalSensor is { } scd40)
if (clima.BarometricPressureSensor is { } pressureSensor)
{
scd40.Updated += Scd40Updated;
pressureSensor.Updated += PressureUpdated;
}

if (clima.HumiditySensor is { } humiditySensor)
{
humiditySensor.Updated += HumidityUpdated;
}

if (clima.CO2ConcentrationSensor is { } co2Sensor)
{
co2Sensor.Updated += Co2Updated;
}

if (clima.WindVane is { } windVane)
Expand Down Expand Up @@ -69,41 +79,41 @@ public override Task Initialize()

Resolver.Log.Info("Initialization complete");

clima.ColorLed.SetColor(Color.Green);
clima.RgbLed.SetColor(Color.Green);

return base.Initialize();
}

private void GnssGsaReceived(object sender, ActiveSatellites e)
private void GnssGsaReceived(object _, ActiveSatellites e)
{
if (e.SatellitesUsedForFix is { } sats)
{
Resolver.Log.Info($"Number of active satellites: {sats.Length}");
}
}

private void GnssGsvReceived(object sender, SatellitesInView e)
private void GnssGsvReceived(object _, SatellitesInView e)
{
Resolver.Log.Info($"Satellites in view: {e.Satellites.Length}");
}

private void GnssVtgReceived(object sender, CourseOverGround e)
private void GnssVtgReceived(object _, CourseOverGround e)
{
if (e is { } cv)
{
Resolver.Log.Info($"{cv}");
};
}

private void GnssRmcReceived(object sender, GnssPositionInfo e)
private void GnssRmcReceived(object _, GnssPositionInfo e)
{
if (e.Valid)
{
Resolver.Log.Info($"GNSS Position: lat: [{e.Position.Latitude}], long: [{e.Position.Longitude}]");
}
}

private void GnssGllReceived(object sender, GnssPositionInfo e)
private void GnssGllReceived(object _, GnssPositionInfo e)
{
if (e.Valid)
{
Expand All @@ -117,14 +127,24 @@ public override Task Run()

var updateInterval = TimeSpan.FromSeconds(5);

if (clima.AtmosphericSensor is { } bme688)
if (clima.TemperatureSensor is { } temp)
{
temp.StartUpdating(updateInterval);
}

if (clima.HumiditySensor is { } humidity)
{
humidity.StartUpdating(updateInterval);
}

if (clima.BarometricPressureSensor is { } pressure)
{
bme688.StartUpdating(updateInterval);
pressure.StartUpdating(updateInterval);
}

if (clima.EnvironmentalSensor is { } scd40)
if (clima.CO2ConcentrationSensor is { } co2)
{
scd40.StartUpdating(updateInterval);
co2.StartUpdating(updateInterval);
}

if (clima.WindVane is { } windVane)
Expand Down Expand Up @@ -160,14 +180,29 @@ public override Task Run()
return base.Run();
}

private void Bme688Updated(object sender, IChangeResult<(Temperature? Temperature, RelativeHumidity? Humidity, Pressure? Pressure, Resistance? GasResistance)> e)
private void TemperatureUpdated(object sender, IChangeResult<Temperature> e)
{
Resolver.Log.Info($"BME688: {(int)e.New.Temperature?.Celsius:0.0}C, {(int)e.New.Humidity?.Percent:0.#}%, {(int)e.New.Pressure?.Millibar:0.#}mbar");
Resolver.Log.Info($"Temperature: {e.New.Celsius:0.#}C");
}

private void PressureUpdated(object sender, IChangeResult<Pressure> e)
{
Resolver.Log.Info($"Pressure: {e.New.Millibar:0.#}mbar");
}

private void HumidityUpdated(object sender, IChangeResult<RelativeHumidity> e)
{
Resolver.Log.Info($"Humidity: {e.New.Percent:0.#}%");
}

private void Co2Updated(object sender, IChangeResult<Concentration> e)
{
Resolver.Log.Info($"CO2: {e.New.PartsPerMillion:0.#}ppm");
}

private void SolarVoltageUpdated(object sender, IChangeResult<Voltage> e)
{
Resolver.Log.Info($"Solar Voltage: {e.New.Volts:0.#} volts");
Resolver.Log.Info($"Solar Voltage: {e.New.Volts:0.#} volts");
}

private void BatteryVoltageUpdated(object sender, IChangeResult<Voltage> e)
Expand All @@ -177,22 +212,17 @@ private void BatteryVoltageUpdated(object sender, IChangeResult<Voltage> e)

private void AnemometerUpdated(object sender, IChangeResult<Speed> e)
{
Resolver.Log.Info($"Anemometer: {e.New.MetersPerSecond:0.#} m/s");
Resolver.Log.Info($"Anemometer: {e.New.MetersPerSecond:0.#} m/s");
}

private void RainGuageUpdated(object sender, IChangeResult<Length> e)
{
Resolver.Log.Info($"Rain Gauge: {e.New.Millimeters:0.#} mm");
Resolver.Log.Info($"Rain Gauge: {e.New.Millimeters:0.#} mm");
}

private void WindvaneUpdated(object sender, IChangeResult<Azimuth> e)
{
Resolver.Log.Info($"Wind Vane: {e.New.Compass16PointCardinalName} ({e.New.Radians:0.#} radians)");
}

private void Scd40Updated(object sender, IChangeResult<(Concentration? Concentration, Temperature? Temperature, RelativeHumidity? Humidity)> e)
{
Resolver.Log.Info($"SCD40: {e.New.Concentration.Value.PartsPerMillion:0.#}ppm, {e.New.Temperature.Value.Celsius:0.0}C, {e.New.Humidity.Value.Percent:0.0}%");
Resolver.Log.Info($"Wind Vane: {e.New.Compass16PointCardinalName} ({e.New.Radians:0.#} radians)");
}
}
}
33 changes: 30 additions & 3 deletions Source/Meadow.Clima/Clima.cs
@@ -1,4 +1,5 @@
using Meadow.Hardware;
using Meadow.Foundation.ICs.IOExpanders;
using Meadow.Hardware;
using Meadow.Logging;
using System;

Expand Down Expand Up @@ -44,8 +45,34 @@ public static IClimaHardware Create()
}
else if (device is IF7CoreComputeMeadowDevice { } ccm)
{
logger?.Info("Instantiating Clima v3 specific hardware");
hardware = new ClimaHardwareV3(ccm, i2cBus);
Mcp23008? mcpVersion = null;
byte version = 0;

try
{
logger?.Info("Instantiating version MCP23008");

var resetPort = ccm.Pins.D02.CreateDigitalOutputPort();

mcpVersion = new Mcp23008(i2cBus, address: 0x27, resetPort: resetPort);

version = mcpVersion.ReadFromPorts();
}
catch
{
logger?.Info("Failed to instantiate version MCP23008");
}

if (version > 4)
{
logger?.Info("Instantiating Clima v4 specific hardware");
hardware = new ClimaHardwareV4(ccm, i2cBus, mcpVersion!);
}
else
{
logger?.Info("Instantiating Clima v3 specific hardware");
hardware = new ClimaHardwareV3(ccm, i2cBus, mcpVersion!);
}
}
else
{
Expand Down

0 comments on commit 8edaeef

Please sign in to comment.