SwitchingRainGauge rainGauge;
public override Task Initialize()
{
Resolver.Log.Info("Initialize...");
rainGauge = new SwitchingRainGauge(Device.Pins.D14);
rainGauge.Updated += (sender, result) => Resolver.Log.Info($"Updated event {result.New.Millimeters}mm");
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()
{
Length rainFall = await rainGauge.Read();
Resolver.Log.Info($"Initial depth: {rainFall.Millimeters}mm");
rainGauge.StartUpdating();
}