From a1dba03df4e2318dd9b91188dcf75e67039e9ae8 Mon Sep 17 00:00:00 2001 From: Adrian Stevens Date: Sun, 10 Dec 2023 17:18:05 -0800 Subject: [PATCH] Update Solar and Mass sensors --- .../Driver/AnalogSolarIntensityGauge.cs | 15 ------------ .../Driver/Readme.md | 2 +- .../MeadowApp.cs | 2 +- .../Sensors.LoadCell.Hx711/Driver/Hx711.cs | 23 ------------------ .../Sensors.LoadCell.Hx711/Driver/Readme.md | 2 +- .../Samples/Hx711_Sample/MeadowApp.cs | 2 +- .../Driver/Nau7802.cs | 24 ------------------- .../Sensors.LoadCell.Nau7802/Driver/Readme.md | 2 +- .../Samples/Nau7802_Sample/MeadowApp.cs | 2 +- 9 files changed, 6 insertions(+), 68 deletions(-) diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Light.AnalogSolarIntensityGauge/Driver/AnalogSolarIntensityGauge.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Light.AnalogSolarIntensityGauge/Driver/AnalogSolarIntensityGauge.cs index d517c01a77..6bc2071b0f 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Light.AnalogSolarIntensityGauge/Driver/AnalogSolarIntensityGauge.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Light.AnalogSolarIntensityGauge/Driver/AnalogSolarIntensityGauge.cs @@ -12,11 +12,6 @@ namespace Meadow.Foundation.Sensors.Light /// public class AnalogSolarIntensityGauge : SamplingSensorBase, ISolarIntensityGauge, IDisposable { - /// - /// Raised when the solar intensity changes - /// - public event EventHandler> SolarIntensityUpdated = default!; - readonly IAnalogInputPort analogInputPort; /// @@ -150,16 +145,6 @@ public override void StopUpdating() analogInputPort.StopUpdating(); } - /// - /// Raise events for subscribers and notify of value changes - /// - /// The updated sensor data - protected override void RaiseEventsAndNotify(IChangeResult changeResult) - { - this.SolarIntensityUpdated?.Invoke(this, changeResult); - base.RaiseEventsAndNotify(changeResult); - } - /// /// Converts a voltage reading to a solar intensity percentage, taking into /// account the minimum and maximum expected values. diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Light.AnalogSolarIntensityGauge/Driver/Readme.md b/Source/Meadow.Foundation.Peripherals/Sensors.Light.AnalogSolarIntensityGauge/Driver/Readme.md index 0e6b9dd5cf..9cda4e57fd 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Light.AnalogSolarIntensityGauge/Driver/Readme.md +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Light.AnalogSolarIntensityGauge/Driver/Readme.md @@ -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( diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Light.AnalogSolarIntensityGauge/Samples/AnalogSolarIntensityGauge_Sample/MeadowApp.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Light.AnalogSolarIntensityGauge/Samples/AnalogSolarIntensityGauge_Sample/MeadowApp.cs index 87c0ecd998..db1f6d8c12 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Light.AnalogSolarIntensityGauge/Samples/AnalogSolarIntensityGauge_Sample/MeadowApp.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Light.AnalogSolarIntensityGauge/Samples/AnalogSolarIntensityGauge_Sample/MeadowApp.cs @@ -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( diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.LoadCell.Hx711/Driver/Hx711.cs b/Source/Meadow.Foundation.Peripherals/Sensors.LoadCell.Hx711/Driver/Hx711.cs index d630dea9ae..6242b5540a 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.LoadCell.Hx711/Driver/Hx711.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.LoadCell.Hx711/Driver/Hx711.cs @@ -49,11 +49,6 @@ public partial class Hx711 : PollingSensorBase, IMassSensor, IDisposable /// public uint TareValue { get; set; } = 0; - /// - /// Mass changed event - /// - public event EventHandler> MassUpdated = default!; - /// /// Gets default sample period (1 Second) /// @@ -302,24 +297,6 @@ private unsafe uint ReadADC() return count; } - /// - /// Inheritance-safe way to raise events and notify observers. - /// - /// - protected override void RaiseEventsAndNotify(IChangeResult changeResult) - { - try - { - MassUpdated?.Invoke(this, changeResult); - base.RaiseEventsAndNotify(changeResult); - } - catch (Exception ex) - { - Resolver.Log.Info($"HX711 event handler threw: {ex.Message}"); - throw; - } - } - /// /// Dispose of the object /// diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.LoadCell.Hx711/Driver/Readme.md b/Source/Meadow.Foundation.Peripherals/Sensors.LoadCell.Hx711/Driver/Readme.md index 2c30d0ef46..78541c2357 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.LoadCell.Hx711/Driver/Readme.md +++ b/Source/Meadow.Foundation.Peripherals/Sensors.LoadCell.Hx711/Driver/Readme.md @@ -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() diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.LoadCell.Hx711/Samples/Hx711_Sample/MeadowApp.cs b/Source/Meadow.Foundation.Peripherals/Sensors.LoadCell.Hx711/Samples/Hx711_Sample/MeadowApp.cs index 5230dd78d1..35687a5c0f 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.LoadCell.Hx711/Samples/Hx711_Sample/MeadowApp.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.LoadCell.Hx711/Samples/Hx711_Sample/MeadowApp.cs @@ -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() diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.LoadCell.Nau7802/Driver/Nau7802.cs b/Source/Meadow.Foundation.Peripherals/Sensors.LoadCell.Nau7802/Driver/Nau7802.cs index 3fc8e35b62..42a71b4824 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.LoadCell.Nau7802/Driver/Nau7802.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.LoadCell.Nau7802/Driver/Nau7802.cs @@ -12,11 +12,6 @@ namespace Meadow.Foundation.Sensors.LoadCell /// public partial class Nau7802 : ByteCommsSensorBase, IMassSensor, II2cPeripheral { - /// - /// Raised when the mass value changes - /// - public event EventHandler> MassUpdated = default!; - private readonly byte[] readBuffer = new byte[3]; private double gramsPerAdcUnit = 0; private PU_CTRL_BITS currentPuCTRL; @@ -284,24 +279,5 @@ protected override Task ReadSensor() // convert to desired units return Task.FromResult(new Mass(grams, Units.Mass.UnitType.Grams)); } - - - /// - /// Inheritance-safe way to raise events and notify observers. - /// - /// - protected override void RaiseEventsAndNotify(IChangeResult changeResult) - { - try - { - MassUpdated?.Invoke(this, changeResult); - base.RaiseEventsAndNotify(changeResult); - } - catch (Exception ex) - { - Resolver.Log.Info($"NAU7802 event handler threw: {ex.Message}"); - throw; - } - } } } \ No newline at end of file diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.LoadCell.Nau7802/Driver/Readme.md b/Source/Meadow.Foundation.Peripherals/Sensors.LoadCell.Nau7802/Driver/Readme.md index 963add8f85..9bec44b176 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.LoadCell.Nau7802/Driver/Readme.md +++ b/Source/Meadow.Foundation.Peripherals/Sensors.LoadCell.Nau7802/Driver/Readme.md @@ -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() diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.LoadCell.Nau7802/Samples/Nau7802_Sample/MeadowApp.cs b/Source/Meadow.Foundation.Peripherals/Sensors.LoadCell.Nau7802/Samples/Nau7802_Sample/MeadowApp.cs index 0fee3cd3f7..fe711dc1ca 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.LoadCell.Nau7802/Samples/Nau7802_Sample/MeadowApp.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.LoadCell.Nau7802/Samples/Nau7802_Sample/MeadowApp.cs @@ -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()