Skip to content

Commit 58ae779

Browse files
authored
Merge pull request #98 from doingnz/add-OffsetToNorth-WindDirection-Calibration
Add config option to calibrate WindDirection
2 parents 478e236 + c621742 commit 58ae779

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

Source/Clima_Demo/app.config.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,8 @@ MeadowCloud:
3030

3131
# How often to send metrics to Meadow.Cloud
3232
HealthMetricsIntervalMinutes: 5
33+
34+
35+
# Settings for Clima
36+
Clima:
37+
OffsetToNorth: 0.0

Source/Meadow.Clima/Controllers/SensorController.cs

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using Meadow.Units;
44
using System;
55
using System.Threading.Tasks;
6+
using YamlDotNet.Core.Tokens;
67

78
namespace Meadow.Devices.Clima.Controllers;
89

@@ -33,6 +34,14 @@ public SensorController(IClimaHardware clima)
3334
{
3435
latestData = new SensorData();
3536
this.clima = clima;
37+
38+
if (Resolver.App.Settings.TryGetValue("Clima.OffsetToNorth", out string offsetToNorthSetting))
39+
{
40+
if (Double.TryParse(offsetToNorthSetting, out double trueNorth))
41+
{
42+
OffsetToNorth = new Azimuth(trueNorth);
43+
}
44+
}
3645
}
3746

3847
/// <summary>
@@ -218,15 +227,33 @@ private void RainGaugeUpdated(object sender, IChangeResult<Length> e)
218227
Resolver.Log.InfoIf(LogSensorData, $"Rain Gauge: {e.New.Millimeters:0.#} mm");
219228
}
220229

230+
/// <summary>
231+
/// 0 to 360 degree offset to true north updated from app.config.yaml
232+
/// </summary>
233+
/// <remarks>
234+
/// After install of Clima, point wind vane at true north, run Clima_Demo and record uncalibrated WindDirection.
235+
/// Update app.config.yaml with the uncalibrated WindDirection.
236+
/// Deploy the updated app.config.yaml and this direction will be reported as 0 Degrees.
237+
/// </remarks>
238+
/// <example>
239+
/// # Settings for Clima
240+
/// Clima:
241+
/// OffsetToNorth: 0.0
242+
/// </example>
243+
public Azimuth OffsetToNorth { get; private set; } = new Azimuth(0.0);
244+
221245
private void WindvaneUpdated(object sender, IChangeResult<Azimuth> e)
222246
{
223-
windVaneBuffer.Append(e.New);
247+
Azimuth newAzimuth = e.New - OffsetToNorth;
248+
windVaneBuffer.Append(newAzimuth);
249+
250+
Azimuth mean = windVaneBuffer.Mean();
224251

225252
lock (latestData)
226253
{
227-
latestData.WindDirection = windVaneBuffer.Mean();
254+
latestData.WindDirection = mean;
228255
}
229256

230-
Resolver.Log.InfoIf(LogSensorData, $"Wind Vane: {e.New.DecimalDegrees} (mean: {windVaneBuffer.Mean().DecimalDegrees})");
257+
Resolver.Log.InfoIf(LogSensorData, $"Wind Vane: {newAzimuth}, Average: {mean.DecimalDegrees} (uncalibrated: {e.New})");
231258
}
232259
}

0 commit comments

Comments
 (0)