Remarks
SwitchingRainGauge | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
Code Example
SwitchingRainGauge rainGauge;
public override Task Initialize()
{
Resolver.Log.Info("Initialize...");
// initialize the rain gauge driver
rainGauge = new SwitchingRainGauge(Device.Pins.D15);
//==== Classic event example:
rainGauge.Updated += (sender, result) => Resolver.Log.Info($"Updated event {result.New.Millimeters}mm");
//==== IObservable Pattern
var observer = SwitchingRainGauge.CreateObserver(
handler: result => Resolver.Log.Info($"Rain depth: {result.New.Millimeters}mm"),
filter: null
);
rainGauge.Subscribe(observer);
return Task.CompletedTask;
}
public override async Task Run()
{
// get initial reading, just to test the API - should be 0
Length rainFall = await rainGauge.Read();
Resolver.Log.Info($"Initial depth: {rainFall.Millimeters}mm");
// start the sensor
rainGauge.StartUpdating();
}
Sample project(s) available on GitHub
Characteristic | Locus |
---|---|
Inheritance | System.Object ObservableBase<Length> SamplingSensorBase<Length> > SwitchingRainGauge |
Implements | ISamplingSensor<Length> |
Inherited Members | SamplingSensorBase<Length>.samplingLock SamplingSensorBase<Length>.Updated SamplingSensorBase<Length>.SamplingTokenSource SamplingSensorBase<Length>.Conditions SamplingSensorBase<Length>.IsSampling SamplingSensorBase<Length>.UpdateInterval SamplingSensorBase<Length>.RaiseEventsAndNotify(IChangeResult<>) SamplingSensorBase<Length>.Read() ObservableBase<Length>.observers ObservableBase<Length>.NotifyObservers(IChangeResult<>) Meadow.Foundation.ObservableBase<Length>.Subscribe(IObserver<>) Meadow.Foundation.ObservableBase<Length>.CreateObserver(Action<>, System.Nullable<Predicate<IChangeResult<UNIT>>>) |
Namespace | Meadow.Foundation.Sensors.Weather |
Assembly | RainGauge.dll |
Syntax
public class SwitchingRainGauge : SamplingSensorBase<Length>, ISamplingSensor<Length>
Constructors
SwitchingRainGauge(IDigitalInputPort, Length)
Create a new SwitchingRainGauge object
Declaration
public SwitchingRainGauge(IDigitalInputPort rainSensorPort, Length depthPerClick)
Parameters
Type | Name | Description |
---|---|---|
IDigitalInputPort | rainSensorPort | The port for the rain sensor pin |
Length | depthPerClick | The depth per click |
SwitchingRainGauge(IPin)
Create a new SwitchingRainGauge object with a default depth of 0.2794 per click
Declaration
public SwitchingRainGauge(IPin rainSensorPin)
Parameters
Type | Name | Description |
---|---|---|
IPin | rainSensorPin | The rain sensor pin |
SwitchingRainGauge(IPin, Length)
Create a new SwitchingRainGauge object
Declaration
public SwitchingRainGauge(IPin rainSensorPin, Length depthPerClick)
Parameters
Type | Name | Description |
---|---|---|
IPin | rainSensorPin | The rain sensor pin |
Length | depthPerClick | The depth per click |
Properties
ClickCount
The number of times the rain tilt sensor has triggered This count is multiplied by the depth per click to calculate the rain depth
Declaration
public int ClickCount { get; protected set; }
Property Value
Type | Description |
---|---|
System.Int32 |
DepthPerClick
The amount of rain recorded per raingauge event
Declaration
public Length DepthPerClick { get; set; }
Property Value
Type | Description |
---|---|
Length |
RainDepth
The total accumulated rain depth
Declaration
public Length RainDepth { get; }
Property Value
Type | Description |
---|---|
Length |
Methods
ReadSensor()
Convenience method to get the current rain depth
Declaration
protected override Task<Length> ReadSensor()
Returns
Type | Description |
---|---|
Task<Length> |
Overrides
Meadow.Foundation.SamplingSensorBase<Length>.ReadSensor()
Reset()
Reset the rain height
Declaration
public void Reset()
StartUpdating(Nullable<TimeSpan>)
Start the sensor
Declaration
public override void StartUpdating(TimeSpan? updateInterval = null)
Parameters
Type | Name | Description |
---|---|---|
System.Nullable<TimeSpan> | updateInterval |
StopUpdating()
Stops sampling the sensor
Declaration
public override void StopUpdating()
Overrides
Meadow.Foundation.SamplingSensorBase<Length>.StopUpdating()