private Tcs3472x sensor;
public override Task Initialize()
{
Resolver.Log.Info("Initialize...");
sensor = new Tcs3472x(Device.CreateI2cBus());
var consumer = Tcs3472x.CreateObserver(
handler: result => Resolver.Log.Info($"Observer: filter satisfied: {result.New}, old: {result.Old}"),
filter: result =>
{
if (result.Old is { } old)
{
return Math.Abs(result.New.R - old.R) > 50;
}
return false;
});
sensor.Subscribe(consumer);
sensor.Updated += (sender, result) =>
{
Resolver.Log.Info($" Color: {result.New}");
};
return Task.CompletedTask;
}
public override async Task Run()
{
var result = await sensor.Read();
Resolver.Log.Info($"Initial reading: {result}");
sensor.StartUpdating(TimeSpan.FromSeconds(1));
}