From ebd97e04eb68baaf0afdfd71412d9b041985a5f7 Mon Sep 17 00:00:00 2001 From: Adrian Stevens Date: Tue, 23 Jul 2024 22:26:54 -0700 Subject: [PATCH] Fix type of BH1745 (remove IsValid bool) --- .../Sensors.Light.Bh1745/Driver/Bh1745.cs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Light.Bh1745/Driver/Bh1745.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Light.Bh1745/Driver/Bh1745.cs index 7f49b0aa3c..0d2260769c 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Light.Bh1745/Driver/Bh1745.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Light.Bh1745/Driver/Bh1745.cs @@ -11,7 +11,7 @@ namespace Meadow.Foundation.Sensors.Light /// Represents a BH1745 Luminance and Color Sensor /// public partial class Bh1745 - : ByteCommsSensorBase<(Illuminance? AmbientLight, Color? Color, bool Valid)>, + : ByteCommsSensorBase<(Illuminance? AmbientLight, Color? Color)>, ILightSensor, II2cPeripheral { private event EventHandler> _lightHandlers = default!; @@ -260,15 +260,22 @@ public Bh1745(II2cBus i2cBus, byte address = (byte)Addresses.Default) /// Reads data from the sensor /// /// The latest sensor reading - protected override Task<(Illuminance? AmbientLight, Color? Color, bool Valid)> ReadSensor() + protected override Task<(Illuminance? AmbientLight, Color? Color)> ReadSensor() { - (Illuminance? AmbientLight, Color? Color, bool Valid) conditions; + (Illuminance? AmbientLight, Color? Color) conditions; // get the ambient light var clearData = ReadClearDataRegister(); if (clearData == 0) { conditions.Color = Color.Black; } + if (ReadMeasurementIsValid() == false) + { + conditions.AmbientLight = null; + conditions.Color = null; + return Task.FromResult(conditions); + } + // apply channel multipliers and normalize double compensatedRed = ReadRedDataRegister() * CompensationMultipliers.Red / (int)MeasurementTime * 360; double compensatedGreen = ReadGreenDataRegister() * CompensationMultipliers.Green / (int)MeasurementTime * 360; @@ -284,8 +291,6 @@ public Bh1745(II2cBus i2cBus, byte address = (byte)Addresses.Default) conditions.AmbientLight = new Illuminance(compensatedClear, Units.Illuminance.UnitType.Lux); - conditions.Valid = ReadMeasurementIsValid(); - return Task.FromResult(conditions); } @@ -293,7 +298,7 @@ public Bh1745(II2cBus i2cBus, byte address = (byte)Addresses.Default) /// Raise events for subscribers and notify of value changes /// /// The updated sensor data - protected override void RaiseEventsAndNotify(IChangeResult<(Illuminance? AmbientLight, Color? Color, bool Valid)> changeResult) + protected override void RaiseEventsAndNotify(IChangeResult<(Illuminance? AmbientLight, Color? Color)> changeResult) { if (changeResult.New.AmbientLight is { } ambient) {