From f31010d3640a39868990af5b91d518bba953fb94 Mon Sep 17 00:00:00 2001 From: ctacke Date: Sun, 23 Jan 2022 14:33:53 -0600 Subject: [PATCH 1/3] Analog change effects --- .../Sensors/Environmental/AnalogWaterLevel.cs | 2 +- .../Sensors/Hid/AnalogJoystick.cs | 16 +++++++++++----- .../Sensors/Temperature/AnalogTemperature.cs | 8 ++++---- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/Source/Meadow.Foundation.Core/Sensors/Environmental/AnalogWaterLevel.cs b/Source/Meadow.Foundation.Core/Sensors/Environmental/AnalogWaterLevel.cs index 941a07e46c..944fbb5862 100644 --- a/Source/Meadow.Foundation.Core/Sensors/Environmental/AnalogWaterLevel.cs +++ b/Source/Meadow.Foundation.Core/Sensors/Environmental/AnalogWaterLevel.cs @@ -38,7 +38,7 @@ public AnalogWaterLevel( IPin analogPin, Calibration? calibration = null, int updateIntervalMs = 1000) - : this(device.CreateAnalogInputPort(analogPin), calibration) + : this(device.CreateAnalogInputPort(analogPin, 5, TimeSpan.FromMilliseconds(40), new Voltage(3.3, Voltage.UnitType.Volts)), calibration) { base.UpdateInterval = TimeSpan.FromMilliseconds(updateIntervalMs); } diff --git a/Source/Meadow.Foundation.Core/Sensors/Hid/AnalogJoystick.cs b/Source/Meadow.Foundation.Core/Sensors/Hid/AnalogJoystick.cs index a628a3732f..a3826820d3 100644 --- a/Source/Meadow.Foundation.Core/Sensors/Hid/AnalogJoystick.cs +++ b/Source/Meadow.Foundation.Core/Sensors/Hid/AnalogJoystick.cs @@ -78,12 +78,18 @@ public DigitalJoystickPosition? DigitalPosition { /// to wait in between samples during a reading. public AnalogJoystick( IAnalogInputController device, IPin horizontalPin, IPin verticalPin, - JoystickCalibration? calibration = null, bool isInverted = false, - int updateIntervalMs = 1000, - int sampleCount = 5, int sampleIntervalMs = 40) + JoystickCalibration? calibration = null, bool isInverted = false) + : this(device, horizontalPin, verticalPin, calibration, isInverted, 5, TimeSpan.FromMilliseconds(40)) + { } + + public AnalogJoystick( + IAnalogInputController device, IPin horizontalPin, IPin verticalPin, + JoystickCalibration? calibration, bool isInverted, + int sampleCount, + TimeSpan sampleInterval) : this( - device.CreateAnalogInputPort(horizontalPin, updateIntervalMs, sampleCount, sampleIntervalMs), - device.CreateAnalogInputPort(verticalPin, updateIntervalMs, sampleCount, sampleIntervalMs), + device.CreateAnalogInputPort(horizontalPin, sampleCount, sampleInterval, new Voltage(3.3, VU.Volts)), + device.CreateAnalogInputPort(verticalPin, sampleCount, sampleInterval, new Voltage(3.3, VU.Volts)), calibration, isInverted) { } diff --git a/Source/Meadow.Foundation.Core/Sensors/Temperature/AnalogTemperature.cs b/Source/Meadow.Foundation.Core/Sensors/Temperature/AnalogTemperature.cs index e75c1ee070..df8d02114d 100644 --- a/Source/Meadow.Foundation.Core/Sensors/Temperature/AnalogTemperature.cs +++ b/Source/Meadow.Foundation.Core/Sensors/Temperature/AnalogTemperature.cs @@ -114,13 +114,13 @@ public enum KnownSensorType /// Calibration for the analog temperature sensor. Only used if sensorType is set to Custom. /// How many samples to take during a given /// reading. These are automatically averaged to reduce noise. - /// The time, in milliseconds, + /// The time, /// to wait in between samples during a reading. public AnalogTemperature( IAnalogInputController device, IPin analogPin, - KnownSensorType sensorType, Calibration? calibration = null, - int sampleCount = 5, int sampleIntervalMs = 40) - : this(device.CreateAnalogInputPort(analogPin, sampleCount, sampleIntervalMs), + KnownSensorType sensorType, Calibration? calibration, + int sampleCount, TimeSpan sampleInterval) + : this(device.CreateAnalogInputPort(analogPin, sampleCount, sampleInterval, new Voltage(3.3, Voltage.UnitType.Volts)), sensorType, calibration) { } From 08dfae63975c7feaea2bb1004871f517ce4764b5 Mon Sep 17 00:00:00 2001 From: Adrian Stevens Date: Mon, 24 Jan 2022 21:04:27 -0800 Subject: [PATCH 2/3] Analog port unitization updates --- .../MeadowApp.cs | 5 ++- .../ByteCommsSensorBase.cs | 5 +++ .../Sensors/Hid/AnalogJoystick.cs | 19 ++++++---- .../Sensors/Light/AnalogLightSensor.cs | 26 +++---------- .../Sensors/Temperature/AnalogTemperature.cs | 6 +-- .../Driver/Sensors.Distance.Gp2d12/Gp2d12.cs | 2 +- .../MaxBotix.Analog.cs | 11 ++++-- .../Driver/Sensors.Hid.Tsc2004/Tsc2004.cs | 2 +- .../Sensors.Light.Alspt19315C/Alspt19315C.cs | 4 +- .../AnalogSolarGauge.cs | 38 ++++++++++--------- .../AnalogSolarGauge_Sample/MeadowApp.cs | 2 +- .../Driver/Sensors.Light.Temt6000/Temt6000.cs | 4 +- .../Sensors.Moisture.Capacitive/Capacitive.cs | 17 +++++---- .../Driver/Sensors.Moisture.Fc28/Fc28.cs | 14 ++++--- .../Sensors.Motion.Adxl3xx/Adxl3xxBase.cs | 14 ++++--- .../Driver/Sensors.Sound.Ky038/Ky038.cs | 3 +- .../Sensors.Weather.WindVane/WindVane.cs | 7 ++-- 17 files changed, 96 insertions(+), 83 deletions(-) diff --git a/Source/Meadow.Foundation.Core.Samples/Sensors.HID.AnalogJoystick_Sample/MeadowApp.cs b/Source/Meadow.Foundation.Core.Samples/Sensors.HID.AnalogJoystick_Sample/MeadowApp.cs index 01caa001b0..a1e4b8d0fd 100644 --- a/Source/Meadow.Foundation.Core.Samples/Sensors.HID.AnalogJoystick_Sample/MeadowApp.cs +++ b/Source/Meadow.Foundation.Core.Samples/Sensors.HID.AnalogJoystick_Sample/MeadowApp.cs @@ -3,6 +3,7 @@ using Meadow.Devices; using Meadow.Foundation.Sensors.Hid; using Meadow.Peripherals.Sensors.Hid; +using Meadow.Units; namespace MeadowApp { @@ -33,8 +34,8 @@ void Initialize() // these are pretty fast updates (40ms in total), if you need more time to process, you can // increase the sample interval duration and/or standby duration. joystick = new AnalogJoystick( - Device.CreateAnalogInputPort(Device.Pins.A01, 1, 10), - Device.CreateAnalogInputPort(Device.Pins.A00, 1, 10), + Device.CreateAnalogInputPort(Device.Pins.A01, 1, TimeSpan.FromMilliseconds(10), new Voltage(3.3)), + Device.CreateAnalogInputPort(Device.Pins.A00, 1, TimeSpan.FromMilliseconds(10), new Voltage(3.3)), null, false); Console.WriteLine("Hardware initialization complete."); diff --git a/Source/Meadow.Foundation.Core/ByteCommsSensorBase.cs b/Source/Meadow.Foundation.Core/ByteCommsSensorBase.cs index edc5a93ac3..80e460ba9b 100644 --- a/Source/Meadow.Foundation.Core/ByteCommsSensorBase.cs +++ b/Source/Meadow.Foundation.Core/ByteCommsSensorBase.cs @@ -61,6 +61,11 @@ protected ByteCommsSensorBase( Init(readBufferSize, writeBufferSize); } + /// + /// ByteCommsSensorBase abstract ctor with no bus + /// + /// Read buffer size + /// Write buffer size protected ByteCommsSensorBase( int readBufferSize = 8, int writeBufferSize = 8) { diff --git a/Source/Meadow.Foundation.Core/Sensors/Hid/AnalogJoystick.cs b/Source/Meadow.Foundation.Core/Sensors/Hid/AnalogJoystick.cs index a3826820d3..9595e72245 100644 --- a/Source/Meadow.Foundation.Core/Sensors/Hid/AnalogJoystick.cs +++ b/Source/Meadow.Foundation.Core/Sensors/Hid/AnalogJoystick.cs @@ -69,19 +69,24 @@ public DigitalJoystickPosition? DigitalPosition { /// /// Calibration for the joystick. /// Whether or not the vertical component is inverted. - /// The time, in milliseconds, to wait - /// between sets of sample readings. This value determines how often - /// `Changed` events are raised and `IObservable` consumers are notified. - /// How many samples to take during a given - /// reading. These are automatically averaged to reduce noise. - /// The time, in milliseconds, - /// to wait in between samples during a reading. public AnalogJoystick( IAnalogInputController device, IPin horizontalPin, IPin verticalPin, JoystickCalibration? calibration = null, bool isInverted = false) : this(device, horizontalPin, verticalPin, calibration, isInverted, 5, TimeSpan.FromMilliseconds(40)) { } + /// + /// Creates a 2-axis analog joystick + /// + /// The `IAnalogInputController` to create the port on. + /// + /// + /// Calibration for the joystick. + /// Whether or not the vertical component is inverted. + /// How many samples to take during a given + /// reading. These are automatically averaged to reduce noise. + /// The time, in milliseconds, + /// to wait in between samples during a reading. public AnalogJoystick( IAnalogInputController device, IPin horizontalPin, IPin verticalPin, JoystickCalibration? calibration, bool isInverted, diff --git a/Source/Meadow.Foundation.Core/Sensors/Light/AnalogLightSensor.cs b/Source/Meadow.Foundation.Core/Sensors/Light/AnalogLightSensor.cs index aa3390cecd..ee2749b274 100644 --- a/Source/Meadow.Foundation.Core/Sensors/Light/AnalogLightSensor.cs +++ b/Source/Meadow.Foundation.Core/Sensors/Light/AnalogLightSensor.cs @@ -17,18 +17,6 @@ public partial class AnalogLightSensor /// protected IAnalogInputPort AnalogInputPort { get; } - /// - /// How many samples to take during a given - /// reading. These are automatically averaged to reduce noise. - /// - protected int sampleCount = 5; - /// - /// The time, in milliseconds, to wait - /// between sets of sample readings. This value determines how often - /// `Changed` events are raised and `IObservable` consumers are notified - /// - protected int sampleIntervalMs = 40; - /// /// Raised when the value of the reading changes. /// @@ -52,24 +40,22 @@ public partial class AnalogLightSensor /// The `IAnalogInputController` to create the port on. /// Analog pin the sensor is connected to. /// Calibration for the analog sensor. - /// The time, in milliseconds, to wait + /// The time, in milliseconds, to wait /// between sets of sample readings. This value determines how often /// `Changed` events are raised and `IObservable` consumers are notified. /// How many samples to take during a given /// reading. These are automatically averaged to reduce noise. - /// The time, in milliseconds, + /// The time, in milliseconds, /// to wait in between samples during a reading. public AnalogLightSensor( IAnalogInputController device, IPin analogPin, Calibration? calibration = null, - int updateIntervalMs = 1000, - int sampleCount = 5, int sampleIntervalMs = 40) - : this(device.CreateAnalogInputPort(analogPin), calibration) + TimeSpan? updateInterval = null, + int sampleCount = 5, TimeSpan? sampleInterval = null) + : this(device.CreateAnalogInputPort(analogPin, sampleCount, sampleInterval ?? new TimeSpan(0, 0, 40), new Voltage(3.3)), calibration) { - base.UpdateInterval = TimeSpan.FromMilliseconds(updateIntervalMs); - this.sampleCount = sampleCount; - this.sampleIntervalMs = sampleIntervalMs; + base.UpdateInterval = updateInterval ?? new TimeSpan(0, 0, 10); } /// diff --git a/Source/Meadow.Foundation.Core/Sensors/Temperature/AnalogTemperature.cs b/Source/Meadow.Foundation.Core/Sensors/Temperature/AnalogTemperature.cs index df8d02114d..71d2002aee 100644 --- a/Source/Meadow.Foundation.Core/Sensors/Temperature/AnalogTemperature.cs +++ b/Source/Meadow.Foundation.Core/Sensors/Temperature/AnalogTemperature.cs @@ -118,9 +118,9 @@ public enum KnownSensorType /// to wait in between samples during a reading. public AnalogTemperature( IAnalogInputController device, IPin analogPin, - KnownSensorType sensorType, Calibration? calibration, - int sampleCount, TimeSpan sampleInterval) - : this(device.CreateAnalogInputPort(analogPin, sampleCount, sampleInterval, new Voltage(3.3, Voltage.UnitType.Volts)), + KnownSensorType sensorType, Calibration? calibration = null, + int sampleCount = 5, TimeSpan? sampleInterval = null) + : this(device.CreateAnalogInputPort(analogPin, sampleCount, sampleInterval ?? TimeSpan.FromMilliseconds(40), new Voltage(3.3, Voltage.UnitType.Volts)), sensorType, calibration) { } diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Distance.Gp2d12/Driver/Sensors.Distance.Gp2d12/Gp2d12.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Distance.Gp2d12/Driver/Sensors.Distance.Gp2d12/Gp2d12.cs index 5d9020b148..3d3f6e8c75 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Distance.Gp2d12/Driver/Sensors.Distance.Gp2d12/Gp2d12.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Distance.Gp2d12/Driver/Sensors.Distance.Gp2d12/Gp2d12.cs @@ -43,7 +43,7 @@ public class Gp2d12 : SensorBase, IRangeFinder /// public Gp2d12(IAnalogInputController device, IPin analogInputPin) { - AnalogInputPort = device.CreateAnalogInputPort(analogInputPin); + AnalogInputPort = device.CreateAnalogInputPort(analogInputPin, 5, TimeSpan.FromMilliseconds(40), new Voltage(3.3)); // wire up our observable // have to convert from voltage to length units for our consumers diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Distance.MaxBotix/Driver/Sensors.Distance.MaxBotix/MaxBotix.Analog.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Distance.MaxBotix/Driver/Sensors.Distance.MaxBotix/MaxBotix.Analog.cs index c4e92a0f94..378285d3af 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Distance.MaxBotix/Driver/Sensors.Distance.MaxBotix/MaxBotix.Analog.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Distance.MaxBotix/Driver/Sensors.Distance.MaxBotix/MaxBotix.Analog.cs @@ -1,6 +1,7 @@ using Meadow.Devices; using Meadow.Hardware; using Meadow.Units; +using System; using System.Threading.Tasks; namespace Meadow.Foundation.Sensors.Distance @@ -19,9 +20,13 @@ public MaxBotix(IAnalogInputPort analogIntputPort, SensorType sensor) AnalogInitialize(); } - public MaxBotix(IMeadowDevice device, IPin analogIntputPin, - SensorType sensor) : - this(device.CreateAnalogInputPort(analogIntputPin), sensor) + public MaxBotix(SensorType sensor, + IMeadowDevice device, + IPin analogIntputPin, + int sampleCount = 5, + TimeSpan? sampleInterval = null, + Voltage? voltage = null) : + this(device.CreateAnalogInputPort(analogIntputPin, sampleCount, sampleInterval ?? TimeSpan.FromMilliseconds(40), voltage ?? new Voltage(3.3)), sensor) { } diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Hid.Tsc2004/Driver/Sensors.Hid.Tsc2004/Tsc2004.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Hid.Tsc2004/Driver/Sensors.Hid.Tsc2004/Tsc2004.cs index ce0c651ad6..10c6486445 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Hid.Tsc2004/Driver/Sensors.Hid.Tsc2004/Tsc2004.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Hid.Tsc2004/Driver/Sensors.Hid.Tsc2004/Tsc2004.cs @@ -129,7 +129,7 @@ void WriteRegister16(byte register, ushort value) data[1] = (byte)((value >> 8) & 0xFF); data[2] = (byte)((value >> 0) & 0xFF); - i2CPeripheral.WriteBytes(data); + i2CPeripheral.Write(data); } void SendCommand(byte command) diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Light.Alspt19315C/Driver/Sensors.Light.Alspt19315C/Alspt19315C.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Light.Alspt19315C/Driver/Sensors.Light.Alspt19315C/Alspt19315C.cs index bbfc030903..a36a6f0a69 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Light.Alspt19315C/Driver/Sensors.Light.Alspt19315C/Alspt19315C.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Light.Alspt19315C/Driver/Sensors.Light.Alspt19315C/Alspt19315C.cs @@ -23,8 +23,8 @@ public class Alspt19315C : SensorBase /// Create a new light sensor object using a static reference voltage. /// /// AnalogChannel connected to the sensor. - public Alspt19315C(IAnalogInputController device, IPin pin) - : this(device.CreateAnalogInputPort(pin)) + public Alspt19315C(IAnalogInputController device, IPin pin, int sampleCount = 5, TimeSpan? sampleInterval = null, Voltage? voltage = null) + : this(device.CreateAnalogInputPort(pin, sampleCount, sampleInterval ?? TimeSpan.FromMilliseconds(40), voltage ?? new Voltage(3.3))) { } diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Light.AnalogSolarGauge/Driver/Sensors.Light.AnalogSolarGauge/AnalogSolarGauge.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Light.AnalogSolarGauge/Driver/Sensors.Light.AnalogSolarGauge/AnalogSolarGauge.cs index cc35baadd8..fa1ede98e2 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Light.AnalogSolarGauge/Driver/Sensors.Light.AnalogSolarGauge/AnalogSolarGauge.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Light.AnalogSolarGauge/Driver/Sensors.Light.AnalogSolarGauge/AnalogSolarGauge.cs @@ -18,9 +18,7 @@ public class AnalogSolarGauge : SensorBase, public event EventHandler> SolarIntensityUpdated = delegate { }; //==== internals - protected IAnalogInputPort analogIn; - protected int sampleCount = 5; - protected int sampleIntervalMs = 40; + protected IAnalogInputPort analogInputPort; //==== properties public Voltage MinVoltageReference { get; protected set; } = new Voltage(0, VU.Volts); @@ -39,24 +37,28 @@ public class AnalogSolarGauge : SensorBase, /// Analog pin the temperature sensor is connected to. /// The minimum voltage expected when the solar panel isn't receiving light. Default is 0. /// The maxmimu voltage expected when the solar panel is in full sun. Default is 3.3V. - /// The time, in milliseconds, to wait + /// The time to wait /// between sets of sample readings. This value determines how often /// `Changed` events are raised and `IObservable` consumers are notified. /// How many samples to take during a given /// reading. These are automatically averaged to reduce noise. - /// The time, in milliseconds, + /// The time, /// to wait in between samples during a reading. public AnalogSolarGauge( - IAnalogInputController device, IPin analogPin, - Voltage? minVoltageReference = null, Voltage? maxVoltageReference = null, - int updateIntervalMs = 10000, - int sampleCount = 5, int sampleIntervalMs = 40) - : this(device.CreateAnalogInputPort(analogPin, updateIntervalMs, sampleCount, sampleIntervalMs), + IAnalogInputController device, + IPin analogPin, + Voltage? minVoltageReference = null, + Voltage? maxVoltageReference = null, + TimeSpan? updateInterval = null, + int sampleCount = 5, + TimeSpan? sampleInterval = null) + : this(device.CreateAnalogInputPort(analogPin, + sampleCount, + sampleInterval ?? new TimeSpan(0, 0, 0, 40), + maxVoltageReference ?? new Voltage(3.3)), minVoltageReference, maxVoltageReference) { - base.UpdateInterval = TimeSpan.FromMilliseconds(updateIntervalMs); - this.sampleCount = sampleCount; - this.sampleIntervalMs = sampleIntervalMs; + base.UpdateInterval = updateInterval ?? new TimeSpan(0, 0, 10); } /// @@ -73,7 +75,7 @@ public AnalogSolarGauge( if (maxVoltageReference is { } maxV) { this.MaxVoltageReference = maxV; } // TODO: input port validation if any (is it constructed all right?) - this.analogIn = analogIn; + this.analogInputPort = analogIn; Init(); } @@ -93,13 +95,13 @@ protected void Init() RaiseEventsAndNotify(changeResult); }, null); - analogIn.Subscribe(observer); + analogInputPort.Subscribe(observer); } protected override async Task ReadSensor() { // read the voltage - Voltage voltage = await analogIn.Read(); + Voltage voltage = await analogInputPort.Read(); // convert the voltage var newSolarIntensity = ConvertVoltageToIntensity(voltage); @@ -123,7 +125,7 @@ protected override async Task ReadSensor() /// The default is 5 seconds. public void StartUpdating(TimeSpan updateInterval) { - analogIn.StartUpdating(updateInterval); + analogInputPort.StartUpdating(updateInterval); } /// @@ -131,7 +133,7 @@ public void StartUpdating(TimeSpan updateInterval) /// public void StopUpdating() { - analogIn.StopUpdating(); + analogInputPort.StopUpdating(); } protected override void RaiseEventsAndNotify(IChangeResult changeResult) diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Light.AnalogSolarGauge/Samples/AnalogSolarGauge_Sample/MeadowApp.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Light.AnalogSolarGauge/Samples/AnalogSolarGauge_Sample/MeadowApp.cs index 10129a8c2f..540de69acc 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Light.AnalogSolarGauge/Samples/AnalogSolarGauge_Sample/MeadowApp.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Light.AnalogSolarGauge/Samples/AnalogSolarGauge_Sample/MeadowApp.cs @@ -16,7 +16,7 @@ public class MeadowApp : App public MeadowApp() { Console.WriteLine("Initialize hardware..."); - solarGauge = new AnalogSolarGauge(Device, Device.Pins.A02, updateIntervalMs: 1000); + solarGauge = new AnalogSolarGauge(Device, Device.Pins.A02, updateInterval: TimeSpan.FromSeconds(1)); //==== classic .NET Event solarGauge.SolarIntensityUpdated += (s, result) => Console.WriteLine($"SolarIntensityUpdated: {result.New * 100:n2}%"); diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Light.Temt6000/Driver/Sensors.Light.Temt6000/Temt6000.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Light.Temt6000/Driver/Sensors.Light.Temt6000/Temt6000.cs index 172540a8e6..6f74678f65 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Light.Temt6000/Driver/Sensors.Light.Temt6000/Temt6000.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Light.Temt6000/Driver/Sensors.Light.Temt6000/Temt6000.cs @@ -23,8 +23,8 @@ public class Temt6000 : SensorBase /// Creates a new Temt6000 driver /// /// AnalogChannel connected to the sensor. - public Temt6000(IAnalogInputController device, IPin pin) - : this(device.CreateAnalogInputPort(pin)) + public Temt6000(IAnalogInputController device, IPin pin, int sampleCount = 5, TimeSpan? sampleInterval = null, Voltage? voltage = null) + : this(device.CreateAnalogInputPort(pin, sampleCount, sampleInterval ?? TimeSpan.FromMilliseconds(40), voltage ?? new Voltage(3.3))) { } diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Moisture.Capacitive/Driver/Sensors.Moisture.Capacitive/Capacitive.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Moisture.Capacitive/Driver/Sensors.Moisture.Capacitive/Capacitive.cs index 38a4b651b8..e27c20fe9a 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Moisture.Capacitive/Driver/Sensors.Moisture.Capacitive/Capacitive.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Moisture.Capacitive/Driver/Sensors.Moisture.Capacitive/Capacitive.cs @@ -44,20 +44,21 @@ public class Capacitive : SensorBase, IMoistureSensor /// /// The `IAnalogInputController` to create the port on. /// Analog pin the temperature sensor is connected to. - /// The time, in milliseconds, to wait - /// between sets of sample readings. This value determines how often - /// `Changed` events are raised and `IObservable` consumers are notified. + /// The time, to wait between sets of sample readings. + /// This value determines how often`Changed` events are raised and `IObservable` consumers are notified. /// How many samples to take during a given /// reading. These are automatically averaged to reduce noise. - /// The time, in milliseconds, - /// to wait in between samples during a reading. + /// The time, to wait in between samples during a reading. public Capacitive( IAnalogInputController device, IPin analogPin, Voltage? minimumVoltageCalibration, Voltage? maximumVoltageCalibration, - int sampleCount = 5, int sampleIntervalMs = 40) - : this(device.CreateAnalogInputPort(analogPin, sampleCount, sampleIntervalMs), + TimeSpan? updateInterval = null, + int sampleCount = 5, TimeSpan? sampleInterval = null) + : this(device.CreateAnalogInputPort(analogPin, sampleCount, sampleInterval ?? TimeSpan.FromMilliseconds(40), new Voltage(3.3)), minimumVoltageCalibration, maximumVoltageCalibration) - { } + { + this.UpdateInterval = updateInterval ?? TimeSpan.FromSeconds(5); + } /// /// Creates a Capacitive soil moisture sensor object with the especified AnalogInputPort. diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Moisture.Fc28/Driver/Sensors.Moisture.Fc28/Fc28.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Moisture.Fc28/Driver/Sensors.Moisture.Fc28/Fc28.cs index b31179789f..c5a99d4eb0 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Moisture.Fc28/Driver/Sensors.Moisture.Fc28/Fc28.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Moisture.Fc28/Driver/Sensors.Moisture.Fc28/Fc28.cs @@ -46,16 +46,18 @@ public class Fc28 : SensorBase, IMoistureSensor /// /// Creates a FC28 soil moisture sensor object with the especified analog pin, digital pin and IO device. /// - /// - /// + /// + /// public Fc28( IMeadowDevice device, IPin analogPin, IPin digitalPin, Voltage? minimumVoltageCalibration, Voltage? maximumVoltageCalibration, - int updateIntervalMs = 1000, - int sampleCount = 5, int sampleIntervalMs = 40) - : this(device.CreateAnalogInputPort(analogPin, updateIntervalMs, sampleCount, sampleIntervalMs), + TimeSpan? updateInterval = null, + int sampleCount = 5, TimeSpan? sampleInterval = null) + : this(device.CreateAnalogInputPort(analogPin, sampleCount, sampleInterval ?? new TimeSpan(0, 0, 0, 40), new Voltage(3.3)), device.CreateDigitalOutputPort(digitalPin), minimumVoltageCalibration, maximumVoltageCalibration) - { } + { + this.UpdateInterval = updateInterval ?? new TimeSpan(0, 0, 1); + } /// /// Creates a FC28 soil moisture sensor object with the especified analog pin and digital pin. diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Adxl3xx/Driver/Sensors.Motion.Adxl3xx/Adxl3xxBase.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Adxl3xx/Driver/Sensors.Motion.Adxl3xx/Adxl3xxBase.cs index 2507e66551..129d1285b8 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Adxl3xx/Driver/Sensors.Motion.Adxl3xx/Adxl3xxBase.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Adxl3xx/Driver/Sensors.Motion.Adxl3xx/Adxl3xxBase.cs @@ -40,11 +40,15 @@ protected Adxl3xxBase(IAnalogInputController device, IPin xPin, IPin yPin, IPin zPin, int gravityRange, Voltage? supplyVoltage) { - XAnalogIn = device.CreateAnalogInputPort(xPin); - YAnalogIn = device.CreateAnalogInputPort(yPin); - ZAnalogIn = device.CreateAnalogInputPort(zPin); - GravityRange = (double)gravityRange; - if(supplyVoltage is { } supplyV) { this.SupplyVoltage = supplyV; } + XAnalogIn = device.CreateAnalogInputPort(xPin, 5, TimeSpan.FromMilliseconds(40), supplyVoltage ?? new Voltage(3.3)); + YAnalogIn = device.CreateAnalogInputPort(yPin, 5, TimeSpan.FromMilliseconds(40), supplyVoltage ?? new Voltage(3.3)); + ZAnalogIn = device.CreateAnalogInputPort(zPin, 5, TimeSpan.FromMilliseconds(40), supplyVoltage ?? new Voltage(3.3)); + GravityRange = gravityRange; + + if(supplyVoltage is { } supplyV) + { + SupplyVoltage = supplyV; + } } protected override void RaiseEventsAndNotify(IChangeResult changeResult) diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Sound.Ky038/Driver/Sensors.Sound.Ky038/Ky038.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Sound.Ky038/Driver/Sensors.Sound.Ky038/Ky038.cs index c9745e7089..abb741c5a0 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Sound.Ky038/Driver/Sensors.Sound.Ky038/Ky038.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Sound.Ky038/Driver/Sensors.Sound.Ky038/Ky038.cs @@ -12,7 +12,8 @@ public class Ky038 protected IDigitalInputPort digitalInputPort; public Ky038(IMeadowDevice device, IPin A0, IPin D0) : - this (device.CreateAnalogInputPort(A0), device.CreateDigitalInputPort(D0)) + this (device.CreateAnalogInputPort(A0, 5, TimeSpan.FromMilliseconds(50), new Units.Voltage(3.3)), + device.CreateDigitalInputPort(D0)) { } diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Weather.WindVane/Driver/Sensors.Weather.WindVane/WindVane.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Weather.WindVane/Driver/Sensors.Weather.WindVane/WindVane.cs index 2c9d3e83f1..ba8483b01b 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Weather.WindVane/Driver/Sensors.Weather.WindVane/WindVane.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Weather.WindVane/Driver/Sensors.Weather.WindVane/WindVane.cs @@ -54,11 +54,12 @@ public partial class WindVane public WindVane( IAnalogInputController device, IPin analogInputPin, IDictionary azimuthVoltages = null, - int updateIntervalMs = 1000, - int sampleCount = 1, int sampleIntervalMs = 40) - : this(device.CreateAnalogInputPort(analogInputPin, updateIntervalMs, sampleCount, sampleIntervalMs) + TimeSpan? updateInterval = null, + int sampleCount = 1, TimeSpan? sampleInterval = null) + : this(device.CreateAnalogInputPort(analogInputPin, sampleCount, sampleInterval ?? TimeSpan.FromMilliseconds(40), new Voltage(3.3)) , azimuthVoltages) { + this.UpdateInterval = updateInterval ?? new TimeSpan(0, 0, 1); } /// From 33ce74363986af101e66a9c254f3215b705d39ca Mon Sep 17 00:00:00 2001 From: Adrian Stevens Date: Mon, 24 Jan 2022 21:39:01 -0800 Subject: [PATCH 3/3] Minor cleanup --- .../Sensors/Environmental/AnalogWaterLevel.cs | 4 ++-- .../Driver/Sensors.Distance.Gp2d12/Gp2d12.cs | 8 ++++++-- .../Driver/Sensors.Distance.MaxBotix/MaxBotix.Analog.cs | 4 ++-- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/Source/Meadow.Foundation.Core/Sensors/Environmental/AnalogWaterLevel.cs b/Source/Meadow.Foundation.Core/Sensors/Environmental/AnalogWaterLevel.cs index 944fbb5862..dd4851d038 100644 --- a/Source/Meadow.Foundation.Core/Sensors/Environmental/AnalogWaterLevel.cs +++ b/Source/Meadow.Foundation.Core/Sensors/Environmental/AnalogWaterLevel.cs @@ -37,10 +37,10 @@ public AnalogWaterLevel( IAnalogInputController device, IPin analogPin, Calibration? calibration = null, - int updateIntervalMs = 1000) + TimeSpan? updateInterval = null) : this(device.CreateAnalogInputPort(analogPin, 5, TimeSpan.FromMilliseconds(40), new Voltage(3.3, Voltage.UnitType.Volts)), calibration) { - base.UpdateInterval = TimeSpan.FromMilliseconds(updateIntervalMs); + base.UpdateInterval = updateInterval ?? TimeSpan.FromSeconds(1000); } /// diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Distance.Gp2d12/Driver/Sensors.Distance.Gp2d12/Gp2d12.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Distance.Gp2d12/Driver/Sensors.Distance.Gp2d12/Gp2d12.cs index 3d3f6e8c75..89b2a0babe 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Distance.Gp2d12/Driver/Sensors.Distance.Gp2d12/Gp2d12.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Distance.Gp2d12/Driver/Sensors.Distance.Gp2d12/Gp2d12.cs @@ -41,9 +41,13 @@ public class Gp2d12 : SensorBase, IRangeFinder /// /// Create a new Gp2d12 object with an IO Device /// - public Gp2d12(IAnalogInputController device, IPin analogInputPin) + public Gp2d12(IAnalogInputController device, + IPin analogInputPin, + int sampleCount = 5, + TimeSpan? sampleInterval = null, + Voltage? voltage = null) { - AnalogInputPort = device.CreateAnalogInputPort(analogInputPin, 5, TimeSpan.FromMilliseconds(40), new Voltage(3.3)); + AnalogInputPort = device.CreateAnalogInputPort(analogInputPin, sampleCount, sampleInterval ?? TimeSpan.FromMilliseconds(40), voltage ?? new Voltage(3.3)); // wire up our observable // have to convert from voltage to length units for our consumers diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Distance.MaxBotix/Driver/Sensors.Distance.MaxBotix/MaxBotix.Analog.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Distance.MaxBotix/Driver/Sensors.Distance.MaxBotix/MaxBotix.Analog.cs index 378285d3af..044ea63c88 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Distance.MaxBotix/Driver/Sensors.Distance.MaxBotix/MaxBotix.Analog.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Distance.MaxBotix/Driver/Sensors.Distance.MaxBotix/MaxBotix.Analog.cs @@ -22,11 +22,11 @@ public MaxBotix(IAnalogInputPort analogIntputPort, SensorType sensor) public MaxBotix(SensorType sensor, IMeadowDevice device, - IPin analogIntputPin, + IPin analogInputPin, int sampleCount = 5, TimeSpan? sampleInterval = null, Voltage? voltage = null) : - this(device.CreateAnalogInputPort(analogIntputPin, sampleCount, sampleInterval ?? TimeSpan.FromMilliseconds(40), voltage ?? new Voltage(3.3)), sensor) + this(device.CreateAnalogInputPort(analogInputPin, sampleCount, sampleInterval ?? TimeSpan.FromMilliseconds(40), voltage ?? new Voltage(3.3)), sensor) { }