Characteristic Locus
Inheritance System.Object FilterableChangeObservableBase<WindVane.WindVaneChangeResult, Azimuth> > WindVane
Implements System.IObservable<WindVane.WindVaneChangeResult>
Inherited Members FilterableChangeObservableBase<WindVane.WindVaneChangeResult, Azimuth>._observers FilterableChangeObservableBase<WindVane.WindVaneChangeResult, Azimuth>.NotifyObservers(WindVane.WindVaneChangeResult) FilterableChangeObservableBase<WindVane.WindVaneChangeResult, Azimuth>.Subscribe(IObserver<WindVane.WindVaneChangeResult>) System.Object.ToString() System.Object.Equals(System.Object) System.Object.Equals(System.Object, System.Object) System.Object.ReferenceEquals(System.Object, System.Object) System.Object.GetHashCode() System.Object.GetType() System.Object.MemberwiseClone()
Namespace Meadow.Foundation.Sensors.Weather
Assembly WindVane.dll

Syntax

public class WindVane : FilterableChangeObservableBase<WindVane.WindVaneChangeResult, Azimuth>, IObservable<WindVane.WindVaneChangeResult>

Constructors

WindVane(IAnalogInputPort, IDictionary<Single, Azimuth>)

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

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

Parameters

Type Name Description
IAnalogInputPort inputPort

The analog input.

System.Collections.Generic.IDictionary<System.Single, Azimuth> azimuthVoltages

Optional. Supply if you have custom azimuth voltages.

WindVane(IIODevice, IPin, IDictionary<Single, Azimuth>)

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

Declaration
public WindVane(IIODevice device, IPin analogInputPin, IDictionary<float, Azimuth> azimuthVoltages = null)

Parameters

Type Name Description
IIODevice device

The IO Device.

IPin analogInputPin

The analog input pin.

System.Collections.Generic.IDictionary<System.Single, Azimuth> azimuthVoltages

Optional. Supply if you have custom azimuth voltages.

Fields

inputPort

Declaration
protected IAnalogInputPort inputPort

Field Value

Type Description
IAnalogInputPort

Properties

AzimuthVoltages

Voltage -> wind azimuth lookup dictionary.

Declaration
public IDictionary<float, Azimuth> AzimuthVoltages { get; protected set; }

Property Value

Type Description
System.Collections.Generic.IDictionary<System.Single, Azimuth>

LastRecordedWindAzimuth

The last recorded azimuth of the wind.

Declaration
public Azimuth LastRecordedWindAzimuth { get; protected set; }

Property Value

Type Description
Azimuth

Methods

HandleAnalogUpdate(FloatChangeResult)

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

Declaration
protected void HandleAnalogUpdate(FloatChangeResult result)

Parameters

Type Name Description
FloatChangeResult result

Init()

Declaration
protected void Init()

LoadDefaultAzimuthVoltages()

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

Declaration
protected void LoadDefaultAzimuthVoltages()

LookupWindDirection(Single)

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

Declaration
protected Azimuth LookupWindDirection(float voltage)

Parameters

Type Name Description
System.Single voltage

Returns

Type Description
Azimuth

RaiseUpdated(WindVane.WindVaneChangeResult)

Thread and inheritance safe way to raise the event and notify subs

Declaration
protected void RaiseUpdated(WindVane.WindVaneChangeResult changeResult)

Parameters

Type Name Description
WindVane.WindVaneChangeResult changeResult

Read(Int32, Int32)

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

Declaration
public Task<Azimuth> Read(int sampleCount = 5, int sampleIntervalDuration = 20)

Parameters

Type Name Description
System.Int32 sampleCount

The number of sample readings to take. Must be greater than 0. These samples are automatically averaged.

System.Int32 sampleIntervalDuration

The time, in milliseconds, to wait in between samples during a reading.

Returns

Type Description
System.Threading.Tasks.Task<Azimuth>

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

StartUpdating(Int32, Int32, Int32)

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(int sampleCount = 5, int sampleIntervalDuration = 20, int standbyDuration = 500)

Parameters

Type Name Description
System.Int32 sampleCount

How many samples to take during a given reading. These are automatically averaged to reduce noise.

System.Int32 sampleIntervalDuration

The time, in milliseconds, to wait in between samples during a reading.

System.Int32 standbyDuration

The time, in milliseconds, to wait between sets of sample readings. This value determines how often Changed events are raised and IObservable consumers are notified.

StopUpdating()

Stops sampling the temperature.

Declaration
public void StopUpdating()

Events

Updated

Raised when the azimuth of the wind changes.

Declaration
public event EventHandler<WindVane.WindVaneChangeResult> Updated

Event Type

Type Description
System.EventHandler<WindVane.WindVaneChangeResult>