Skip to content

Commit

Permalink
Merge pull request #1054 from WildernessLabs/Bh1745
Browse files Browse the repository at this point in the history
Fix type of BH1745 (remove IsValid bool)
  • Loading branch information
jorgedevs authored Jul 24, 2024
2 parents dd84b68 + ebd97e0 commit e18332b
Showing 1 changed file with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace Meadow.Foundation.Sensors.Light
/// Represents a BH1745 Luminance and Color Sensor
/// </summary>
public partial class Bh1745
: ByteCommsSensorBase<(Illuminance? AmbientLight, Color? Color, bool Valid)>,
: ByteCommsSensorBase<(Illuminance? AmbientLight, Color? Color)>,
ILightSensor, II2cPeripheral
{
private event EventHandler<IChangeResult<Illuminance>> _lightHandlers = default!;
Expand Down Expand Up @@ -260,15 +260,22 @@ public Bh1745(II2cBus i2cBus, byte address = (byte)Addresses.Default)
/// Reads data from the sensor
/// </summary>
/// <returns>The latest sensor reading</returns>
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;
Expand All @@ -284,16 +291,14 @@ 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);
}

/// <summary>
/// Raise events for subscribers and notify of value changes
/// </summary>
/// <param name="changeResult">The updated sensor data</param>
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)
{
Expand Down

0 comments on commit e18332b

Please sign in to comment.