AnalogSolarIntensityGauge solarGauge;
public override Task Initialize()
{
Resolver.Log.Info("Initialize...");
solarGauge = new AnalogSolarIntensityGauge(Device.Pins.A02, updateInterval: TimeSpan.FromSeconds(1));
solarGauge.Updated += (s, result) => Resolver.Log.Info($"SolarIntensityUpdated: {result.New * 100:n2}%");
var observer = AnalogSolarIntensityGauge.CreateObserver(
handler: result => Resolver.Log.Info($"Observer filter satisfied, new intensity: {result.New * 100:n2}%"),
filter: result =>
{
if (result.Old is { } old)
{
return (Math.Abs(result.New - old) > 0.05);
}
return false;
});
solarGauge.Subscribe(observer);
return Task.CompletedTask;
}
public override async Task Run()
{
var result = await solarGauge.Read();
Resolver.Log.Info($"Solar Intensity: {result * 100:n2}%");
solarGauge.StartUpdating(TimeSpan.FromSeconds(1));
}