Remarks

WindVane
Status Status badge: working
Source code GitHub
Datasheet(s) GitHub
NuGet package NuGet Gallery for Meadow.Foundation.Sensors.Weather.WindVane

Code Example

WindVane windVane;

public override Task Initialize()
{
    Console.WriteLine("Initialize...");

    // initialize the wind vane driver
    windVane = new WindVane(Device, Device.Pins.A00);

    //==== Classic event example:
    windVane.Updated += (sender, result) => Console.WriteLine($"Updated event {result.New.DecimalDegrees}");

    //==== IObservable Pattern
    var observer = WindVane.CreateObserver(
        handler: result => Console.WriteLine($"Wind Direction: {result.New.Compass16PointCardinalName}"),
        filter: null
    );
    windVane.Subscribe(observer);

    return Task.CompletedTask;
}

public override async Task Run()
{
    // get initial reading, just to test the API
    Azimuth azi = await windVane.Read();
    Console.WriteLine($"Initial azimuth: {azi.Compass16PointCardinalName}");

    // start updating
    windVane.StartUpdating(TimeSpan.FromSeconds(1));
}

Sample project(s) available on GitHub

Characteristic Locus
Inheritance System.Object ObservableBase<Azimuth> SensorBase<Azimuth> > WindVane
Implements IWindVane
Inherited Members SensorBase<Azimuth>.Updated SensorBase<Azimuth>.samplingLock SensorBase<Azimuth>.SamplingTokenSource SensorBase<Azimuth>.Conditions SensorBase<Azimuth>.IsSampling SensorBase<Azimuth>.UpdateInterval SensorBase<Azimuth>.RaiseEventsAndNotify(IChangeResult<>) SensorBase<Azimuth>.Read() ObservableBase<Azimuth>.observers ObservableBase<Azimuth>.NotifyObservers(IChangeResult<>) Meadow.Foundation.ObservableBase<Azimuth>.Subscribe(IObserver<>) Meadow.Foundation.ObservableBase<Azimuth>.CreateObserver(Action<>, System.Nullable<Predicate<IChangeResult<UNIT>>>)
Namespace Meadow.Foundation.Sensors.Weather
Assembly WindVane.dll

Syntax

public class WindVane : SensorBase<Azimuth>, IWindVane

Constructors

WindVane(IAnalogInputController, IPin, IDictionary<Voltage, Azimuth>, Nullable<TimeSpan>, Int32, Nullable<TimeSpan>)

Creates a new WindVane on the specified IO Device's analog input Optionally, with a custom voltage to azimuth lookup

Declaration
public WindVane(IAnalogInputController device, IPin analogInputPin, IDictionary<Voltage, Azimuth> azimuthVoltages = null, TimeSpan? updateInterval = null, int sampleCount = 1, TimeSpan? sampleInterval = null)

Parameters

Type Name Description
IAnalogInputController device

The IO Device

IPin analogInputPin

The analog input pin

IDictionary<Voltage, Azimuth> azimuthVoltages

Optional - Supply if you have custom azimuth voltages

System.Nullable<TimeSpan> updateInterval

The sensor update interval

System.Int32 sampleCount

Sample couple

System.Nullable<TimeSpan> sampleInterval

Sample interval

WindVane(IAnalogInputPort, IDictionary<Voltage, Azimuth>)

Creates a new WindVane on the specified input port. Optionally, with a custom voltage to azimuth lookup.

Declaration
public WindVane(IAnalogInputPort inputPort, IDictionary<Voltage, Azimuth> azimuthVoltages = null)

Parameters

Type Name Description
IAnalogInputPort inputPort

The analog input

IDictionary<Voltage, Azimuth> azimuthVoltages

Optional. Supply if you have custom azimuth voltages

Properties

AzimuthVoltages

Voltage -> wind azimuth lookup dictionary

Declaration
public ReadOnlyDictionary<Voltage, Azimuth> AzimuthVoltages { get; protected set; }

Property Value

Type Description
ReadOnlyDictionary<Voltage, Azimuth>

SampleCount

Number of samples to take per reading. Default is 2

Declaration
public int SampleCount { get; set; }

Property Value

Type Description
System.Int32

SampleInterval

Duration of time between samples (default is 40ms)

Declaration
public TimeSpan SampleInterval { get; set; }

Property Value

Type Description
TimeSpan

WindAzimuth

The last recorded azimuth of the wind

Declaration
public Azimuth? WindAzimuth { get; protected set; }

Property Value

Type Description
System.Nullable<Azimuth>

Methods

GetDefaultAzimuthVoltages()

Loads a default set of voltage -> azimuth lookup values based on a 4.7kΩ / 1kΩ voltage divider

Declaration
protected ReadOnlyDictionary<Voltage, Azimuth> GetDefaultAzimuthVoltages()

Returns

Type Description
ReadOnlyDictionary<Voltage, Azimuth>

HandleAnalogUpdate(IChangeResult<Voltage>)

Takes the analog reading and converts to the wind azimuth, then raises the event/updates subscribers

Declaration
protected void HandleAnalogUpdate(IChangeResult<Voltage> result)

Parameters

Type Name Description
IChangeResult<Voltage> result

LookupWindDirection(Voltage)

Finds the closest wind azimuth that matches the passed in voltage, based on the AziumuthVoltages

Declaration
protected Azimuth LookupWindDirection(Voltage voltage)

Parameters

Type Name Description
Voltage voltage

The voltage

Returns

Type Description
Azimuth

The Azimuth value

ReadSensor()

Convenience method to get the current wind azimuth. For frequent reads, use StartSampling() and StopSampling() in conjunction with the SampleBuffer

Declaration
protected override Task<Azimuth> ReadSensor()

Returns

Type Description
Task<Azimuth>

A float value that's an average value of all the samples taken

Overrides

Meadow.Foundation.SensorBase<Azimuth>.ReadSensor()

StartUpdating(TimeSpan)

Starts continuously sampling the sensor.

This method also starts raising Updated events and IObservable subscribers getting notified. Use the standbyDuration parameter to specify how often events and notifications are raised/sent.

Declaration
public void StartUpdating(TimeSpan updateInterval)

Parameters

Type Name Description
TimeSpan updateInterval

A TimeSpan that specifies how long to wait between readings. This value influences how often *Updated events are raised and IObservable consumers are notified. The default is 5 seconds.

StopUpdating()

Stops sampling the sensor

Declaration
public void StopUpdating()