Meadow.Foundation.Sensors.Weather.SwitchingRainGauge
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.D14);
//==== 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
Class SwitchingRainGauge
Represents a simple switching rain gauge
Assembly: RainGauge.dll
View Source
public class SwitchingRainGauge : SamplingSensorBase<Length>, IObservable<IChangeResult<Length>>, IRainGauge, ISamplingSensor<Length>, ISensor<Length>, ISensor, ISamplingSensor, IDisposable
Inheritance: System.Object
-> Meadow.Foundation.ObservableBase<UNIT>
Implements:
System.IObservable<Meadow.IChangeResult<Meadow.Units.Length>>
, Meadow.Peripherals.Sensors.Weather.IRainGauge
, Meadow.Peripherals.Sensors.ISamplingSensor<Meadow.Units.Length>
, Meadow.Peripherals.Sensors.ISensor<Meadow.Units.Length>
, Meadow.Peripherals.Sensors.ISensor
, Meadow.Peripherals.Sensors.ISamplingSensor
, System.IDisposable
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
View Source
public int ClickCount { get; protected set; }
RainDepth
The total accumulated rain depth
View Source
public Length RainDepth { get; }
DepthPerClick
The amount of rain recorded per rain-gauge event
View Source
public Length DepthPerClick { get; set; }
IsDisposed
Is the object disposed
View Source
public bool IsDisposed { get; }
Methods
Reset()
Reset the rain height
View Source
public void Reset()
StartUpdating(TimeSpan?)
Start the sensor
View Source
public override void StartUpdating(TimeSpan? updateInterval = null)
Parameters
Type | Name |
---|---|
System.Nullable<System.TimeSpan> | updateInterval |
StopUpdating()
Stops sampling the sensor
View Source
public override void StopUpdating()
ReadSensor()
Convenience method to get the current rain depth
View Source
protected override Task<Length> ReadSensor()
Returns
System.Threading.Tasks.Task<Meadow.Units.Length>
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
View Source
public void Dispose()
Dispose(bool)
Dispose of the object
View Source
protected virtual void Dispose(bool disposing)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | disposing | Is disposing |
Implements
System.IObservable<Meadow.IChangeResult<Meadow.Units.Length>>
Meadow.Peripherals.Sensors.Weather.IRainGauge
Meadow.Peripherals.Sensors.ISamplingSensor<Meadow.Units.Length>
Meadow.Peripherals.Sensors.ISensor<Meadow.Units.Length>
Meadow.Peripherals.Sensors.ISensor
Meadow.Peripherals.Sensors.ISamplingSensor
System.IDisposable