Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix type of BH1745 (remove IsValid bool) #1054

Merged
merged 1 commit into from
Jul 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading