Remarks
WindVane | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
Code Example
WindVane windVane;
public override Task Initialize()
{
Resolver.Log.Info("Initialize...");
// initialize the wind vane driver
windVane = new WindVane(Device.Pins.A00);
//==== Classic event example:
windVane.Updated += (sender, result) => Resolver.Log.Info($"Updated event {result.New.DecimalDegrees}");
//==== IObservable Pattern
var observer = WindVane.CreateObserver(
handler: result => Resolver.Log.Info($"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();
Resolver.Log.Info($"Initial azimuth: {azi.Compass16PointCardinalName}");
// start updating
windVane.StartUpdating(TimeSpan.FromSeconds(1));
}
Sample project(s) available on GitHub
Syntax
public class WindVane : SamplingSensorBase<Azimuth>, IObservable<IChangeResult<Azimuth>>, IWindVane, ISamplingSensor<Azimuth>, ISensor<Azimuth>
Constructors
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 |
Remarks
WindVane | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
Code Example
WindVane windVane;
public override Task Initialize()
{
Resolver.Log.Info("Initialize...");
// initialize the wind vane driver
windVane = new WindVane(Device.Pins.A00);
//==== Classic event example:
windVane.Updated += (sender, result) => Resolver.Log.Info($"Updated event {result.New.DecimalDegrees}");
//==== IObservable Pattern
var observer = WindVane.CreateObserver(
handler: result => Resolver.Log.Info($"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();
Resolver.Log.Info($"Initial azimuth: {azi.Compass16PointCardinalName}");
// start updating
windVane.StartUpdating(TimeSpan.FromSeconds(1));
}
WindVane(IPin, IDictionary<Voltage, Azimuth>, TimeSpan?, int, TimeSpan?)
Creates a new WindVane
on the specified IO Device's analog input
Optionally, with a custom voltage to azimuth lookup
Declaration
public WindVane(IPin analogInputPin, IDictionary<Voltage, Azimuth> azimuthVoltages = null, TimeSpan? updateInterval = null, int sampleCount = 1, TimeSpan? sampleInterval = null)
Parameters
Type | Name | Description |
---|---|---|
IPin | analogInputPin | The analog input pin |
IDictionary<Voltage, Azimuth> | azimuthVoltages | Optional - Supply if you have custom azimuth voltages |
TimeSpan? | updateInterval | The sensor update interval |
int | sampleCount | Sample couple |
TimeSpan? | sampleInterval | Sample interval |
Remarks
WindVane | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
Code Example
WindVane windVane;
public override Task Initialize()
{
Resolver.Log.Info("Initialize...");
// initialize the wind vane driver
windVane = new WindVane(Device.Pins.A00);
//==== Classic event example:
windVane.Updated += (sender, result) => Resolver.Log.Info($"Updated event {result.New.DecimalDegrees}");
//==== IObservable Pattern
var observer = WindVane.CreateObserver(
handler: result => Resolver.Log.Info($"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();
Resolver.Log.Info($"Initial azimuth: {azi.Compass16PointCardinalName}");
// start updating
windVane.StartUpdating(TimeSpan.FromSeconds(1));
}
Properties
AzimuthVoltages
Voltage -> wind azimuth lookup dictionary
Declaration
public ReadOnlyDictionary<Voltage, Azimuth> AzimuthVoltages { get; protected set; }
Property Value
Type | Description |
---|---|
ReadOnlyDictionary<Voltage, Azimuth> |
Remarks
WindVane | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
Code Example
WindVane windVane;
public override Task Initialize()
{
Resolver.Log.Info("Initialize...");
// initialize the wind vane driver
windVane = new WindVane(Device.Pins.A00);
//==== Classic event example:
windVane.Updated += (sender, result) => Resolver.Log.Info($"Updated event {result.New.DecimalDegrees}");
//==== IObservable Pattern
var observer = WindVane.CreateObserver(
handler: result => Resolver.Log.Info($"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();
Resolver.Log.Info($"Initial azimuth: {azi.Compass16PointCardinalName}");
// start updating
windVane.StartUpdating(TimeSpan.FromSeconds(1));
}
SampleCount
Number of samples to take per reading. Default is 2
Declaration
public int SampleCount { get; set; }
Property Value
Type | Description |
---|---|
int |
Remarks
WindVane | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
Code Example
WindVane windVane;
public override Task Initialize()
{
Resolver.Log.Info("Initialize...");
// initialize the wind vane driver
windVane = new WindVane(Device.Pins.A00);
//==== Classic event example:
windVane.Updated += (sender, result) => Resolver.Log.Info($"Updated event {result.New.DecimalDegrees}");
//==== IObservable Pattern
var observer = WindVane.CreateObserver(
handler: result => Resolver.Log.Info($"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();
Resolver.Log.Info($"Initial azimuth: {azi.Compass16PointCardinalName}");
// start updating
windVane.StartUpdating(TimeSpan.FromSeconds(1));
}
SampleInterval
Duration of time between samples (default is 40ms)
Declaration
public TimeSpan SampleInterval { get; set; }
Property Value
Type | Description |
---|---|
TimeSpan |
Remarks
WindVane | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
Code Example
WindVane windVane;
public override Task Initialize()
{
Resolver.Log.Info("Initialize...");
// initialize the wind vane driver
windVane = new WindVane(Device.Pins.A00);
//==== Classic event example:
windVane.Updated += (sender, result) => Resolver.Log.Info($"Updated event {result.New.DecimalDegrees}");
//==== IObservable Pattern
var observer = WindVane.CreateObserver(
handler: result => Resolver.Log.Info($"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();
Resolver.Log.Info($"Initial azimuth: {azi.Compass16PointCardinalName}");
// start updating
windVane.StartUpdating(TimeSpan.FromSeconds(1));
}
WindAzimuth
The last recorded azimuth of the wind
Declaration
public Azimuth? WindAzimuth { get; protected set; }
Property Value
Type | Description |
---|---|
Azimuth? |
Remarks
WindVane | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
Code Example
WindVane windVane;
public override Task Initialize()
{
Resolver.Log.Info("Initialize...");
// initialize the wind vane driver
windVane = new WindVane(Device.Pins.A00);
//==== Classic event example:
windVane.Updated += (sender, result) => Resolver.Log.Info($"Updated event {result.New.DecimalDegrees}");
//==== IObservable Pattern
var observer = WindVane.CreateObserver(
handler: result => Resolver.Log.Info($"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();
Resolver.Log.Info($"Initial azimuth: {azi.Compass16PointCardinalName}");
// start updating
windVane.StartUpdating(TimeSpan.FromSeconds(1));
}
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> |
Remarks
WindVane | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
Code Example
WindVane windVane;
public override Task Initialize()
{
Resolver.Log.Info("Initialize...");
// initialize the wind vane driver
windVane = new WindVane(Device.Pins.A00);
//==== Classic event example:
windVane.Updated += (sender, result) => Resolver.Log.Info($"Updated event {result.New.DecimalDegrees}");
//==== IObservable Pattern
var observer = WindVane.CreateObserver(
handler: result => Resolver.Log.Info($"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();
Resolver.Log.Info($"Initial azimuth: {azi.Compass16PointCardinalName}");
// start updating
windVane.StartUpdating(TimeSpan.FromSeconds(1));
}
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 |
Remarks
WindVane | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
Code Example
WindVane windVane;
public override Task Initialize()
{
Resolver.Log.Info("Initialize...");
// initialize the wind vane driver
windVane = new WindVane(Device.Pins.A00);
//==== Classic event example:
windVane.Updated += (sender, result) => Resolver.Log.Info($"Updated event {result.New.DecimalDegrees}");
//==== IObservable Pattern
var observer = WindVane.CreateObserver(
handler: result => Resolver.Log.Info($"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();
Resolver.Log.Info($"Initial azimuth: {azi.Compass16PointCardinalName}");
// start updating
windVane.StartUpdating(TimeSpan.FromSeconds(1));
}
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 |
Remarks
WindVane | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
Code Example
WindVane windVane;
public override Task Initialize()
{
Resolver.Log.Info("Initialize...");
// initialize the wind vane driver
windVane = new WindVane(Device.Pins.A00);
//==== Classic event example:
windVane.Updated += (sender, result) => Resolver.Log.Info($"Updated event {result.New.DecimalDegrees}");
//==== IObservable Pattern
var observer = WindVane.CreateObserver(
handler: result => Resolver.Log.Info($"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();
Resolver.Log.Info($"Initial azimuth: {azi.Compass16PointCardinalName}");
// start updating
windVane.StartUpdating(TimeSpan.FromSeconds(1));
}
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
Remarks
WindVane | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
Code Example
WindVane windVane;
public override Task Initialize()
{
Resolver.Log.Info("Initialize...");
// initialize the wind vane driver
windVane = new WindVane(Device.Pins.A00);
//==== Classic event example:
windVane.Updated += (sender, result) => Resolver.Log.Info($"Updated event {result.New.DecimalDegrees}");
//==== IObservable Pattern
var observer = WindVane.CreateObserver(
handler: result => Resolver.Log.Info($"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();
Resolver.Log.Info($"Initial azimuth: {azi.Compass16PointCardinalName}");
// start updating
windVane.StartUpdating(TimeSpan.FromSeconds(1));
}
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 override void StartUpdating(TimeSpan? updateInterval)
Parameters
Type | Name | Description |
---|---|---|
TimeSpan? | updateInterval | A |
Overrides
Remarks
WindVane | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
Code Example
WindVane windVane;
public override Task Initialize()
{
Resolver.Log.Info("Initialize...");
// initialize the wind vane driver
windVane = new WindVane(Device.Pins.A00);
//==== Classic event example:
windVane.Updated += (sender, result) => Resolver.Log.Info($"Updated event {result.New.DecimalDegrees}");
//==== IObservable Pattern
var observer = WindVane.CreateObserver(
handler: result => Resolver.Log.Info($"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();
Resolver.Log.Info($"Initial azimuth: {azi.Compass16PointCardinalName}");
// start updating
windVane.StartUpdating(TimeSpan.FromSeconds(1));
}
StopUpdating()
Stops sampling the sensor
Declaration
public override void StopUpdating()
Overrides
Remarks
WindVane | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
Code Example
WindVane windVane;
public override Task Initialize()
{
Resolver.Log.Info("Initialize...");
// initialize the wind vane driver
windVane = new WindVane(Device.Pins.A00);
//==== Classic event example:
windVane.Updated += (sender, result) => Resolver.Log.Info($"Updated event {result.New.DecimalDegrees}");
//==== IObservable Pattern
var observer = WindVane.CreateObserver(
handler: result => Resolver.Log.Info($"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();
Resolver.Log.Info($"Initial azimuth: {azi.Compass16PointCardinalName}");
// start updating
windVane.StartUpdating(TimeSpan.FromSeconds(1));
}