Skip to content

Commit

Permalink
Update Solar and Mass sensors
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianstevens committed Dec 11, 2023
1 parent 161bdb9 commit a1dba03
Show file tree
Hide file tree
Showing 9 changed files with 6 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ namespace Meadow.Foundation.Sensors.Light
/// </summary>
public class AnalogSolarIntensityGauge : SamplingSensorBase<float>, ISolarIntensityGauge, IDisposable

Check failure on line 13 in Source/Meadow.Foundation.Peripherals/Sensors.Light.AnalogSolarIntensityGauge/Driver/AnalogSolarIntensityGauge.cs

View workflow job for this annotation

GitHub Actions / build

'AnalogSolarIntensityGauge' does not implement interface member 'ISolarIntensityGauge.SolarIntensityUpdated'

Check failure on line 13 in Source/Meadow.Foundation.Peripherals/Sensors.Light.AnalogSolarIntensityGauge/Driver/AnalogSolarIntensityGauge.cs

View workflow job for this annotation

GitHub Actions / build

'AnalogSolarIntensityGauge' does not implement interface member 'ISolarIntensityGauge.SolarIntensityUpdated'
{
/// <summary>
/// Raised when the solar intensity changes
/// </summary>
public event EventHandler<IChangeResult<float>> SolarIntensityUpdated = default!;

readonly IAnalogInputPort analogInputPort;

/// <summary>
Expand Down Expand Up @@ -150,16 +145,6 @@ public override void StopUpdating()
analogInputPort.StopUpdating();
}

/// <summary>
/// Raise events for subscribers and notify of value changes
/// </summary>
/// <param name="changeResult">The updated sensor data</param>
protected override void RaiseEventsAndNotify(IChangeResult<float> changeResult)
{
this.SolarIntensityUpdated?.Invoke(this, changeResult);
base.RaiseEventsAndNotify(changeResult);
}

/// <summary>
/// Converts a voltage reading to a solar intensity percentage, taking into
/// account the minimum and maximum expected values.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public override Task Initialize()
solarGauge = new AnalogSolarIntensityGauge(Device.Pins.A02, updateInterval: TimeSpan.FromSeconds(1));

//==== classic .NET Event
solarGauge.SolarIntensityUpdated += (s, result) => Resolver.Log.Info($"SolarIntensityUpdated: {result.New * 100:n2}%");
solarGauge.Updated += (s, result) => Resolver.Log.Info($"SolarIntensityUpdated: {result.New * 100:n2}%");

//==== Filterable observer
var observer = AnalogSolarIntensityGauge.CreateObserver(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public override Task Initialize()
solarGauge = new AnalogSolarIntensityGauge(Device.Pins.A02, updateInterval: TimeSpan.FromSeconds(1));

//==== classic .NET Event
solarGauge.SolarIntensityUpdated += (s, result) => Resolver.Log.Info($"SolarIntensityUpdated: {result.New * 100:n2}%");
solarGauge.Updated += (s, result) => Resolver.Log.Info($"SolarIntensityUpdated: {result.New * 100:n2}%");

//==== Filterable observer
var observer = AnalogSolarIntensityGauge.CreateObserver(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,6 @@ public partial class Hx711 : PollingSensorBase<Mass>, IMassSensor, IDisposable
/// </summary>
public uint TareValue { get; set; } = 0;

/// <summary>
/// Mass changed event
/// </summary>
public event EventHandler<IChangeResult<Mass>> MassUpdated = default!;

/// <summary>
/// Gets default sample period (1 Second)
/// </summary>
Expand Down Expand Up @@ -302,24 +297,6 @@ private unsafe uint ReadADC()
return count;
}

/// <summary>
/// Inheritance-safe way to raise events and notify observers.
/// </summary>
/// <param name="changeResult"></param>
protected override void RaiseEventsAndNotify(IChangeResult<Mass> changeResult)
{
try
{
MassUpdated?.Invoke(this, changeResult);
base.RaiseEventsAndNotify(changeResult);
}
catch (Exception ex)
{
Resolver.Log.Info($"HX711 event handler threw: {ex.Message}");
throw;
}
}

/// <summary>
/// Dispose of the object
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public override async Task Initialize()
loadSensor.Tare();
}

loadSensor.MassUpdated += (sender, values) => Resolver.Log.Info($"Mass is now returned {values.New.Grams:N2}g");
loadSensor.Updated += (sender, values) => Resolver.Log.Info($"Mass is now returned {values.New.Grams:N2}g");
}

public override Task Run()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public override async Task Initialize()
loadSensor.Tare();
}

loadSensor.MassUpdated += (sender, values) => Resolver.Log.Info($"Mass is now returned {values.New.Grams:N2}g");
loadSensor.Updated += (sender, values) => Resolver.Log.Info($"Mass is now returned {values.New.Grams:N2}g");
}

public override Task Run()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ namespace Meadow.Foundation.Sensors.LoadCell
/// </summary>
public partial class Nau7802 : ByteCommsSensorBase<Mass>, IMassSensor, II2cPeripheral

Check failure on line 13 in Source/Meadow.Foundation.Peripherals/Sensors.LoadCell.Nau7802/Driver/Nau7802.cs

View workflow job for this annotation

GitHub Actions / build

'Nau7802' does not implement interface member 'IMassSensor.MassUpdated'
{
/// <summary>
/// Raised when the mass value changes
/// </summary>
public event EventHandler<IChangeResult<Mass>> MassUpdated = default!;

private readonly byte[] readBuffer = new byte[3];
private double gramsPerAdcUnit = 0;
private PU_CTRL_BITS currentPuCTRL;
Expand Down Expand Up @@ -284,24 +279,5 @@ protected override Task<Mass> ReadSensor()
// convert to desired units
return Task.FromResult(new Mass(grams, Units.Mass.UnitType.Grams));
}


/// <summary>
/// Inheritance-safe way to raise events and notify observers.
/// </summary>
/// <param name="changeResult"></param>
protected override void RaiseEventsAndNotify(IChangeResult<Mass> changeResult)
{
try
{
MassUpdated?.Invoke(this, changeResult);
base.RaiseEventsAndNotify(changeResult);
}
catch (Exception ex)
{
Resolver.Log.Info($"NAU7802 event handler threw: {ex.Message}");
throw;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public override async Task Initialize()
loadSensor.Tare();
}

loadSensor.MassUpdated += (sender, values) => Resolver.Log.Info($"Mass is now returned {values.New.Grams:N2}g");
loadSensor.Updated += (sender, values) => Resolver.Log.Info($"Mass is now returned {values.New.Grams:N2}g");
}

public override Task Run()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public override async Task Initialize()
loadSensor.Tare();
}

loadSensor.MassUpdated += (sender, values) => Resolver.Log.Info($"Mass is now returned {values.New.Grams:N2}g");
loadSensor.Updated += (sender, values) => Resolver.Log.Info($"Mass is now returned {values.New.Grams:N2}g");
}

public override Task Run()
Expand Down

0 comments on commit a1dba03

Please sign in to comment.