diff --git a/.github/workflows/main-ci.yml b/.github/workflows/main-ci.yml index 65e4c89cbc..46c7ebcb88 100644 --- a/.github/workflows/main-ci.yml +++ b/.github/workflows/main-ci.yml @@ -18,6 +18,7 @@ jobs: uses: actions/checkout@v3 with: path: Meadow.Foundation + ref: main - name: Setup .NET SDK uses: actions/setup-dotnet@v1 diff --git a/Source/Meadow.Foundation.Core.Samples/Audio.PiezoSpeaker_Sample/Audio.PiezoSpeaker_Sample.csproj b/Source/Meadow.Foundation.Core.Samples/Audio.PiezoSpeaker_Sample/Audio.PiezoSpeaker_Sample.csproj index 7eba3d3988..3e22ed8068 100644 --- a/Source/Meadow.Foundation.Core.Samples/Audio.PiezoSpeaker_Sample/Audio.PiezoSpeaker_Sample.csproj +++ b/Source/Meadow.Foundation.Core.Samples/Audio.PiezoSpeaker_Sample/Audio.PiezoSpeaker_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Core.Samples/Generators.SoftPwmPort_Sample/Generators.SoftPwmPort_Sample.csproj b/Source/Meadow.Foundation.Core.Samples/Generators.SoftPwmPort_Sample/Generators.SoftPwmPort_Sample.csproj index 7eba3d3988..3e22ed8068 100644 --- a/Source/Meadow.Foundation.Core.Samples/Generators.SoftPwmPort_Sample/Generators.SoftPwmPort_Sample.csproj +++ b/Source/Meadow.Foundation.Core.Samples/Generators.SoftPwmPort_Sample/Generators.SoftPwmPort_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Core.Samples/Leds.LedBarGraph_Sample/Leds.LedBarGraph_Sample.csproj b/Source/Meadow.Foundation.Core.Samples/Leds.LedBarGraph_Sample/Leds.LedBarGraph_Sample.csproj index 7eba3d3988..3e22ed8068 100644 --- a/Source/Meadow.Foundation.Core.Samples/Leds.LedBarGraph_Sample/Leds.LedBarGraph_Sample.csproj +++ b/Source/Meadow.Foundation.Core.Samples/Leds.LedBarGraph_Sample/Leds.LedBarGraph_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Core.Samples/Leds.Led_Sample/Leds.Led_Sample.csproj b/Source/Meadow.Foundation.Core.Samples/Leds.Led_Sample/Leds.Led_Sample.csproj index 7eba3d3988..3e22ed8068 100644 --- a/Source/Meadow.Foundation.Core.Samples/Leds.Led_Sample/Leds.Led_Sample.csproj +++ b/Source/Meadow.Foundation.Core.Samples/Leds.Led_Sample/Leds.Led_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Core.Samples/Leds.Led_Sample/MeadowApp.cs b/Source/Meadow.Foundation.Core.Samples/Leds.Led_Sample/MeadowApp.cs index 975997052d..1c9dd6a119 100644 --- a/Source/Meadow.Foundation.Core.Samples/Leds.Led_Sample/MeadowApp.cs +++ b/Source/Meadow.Foundation.Core.Samples/Leds.Led_Sample/MeadowApp.cs @@ -52,11 +52,11 @@ public override async Task Run() Resolver.Log.Error("Error level message"); Resolver.Log.Warn("Warn level message"); - Resolver.Log.Info("TestLeds..."); + Resolver.Log.Info("Test Leds..."); while (true) { - Resolver.Log.Error("Turning on each led every 100ms"); + Resolver.Log.Info("Turning on each led every 100ms"); foreach (var led in leds) { led.IsOn = true; diff --git a/Source/Meadow.Foundation.Core.Samples/Leds.PwmLedBarGraph_Sample/Leds.PwmLedBarGraph_Sample.csproj b/Source/Meadow.Foundation.Core.Samples/Leds.PwmLedBarGraph_Sample/Leds.PwmLedBarGraph_Sample.csproj index 7eba3d3988..3e22ed8068 100644 --- a/Source/Meadow.Foundation.Core.Samples/Leds.PwmLedBarGraph_Sample/Leds.PwmLedBarGraph_Sample.csproj +++ b/Source/Meadow.Foundation.Core.Samples/Leds.PwmLedBarGraph_Sample/Leds.PwmLedBarGraph_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Core.Samples/Leds.PwmLed_Onboard_Sample/Leds.PwmLed_Onboard_Sample.csproj b/Source/Meadow.Foundation.Core.Samples/Leds.PwmLed_Onboard_Sample/Leds.PwmLed_Onboard_Sample.csproj index 7eba3d3988..3e22ed8068 100644 --- a/Source/Meadow.Foundation.Core.Samples/Leds.PwmLed_Onboard_Sample/Leds.PwmLed_Onboard_Sample.csproj +++ b/Source/Meadow.Foundation.Core.Samples/Leds.PwmLed_Onboard_Sample/Leds.PwmLed_Onboard_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Core.Samples/Leds.PwmLed_Sample/Leds.PwmLed_Sample.csproj b/Source/Meadow.Foundation.Core.Samples/Leds.PwmLed_Sample/Leds.PwmLed_Sample.csproj index 7eba3d3988..3e22ed8068 100644 --- a/Source/Meadow.Foundation.Core.Samples/Leds.PwmLed_Sample/Leds.PwmLed_Sample.csproj +++ b/Source/Meadow.Foundation.Core.Samples/Leds.PwmLed_Sample/Leds.PwmLed_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Core.Samples/Leds.RgbLed_Sample/Leds.RgbLed_Sample.csproj b/Source/Meadow.Foundation.Core.Samples/Leds.RgbLed_Sample/Leds.RgbLed_Sample.csproj index 7eba3d3988..3e22ed8068 100644 --- a/Source/Meadow.Foundation.Core.Samples/Leds.RgbLed_Sample/Leds.RgbLed_Sample.csproj +++ b/Source/Meadow.Foundation.Core.Samples/Leds.RgbLed_Sample/Leds.RgbLed_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Core.Samples/Leds.RgbPwmLed_Onboard_Sample/Leds.RgbPwmLed_Onboard_Sample.csproj b/Source/Meadow.Foundation.Core.Samples/Leds.RgbPwmLed_Onboard_Sample/Leds.RgbPwmLed_Onboard_Sample.csproj index 7eba3d3988..3e22ed8068 100644 --- a/Source/Meadow.Foundation.Core.Samples/Leds.RgbPwmLed_Onboard_Sample/Leds.RgbPwmLed_Onboard_Sample.csproj +++ b/Source/Meadow.Foundation.Core.Samples/Leds.RgbPwmLed_Onboard_Sample/Leds.RgbPwmLed_Onboard_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Core.Samples/Leds.RgbPwmLed_Sample/Leds.RgbPwmLed_Sample.csproj b/Source/Meadow.Foundation.Core.Samples/Leds.RgbPwmLed_Sample/Leds.RgbPwmLed_Sample.csproj index 7eba3d3988..3e22ed8068 100644 --- a/Source/Meadow.Foundation.Core.Samples/Leds.RgbPwmLed_Sample/Leds.RgbPwmLed_Sample.csproj +++ b/Source/Meadow.Foundation.Core.Samples/Leds.RgbPwmLed_Sample/Leds.RgbPwmLed_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Core.Samples/Motor.BidirectionalDcMotor_Sample/Motor.BidirectionalDcMotor_Sample.csproj b/Source/Meadow.Foundation.Core.Samples/Motor.BidirectionalDcMotor_Sample/Motor.BidirectionalDcMotor_Sample.csproj index 28f6080700..d2d032963c 100644 --- a/Source/Meadow.Foundation.Core.Samples/Motor.BidirectionalDcMotor_Sample/Motor.BidirectionalDcMotor_Sample.csproj +++ b/Source/Meadow.Foundation.Core.Samples/Motor.BidirectionalDcMotor_Sample/Motor.BidirectionalDcMotor_Sample.csproj @@ -10,7 +10,7 @@ 10 - - + + diff --git a/Source/Meadow.Foundation.Core.Samples/Motor.HBridgeMotor_Sample/Motor.HBridgeMotor_Sample.csproj b/Source/Meadow.Foundation.Core.Samples/Motor.HBridgeMotor_Sample/Motor.HBridgeMotor_Sample.csproj index 7eba3d3988..3e22ed8068 100644 --- a/Source/Meadow.Foundation.Core.Samples/Motor.HBridgeMotor_Sample/Motor.HBridgeMotor_Sample.csproj +++ b/Source/Meadow.Foundation.Core.Samples/Motor.HBridgeMotor_Sample/Motor.HBridgeMotor_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Core.Samples/Relays.Relay_Sample/Relays.Relay_Sample.csproj b/Source/Meadow.Foundation.Core.Samples/Relays.Relay_Sample/Relays.Relay_Sample.csproj index 7eba3d3988..3e22ed8068 100644 --- a/Source/Meadow.Foundation.Core.Samples/Relays.Relay_Sample/Relays.Relay_Sample.csproj +++ b/Source/Meadow.Foundation.Core.Samples/Relays.Relay_Sample/Relays.Relay_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Core.Samples/Sensors.Buttons.PushButton_BasicSample/Sensors.Buttons.PushButton_BasicSample.csproj b/Source/Meadow.Foundation.Core.Samples/Sensors.Buttons.PushButton_BasicSample/Sensors.Buttons.PushButton_BasicSample.csproj index 7eba3d3988..3e22ed8068 100644 --- a/Source/Meadow.Foundation.Core.Samples/Sensors.Buttons.PushButton_BasicSample/Sensors.Buttons.PushButton_BasicSample.csproj +++ b/Source/Meadow.Foundation.Core.Samples/Sensors.Buttons.PushButton_BasicSample/Sensors.Buttons.PushButton_BasicSample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Core.Samples/Sensors.Buttons.PushButton_Sample/Sensors.Buttons.PushButton_Sample.csproj b/Source/Meadow.Foundation.Core.Samples/Sensors.Buttons.PushButton_Sample/Sensors.Buttons.PushButton_Sample.csproj index 7eba3d3988..3e22ed8068 100644 --- a/Source/Meadow.Foundation.Core.Samples/Sensors.Buttons.PushButton_Sample/Sensors.Buttons.PushButton_Sample.csproj +++ b/Source/Meadow.Foundation.Core.Samples/Sensors.Buttons.PushButton_Sample/Sensors.Buttons.PushButton_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Core.Samples/Sensors.Environmental.AnalogWaterLevel_Sample/Sensors.Environmental.AnalogWaterLevel_Sample.csproj b/Source/Meadow.Foundation.Core.Samples/Sensors.Environmental.AnalogWaterLevel_Sample/Sensors.Environmental.AnalogWaterLevel_Sample.csproj index 7eba3d3988..3e22ed8068 100644 --- a/Source/Meadow.Foundation.Core.Samples/Sensors.Environmental.AnalogWaterLevel_Sample/Sensors.Environmental.AnalogWaterLevel_Sample.csproj +++ b/Source/Meadow.Foundation.Core.Samples/Sensors.Environmental.AnalogWaterLevel_Sample/Sensors.Environmental.AnalogWaterLevel_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Core.Samples/Sensors.HID.AnalogJoystick_Sample/Sensors.HID.AnalogJoystick_Sample.csproj b/Source/Meadow.Foundation.Core.Samples/Sensors.HID.AnalogJoystick_Sample/Sensors.HID.AnalogJoystick_Sample.csproj index 7ec339c822..6537c93c06 100644 --- a/Source/Meadow.Foundation.Core.Samples/Sensors.HID.AnalogJoystick_Sample/Sensors.HID.AnalogJoystick_Sample.csproj +++ b/Source/Meadow.Foundation.Core.Samples/Sensors.HID.AnalogJoystick_Sample/Sensors.HID.AnalogJoystick_Sample.csproj @@ -13,7 +13,7 @@ 8.0 - - + + diff --git a/Source/Meadow.Foundation.Core.Samples/Sensors.HallEffect_Sample/Sensors.HallEffect_Sample.csproj b/Source/Meadow.Foundation.Core.Samples/Sensors.HallEffect_Sample/Sensors.HallEffect_Sample.csproj index 7eba3d3988..3e22ed8068 100644 --- a/Source/Meadow.Foundation.Core.Samples/Sensors.HallEffect_Sample/Sensors.HallEffect_Sample.csproj +++ b/Source/Meadow.Foundation.Core.Samples/Sensors.HallEffect_Sample/Sensors.HallEffect_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Core.Samples/Sensors.Light.AnalogLightSensor_Sample/Sensors.Light.AnalogLightSensor_Sample.csproj b/Source/Meadow.Foundation.Core.Samples/Sensors.Light.AnalogLightSensor_Sample/Sensors.Light.AnalogLightSensor_Sample.csproj index cc82b99e91..a45a1d9271 100644 --- a/Source/Meadow.Foundation.Core.Samples/Sensors.Light.AnalogLightSensor_Sample/Sensors.Light.AnalogLightSensor_Sample.csproj +++ b/Source/Meadow.Foundation.Core.Samples/Sensors.Light.AnalogLightSensor_Sample/Sensors.Light.AnalogLightSensor_Sample.csproj @@ -14,7 +14,7 @@ - - + + diff --git a/Source/Meadow.Foundation.Core.Samples/Sensors.Rotary.RotaryEncoderWithButton_Sample/Sensors.Rotary.RotaryEncoderWithButton_Sample.csproj b/Source/Meadow.Foundation.Core.Samples/Sensors.Rotary.RotaryEncoderWithButton_Sample/Sensors.Rotary.RotaryEncoderWithButton_Sample.csproj index 004277e409..43294afc01 100644 --- a/Source/Meadow.Foundation.Core.Samples/Sensors.Rotary.RotaryEncoderWithButton_Sample/Sensors.Rotary.RotaryEncoderWithButton_Sample.csproj +++ b/Source/Meadow.Foundation.Core.Samples/Sensors.Rotary.RotaryEncoderWithButton_Sample/Sensors.Rotary.RotaryEncoderWithButton_Sample.csproj @@ -11,7 +11,7 @@ - - + + diff --git a/Source/Meadow.Foundation.Core.Samples/Sensors.Rotary.RotaryEncoder_Sample/Sensors.Rotary.RotaryEncoder_Sample.csproj b/Source/Meadow.Foundation.Core.Samples/Sensors.Rotary.RotaryEncoder_Sample/Sensors.Rotary.RotaryEncoder_Sample.csproj index 004277e409..43294afc01 100644 --- a/Source/Meadow.Foundation.Core.Samples/Sensors.Rotary.RotaryEncoder_Sample/Sensors.Rotary.RotaryEncoder_Sample.csproj +++ b/Source/Meadow.Foundation.Core.Samples/Sensors.Rotary.RotaryEncoder_Sample/Sensors.Rotary.RotaryEncoder_Sample.csproj @@ -11,7 +11,7 @@ - - + + diff --git a/Source/Meadow.Foundation.Core.Samples/Sensors.Switches.DipSwitch_Sample/Sensors.Switches.DipSwitch_Sample.csproj b/Source/Meadow.Foundation.Core.Samples/Sensors.Switches.DipSwitch_Sample/Sensors.Switches.DipSwitch_Sample.csproj index 7eba3d3988..3e22ed8068 100644 --- a/Source/Meadow.Foundation.Core.Samples/Sensors.Switches.DipSwitch_Sample/Sensors.Switches.DipSwitch_Sample.csproj +++ b/Source/Meadow.Foundation.Core.Samples/Sensors.Switches.DipSwitch_Sample/Sensors.Switches.DipSwitch_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Core.Samples/Sensors.Switches.SpdtSwitch_Sample/Sensors.Switches.SpdtSwitch_Sample.csproj b/Source/Meadow.Foundation.Core.Samples/Sensors.Switches.SpdtSwitch_Sample/Sensors.Switches.SpdtSwitch_Sample.csproj index 7eba3d3988..3e22ed8068 100644 --- a/Source/Meadow.Foundation.Core.Samples/Sensors.Switches.SpdtSwitch_Sample/Sensors.Switches.SpdtSwitch_Sample.csproj +++ b/Source/Meadow.Foundation.Core.Samples/Sensors.Switches.SpdtSwitch_Sample/Sensors.Switches.SpdtSwitch_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Core.Samples/Sensors.Switches.SpstSwitch_Sample/Sensors.Switches.SpstSwitch_Sample.csproj b/Source/Meadow.Foundation.Core.Samples/Sensors.Switches.SpstSwitch_Sample/Sensors.Switches.SpstSwitch_Sample.csproj index 7eba3d3988..3e22ed8068 100644 --- a/Source/Meadow.Foundation.Core.Samples/Sensors.Switches.SpstSwitch_Sample/Sensors.Switches.SpstSwitch_Sample.csproj +++ b/Source/Meadow.Foundation.Core.Samples/Sensors.Switches.SpstSwitch_Sample/Sensors.Switches.SpstSwitch_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Core.Samples/Sensors.Temperature.AnalogTemperature_Sample/Sensors.Temperature.AnalogTemperature_Sample.csproj b/Source/Meadow.Foundation.Core.Samples/Sensors.Temperature.AnalogTemperature_Sample/Sensors.Temperature.AnalogTemperature_Sample.csproj index cc82b99e91..a45a1d9271 100644 --- a/Source/Meadow.Foundation.Core.Samples/Sensors.Temperature.AnalogTemperature_Sample/Sensors.Temperature.AnalogTemperature_Sample.csproj +++ b/Source/Meadow.Foundation.Core.Samples/Sensors.Temperature.AnalogTemperature_Sample/Sensors.Temperature.AnalogTemperature_Sample.csproj @@ -14,7 +14,7 @@ - - + + diff --git a/Source/Meadow.Foundation.Core/Communications/I2cCommunications.cs b/Source/Meadow.Foundation.Core/Communications/I2cCommunications.cs index 0fe460d561..e928aa7b83 100644 --- a/Source/Meadow.Foundation.Core/Communications/I2cCommunications.cs +++ b/Source/Meadow.Foundation.Core/Communications/I2cCommunications.cs @@ -192,7 +192,7 @@ public virtual void WriteRegister(byte address, Span writeBuffer, ByteOrde case ByteOrder.BigEndian: for (int i = 0; i < writeBuffer.Length; i++) { - WriteBuffer.Span[i + 1] = writeBuffer[writeBuffer.Length - (i + 1)]; + WriteBuffer.Span[i + 1] = writeBuffer[^(i + 1)]; } break; } diff --git a/Source/Meadow.Foundation.Core/Communications/SpiCommunications.cs b/Source/Meadow.Foundation.Core/Communications/SpiCommunications.cs index f82c4ed7f9..c40ea3cf59 100644 --- a/Source/Meadow.Foundation.Core/Communications/SpiCommunications.cs +++ b/Source/Meadow.Foundation.Core/Communications/SpiCommunications.cs @@ -244,7 +244,7 @@ public virtual void WriteRegister(byte address, Span writeBuffer, ByteOrde case ByteOrder.BigEndian: for (int i = 0; i < writeBuffer.Length; i++) { - WriteBuffer.Span[i + 1] = writeBuffer[writeBuffer.Length - (i + 1)]; + WriteBuffer.Span[i + 1] = writeBuffer[^(i + 1)]; } break; } diff --git a/Source/Meadow.Foundation.Core/Meadow.Foundation.Core.csproj b/Source/Meadow.Foundation.Core/Meadow.Foundation.Core.csproj index 78aba0b9a9..54481ed7e0 100644 --- a/Source/Meadow.Foundation.Core/Meadow.Foundation.Core.csproj +++ b/Source/Meadow.Foundation.Core/Meadow.Foundation.Core.csproj @@ -27,6 +27,6 @@ - + diff --git a/Source/Meadow.Foundation.Core/SamplingSensorBase.cs b/Source/Meadow.Foundation.Core/SamplingSensorBase.cs index 6990702595..4b80abb87e 100644 --- a/Source/Meadow.Foundation.Core/SamplingSensorBase.cs +++ b/Source/Meadow.Foundation.Core/SamplingSensorBase.cs @@ -14,6 +14,7 @@ public abstract class SamplingSensorBase : ObservableBase, ISampling where UNIT : struct { private UNIT? _lastEventValue; + private UNIT _conditions; /// /// Raised when the sensor has new data @@ -44,7 +45,11 @@ protected void RaiseUpdated(UNIT newValue) /// /// The last read conditions /// - public UNIT Conditions { get; protected set; } + public UNIT Conditions + { + get => IsSampling ? _conditions : ReadSensor().Result; + protected set => _conditions = value; + } /// /// Gets a value indicating whether the sensor is currently in a sampling diff --git a/Source/Meadow.Foundation.Core/Sensors/Switches/SpdtSwitch.cs b/Source/Meadow.Foundation.Core/Sensors/Switches/SpdtSwitch.cs index bd6118c3bd..984c582601 100644 --- a/Source/Meadow.Foundation.Core/Sensors/Switches/SpdtSwitch.cs +++ b/Source/Meadow.Foundation.Core/Sensors/Switches/SpdtSwitch.cs @@ -17,7 +17,7 @@ public class SpdtSwitch : ISwitch, IDisposable public bool IsOn { get => DigitalInputPort.State; - protected set => Changed(this, new EventArgs()); + protected set => Changed(this, EventArgs.Empty); } /// diff --git a/Source/Meadow.Foundation.Core/Sensors/Switches/SpstSwitch.cs b/Source/Meadow.Foundation.Core/Sensors/Switches/SpstSwitch.cs index 11b1a10a77..ab447aa01e 100644 --- a/Source/Meadow.Foundation.Core/Sensors/Switches/SpstSwitch.cs +++ b/Source/Meadow.Foundation.Core/Sensors/Switches/SpstSwitch.cs @@ -20,7 +20,7 @@ public class SpstSwitch : ISwitch public bool IsOn { get => DigitalInputPort.State; - protected set => Changed(this, new EventArgs()); + protected set => Changed(this, EventArgs.Empty); } /// diff --git a/Source/Meadow.Foundation.Core/Simulation/BaseSimulatedSensor.cs b/Source/Meadow.Foundation.Core/Simulation/BaseSimulatedSensor.cs new file mode 100644 index 0000000000..2821f1e981 --- /dev/null +++ b/Source/Meadow.Foundation.Core/Simulation/BaseSimulatedSensor.cs @@ -0,0 +1,254 @@ +using Meadow.Hardware; +using Meadow.Peripherals.Sensors; +using System; +using System.Threading; +using System.Threading.Tasks; + +namespace Meadow.Foundation.Sensors; + +/* +/// +/// Represents a simulated tone generator that implements both IToneGenerator and ISimulatedSensor interfaces. +/// +public class SimulatedToneGenerator : IToneGenerator, ISimulatedSensor +{ +} + +/// +/// Represents a simulated RgbPwmLed that implements both IRgbPwmLed and ISimulatedSensor interfaces. +/// +public class SimulatedRgbPwmLed : IRgbPwmLed, ISimulatedSensor +{ +} + +/// +/// Represents a simulated barometric pressure sensor that implements both IBarometricPressureSensor and ISimulatedSensor interfaces. +/// +public class SimulatedBarometricPressureSensor : IBarometricPressureSensor, ISimulatedSensor +{ +} + +/// +/// Represents a simulated gas resistance sensor that implements both IGasResistanceSensor and ISimulatedSensor interfaces. +/// +public class SimulatedGasResistanceSensor : IGasResistanceSensor, ISimulatedSensor +{ +} +*/ + +/// +/// A base class for simple simulated single-unit sensors +/// +/// The type of Unit the device simulates +public abstract class BaseSimulatedSensor : ISimulatedSensor + where TUNIT : struct, IComparable +{ + private readonly Random _random = new(); + private TUNIT? _currentCondition; + private readonly TUNIT? _minCondition; + private readonly TUNIT? _maxCondition; + private SimulationBehavior _behavior; + private Timer? _simulationTimer; + private int _sawtoothDirection = 1; + private Timer? _reportTimer; + + /// + /// Gets the zero condition for the snsor unit + /// + public abstract TUNIT ZeroCondition { get; } + /// + /// Gets a condition incremented by a step value (used for interrupt value changes) + /// + /// The initial value to increment + protected abstract TUNIT IncrementCondition(TUNIT currentCondition); + /// + /// Gets a condition decremented by a step value (used for interrupt value changes) + /// + /// The initial value to decrement + protected abstract TUNIT DecrementCondition(TUNIT currentCondition); + /// + /// Gets a condition incremented by the provided root value amount + /// + /// The initial value to increment + /// The delta to increment by + protected abstract TUNIT IncrementCondition(TUNIT currentCondition, double conditionDelta); + /// + /// Gets a condition decremented by the provided root value amount + /// + /// The initial value to decrement + /// The delta to decrement by + protected abstract TUNIT DecrementCondition(TUNIT currentCondition, double conditionDelta); + /// + /// The upper/lower bound for a random walk + /// + protected abstract double RandomWalkRange { get; } + /// + /// The step amount for a sawtooth simulation + /// + protected abstract double SawtoothStepAmount { get; } + + /// + public event EventHandler> Updated = default!; + /// + public SimulationBehavior[] SupportedBehaviors => new SimulationBehavior[] { SimulationBehavior.RandomWalk, SimulationBehavior.Sawtooth }; + /// + public Type ValueType => typeof(TUNIT); + /// + public TimeSpan UpdateInterval { get; private set; } + /// + public bool IsSampling { get; private set; } + + /// + /// Initializes a new instance of the TemperatureSensorSimulated class. + /// + /// The initial temperature value of the sensor. + /// The minimum temperature value for the simulation. + /// The maximum temperature value for the simulation. + /// The digital interrupt port used for incrementing the temperature. + /// The digital interrupt port used for decrementing the temperature. + public BaseSimulatedSensor( + TUNIT initialCondition, + TUNIT minimumCondition, + TUNIT maximumCondition, + IDigitalInterruptPort incrementPort, + IDigitalInterruptPort decrementPort) + { + _currentCondition = initialCondition; + _minCondition = minimumCondition; + _maxCondition = maximumCondition; + + incrementPort.Changed += (s, e) => + { + var updated = IncrementCondition(CurrentCondition!.Value); + if (_maxCondition == null || updated.CompareTo(_maxCondition) <= 0) + { + CurrentCondition = updated; + } + }; + decrementPort.Changed += (s, e) => + { + var updated = DecrementCondition(CurrentCondition!.Value); + if (updated.CompareTo(_minCondition ?? ZeroCondition) >= 0) + { + CurrentCondition = updated; + } + }; + } + + /// + /// Initializes a new instance of the TemperatureSensorSimulated class with specified parameters. + /// + /// The initial temperature value of the sensor. + /// The minimum temperature value for the simulation. + /// The maximum temperature value for the simulation. + /// The simulation behavior for the sensor (default is SimulationBehavior.RandomWalk). + public BaseSimulatedSensor( + TUNIT initialCondition, + TUNIT minimumCondition, + TUNIT maximumCondition, + SimulationBehavior behavior = SimulationBehavior.RandomWalk) + { + _currentCondition = initialCondition; + _minCondition = minimumCondition; + _maxCondition = maximumCondition; + + StartSimulation(behavior); + } + + private void SimulationProc(object? o) + { + try + { + var delta = _behavior switch + { + SimulationBehavior.RandomWalk => _random.NextDouble() * (RandomWalkRange * 2) - RandomWalkRange, + _ => SawtoothStepAmount * _sawtoothDirection + }; + + if (_currentCondition == null) return; + + var newCondition = IncrementCondition(CurrentCondition!.Value, delta); + if ((newCondition.CompareTo(_minCondition!.Value) < 0) || + (newCondition.CompareTo(_maxCondition!.Value) > 0)) + { + newCondition = DecrementCondition(CurrentCondition!.Value, delta); + + _sawtoothDirection *= -1; + } + + CurrentCondition = newCondition; + } + finally + { + _simulationTimer?.Change(TimeSpan.FromSeconds(1), TimeSpan.FromMilliseconds(-1)); + } + } + + private void ReportTimerProc(object? o) + { + Updated?.Invoke(this, new ChangeResult(CurrentCondition!.Value, CurrentCondition!.Value)); + } + + /// + protected TUNIT? CurrentCondition + { + get => _currentCondition; + private set + { + if (value.Equals(CurrentCondition)) return; + + if (value != null) + { + var previous = _currentCondition; + _currentCondition = value; + Updated?.Invoke(this, new ChangeResult(CurrentCondition!.Value, previous)); + } + } + } + + /// + public Task Read() + { + return Task.FromResult(CurrentCondition ?? ZeroCondition); + } + + /// + /// Starts updating the sensor value at the specified interval + /// + /// + public void StartUpdating(TimeSpan? updateInterval = null) + { + UpdateInterval = updateInterval ?? TimeSpan.FromSeconds(1); + IsSampling = true; + _reportTimer = new Timer(ReportTimerProc, null, updateInterval!.Value, updateInterval.Value); + } + + /// + /// Stops updating the sensor + /// + public void StopUpdating() + { + IsSampling = false; + _reportTimer?.Dispose(); + } + + /// + public void SetSensorValue(object value) + { + if (value is TUNIT condition) + { + CurrentCondition = condition; + } + else + { + throw new ArgumentException($"Expected a parameter of type '{ValueType.Name}' but received a '{value.GetType().Name}'"); + } + } + + /// + public void StartSimulation(SimulationBehavior behavior) + { + _behavior = behavior; + _simulationTimer = new Timer(SimulationProc, null, TimeSpan.FromSeconds(1), TimeSpan.FromMilliseconds(-1)); + } +} \ No newline at end of file diff --git a/Source/Meadow.Foundation.Core/Simulation/SimulatedLightSensor.cs b/Source/Meadow.Foundation.Core/Simulation/SimulatedLightSensor.cs new file mode 100644 index 0000000000..1401c29cc2 --- /dev/null +++ b/Source/Meadow.Foundation.Core/Simulation/SimulatedLightSensor.cs @@ -0,0 +1,73 @@ +using Meadow.Hardware; +using Meadow.Peripherals.Sensors; +using Meadow.Peripherals.Sensors.Light; +using Meadow.Units; + +namespace Meadow.Foundation.Sensors; + +/// +/// Represents a simulated light sensor that implements both ILightSensor and ISimulatedSensor interfaces. +/// +public class SimulatedLightSensor : BaseSimulatedSensor, ILightSensor +{ + /// + /// Creates a SimulatedLightSensor + /// + /// The initial illuminance value of the sensor. + /// The minimum illuminance value for the simulation. + /// The maximum illuminance value for the simulation. + /// The digital interrupt port used for incrementing the illuminance. + /// The digital interrupt port used for decrementing the illuminance. + public SimulatedLightSensor(Illuminance initialCondition, Illuminance minimumCondition, Illuminance maximumCondition, IDigitalInterruptPort incrementPort, IDigitalInterruptPort decrementPort) + : base(initialCondition, minimumCondition, maximumCondition, incrementPort, decrementPort) + { + } + + /// + /// Creates a SimulatedLightSensor + /// + /// The initial illuminance value of the sensor. + /// The minimum illuminance value for the simulation. + /// The maximum illuminance value for the simulation. + /// The simulation behavior for the sensor (default is SimulationBehavior.RandomWalk). + public SimulatedLightSensor(Illuminance initialCondition, Illuminance minimumCondition, Illuminance maximumCondition, SimulationBehavior behavior = SimulationBehavior.RandomWalk) + : base(initialCondition, minimumCondition, maximumCondition, behavior) + { + } + + /// + public Illuminance? Illuminance => CurrentCondition; + + /// + public override Illuminance ZeroCondition => Units.Illuminance.Zero; + + /// + protected override double RandomWalkRange => 100d; + + /// + protected override double SawtoothStepAmount => 10d; + + /// + protected override Illuminance DecrementCondition(Illuminance currentCondition) + { + return new Illuminance(currentCondition.Lux - 100); + } + + /// + protected override Illuminance DecrementCondition(Illuminance currentCondition, double conditionDelta) + { + return new Illuminance(currentCondition.Lux - conditionDelta); + } + + /// + protected override Illuminance IncrementCondition(Illuminance currentCondition) + { + return new Illuminance(currentCondition.Lux + 100); + } + + /// + protected override Illuminance IncrementCondition(Illuminance currentCondition, double conditionDelta) + { + return new Illuminance(currentCondition.Lux + conditionDelta); + } +} diff --git a/Source/Meadow.Foundation.Libraries_and_Frameworks/Audio.MicroAudio/Driver/Audio.MicroAudio.csproj b/Source/Meadow.Foundation.Libraries_and_Frameworks/Audio.MicroAudio/Driver/Audio.MicroAudio.csproj index 69cd786cc4..44f16393ea 100644 --- a/Source/Meadow.Foundation.Libraries_and_Frameworks/Audio.MicroAudio/Driver/Audio.MicroAudio.csproj +++ b/Source/Meadow.Foundation.Libraries_and_Frameworks/Audio.MicroAudio/Driver/Audio.MicroAudio.csproj @@ -22,6 +22,6 @@ - + diff --git a/Source/Meadow.Foundation.Libraries_and_Frameworks/Audio.MicroAudio/Samples/Audio.MicroAudio_Sample/Audio.MicroAudio_Sample.csproj b/Source/Meadow.Foundation.Libraries_and_Frameworks/Audio.MicroAudio/Samples/Audio.MicroAudio_Sample/Audio.MicroAudio_Sample.csproj index 094ecd5cd1..658a2530b4 100644 --- a/Source/Meadow.Foundation.Libraries_and_Frameworks/Audio.MicroAudio/Samples/Audio.MicroAudio_Sample/Audio.MicroAudio_Sample.csproj +++ b/Source/Meadow.Foundation.Libraries_and_Frameworks/Audio.MicroAudio/Samples/Audio.MicroAudio_Sample/Audio.MicroAudio_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Libraries_and_Frameworks/DataLoggers.AdafruitIO/Driver/DataLoggers.AdafruitIO.csproj b/Source/Meadow.Foundation.Libraries_and_Frameworks/DataLoggers.AdafruitIO/Driver/DataLoggers.AdafruitIO.csproj index 44f0f8d586..f724002110 100644 --- a/Source/Meadow.Foundation.Libraries_and_Frameworks/DataLoggers.AdafruitIO/Driver/DataLoggers.AdafruitIO.csproj +++ b/Source/Meadow.Foundation.Libraries_and_Frameworks/DataLoggers.AdafruitIO/Driver/DataLoggers.AdafruitIO.csproj @@ -22,6 +22,6 @@ - + diff --git a/Source/Meadow.Foundation.Libraries_and_Frameworks/DataLoggers.SensorReading/Driver/DataLoggers.SensorReading.csproj b/Source/Meadow.Foundation.Libraries_and_Frameworks/DataLoggers.SensorReading/Driver/DataLoggers.SensorReading.csproj index 42aa653a89..50903d6895 100644 --- a/Source/Meadow.Foundation.Libraries_and_Frameworks/DataLoggers.SensorReading/Driver/DataLoggers.SensorReading.csproj +++ b/Source/Meadow.Foundation.Libraries_and_Frameworks/DataLoggers.SensorReading/Driver/DataLoggers.SensorReading.csproj @@ -22,6 +22,6 @@ - + diff --git a/Source/Meadow.Foundation.Libraries_and_Frameworks/DataLoggers.ThingSpeak/Driver/DataLoggers.ThingSpeak.csproj b/Source/Meadow.Foundation.Libraries_and_Frameworks/DataLoggers.ThingSpeak/Driver/DataLoggers.ThingSpeak.csproj index f81f3afbde..2f1d97c65f 100644 --- a/Source/Meadow.Foundation.Libraries_and_Frameworks/DataLoggers.ThingSpeak/Driver/DataLoggers.ThingSpeak.csproj +++ b/Source/Meadow.Foundation.Libraries_and_Frameworks/DataLoggers.ThingSpeak/Driver/DataLoggers.ThingSpeak.csproj @@ -22,6 +22,6 @@ - + diff --git a/Source/Meadow.Foundation.Libraries_and_Frameworks/Displays.TextDisplayMenu/Driver/Displays.TextDisplayMenu.csproj b/Source/Meadow.Foundation.Libraries_and_Frameworks/Displays.TextDisplayMenu/Driver/Displays.TextDisplayMenu.csproj index d093d88f28..c1f294a84d 100644 --- a/Source/Meadow.Foundation.Libraries_and_Frameworks/Displays.TextDisplayMenu/Driver/Displays.TextDisplayMenu.csproj +++ b/Source/Meadow.Foundation.Libraries_and_Frameworks/Displays.TextDisplayMenu/Driver/Displays.TextDisplayMenu.csproj @@ -22,7 +22,7 @@ - - + + diff --git a/Source/Meadow.Foundation.Libraries_and_Frameworks/Displays.TextDisplayMenu/Samples/TextDisplayMenuTft_Sample/TextDisplayMenuTft_Sample.csproj b/Source/Meadow.Foundation.Libraries_and_Frameworks/Displays.TextDisplayMenu/Samples/TextDisplayMenuTft_Sample/TextDisplayMenuTft_Sample.csproj index 6ebba269d0..7c6a824b65 100644 --- a/Source/Meadow.Foundation.Libraries_and_Frameworks/Displays.TextDisplayMenu/Samples/TextDisplayMenuTft_Sample/TextDisplayMenuTft_Sample.csproj +++ b/Source/Meadow.Foundation.Libraries_and_Frameworks/Displays.TextDisplayMenu/Samples/TextDisplayMenuTft_Sample/TextDisplayMenuTft_Sample.csproj @@ -15,9 +15,9 @@ - - - + + + diff --git a/Source/Meadow.Foundation.Libraries_and_Frameworks/Displays.TextDisplayMenu/Samples/TextDisplayMenu_GameMenu_Sample/TextDisplayMenu_GameMenu_Sample.csproj b/Source/Meadow.Foundation.Libraries_and_Frameworks/Displays.TextDisplayMenu/Samples/TextDisplayMenu_GameMenu_Sample/TextDisplayMenu_GameMenu_Sample.csproj index 4c9b192fb6..33322cf4b5 100644 --- a/Source/Meadow.Foundation.Libraries_and_Frameworks/Displays.TextDisplayMenu/Samples/TextDisplayMenu_GameMenu_Sample/TextDisplayMenu_GameMenu_Sample.csproj +++ b/Source/Meadow.Foundation.Libraries_and_Frameworks/Displays.TextDisplayMenu/Samples/TextDisplayMenu_GameMenu_Sample/TextDisplayMenu_GameMenu_Sample.csproj @@ -15,9 +15,9 @@ - - - + + + diff --git a/Source/Meadow.Foundation.Libraries_and_Frameworks/Displays.TextDisplayMenu/Samples/TextDisplayMenu_Sample/TextDisplayMenu_Sample.csproj b/Source/Meadow.Foundation.Libraries_and_Frameworks/Displays.TextDisplayMenu/Samples/TextDisplayMenu_Sample/TextDisplayMenu_Sample.csproj index 4c9b192fb6..33322cf4b5 100644 --- a/Source/Meadow.Foundation.Libraries_and_Frameworks/Displays.TextDisplayMenu/Samples/TextDisplayMenu_Sample/TextDisplayMenu_Sample.csproj +++ b/Source/Meadow.Foundation.Libraries_and_Frameworks/Displays.TextDisplayMenu/Samples/TextDisplayMenu_Sample/TextDisplayMenu_Sample.csproj @@ -15,9 +15,9 @@ - - - + + + diff --git a/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroGraphics/Driver/Buffers/BufferRgb666.cs b/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroGraphics/Driver/Buffers/BufferRgb666.cs new file mode 100644 index 0000000000..ad03fd1f13 --- /dev/null +++ b/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroGraphics/Driver/Buffers/BufferRgb666.cs @@ -0,0 +1,179 @@ +using Meadow.Peripherals.Displays; +using System; + +namespace Meadow.Foundation.Graphics.Buffers +{ + /// + /// Represents an 18bpp color pixel buffer + /// + public class BufferRgb666 : PixelBufferBase + { + /// + /// Color mode of the buffer + /// + public override ColorMode ColorMode => ColorMode.Format18bppRgb666; + + /// + /// Number of bytes in buffer + /// + public override int ByteCount => Width * Height * 3; + + /// + /// Create a new BufferRgb666 object + /// + /// The width in pixels + /// The height in pixels + /// The backing buffer + public BufferRgb666(int width, int height, byte[] buffer) : base(width, height, buffer) { } + + /// + /// Create a new BufferRgb666 object + /// + /// The width in pixels + /// The height in pixels + public BufferRgb666(int width, int height) : base(width, height) { } + + /// + /// Create a new BufferRgb666 object + /// + public BufferRgb666() : base() { } + + /// + /// Get the pixel color + /// + /// The X pixel position + /// The Y pixel position + /// The pixel color + public override Color GetPixel(int x, int y) + { + int index = ((y * Width) + x) * 3; + byte r = (byte)(Buffer[index] & 0xFC); // RRRRRR00 + byte g = (byte)(Buffer[index + 1] & 0xFC);// GGGGGG00 + byte b = (byte)(Buffer[index + 2] & 0xFC);// BBBBBB00 + + return new Color(r, g, b); + } + + /// + /// Set the pixel color + /// + /// X pixel position + /// Y pixel position + /// The pixel color + public override void SetPixel(int x, int y, Color color) + { + int index = ((y * Width) + x) * 3; + Buffer[index] = (byte)(color.R & 0xFC); // RRRRRR00 + Buffer[index + 1] = (byte)(color.G & 0xFC);// GGGGGG00 + Buffer[index + 2] = (byte)(color.B & 0xFC);// BBBBBB00 + } + + /// + /// Fill buffer with a color + /// + /// The fill color + public override void Fill(Color color) + { + Console.WriteLine("Fill"); + + byte[] value = { (byte)(color.R & 0xFC), (byte)(color.G & 0xFC), (byte)(color.B & 0xFC) }; + int arrayMidPoint = Buffer.Length / 2; + int copyLength; + + // Fill the initial part of the buffer + for (int i = 0; i < 3; i++) + { + Buffer[i] = value[i]; + } + + // Use Array.Copy to fill the buffer in larger chunks + for (copyLength = 3; copyLength < arrayMidPoint; copyLength <<= 1) + { + Array.Copy(Buffer, 0, Buffer, copyLength, copyLength); + } + + // Copy whatever is remaining + Array.Copy(Buffer, 0, Buffer, copyLength, Buffer.Length - copyLength); + } + + /// + /// Fill a region with a color + /// + /// X start position in pixels + /// Y start position in pixels + /// Width in pixels + /// Height in pixels + /// The fill color + /// Throws an exception if fill area is beyond the buffer bounds + public override void Fill(int x, int y, int width, int height, Color color) + { + if (x < 0 || x + width > Width || + y < 0 || y + height > Height) + { + throw new ArgumentOutOfRangeException(); + } + + byte[] value = { (byte)(color.R & 0xFC), (byte)(color.G & 0xFC), (byte)(color.B & 0xFC) }; + int index = (y * Width + x) * 3 - 1; + + // Fill the first line + for (int i = 0; i < width; i++) + { + Buffer[++index] = value[0]; + Buffer[++index] = value[1]; + Buffer[++index] = value[2]; + } + + //array copy the rest + for (int j = 0; j < height - 1; j++) + { + Array.Copy(Buffer, + (y + j) * Width * 3 + x * 3, + Buffer, + (y + j + 1) * Width * 3 + x * 3, + width * 3); + } + } + + /// + /// Invert the pixel + /// + /// x position of pixel + /// y position of pixel + public override void InvertPixel(int x, int y) + { + int index = ((y * Width) + x) * 3; + Buffer[index] = (byte)(~Buffer[index] & 0xFC); // Invert R + Buffer[index + 1] = (byte)(~Buffer[index + 1] & 0xFC);// Invert G + Buffer[index + 2] = (byte)(~Buffer[index + 2] & 0xFC);// Invert B + } + + /// + /// Write a buffer to specific location to the current buffer + /// + /// x origin + /// y origin + /// buffer to write + public override void WriteBuffer(int x, int y, IPixelBuffer buffer) + { + if (buffer.ColorMode == ColorMode) + { + int sourceIndex, destinationIndex; + int length = buffer.Width * 3; + + for (int i = 0; i < buffer.Height; i++) + { + sourceIndex = length * i; + destinationIndex = (Width * (y + i) + x) * 3; + + Array.Copy(buffer.Buffer, sourceIndex, Buffer, destinationIndex, length); + } + } + else + { + // Fall back to a slow write + base.WriteBuffer(x, y, buffer); + } + } + } +} \ No newline at end of file diff --git a/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroGraphics/Driver/Buffers/PixelBufferBase.cs b/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroGraphics/Driver/Buffers/PixelBufferBase.cs index 4dc714d4d7..b6a86e3045 100644 --- a/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroGraphics/Driver/Buffers/PixelBufferBase.cs +++ b/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroGraphics/Driver/Buffers/PixelBufferBase.cs @@ -1,4 +1,5 @@ using Meadow.Peripherals.Displays; +using Meadow.Units; using System; using System.Linq; @@ -54,7 +55,7 @@ public int BitDepth /// /// Number of bytes in buffer /// - public int ByteCount => (Width * Height * BitDepth) >> 3; + public virtual int ByteCount => (Width * Height * BitDepth) >> 3; /// /// The buffer that holds the pixel data @@ -223,7 +224,7 @@ protected void WriteBufferSlow(int originX, int originY, IPixelBuffer buffer) /// Buffer type /// Rotation /// The new buffer - public T RotateAndConvert(RotationType rotation) + public T Rotate(RotationType rotation) where T : PixelBufferBase, new() { T newBuffer; @@ -266,7 +267,7 @@ public T RotateAndConvert(RotationType rotation) } /// - /// Create a new buffer scaled up from the existing buffer + /// Create a new buffer integer scaled up from the existing buffer /// /// Buffer type /// Integer scale ratio @@ -281,7 +282,6 @@ public T ScaleUp(int scaleFactor) Height = Height * scaleFactor, }; newBuffer.InitializeBuffer(true); - newBuffer.Clear(); for (int i = 0; i < Width; i++) { @@ -294,12 +294,11 @@ public T ScaleUp(int scaleFactor) } /// - /// Create a new pixel buffer and - /// copy/convert pixel data from existing buffer + /// Create a new pixel buffer and copy/convert pixel data from existing buffer /// /// The buffer type to convert to /// A pixel buffer derived from PixelBufferBase - public T ConvertPixelBuffer() + public T Convert() where T : PixelBufferBase, new() { if (GetType() == typeof(T)) @@ -343,19 +342,159 @@ public T ConvertPixelBuffer() return newBuffer; } + /// + /// Resize the buffer to new dimensions using the nearest neighbor algorithm + /// + /// Buffer type + /// New width + /// New height + /// The resized buffer + public T Resize(int newWidth, int newHeight) + where T : PixelBufferBase, new() + { + T newBuffer = new() + { + Width = newWidth, + Height = newHeight, + }; + + float xRatio = (float)Width / newWidth; + float yRatio = (float)Height / newHeight; + + for (int i = 0; i < newWidth; i++) + { + for (int j = 0; j < newHeight; j++) + { + int srcX = (int)(i * xRatio); + int srcY = (int)(j * yRatio); + newBuffer.SetPixel(i, j, GetPixel(srcX, srcY)); + } + } + return newBuffer; + } + + /// + /// Resize the buffer to new dimensions using bilinear interpolation + /// + /// Buffer type + /// New width + /// New height + /// The resized buffer + public T ResizeBilinear(int newWidth, int newHeight) + where T : PixelBufferBase, new() + { + T newBuffer = new() + { + Width = newWidth, + Height = newHeight, + }; + newBuffer.InitializeBuffer(true); + + float xRatio = (float)(Width - 1) / newWidth; + float yRatio = (float)(Height - 1) / newHeight; + + for (int i = 0; i < newWidth; i++) + { + for (int j = 0; j < newHeight; j++) + { + float gx = i * xRatio; + float gy = j * yRatio; + int gxi = (int)gx; + int gyi = (int)gy; + + var c00 = GetPixel(gxi, gyi); + var c10 = GetPixel(gxi + 1, gyi); + var c01 = GetPixel(gxi, gyi + 1); + var c11 = GetPixel(gxi + 1, gyi + 1); + + float w00 = (1 - (gx - gxi)) * (1 - (gy - gyi)); + float w10 = (gx - gxi) * (1 - (gy - gyi)); + float w01 = (1 - (gx - gxi)) * (gy - gyi); + float w11 = (gx - gxi) * (gy - gyi); + + var r = (byte)(c00.R * w00 + c10.R * w10 + c01.R * w01 + c11.R * w11); + var g = (byte)(c00.G * w00 + c10.G * w10 + c01.G * w01 + c11.G * w11); + var b = (byte)(c00.B * w00 + c10.B * w10 + c01.B * w01 + c11.B * w11); + + newBuffer.SetPixel(i, j, new Color(r, g, b)); + } + } + + return newBuffer; + } + + /// + /// Rotate the buffer by an arbitrary angle + /// + /// Buffer type + /// Rotation angle in degrees + /// The rotated buffer + public T Rotate(Angle angle) + where T : PixelBufferBase, new() + { + // Convert angle to radians + var radians = (float)angle.Radians; + + // Calculate sine and cosine of the angle + var cos = MathF.Cos(radians); + var sin = MathF.Sin(radians); + + // Calculate the new width and height of the bounding box + int newWidth = (int)MathF.Ceiling(MathF.Abs(Width * cos) + MathF.Abs(Height * sin)); + int newHeight = (int)MathF.Ceiling(MathF.Abs(Width * sin) + MathF.Abs(Height * cos)); + + // Create a new buffer + T newBuffer = new() + { + Width = newWidth, + Height = newHeight, + }; + newBuffer.InitializeBuffer(true); + newBuffer.Clear(); + + // Center of the original and new buffer + int x0 = Width / 2; + int y0 = Height / 2; + int x1 = newWidth / 2; + int y1 = newHeight / 2; + + // Map each pixel from the original buffer to the new buffer + for (int x = 0; x < Width; x++) + { + for (int y = 0; y < Height; y++) + { + // Calculate the coordinates relative to the center + int dx = x - x0; + int dy = y - y0; + + // Apply the rotation matrix + int newX = (int)(dx * cos - dy * sin + x1); + int newY = (int)(dx * sin + dy * cos + y1); + + // Set the pixel in the new buffer if within bounds + if (newX >= 0 && newX < newWidth && newY >= 0 && newY < newHeight) + { + newBuffer.SetPixel(newX, newY, GetPixel(x, y)); + } + } + } + + return newBuffer; + } + /// /// Calculate the uncorrected distance between two colors using bytes for red, green, blue /// /// /// - /// The distance as a double - public double GetColorDistance(Color color1, Color color2) + /// The distance as a float + public float GetColorDistance(Color color1, Color color2) { - var rDeltaSquared = Math.Abs(color1.R - color2.R) ^ 2; - var gDeltaSquared = Math.Abs(color1.G - color2.G) ^ 2; - var bDeltaSquared = Math.Abs(color1.B - color2.B) ^ 2; + var rDeltaSquared = MathF.Pow(MathF.Abs(color1.R - color2.R), 2); + var gDeltaSquared = MathF.Pow(MathF.Abs(color1.G - color2.G), 2); + var bDeltaSquared = MathF.Pow(MathF.Abs(color1.B - color2.B), 2); - return Math.Sqrt(rDeltaSquared + gDeltaSquared + bDeltaSquared); + return MathF.Sqrt(rDeltaSquared + gDeltaSquared + bDeltaSquared); } /// @@ -366,7 +505,7 @@ protected virtual void Dispose(bool disposing) { if (!isDisposed) { - if (createdBuffer) + if (disposing && createdBuffer) { if (disposing) { diff --git a/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroGraphics/Driver/Graphics.MicroGraphics.csproj b/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroGraphics/Driver/Graphics.MicroGraphics.csproj index 8b949e6ae4..158c577724 100644 --- a/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroGraphics/Driver/Graphics.MicroGraphics.csproj +++ b/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroGraphics/Driver/Graphics.MicroGraphics.csproj @@ -22,6 +22,6 @@ - + diff --git a/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroGraphics/Driver/GraphicsPath.cs b/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroGraphics/Driver/GraphicsPath.cs index 25f7e1825e..6fc5a6583a 100644 --- a/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroGraphics/Driver/GraphicsPath.cs +++ b/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroGraphics/Driver/GraphicsPath.cs @@ -1,4 +1,5 @@ -using System; +using Meadow.Units; +using System; using System.Collections.Generic; using System.Linq; @@ -19,8 +20,7 @@ public enum PathDirection CounterClockwise } - //https://api.skia.org/classSkPath.html#ac36f638ac96f3428626e993eacf84ff0ab2c02031eada4693dcf0f0724aec22a6 - internal enum VerbType //from Skia, could change + internal enum VerbType { Move, Line, @@ -40,7 +40,7 @@ public PathAction(Point pathPoint, VerbType verb) } /// - /// Represents a 2D graphics paths + /// Represents a 2D graphics path /// public class GraphicsPath { @@ -50,19 +50,19 @@ public class GraphicsPath public Point LastPoint => PathActions.LastOrDefault().PathPoint; /// - /// The number of points in th path + /// The number of points in the path /// public int PointCount => PathActions.Count; /// /// The collection of points /// - public Point[]? Points; + public Point[] Points { get; private set; } /// /// The number of verbs/actions used /// - public int VerbCount => PathActions.Count; //need to figure out if/when this wouldn't be equal to PointCount + public int VerbCount => PathActions.Count; /// /// The collection of actions @@ -76,26 +76,27 @@ public Rect Bounds { get { - if (Points == null) + if (PathActions == null || PathActions.Count == 0) { return new Rect(0, 0, 0, 0); } - Point min = Points[0]; - Point max = Points[0]; + Point min = PathActions[0].PathPoint; + Point max = PathActions[0].PathPoint; - foreach (var p in Points) + foreach (var action in PathActions) { - min.X = Math.Min(min.X, p.X); - min.Y = Math.Min(min.Y, p.Y); - max.X = Math.Max(max.X, p.X); - max.Y = Math.Min(max.X, p.Y); + min.X = Math.Min(min.X, action.PathPoint.X); + min.Y = Math.Min(min.Y, action.PathPoint.Y); + max.X = Math.Max(max.X, action.PathPoint.X); + max.Y = Math.Max(max.Y, action.PathPoint.Y); } return new Rect(min.X, min.Y, max.X, max.Y); } } + /// /// Create a new GraphicsPath object /// @@ -116,7 +117,7 @@ public GraphicsPath(GraphicsPath path) /// public void Reset() { - PathActions = new List(); + PathActions.Clear(); } /// @@ -290,6 +291,87 @@ public void AddPathReverse(GraphicsPath path) } } + /// + /// Scales the path by the specified factors in the X and Y directions. + /// + /// The scale factor in the X direction. + /// The scale factor in the Y direction. + public void Scale(float scaleX, float scaleY) + { + for (int i = 0; i < PathActions.Count; i++) + { + var action = PathActions[i]; + action.PathPoint = new Point((int)(action.PathPoint.X * scaleX), (int)(action.PathPoint.Y * scaleY)); + PathActions[i] = action; + } + } + + /// + /// Translates the path by the specified amounts in the X and Y directions. + /// + /// The amount to translate in the X direction. + /// The amount to translate in the Y direction. + public void Translate(float dx, float dy) + { + for (int i = 0; i < PathActions.Count; i++) + { + var action = PathActions[i]; + action.PathPoint = new Point((int)(action.PathPoint.X + dx), (int)(action.PathPoint.Y + dy)); + PathActions[i] = action; + } + } + + /// + /// Rotates the path by the specified angle. + /// + /// The angle to rotate the path, in degrees. + public void Rotate(Angle angle) + { + float radians = (float)angle.Radians; + float cos = MathF.Cos(radians); + float sin = MathF.Sin(radians); + + for (int i = 0; i < PathActions.Count; i++) + { + var action = PathActions[i]; + float x = action.PathPoint.X; + float y = action.PathPoint.Y; + action.PathPoint = new Point( + (int)(x * cos - y * sin), + (int)(x * sin + y * cos)); + PathActions[i] = action; + } + } + + /// + /// Determines if a point lies on the path within a specified tolerance. + /// + /// The point to check. + /// The tolerance within which the point is considered to be on the path. + /// True if the point is on the path; otherwise, false. + public bool IsPointOnPath(Point point, float tolerance = 0.5f) + { + foreach (var action in PathActions) + { + if (MathF.Abs(action.PathPoint.X - point.X) <= tolerance && MathF.Abs(action.PathPoint.Y - point.Y) <= tolerance) + { + return true; + } + } + return false; + } + + /// + /// Clips the path to a specified rectangular area. + /// + /// The rectangle to which the path will be clipped. + public void Clip(Rect clipRect) + { + PathActions = PathActions.Where(action => + action.PathPoint.X >= clipRect.Left && action.PathPoint.X <= clipRect.Right && + action.PathPoint.Y >= clipRect.Top && action.PathPoint.Y <= clipRect.Bottom).ToList(); + } + /// /// Close the path /// @@ -320,9 +402,8 @@ PathAction GetPathStart() index++; } return PathActions[index]; - } return PathActions[0]; } } -} \ No newline at end of file +} diff --git a/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroGraphics/Driver/MicroGraphics.Antialiasing.cs b/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroGraphics/Driver/MicroGraphics.Antialiasing.cs new file mode 100644 index 0000000000..7557017495 --- /dev/null +++ b/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroGraphics/Driver/MicroGraphics.Antialiasing.cs @@ -0,0 +1,132 @@ +using System; + +namespace Meadow.Foundation.Graphics +{ + public partial class MicroGraphics + { + /// + /// Draws an anti-aliased line between two points using the Xiaolin Wu algorithm + /// + /// The x-coordinate of the starting point of the line + /// The y-coordinate of the starting point of the line + /// The x-coordinate of the ending point of the line + /// The y-coordinate of the ending point of the line + /// The color of the line + /// + /// This method uses the Xiaolin Wu line algorithm to draw an anti-aliased line between two points. + /// + public void DrawLineAntialiased(float x0, float y0, float x1, float y1, Color color) + { + bool steep = MathF.Abs(y1 - y0) > MathF.Abs(x1 - x0); + float temp; + if (steep) + { + temp = x0; x0 = y0; y0 = temp; + temp = x1; x1 = y1; y1 = temp; + } + if (x0 > x1) + { + temp = x0; x0 = x1; x1 = temp; + temp = y0; y0 = y1; y1 = temp; + } + + float dx = x1 - x0; + float dy = y1 - y0; + float gradient = dy / dx; + + float xEnd = Round(x0); + float yEnd = y0 + gradient * (xEnd - x0); + float xGap = GetRFPart(x0 + 0.5f); + float xPixel1 = xEnd; + float yPixel1 = GetIPart(yEnd); + + if (steep) + { + DrawPixelWithAlpha(yPixel1, xPixel1, color, GetRFPart(yEnd) * xGap); + DrawPixelWithAlpha(yPixel1 + 1, xPixel1, color, GetFPart(yEnd) * xGap); + } + else + { + DrawPixelWithAlpha(xPixel1, yPixel1, color, GetRFPart(yEnd) * xGap); + DrawPixelWithAlpha(xPixel1, yPixel1 + 1, color, GetFPart(yEnd) * xGap); + } + float intery = yEnd + gradient; + + xEnd = Round(x1); + yEnd = y1 + gradient * (xEnd - x1); + xGap = GetFPart(x1 + 0.5f); + + float xPixel2 = xEnd; + float yPixel2 = GetIPart(yEnd); + if (steep) + { + DrawPixelWithAlpha(yPixel2, xPixel2, color, GetRFPart(yEnd) * xGap); + DrawPixelWithAlpha(yPixel2 + 1, xPixel2, color, GetFPart(yEnd) * xGap); + } + else + { + DrawPixelWithAlpha(xPixel2, yPixel2, color, GetRFPart(yEnd) * xGap); + DrawPixelWithAlpha(xPixel2, yPixel2 + 1, color, GetFPart(yEnd) * xGap); + } + + if (steep) + { + for (int x = (int)(xPixel1 + 1); x <= xPixel2 - 1; x++) + { + DrawPixelWithAlpha(GetIPart(intery), x, color, GetRFPart(intery)); + DrawPixelWithAlpha(GetIPart(intery) + 1, x, color, GetFPart(intery)); + intery += gradient; + } + } + else + { + for (int x = (int)(xPixel1 + 1); x <= xPixel2 - 1; x++) + { + DrawPixelWithAlpha(x, GetIPart(intery), color, GetRFPart(intery)); + DrawPixelWithAlpha(x, GetIPart(intery) + 1, color, GetFPart(intery)); + intery += gradient; + } + } + } + + /// + /// Draw an anti-aliased triangle + /// + /// Vertex #0 x coordinate + /// Vertex #0 y coordinate + /// Vertex #1 x coordinate + /// Vertex #1 y coordinate + /// Vertex #2 x coordinate + /// Vertex #2 y coordinate + /// The color of the triangle + /// Draw a filled triangle? + public void DrawTriangleAntialiased(int x0, int y0, int x1, int y1, int x2, int y2, Color color, bool filled = false) + { + DrawLineAntialiased(x0, y0, x1, y1, color); + DrawLineAntialiased(x1, y1, x2, y2, color); + DrawLineAntialiased(x2, y2, x0, y0, color); + if (filled) + { + DrawTriangleFilled(x0, y0, x1, y1, x2, y2, color); + } + } + + private int GetIPart(float value) => (int)value; + + private int Round(float value) => GetIPart(value + 0.5f); + + private float GetFPart(float value) + { + if (value < 0) + { + return 1 - (value - MathF.Floor(value)); + } + return value - MathF.Floor(value); + } + + private float GetRFPart(float value) + { + return 1 - GetFPart(value); + } + } +} \ No newline at end of file diff --git a/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroGraphics/Driver/MicroGraphics.GraphicsPath.cs b/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroGraphics/Driver/MicroGraphics.GraphicsPath.cs index e7c307067b..f54c7365da 100644 --- a/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroGraphics/Driver/MicroGraphics.GraphicsPath.cs +++ b/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroGraphics/Driver/MicroGraphics.GraphicsPath.cs @@ -1,4 +1,7 @@ -namespace Meadow.Foundation.Graphics +using System; +using System.Collections.Generic; + +namespace Meadow.Foundation.Graphics { public partial class MicroGraphics { @@ -7,18 +10,20 @@ public partial class MicroGraphics /// /// The path /// Should pixels be enabled (on) or disabled (off) - public void DrawPath(GraphicsPath path, bool enabled) + /// Fill the path (true) or draw the outline (false, default) + public void DrawPath(GraphicsPath path, bool enabled, bool filled = false) { - DrawPath(path, (enabled ? Color.White : Color.Black)); + DrawPath(path, enabled ? Color.White : Color.Black, filled); } /// /// Draw a graphics path /// /// The path - public void DrawPath(GraphicsPath path) + /// Fill the path (true) or draw the outline (false, default) + public void DrawPath(GraphicsPath path, bool filled = false) { - DrawPath(path, PenColor); + DrawPath(path, PenColor, filled); } /// @@ -26,8 +31,15 @@ public void DrawPath(GraphicsPath path) /// /// The path /// The color to draw the path - public void DrawPath(GraphicsPath path, Color color) + /// Fill the path (true) or draw the outline (false, default) + public void DrawPath(GraphicsPath path, Color color, bool filled = false) { + if (filled) + { + FillPath(path, color); + return; + } + for (int i = 0; i < path.PointCount; i++) { if (path.PathActions[i].Verb == VerbType.Move || i == 0) @@ -42,5 +54,95 @@ public void DrawPath(GraphicsPath path, Color color) color); } } + + /// + /// Draw a filled graphics path + /// + /// The path + /// The color to fill the path + protected void FillPath(GraphicsPath path, Color fillColor) + { + if (path.PointCount < 3) + { + return; // A path must have at least 3 points to form a filled shape + } + + // Find the bounding box of the path + var bounds = path.Bounds; + int minY = bounds.Top; + int maxY = bounds.Top + bounds.Height; + + // Create an edge list for each scanline + List[] edges = new List[maxY - minY + 1]; + for (int i = 0; i < edges.Length; i++) + { + edges[i] = new List(); + } + + // Build the edge list + for (int i = 0; i < path.PointCount; i++) + { + var p1 = path.PathActions[i].PathPoint; + var p2 = path.PathActions[(i + 1) % path.PointCount].PathPoint; + + if (p1.Y == p2.Y) + { + continue; // Skip horizontal lines + } + + var ymin = Math.Min(p1.Y, p2.Y); + var ymax = Math.Max(p1.Y, p2.Y); + var xmin = (p1.Y < p2.Y) ? p1.X : p2.X; + + float invSlope = (float)(p2.X - p1.X) / (p2.Y - p1.Y); + + for (int y = ymin; y < ymax; y++) + { + if (y - minY < 0 || y - minY >= edges.Length) + { + continue; + } + + edges[y - minY].Add(new Edge { X = xmin + invSlope * (y - ymin), InvSlope = invSlope }); + } + } + + // Sort the edges and fill the path + for (int y = minY; y <= maxY; y++) + { + var activeEdges = edges[y - minY]; + if (activeEdges.Count == 0) + { + continue; + } + + activeEdges.Sort((a, b) => a.X.CompareTo(b.X)); + + for (int i = 0; i < activeEdges.Count; i += 2) + { + int xStart = (int)Math.Round(activeEdges[i].X); + int xEnd = (int)Math.Round(activeEdges[i + 1].X); + + for (int x = xStart; x < xEnd; x++) + { + DrawPixel(x, y, fillColor); + } + } + + // Update the edges for the next scanline + for (int i = 0; i < activeEdges.Count; i++) + { + var edge = activeEdges[i]; + edge.X += edge.InvSlope; + activeEdges[i] = edge; + } + } + } + + struct Edge + { + public float X; + public float InvSlope; + } } } \ No newline at end of file diff --git a/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroGraphics/Driver/MicroGraphics.cs b/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroGraphics/Driver/MicroGraphics.cs index da76e9e0ae..815e64a9a8 100644 --- a/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroGraphics/Driver/MicroGraphics.cs +++ b/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroGraphics/Driver/MicroGraphics.cs @@ -19,7 +19,7 @@ public partial class MicroGraphics /// /// PixelBuffer draw target /// - protected IPixelBuffer PixelBuffer => (display != null) ? display.PixelBuffer : memoryBuffer; + protected IPixelBuffer PixelBuffer => display?.PixelBuffer ?? memoryBuffer; private readonly IPixelBuffer memoryBuffer = default!; /// @@ -30,12 +30,12 @@ public partial class MicroGraphics /// /// The color used when a pixel is enabled (on) /// - public Color EnabledColor => display != null ? display.EnabledColor : Color.White; + public Color EnabledColor => display?.EnabledColor ?? Color.White; /// /// The color used when a pixel is not enabled (off) /// - public Color DisabledColor => display != null ? display.EnabledColor : Color.Black; + public Color DisabledColor => display?.DisabledColor ?? Color.Black; /// /// Font used for drawing text to the display @@ -1464,6 +1464,55 @@ public void DrawBufferWithTransparencyColor(int x, int y, IPixelBuffer buffer, C } } + /// + /// Get the color for a pixel at a given location + /// + /// x location + /// y location + public virtual Color GetPixel(int x, int y) + { + if (IgnoreOutOfBoundsPixels && IsCoordinateInBounds(x, y) == false) + { + return Color.Black; + } + + if (display is IRotatableDisplay) + { + return PixelBuffer.GetPixel(x, y); + } + else + { + return PixelBuffer.GetPixel(GetXForRotation(x, y), GetYForRotation(x, y)); + } + } + + /// + /// Draws a pixel with alpha blending at the specified coordinates using the given color and it's alpha value + /// + /// The x-coordinate of the pixel + /// The y-coordinate of the pixel + /// The color to draw + public void DrawPixelWithAlpha(float x, float y, Color color) + { + DrawPixelWithAlpha(x, y, color, color.A); + } + + /// + /// Draws a pixel with alpha blending at the specified coordinates using the given color an external alpha value + /// + /// + /// The alpha channel of the provided color will be ignored + /// + /// The x-coordinate of the pixel + /// The y-coordinate of the pixel + /// The color to draw + /// The alpha value + public void DrawPixelWithAlpha(float x, float y, Color color, float alpha) + { + var background = GetPixel((int)x, (int)y); + DrawPixel((int)x, (int)y, background.Blend(color, alpha)); + } + /// /// Draw an Image onto the display buffer at the specified location /// diff --git a/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroGraphics/Samples/ImageLoadSample/ImageLoad_Sample.csproj b/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroGraphics/Samples/ImageLoadSample/ImageLoad_Sample.csproj index f72b5cf7b4..4bedbde848 100644 --- a/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroGraphics/Samples/ImageLoadSample/ImageLoad_Sample.csproj +++ b/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroGraphics/Samples/ImageLoadSample/ImageLoad_Sample.csproj @@ -29,7 +29,7 @@ - - + + diff --git a/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroLayout/Driver/Charts/LineChart.cs b/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroLayout/Driver/Charts/LineChart.cs index ae48076b13..474d58134b 100644 --- a/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroLayout/Driver/Charts/LineChart.cs +++ b/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroLayout/Driver/Charts/LineChart.cs @@ -194,7 +194,8 @@ private void DrawSeries(MicroGraphics graphics, LineChartSeries series) var xRange = series.Points.MaxX - minX; var yRange = series.Points.MaxY; // - minY; // assuming axis at 0 right now - var lastPoint = new LineSeriesPoint(); + int lastX = 0; + int lastY = 0; var first = true; graphics.Stroke = series.LineStroke; @@ -213,15 +214,15 @@ private void DrawSeries(MicroGraphics graphics, LineChartSeries series) else { graphics.DrawLine( - (int)lastPoint.X + ParentOffsetX, - (int)lastPoint.Y + ParentOffsetY, + lastX + ParentOffsetX, + lastY + ParentOffsetY, scaledX, scaledY, series.LineColor); } - lastPoint.X = scaledX; - lastPoint.Y = scaledY; + lastX = scaledX; + lastY = scaledY; } if (series.ShowPoints) diff --git a/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroLayout/Driver/Charts/LineSeriesPointCollection.cs b/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroLayout/Driver/Charts/LineSeriesPointCollection.cs index 09ba2e2ed9..16a1f34377 100644 --- a/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroLayout/Driver/Charts/LineSeriesPointCollection.cs +++ b/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroLayout/Driver/Charts/LineSeriesPointCollection.cs @@ -44,10 +44,19 @@ public void Add(double x, double y) } /// - /// Adds a point to the collection + /// Adds a series of points to the collection /// /// The point to add public void Add(params LineSeriesPoint[] points) + { + Add((IEnumerable)points); + } + + /// + /// Adds a series of points to the collection + /// + /// The points to add + public void Add(IEnumerable points) { lock (_points) { @@ -103,12 +112,15 @@ public void Remove(params LineSeriesPoint[] points) /// /// Removes all points to the collection /// - public void Clear() + /// Sets the total number of elements the collection can contain without resizing + public void Clear(int capacity = 10) { lock (_points) { _points.Clear(); + _points.Capacity = capacity; + MinX = MaxX = MinY = MaxY = 0; } } diff --git a/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroLayout/Driver/Controls/Control.cs b/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroLayout/Driver/Controls/Control.cs index 59630fa880..b162c3cada 100644 --- a/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroLayout/Driver/Controls/Control.cs +++ b/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroLayout/Driver/Controls/Control.cs @@ -22,7 +22,7 @@ public abstract class Control : IControl public object? Context { get; set; } /// - public IControl? Parent { get; set; } + public virtual IControl? Parent { get; set; } /// /// Initializes a new instance of the class with the specified dimensions. diff --git a/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroLayout/Driver/Controls/Label.cs b/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroLayout/Driver/Controls/Label.cs index 7ad5c19fd9..3ce7873546 100644 --- a/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroLayout/Driver/Controls/Label.cs +++ b/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroLayout/Driver/Controls/Label.cs @@ -5,10 +5,14 @@ /// public class Label : ThemedControl { + private static Color DefaultTextColor = Color.White; + private static Color DefaultBackColor = Color.Transparent; + private string _text = string.Empty; - private Color _textColor = Color.White; - private Color _backColor = Color.Transparent; + private DisplayTheme? _theme; + private Color? _textColor; + private Color? _backColor; private VerticalAlignment _verticalAlignment = VerticalAlignment.Center; private HorizontalAlignment _horizontalAlignment; private IFont? _font; @@ -34,16 +38,7 @@ public Label(int left, int top, int width, int height, ScaleFactor scaleFactor = /// The display theme to apply. public override void ApplyTheme(DisplayTheme theme) { - if (theme != null) - { - if (theme.TextColor != null) TextColor = theme.TextColor.Value; - if (theme.BackgroundColor != null) BackColor = theme.BackgroundColor.Value; - - if (Font == null) - { - Font = theme.Font; - } - } + _theme = theme; } /// @@ -69,7 +64,7 @@ public HorizontalAlignment HorizontalAlignment /// public Color TextColor { - get => _textColor; + get => _textColor ?? _theme?.TextColor ?? DefaultTextColor; set => SetInvalidatingProperty(ref _textColor, value); } @@ -78,7 +73,7 @@ public Color TextColor /// public Color BackColor { - get => _backColor; + get => _backColor ?? _theme?.BackgroundColor ?? DefaultBackColor; set => SetInvalidatingProperty(ref _backColor, value); } diff --git a/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroLayout/Driver/Controls/ListBox.cs b/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroLayout/Driver/Controls/ListBox.cs new file mode 100644 index 0000000000..0b1f53f609 --- /dev/null +++ b/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroLayout/Driver/Controls/ListBox.cs @@ -0,0 +1,245 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Collections.Specialized; + +namespace Meadow.Foundation.Graphics.MicroLayout; + +/// +/// Represents a list box control in the user interface. +/// +public class ListBox : MicroLayout +{ + private int _selectedIndex = -1; + private int _topIndex = 0; + private readonly List _items = new(); + private Color _textColor = Color.White; + private Color _selectedRowColor = Color.LightGray; + private Color _selectedTextColor = Color.Black; + private readonly int _rowHeight; + private readonly IFont _font; + private int _selectedLabelIndex = -1; + + /// + /// An optional function to provide formatting for row objects + /// + public Func? RowFormatter { get; set; } + + /// + /// Spacing, in pixels, between items + /// + public int ItemSpacing { get; } = 1; + /// + /// Items to display in the ListBox + /// + public ObservableCollection Items { get; } = new(); + + /// + /// Creates a ListBox control + /// + /// + /// + /// + /// + /// + public ListBox(int left, int top, int width, int height, IFont font) + : base(left, top, width, height) + { + _font = font; + BackgroundColor = Color.Black; + _rowHeight = font.Height + ItemSpacing; + var rowCount = this.Height / _rowHeight; + CreateRowlabels(rowCount); + Items.CollectionChanged += OnItemsCollectionChanged; + } + + private void CreateRowlabels(int rowCount) + { + var y = 0; + for (var i = 0; i < rowCount; i++) + { + Controls.Add( + new Label(Left, Top + y, this.Width, _rowHeight) + { + Font = _font, + TextColor = TextColor, + BackColor = this.BackgroundColor ?? Color.Transparent, + VerticalAlignment = VerticalAlignment.Center, + }); + + y += _rowHeight; + } + } + + /// + /// Gets or sets the background color for a selected row + /// + public Color SelectedRowColor + { + get => _selectedRowColor; + set + { + _selectedRowColor = value; + + if (_selectedIndex >= 0) + { + (Controls[_selectedIndex] as Label)!.BackColor = SelectedRowColor; + } + } + } + + /// + /// Gets or sets the background color for a selected row + /// + public Color SelectedTextColor + { + get => _selectedTextColor; + set + { + _selectedTextColor = value; + + if (_selectedIndex >= 0) + { + (Controls[_selectedIndex] as Label)!.TextColor = SelectedTextColor; + } + } + } + + /// + /// Gets or sets the foreground color of list items + /// + public Color TextColor + { + get => _textColor; + set + { + _textColor = value; + + foreach (Label label in Controls) + { + label.TextColor = TextColor; + } + } + } + + /// + /// The value of the selected Item + /// + public object? SelectedItem + { + get + { + if (SelectedIndex < 0) return null; + return Items[SelectedIndex]; + } + } + + /// + /// The index of the currently selected Item + /// + public int SelectedIndex + { + get => _selectedIndex; + set + { + SetInvalidatingProperty(ref _selectedIndex, value); + var controlIndex = SelectedIndex - _topIndex; + if (controlIndex >= 0 && controlIndex < Items.Count) + { + SelectLabel(controlIndex); + } + else + { + SelectLabel(-1); + } + } + } + + private void SelectLabel(int index) + { + if (_selectedLabelIndex >= 0) + { + (Controls[_selectedLabelIndex] as Label)!.TextColor = TextColor; + (Controls[_selectedLabelIndex] as Label)!.BackColor = BackgroundColor ?? Color.Transparent; + } + if (index >= 0) + { + (Controls[index] as Label)!.TextColor = SelectedTextColor; + (Controls[index] as Label)!.BackColor = SelectedRowColor; + } + _selectedLabelIndex = index; + } + + /// + /// Gets or sets the index of the top visible Item + /// + public int TopIndex + { + get => _topIndex; + set => SetInvalidatingProperty(ref _topIndex, value); + } + + private void OnItemsCollectionChanged(object sender, NotifyCollectionChangedEventArgs e) + { + switch (e.Action) + { + case NotifyCollectionChangedAction.Add: + // is the added item visible? + if (e.NewStartingIndex < TopIndex + Controls.Count) + { + var i = e.NewStartingIndex - TopIndex; + foreach (var item in e.NewItems) + { + (Controls[i] as Label)!.Text = + RowFormatter != null ? RowFormatter(item) : item.ToString(); + } + } + break; + case NotifyCollectionChangedAction.Remove: + if (e.OldStartingIndex < TopIndex + Controls.Count) + { + var i = e.OldStartingIndex - TopIndex; + + var mustClearSelection = _selectedLabelIndex == i; + var mustMoveSelection = (_selectedLabelIndex > i); + + while (i < Items.Count && i < Controls.Count - 1) + { + (Controls[i] as Label)!.Text = (Controls[i + 1] as Label)!.Text; + i++; + } + (Controls[i] as Label)!.Text = string.Empty; + + if (mustClearSelection) + { + SelectLabel(-1); + } + else if (mustMoveSelection) + { + SelectLabel(_selectedLabelIndex - 1); + } + } + break; + case NotifyCollectionChangedAction.Reset: + foreach (Label label in Controls) + { + label.Text = string.Empty; + } + break; + } + } + + /// + public override void ApplyTheme(DisplayTheme theme) + { + foreach (Label label in Controls) + { + label.ApplyTheme(theme); + } + } + + /// + protected override void OnDraw(MicroGraphics graphics) + { + } +} diff --git a/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroLayout/Driver/ControlsCollection.cs b/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroLayout/Driver/ControlsCollection.cs index 71248b6369..f2197c7ccb 100644 --- a/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroLayout/Driver/ControlsCollection.cs +++ b/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroLayout/Driver/ControlsCollection.cs @@ -3,26 +3,29 @@ namespace Meadow.Foundation.Graphics.MicroLayout; +internal interface IControlContainer +{ + IControl? Parent { get; } + ControlsCollection Controls { get; } +} + /// /// Represents a collection of display controls on a . /// public sealed class ControlsCollection : IEnumerable { - private readonly DisplayScreen _screen; private readonly List _controls = new(); private readonly object _syncRoot = new(); - private readonly IControl? _parent; + private readonly IControlContainer? _container; /// /// Initializes a new instance of the class. /// - /// The that owns the controls collection. /// The parent control (if exists) - internal ControlsCollection(DisplayScreen screen, IControl? parent) + internal ControlsCollection(IControlContainer? parent) { - _screen = screen; - _parent = parent; + _container = parent; } internal object SyncRoot => _syncRoot; @@ -44,7 +47,7 @@ public void Clear() lock (SyncRoot) { _controls.Clear(); - _screen.Invalidate(); + _container?.Parent?.Invalidate(); } } @@ -60,11 +63,14 @@ public void Clear() public void Add(params IControl[] controls) { // Apply screen theme to the added controls, if available. - if (_screen.Theme != null) + if (_container is DisplayScreen screen) { - foreach (IThemedControl control in controls) + if (screen.Theme != null) { - control.ApplyTheme(_screen.Theme); + foreach (IThemedControl control in controls) + { + control.ApplyTheme(screen.Theme); + } } } @@ -72,7 +78,7 @@ public void Add(params IControl[] controls) { foreach (var control in controls) { - control.Parent = _parent; + control.Parent = _container?.Parent; _controls.Add(control); } } diff --git a/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroLayout/Driver/DisplayScreen.cs b/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroLayout/Driver/DisplayScreen.cs index a95fe899dd..fc5d556e83 100644 --- a/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroLayout/Driver/DisplayScreen.cs +++ b/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroLayout/Driver/DisplayScreen.cs @@ -1,5 +1,6 @@ using Meadow.Hardware; using Meadow.Peripherals.Displays; +using System; using System.Linq; using System.Threading; @@ -8,13 +9,16 @@ namespace Meadow.Foundation.Graphics.MicroLayout; /// /// An abstraction of a physical screen /// -public class DisplayScreen +public class DisplayScreen : IControlContainer { private readonly IPixelDisplay _display; private readonly MicroGraphics _graphics; private bool _updateInProgress = false; private Color _backgroundColor; + /// + public IControl Parent => null; + /// /// Gets the Touchscreen associated with the display screen /// @@ -48,7 +52,7 @@ public class DisplayScreen /// The display theme to use. public DisplayScreen(IPixelDisplay physicalDisplay, RotationType rotation = RotationType.Normal, ITouchScreen? touchScreen = null, DisplayTheme? theme = null) { - Controls = new ControlsCollection(this, null); + Controls = new ControlsCollection(this); Theme = theme; _display = physicalDisplay; @@ -149,9 +153,9 @@ private void RefreshTree(IControl control) control.Invalidate(); control.Refresh(_graphics); - if (control is MicroLayout l) + if (control is IControlContainer container) { - foreach (var c in l.Controls) + foreach (var c in container.Controls) { RefreshTree(c); } @@ -179,25 +183,32 @@ private void DrawLoopOnCaller() { while (true) { + if (!_updateInProgress && (IsInvalid || Controls.Any(c => c.IsInvalid))) { - if (!_updateInProgress && (IsInvalid || Controls.Any(c => c.IsInvalid))) - { - _graphics.Clear(BackgroundColor); + _graphics.Clear(BackgroundColor); - lock (Controls.SyncRoot) + lock (Controls.SyncRoot) + { + foreach (var control in Controls) { - foreach (var control in Controls) + if (control != null) { - if (control != null) - { - // TODO: micrographics supports invalidating regions - we need to update to invalidate only regions here, too - RefreshTree(control); - } + // TODO: micrographics supports invalidating regions - we need to update to invalidate only regions here, too + RefreshTree(control); } } + } + try + { _graphics.Show(); - IsInvalid = false; } + catch (Exception ex) + { + // it possible to have a callee error (e.g. an I2C bus problem) + // we'll report it and continue running + Resolver.Log.Warn($"MicroGraphics.Show error while drawing screen: {ex.Message}"); + } + IsInvalid = false; } Thread.Sleep(50); @@ -224,7 +235,16 @@ private void DrawLoopThreaded() RefreshTree(control); } } - _graphics.Show(); + try + { + _graphics.Show(); + } + catch (Exception ex) + { + // it possible to have a callee error (e.g. an I2C bus problem) + // we'll report it and continue running + Resolver.Log.Warn($"MicroGraphics.Show error while drawing screen: {ex.Message}"); + } IsInvalid = false; } } diff --git a/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroLayout/Driver/Graphics.MicroLayout.csproj b/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroLayout/Driver/Graphics.MicroLayout.csproj index 85e3d6aacb..17e77107ef 100644 --- a/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroLayout/Driver/Graphics.MicroLayout.csproj +++ b/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroLayout/Driver/Graphics.MicroLayout.csproj @@ -22,6 +22,6 @@ - + diff --git a/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroLayout/Driver/IControl.cs b/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroLayout/Driver/IControl.cs index 259db6c1d5..6f3acc88f4 100644 --- a/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroLayout/Driver/IControl.cs +++ b/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroLayout/Driver/IControl.cs @@ -6,7 +6,7 @@ public interface IControl { /// - /// Gets of sets the Control's Paretn, if it has one. If the Control is unparented (i.e. Parent is null) then it is directly on the DisplayScreen + /// Gets of sets the Control's Parent, if it has one. If the Control is unparented (i.e. Parent is null) then it is directly on the DisplayScreen /// IControl? Parent { get; set; } diff --git a/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroLayout/Driver/Layouts/AbsoluteLayout.cs b/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroLayout/Driver/Layouts/AbsoluteLayout.cs index a4607c07eb..716d46453b 100644 --- a/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroLayout/Driver/Layouts/AbsoluteLayout.cs +++ b/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroLayout/Driver/Layouts/AbsoluteLayout.cs @@ -5,25 +5,34 @@ /// public class AbsoluteLayout : MicroLayout { + /// + /// Creates a full-screen DisplayAbsoluteLayout + /// + /// The layout's width + /// The layout's height + public AbsoluteLayout(int width, int height) + : base(0, 0, width, height) + { + } + /// /// Creates a full-screen DisplayAbsoluteLayout /// /// The DisplayScreen to associate this layout with public AbsoluteLayout(DisplayScreen screen) - : base(screen, 0, 0, screen.Width, screen.Height) + : base(0, 0, screen.Width, screen.Height) { } /// /// Creates a DisplayAbsoluteLayout /// - /// The DisplayScreen to associate this layout with /// The layout's left position /// The layout's top position /// The layout's width /// The layout's height - public AbsoluteLayout(DisplayScreen screen, int left, int top, int width, int height) - : base(screen, left, top, width, height) + public AbsoluteLayout(int left, int top, int width, int height) + : base(left, top, width, height) { } diff --git a/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroLayout/Driver/MicroLayout.cs b/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroLayout/Driver/Layouts/MicroLayout.cs similarity index 85% rename from Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroLayout/Driver/MicroLayout.cs rename to Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroLayout/Driver/Layouts/MicroLayout.cs index 2e02df8c3e..c5256c6402 100644 --- a/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroLayout/Driver/MicroLayout.cs +++ b/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroLayout/Driver/Layouts/MicroLayout.cs @@ -5,22 +5,21 @@ namespace Meadow.Foundation.Graphics.MicroLayout; /// /// A base class for display layouts /// -public abstract class MicroLayout : ThemedControl +public abstract class MicroLayout : ThemedControl, IControlContainer { private Color? _backColor; /// - /// Creates a DisplayLayout + /// Creates a MicroLayout /// - /// The DisplayScreen to associate this layout with /// The layout's left position /// The layout's top position /// The layout's width /// The layout's height - protected MicroLayout(DisplayScreen screen, int left, int top, int width, int height) + protected MicroLayout(int left, int top, int width, int height) : base(left, top, width, height) { - Controls = new ControlsCollection(screen, this); + Controls = new ControlsCollection(this); } /// diff --git a/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroLayout/Samples/BarChart_Sample/BarChart_Sample.csproj b/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroLayout/Samples/BarChart_Sample/BarChart_Sample.csproj index 240df949b7..5fa9488993 100644 --- a/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroLayout/Samples/BarChart_Sample/BarChart_Sample.csproj +++ b/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroLayout/Samples/BarChart_Sample/BarChart_Sample.csproj @@ -8,9 +8,9 @@ - - - + + + diff --git a/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroLayout/Samples/Ili9488Charts_Sample/Ili9488Charts_Sample.csproj b/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroLayout/Samples/Charts_Sample/Charts_Sample.csproj similarity index 69% rename from Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroLayout/Samples/Ili9488Charts_Sample/Ili9488Charts_Sample.csproj rename to Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroLayout/Samples/Charts_Sample/Charts_Sample.csproj index 1ec33271af..088c4e26da 100644 --- a/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroLayout/Samples/Ili9488Charts_Sample/Ili9488Charts_Sample.csproj +++ b/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroLayout/Samples/Charts_Sample/Charts_Sample.csproj @@ -8,11 +8,11 @@ - - - - - + + + + + diff --git a/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroLayout/Samples/Ili9488Charts_Sample/MeadowApp.cs b/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroLayout/Samples/Charts_Sample/MeadowApp.cs similarity index 95% rename from Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroLayout/Samples/Ili9488Charts_Sample/MeadowApp.cs rename to Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroLayout/Samples/Charts_Sample/MeadowApp.cs index 093fa96fe0..8d44c78fae 100644 --- a/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroLayout/Samples/Ili9488Charts_Sample/MeadowApp.cs +++ b/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroLayout/Samples/Charts_Sample/MeadowApp.cs @@ -66,9 +66,7 @@ public void TextOnBox() while (true) { Thread.Sleep(1000); - var temp = box.ForeColor; - box.ForeColor = label.TextColor; - label.TextColor = temp; + (box.ForeColor, label.TextColor) = (label.TextColor, box.ForeColor); } } diff --git a/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroLayout/Samples/HMI_Sample/HMI_Sample.csproj b/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroLayout/Samples/HMI_Sample/HMI_Sample.csproj index 240df949b7..5fa9488993 100644 --- a/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroLayout/Samples/HMI_Sample/HMI_Sample.csproj +++ b/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroLayout/Samples/HMI_Sample/HMI_Sample.csproj @@ -8,9 +8,9 @@ - - - + + + diff --git a/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroLayout/Samples/HMI_Sample/Program.cs b/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroLayout/Samples/HMI_Sample/Program.cs index aa57d1904b..83fd7be584 100644 --- a/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroLayout/Samples/HMI_Sample/Program.cs +++ b/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroLayout/Samples/HMI_Sample/Program.cs @@ -24,7 +24,7 @@ public override Task Run() screen = new DisplayScreen(display); screen.BackgroundColor = Color.AntiqueWhite; - var splashLayout = new AbsoluteLayout(screen, 0, 0, screen.Width, screen.Height) + var splashLayout = new AbsoluteLayout(0, 0, screen.Width, screen.Height) { }; @@ -43,7 +43,7 @@ public override Task Run() ); splashLayout.Controls.Add(logoImg, wlLabel); - var chartLayout = new AbsoluteLayout(screen, 0, 0, screen.Width, screen.Height); + var chartLayout = new AbsoluteLayout(0, 0, screen.Width, screen.Height); var chart1Label = new Graphics.MicroLayout.Label(0, 0, screen.Width, 16) { diff --git a/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroLayout/Samples/ListBox_Sample/ListBox_Sample.csproj b/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroLayout/Samples/ListBox_Sample/ListBox_Sample.csproj new file mode 100644 index 0000000000..5fa9488993 --- /dev/null +++ b/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroLayout/Samples/ListBox_Sample/ListBox_Sample.csproj @@ -0,0 +1,25 @@ + + + + Exe + net8.0-windows + enable + enable + + + + + + + + + + + PreserveNewest + + + Always + + + + diff --git a/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroLayout/Samples/ListBox_Sample/Program.cs b/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroLayout/Samples/ListBox_Sample/Program.cs new file mode 100644 index 0000000000..48b5a5ab21 --- /dev/null +++ b/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroLayout/Samples/ListBox_Sample/Program.cs @@ -0,0 +1,58 @@ +using Meadow.Foundation.Graphics; +using Meadow.Foundation.Graphics.MicroLayout; + +namespace Meadow.Foundation.Displays.UI; + +public class MeadowApp : App +{ + private DisplayScreen? screen; + + public static async Task Main(string[] args) + { + ApplicationConfiguration.Initialize(); + await MeadowOS.Start(args); + } + + public override Task Run() + { + var display = new WinFormsDisplay(); + display.ControlBox = true; + + var labelFont = new Font16x24(); + + screen = new DisplayScreen(display) + { + BackgroundColor = Color.Cyan + }; + + var listView = new ListBox(0, 0, display.Width, display.Height, labelFont); + + listView.Items.Add("Item A"); + listView.Items.Add("Item B"); + + screen.Controls.Add(listView); + + Task.Run(async () => + { + await Task.Delay(1000); + listView.Items.Add("Item C"); + listView.SelectedIndex = 0; + + await Task.Delay(1000); + listView.Items.Add("Item D"); + await Task.Delay(1000); + listView.Items.Add("Item E"); + await Task.Delay(1000); + listView.Items.Add("Item F"); + await Task.Delay(1000); + listView.Items.Add("Item G"); + await Task.Delay(1000); + listView.Items.RemoveAt(1); + + }); + + System.Windows.Forms.Application.Run(display); + + return Task.CompletedTask; + } +} \ No newline at end of file diff --git a/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroLayout/Samples/MAX7219_Sample/MAX7219_Sample.csproj b/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroLayout/Samples/MAX7219_Sample/MAX7219_Sample.csproj index 5280e31e67..ca62a67ef7 100644 --- a/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroLayout/Samples/MAX7219_Sample/MAX7219_Sample.csproj +++ b/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroLayout/Samples/MAX7219_Sample/MAX7219_Sample.csproj @@ -8,11 +8,11 @@ - - - - - + + + + + diff --git a/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroLayout/Samples/MAX7219_Sample/MeadowApp.cs b/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroLayout/Samples/MAX7219_Sample/MeadowApp.cs index df401e53f9..1edc6890dd 100644 --- a/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroLayout/Samples/MAX7219_Sample/MeadowApp.cs +++ b/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroLayout/Samples/MAX7219_Sample/MeadowApp.cs @@ -56,9 +56,7 @@ public void TextOnBox() while (true) { Thread.Sleep(1000); - var temp = box.ForeColor; - box.ForeColor = label.TextColor; - label.TextColor = temp; + (box.ForeColor, label.TextColor) = (label.TextColor, box.ForeColor); } } diff --git a/Source/Meadow.Foundation.Libraries_and_Frameworks/Sensors.Location.Gnss.NmeaProcessor/Driver/GgaDecoder.cs b/Source/Meadow.Foundation.Libraries_and_Frameworks/Sensors.Location.Gnss.NmeaProcessor/Driver/GgaDecoder.cs index 0916bdb0dd..bb2b5cb4ea 100644 --- a/Source/Meadow.Foundation.Libraries_and_Frameworks/Sensors.Location.Gnss.NmeaProcessor/Driver/GgaDecoder.cs +++ b/Source/Meadow.Foundation.Libraries_and_Frameworks/Sensors.Location.Gnss.NmeaProcessor/Driver/GgaDecoder.cs @@ -49,18 +49,17 @@ public void Process(NmeaSentence sentence) location.Position.Longitude = NmeaUtilities.DegreesMinutesDecode(sentence.DataElements[3], sentence.DataElements[4]); location.FixQuality = (FixType)int.Parse(sentence.DataElements[5]); - int numberOfSatellites; - if (int.TryParse(sentence.DataElements[6], out numberOfSatellites)) + if (int.TryParse(sentence.DataElements[6], out var numberOfSatellites)) { location.NumberOfSatellites = numberOfSatellites; } - decimal horizontalDilutionOfPrecision; - if (decimal.TryParse(sentence.DataElements[7], out horizontalDilutionOfPrecision)) + + if (decimal.TryParse(sentence.DataElements[7], out var horizontalDilutionOfPrecision)) { location.HorizontalDilutionOfPrecision = horizontalDilutionOfPrecision; } - decimal altitude; - if (decimal.TryParse(sentence.DataElements[8], out altitude)) + + if (decimal.TryParse(sentence.DataElements[8], out var altitude)) { location.Position.Altitude = altitude; } diff --git a/Source/Meadow.Foundation.Libraries_and_Frameworks/Sensors.Location.Gnss.NmeaProcessor/Driver/GsaDecoder.cs b/Source/Meadow.Foundation.Libraries_and_Frameworks/Sensors.Location.Gnss.NmeaProcessor/Driver/GsaDecoder.cs index 97845b15ba..3255086dd4 100644 --- a/Source/Meadow.Foundation.Libraries_and_Frameworks/Sensors.Location.Gnss.NmeaProcessor/Driver/GsaDecoder.cs +++ b/Source/Meadow.Foundation.Libraries_and_Frameworks/Sensors.Location.Gnss.NmeaProcessor/Driver/GsaDecoder.cs @@ -40,9 +40,7 @@ public void Process(NmeaSentence sentence) _ => ActiveSatelliteSelection.Unknown, }; - int dimensionalFixType; - - if (int.TryParse(sentence.DataElements[1], out dimensionalFixType)) + if (int.TryParse(sentence.DataElements[1], out var dimensionalFixType)) { satellites.Dimensions = (DimensionalFixType)dimensionalFixType; } @@ -73,22 +71,17 @@ public void Process(NmeaSentence sentence) satellites.SatellitesUsedForFix = null; } - decimal dilutionOfPrecision; - - if (decimal.TryParse(sentence.DataElements[14], out dilutionOfPrecision)) + if (decimal.TryParse(sentence.DataElements[14], out var dilutionOfPrecision)) { satellites.DilutionOfPrecision = dilutionOfPrecision; } - decimal horizontalDilutionOfPrecision; - - if (decimal.TryParse(sentence.DataElements[15], out horizontalDilutionOfPrecision)) + if (decimal.TryParse(sentence.DataElements[15], out var horizontalDilutionOfPrecision)) { satellites.HorizontalDilutionOfPrecision = horizontalDilutionOfPrecision; } - decimal verticalDilutionOfPrecision; - if (decimal.TryParse(sentence.DataElements[16], out verticalDilutionOfPrecision)) + if (decimal.TryParse(sentence.DataElements[16], out var verticalDilutionOfPrecision)) { satellites.VerticalDilutionOfPrecision = verticalDilutionOfPrecision; } diff --git a/Source/Meadow.Foundation.Libraries_and_Frameworks/Sensors.Location.Gnss.NmeaProcessor/Driver/RmcDeocder.cs b/Source/Meadow.Foundation.Libraries_and_Frameworks/Sensors.Location.Gnss.NmeaProcessor/Driver/RmcDeocder.cs index a8b893df2e..101bd35595 100644 --- a/Source/Meadow.Foundation.Libraries_and_Frameworks/Sensors.Location.Gnss.NmeaProcessor/Driver/RmcDeocder.cs +++ b/Source/Meadow.Foundation.Libraries_and_Frameworks/Sensors.Location.Gnss.NmeaProcessor/Driver/RmcDeocder.cs @@ -60,13 +60,12 @@ public void Process(NmeaSentence sentence) position.Position.Longitude = NmeaUtilities.DegreesMinutesDecode(sentence.DataElements[4], sentence.DataElements[5]); //Resolver.Log.Info("40"); - decimal speedInKnots; - if (decimal.TryParse(sentence.DataElements[6], out speedInKnots)) + if (decimal.TryParse(sentence.DataElements[6], out var speedInKnots)) { position.SpeedInKnots = speedInKnots; } - decimal courseHeading; - if (decimal.TryParse(sentence.DataElements[7], out courseHeading)) + + if (decimal.TryParse(sentence.DataElements[7], out var courseHeading)) { position.CourseHeading = courseHeading; } diff --git a/Source/Meadow.Foundation.Libraries_and_Frameworks/Sensors.Location.Gnss.NmeaProcessor/Driver/Sensors.Location.Gnss.NmeaProcessor.csproj b/Source/Meadow.Foundation.Libraries_and_Frameworks/Sensors.Location.Gnss.NmeaProcessor/Driver/Sensors.Location.Gnss.NmeaProcessor.csproj index 662a628618..da43b70041 100644 --- a/Source/Meadow.Foundation.Libraries_and_Frameworks/Sensors.Location.Gnss.NmeaProcessor/Driver/Sensors.Location.Gnss.NmeaProcessor.csproj +++ b/Source/Meadow.Foundation.Libraries_and_Frameworks/Sensors.Location.Gnss.NmeaProcessor/Driver/Sensors.Location.Gnss.NmeaProcessor.csproj @@ -24,6 +24,6 @@ - + diff --git a/Source/Meadow.Foundation.Libraries_and_Frameworks/Sensors.Location.Gnss.NmeaProcessor/Driver/VtgDecoder.cs b/Source/Meadow.Foundation.Libraries_and_Frameworks/Sensors.Location.Gnss.NmeaProcessor/Driver/VtgDecoder.cs index b409663225..3d436b8f09 100644 --- a/Source/Meadow.Foundation.Libraries_and_Frameworks/Sensors.Location.Gnss.NmeaProcessor/Driver/VtgDecoder.cs +++ b/Source/Meadow.Foundation.Libraries_and_Frameworks/Sensors.Location.Gnss.NmeaProcessor/Driver/VtgDecoder.cs @@ -16,18 +16,12 @@ public class VtgDecoder : INmeaDecoder /// /// Prefix for the VTG decoder. /// - public string Prefix - { - get => "VTG"; - } + public string Prefix => "VTG"; /// /// Friendly name for the VTG messages. /// - public string Name - { - get => "Velocity made good"; - } + public string Name => "Velocity made good"; /// /// Process the data from a VTG message. @@ -41,23 +35,22 @@ public void Process(NmeaSentence sentence) course.TalkerID = sentence.TalkerID; - decimal trueHeading; - if (decimal.TryParse(sentence.DataElements[0], out trueHeading)) + if (decimal.TryParse(sentence.DataElements[0], out var trueHeading)) { course.TrueHeading = trueHeading; } - decimal magneticHeading; - if (decimal.TryParse(sentence.DataElements[2], out magneticHeading)) + + if (decimal.TryParse(sentence.DataElements[2], out var magneticHeading)) { course.MagneticHeading = magneticHeading; } - decimal knots; - if (decimal.TryParse(sentence.DataElements[4], out knots)) + + if (decimal.TryParse(sentence.DataElements[4], out var knots)) { course.Knots = knots; } - decimal kph; - if (decimal.TryParse(sentence.DataElements[6], out kph)) + + if (decimal.TryParse(sentence.DataElements[6], out var kph)) { course.Kph = kph; } diff --git a/Source/Meadow.Foundation.Libraries_and_Frameworks/Sensors.Location.Gnss.NmeaProcessor/Samples/NmeaProcessor_Sample/NmeaProcessor_Sample.csproj b/Source/Meadow.Foundation.Libraries_and_Frameworks/Sensors.Location.Gnss.NmeaProcessor/Samples/NmeaProcessor_Sample/NmeaProcessor_Sample.csproj index c71cd1f2f1..9e792fd6d3 100644 --- a/Source/Meadow.Foundation.Libraries_and_Frameworks/Sensors.Location.Gnss.NmeaProcessor/Samples/NmeaProcessor_Sample/NmeaProcessor_Sample.csproj +++ b/Source/Meadow.Foundation.Libraries_and_Frameworks/Sensors.Location.Gnss.NmeaProcessor/Samples/NmeaProcessor_Sample/NmeaProcessor_Sample.csproj @@ -13,7 +13,7 @@ - - + + diff --git a/Source/Meadow.Foundation.Libraries_and_Frameworks/Serialization.MicroJson/Driver/DateTimeConverters.cs b/Source/Meadow.Foundation.Libraries_and_Frameworks/Serialization.MicroJson/Driver/DateTimeConverters.cs index 7f8b7fbe35..8f00269aea 100644 --- a/Source/Meadow.Foundation.Libraries_and_Frameworks/Serialization.MicroJson/Driver/DateTimeConverters.cs +++ b/Source/Meadow.Foundation.Libraries_and_Frameworks/Serialization.MicroJson/Driver/DateTimeConverters.cs @@ -38,7 +38,7 @@ public static DateTime FromIso8601(string input) /// DateTime as an ISO 8601 string in UTC format. public static string ToIso8601(DateTime dateTime) { - return $"{dateTime:yyyy-MM-ddTHH:mm:ss.FFFZ}"; + return dateTime.ToString("o", CultureInfo.InvariantCulture); } /// @@ -48,7 +48,7 @@ public static string ToIso8601(DateTime dateTime) /// DateTime as an ISO 8601 string in UTC format. public static string ToIso8601(DateTimeOffset dateTime) { - return $"{dateTime:yyyy-MM-ddTHH:mm:ss.FFFZ}"; + return dateTime.ToString("o", CultureInfo.InvariantCulture); } /// @@ -84,4 +84,4 @@ public static DateTime FromASPNetAjax(string ajax) return new DateTime(ticks, DateTimeKind.Utc); } -} \ No newline at end of file +} diff --git a/Source/Meadow.Foundation.Libraries_and_Frameworks/Serialization.MicroJson/Driver/MicroJson.TypeSafe.cs b/Source/Meadow.Foundation.Libraries_and_Frameworks/Serialization.MicroJson/Driver/MicroJson.TypeSafe.cs index f07c6409b2..b495712730 100644 --- a/Source/Meadow.Foundation.Libraries_and_Frameworks/Serialization.MicroJson/Driver/MicroJson.TypeSafe.cs +++ b/Source/Meadow.Foundation.Libraries_and_Frameworks/Serialization.MicroJson/Driver/MicroJson.TypeSafe.cs @@ -241,9 +241,20 @@ private static void Deserialize(Hashtable? root, Type type, ref object instance) var targetArray = Array.CreateInstance(elementType, al!.Count); for (int i = 0; i < al.Count; i++) { - object arrayItem = Activator.CreateInstance(elementType); - Deserialize(al[i] as Hashtable, elementType, ref arrayItem); - targetArray.SetValue(arrayItem, i); + if (elementType == typeof(string)) + { + targetArray.SetValue(al[i], i); + } + else if (elementType.IsValueType || elementType.IsEnum) + { + targetArray.SetValue(Convert.ChangeType(al[i], elementType), i); + } + else + { + object arrayItem = Activator.CreateInstance(elementType); + Deserialize(al[i] as Hashtable, elementType, ref arrayItem); + targetArray.SetValue(arrayItem, i); + } } prop.SetValue(instance, targetArray); } diff --git a/Source/Meadow.Foundation.Libraries_and_Frameworks/Serialization.MicroJson/Driver/MicroJson.cs b/Source/Meadow.Foundation.Libraries_and_Frameworks/Serialization.MicroJson/Driver/MicroJson.cs index 78e941febe..91c925531c 100644 --- a/Source/Meadow.Foundation.Libraries_and_Frameworks/Serialization.MicroJson/Driver/MicroJson.cs +++ b/Source/Meadow.Foundation.Libraries_and_Frameworks/Serialization.MicroJson/Driver/MicroJson.cs @@ -1,5 +1,6 @@ using System; using System.Collections; +using System.Globalization; using System.Linq; using System.Reflection; using System.Text; @@ -31,6 +32,32 @@ public static partial class MicroJson return Parser.JsonDecode(json); } + /// + /// Escapes special characters in a string to ensure it is JSON-compliant. + /// + /// The string to escape. + /// The escaped string with special characters properly encoded. + /// + /// This method handles the following special characters: + /// - Double quotes (") are escaped as \". + /// - Backslashes (\) are escaped as \\. + /// - Newlines (\n) are escaped as \\n. + /// - Carriage returns (\r) are escaped as \\r. + /// - Tabs (\t) are escaped as \\t. + /// - Backspaces (\b) are escaped as \\b. + /// - Form feeds (\f) are escaped as \\f. + /// + public static string EscapeString(string value) + { + return "\"" + value.Replace("\\", "\\\\") + .Replace("\"", "\\\"") + .Replace("\n", "\\n") + .Replace("\r", "\\r") + .Replace("\t", "\\t") + .Replace("\b", "\\b") + .Replace("\f", "\\f") + "\""; + } + /// /// Converts an object to a JSON string. /// @@ -59,11 +86,9 @@ public static partial class MicroJson case TypeCode.Boolean: return (bool)o ? "true" : "false"; case TypeCode.String: - return $"\"{o}\"" - .Replace("\n", "\\n") - .Replace("\r", "\\r"); + return EscapeString((string)o); case TypeCode.Char: - return $"\"{o}\""; + return EscapeString(o.ToString()); case TypeCode.Single: case TypeCode.Double: case TypeCode.Decimal: @@ -75,7 +100,14 @@ public static partial class MicroJson case TypeCode.UInt32: case TypeCode.Int64: case TypeCode.UInt64: - return o.ToString(); + if (o is IFormattable formattable) + { + return formattable.ToString(null, System.Globalization.CultureInfo.InvariantCulture); + } + else + { + return o.ToString(); + } case TypeCode.DateTime: return dateTimeFormat switch { diff --git a/Source/Meadow.Foundation.Libraries_and_Frameworks/Serialization.MicroJson/Samples/MicroJson_ArrayList_Sample/MicroJson_ArrayList_Sample.csproj b/Source/Meadow.Foundation.Libraries_and_Frameworks/Serialization.MicroJson/Samples/MicroJson_ArrayList_Sample/MicroJson_ArrayList_Sample.csproj index 16ccb4da76..ce02bed7cd 100644 --- a/Source/Meadow.Foundation.Libraries_and_Frameworks/Serialization.MicroJson/Samples/MicroJson_ArrayList_Sample/MicroJson_ArrayList_Sample.csproj +++ b/Source/Meadow.Foundation.Libraries_and_Frameworks/Serialization.MicroJson/Samples/MicroJson_ArrayList_Sample/MicroJson_ArrayList_Sample.csproj @@ -15,7 +15,7 @@ - + diff --git a/Source/Meadow.Foundation.Libraries_and_Frameworks/Serialization.MicroJson/Samples/MicroJson_Complex_Sample/MicroJson_Complex_Sample.csproj b/Source/Meadow.Foundation.Libraries_and_Frameworks/Serialization.MicroJson/Samples/MicroJson_Complex_Sample/MicroJson_Complex_Sample.csproj index f629da7080..86e9581afb 100644 --- a/Source/Meadow.Foundation.Libraries_and_Frameworks/Serialization.MicroJson/Samples/MicroJson_Complex_Sample/MicroJson_Complex_Sample.csproj +++ b/Source/Meadow.Foundation.Libraries_and_Frameworks/Serialization.MicroJson/Samples/MicroJson_Complex_Sample/MicroJson_Complex_Sample.csproj @@ -15,7 +15,7 @@ - + diff --git a/Source/Meadow.Foundation.Libraries_and_Frameworks/Serialization.MicroJson/Samples/MicroJson_Sample/MicroJson_Sample.csproj b/Source/Meadow.Foundation.Libraries_and_Frameworks/Serialization.MicroJson/Samples/MicroJson_Sample/MicroJson_Sample.csproj index 871da55b05..e774a34e16 100644 --- a/Source/Meadow.Foundation.Libraries_and_Frameworks/Serialization.MicroJson/Samples/MicroJson_Sample/MicroJson_Sample.csproj +++ b/Source/Meadow.Foundation.Libraries_and_Frameworks/Serialization.MicroJson/Samples/MicroJson_Sample/MicroJson_Sample.csproj @@ -7,6 +7,6 @@ - + diff --git a/Source/Meadow.Foundation.Libraries_and_Frameworks/Serialization.MicroJson/Tests/MicroJson.Unit.Tests/BasicTests.cs b/Source/Meadow.Foundation.Libraries_and_Frameworks/Serialization.MicroJson/Tests/MicroJson.Unit.Tests/BasicTests.cs index a54d48c5cf..3d6f71526b 100644 --- a/Source/Meadow.Foundation.Libraries_and_Frameworks/Serialization.MicroJson/Tests/MicroJson.Unit.Tests/BasicTests.cs +++ b/Source/Meadow.Foundation.Libraries_and_Frameworks/Serialization.MicroJson/Tests/MicroJson.Unit.Tests/BasicTests.cs @@ -134,13 +134,13 @@ public void DeserializeDataWithContainsCarriageReturnsTest() { var input = """ { - "Value": "hello + "StringArg": "hello there data" } """; - var result = MicroJson.Deserialize(input); + var result = MicroJson.Deserialize(input); Assert.NotNull(result); } diff --git a/Source/Meadow.Foundation.Libraries_and_Frameworks/Serialization.MicroJson/Tests/MicroJson.Unit.Tests/MicroJson.Unit.Tests.csproj b/Source/Meadow.Foundation.Libraries_and_Frameworks/Serialization.MicroJson/Tests/MicroJson.Unit.Tests/MicroJson.Unit.Tests.csproj index 9b47e7bdc2..2735338b35 100644 --- a/Source/Meadow.Foundation.Libraries_and_Frameworks/Serialization.MicroJson/Tests/MicroJson.Unit.Tests/MicroJson.Unit.Tests.csproj +++ b/Source/Meadow.Foundation.Libraries_and_Frameworks/Serialization.MicroJson/Tests/MicroJson.Unit.Tests/MicroJson.Unit.Tests.csproj @@ -12,12 +12,14 @@ + + @@ -37,8 +39,8 @@ - - + + diff --git a/Source/Meadow.Foundation.Libraries_and_Frameworks/Serialization.MicroJson/Tests/MicroJson.Unit.Tests/WeatherJsonTests.cs b/Source/Meadow.Foundation.Libraries_and_Frameworks/Serialization.MicroJson/Tests/MicroJson.Unit.Tests/WeatherJsonTests.cs index 551881028f..461b0a8724 100644 --- a/Source/Meadow.Foundation.Libraries_and_Frameworks/Serialization.MicroJson/Tests/MicroJson.Unit.Tests/WeatherJsonTests.cs +++ b/Source/Meadow.Foundation.Libraries_and_Frameworks/Serialization.MicroJson/Tests/MicroJson.Unit.Tests/WeatherJsonTests.cs @@ -34,4 +34,16 @@ public void CamelCasedWeatherDeserializationTest() Assert.NotNull(result.Coord); Assert.NotNull(result.Sys); } + + [Fact] + public void OpenMeteoJson() + { + var json = Inputs.GetInputResource("open-meteo.json"); + var result = MicroJson.Deserialize(json); + + Assert.NotNull(result); + Assert.NotNull(result.current); + Assert.NotEmpty(result.hourly.temperature_2m); + Assert.NotEmpty(result.hourly.time); + } } diff --git a/Source/Meadow.Foundation.Libraries_and_Frameworks/Serialization.MicroJson/Tests/MicroJson.Unit.Tests/inputs/open-meteo.json b/Source/Meadow.Foundation.Libraries_and_Frameworks/Serialization.MicroJson/Tests/MicroJson.Unit.Tests/inputs/open-meteo.json new file mode 100644 index 0000000000..aa58ade361 --- /dev/null +++ b/Source/Meadow.Foundation.Libraries_and_Frameworks/Serialization.MicroJson/Tests/MicroJson.Unit.Tests/inputs/open-meteo.json @@ -0,0 +1,41 @@ +{ + "latitude": 60.17136, + "longitude": 24.927353, + "generationtime_ms": 0.11599063873291016, + "utc_offset_seconds": 10800, + "timezone": "Europe/Helsinki", + "timezone_abbreviation": "EEST", + "elevation": 12.0, + "current_units": { + "time": "iso8601", + "interval": "seconds", + "temperature_2m": "°C", + "relative_humidity_2m": "%" + }, + "current": { + "time": "2024-05-20T13:45", + "interval": 900, + "temperature_2m": 19.0, + "relative_humidity_2m": 24 + }, + "hourly_units": { + "time": "iso8601", + "temperature_2m": "°C" + }, + "hourly": { + "time": [ "2024-05-20T00:00", "2024-05-20T01:00", "2024-05-20T02:00", "2024-05-20T03:00", "2024-05-20T04:00", "2024-05-20T05:00", "2024-05-20T06:00", "2024-05-20T07:00", "2024-05-20T08:00", "2024-05-20T09:00", "2024-05-20T10:00", "2024-05-20T11:00", "2024-05-20T12:00", "2024-05-20T13:00", "2024-05-20T14:00", "2024-05-20T15:00", "2024-05-20T16:00", "2024-05-20T17:00", "2024-05-20T18:00", "2024-05-20T19:00", "2024-05-20T20:00", "2024-05-20T21:00", "2024-05-20T22:00", "2024-05-20T23:00", "2024-05-21T00:00", "2024-05-21T01:00", "2024-05-21T02:00", "2024-05-21T03:00", "2024-05-21T04:00", "2024-05-21T05:00", "2024-05-21T06:00", "2024-05-21T07:00", "2024-05-21T08:00", "2024-05-21T09:00", "2024-05-21T10:00", "2024-05-21T11:00", "2024-05-21T12:00", "2024-05-21T13:00", "2024-05-21T14:00", "2024-05-21T15:00", "2024-05-21T16:00", "2024-05-21T17:00", "2024-05-21T18:00", "2024-05-21T19:00", "2024-05-21T20:00", "2024-05-21T21:00", "2024-05-21T22:00", "2024-05-21T23:00", "2024-05-22T00:00", "2024-05-22T01:00", "2024-05-22T02:00", "2024-05-22T03:00", "2024-05-22T04:00", "2024-05-22T05:00", "2024-05-22T06:00", "2024-05-22T07:00", "2024-05-22T08:00", "2024-05-22T09:00", "2024-05-22T10:00", "2024-05-22T11:00", "2024-05-22T12:00", "2024-05-22T13:00", "2024-05-22T14:00", "2024-05-22T15:00", "2024-05-22T16:00", "2024-05-22T17:00", "2024-05-22T18:00", "2024-05-22T19:00", "2024-05-22T20:00", "2024-05-22T21:00", "2024-05-22T22:00", "2024-05-22T23:00", "2024-05-23T00:00", "2024-05-23T01:00", "2024-05-23T02:00", "2024-05-23T03:00", "2024-05-23T04:00", "2024-05-23T05:00", "2024-05-23T06:00", "2024-05-23T07:00", "2024-05-23T08:00", "2024-05-23T09:00", "2024-05-23T10:00", "2024-05-23T11:00", "2024-05-23T12:00", "2024-05-23T13:00", "2024-05-23T14:00", "2024-05-23T15:00", "2024-05-23T16:00", "2024-05-23T17:00", "2024-05-23T18:00", "2024-05-23T19:00", "2024-05-23T20:00", "2024-05-23T21:00", "2024-05-23T22:00", "2024-05-23T23:00", "2024-05-24T00:00", "2024-05-24T01:00", "2024-05-24T02:00", "2024-05-24T03:00", "2024-05-24T04:00", "2024-05-24T05:00", "2024-05-24T06:00", "2024-05-24T07:00", "2024-05-24T08:00", "2024-05-24T09:00", "2024-05-24T10:00", "2024-05-24T11:00", "2024-05-24T12:00", "2024-05-24T13:00", "2024-05-24T14:00", "2024-05-24T15:00", "2024-05-24T16:00", "2024-05-24T17:00", "2024-05-24T18:00", "2024-05-24T19:00", "2024-05-24T20:00", "2024-05-24T21:00", "2024-05-24T22:00", "2024-05-24T23:00", "2024-05-25T00:00", "2024-05-25T01:00", "2024-05-25T02:00", "2024-05-25T03:00", "2024-05-25T04:00", "2024-05-25T05:00", "2024-05-25T06:00", "2024-05-25T07:00", "2024-05-25T08:00", "2024-05-25T09:00", "2024-05-25T10:00", "2024-05-25T11:00", "2024-05-25T12:00", "2024-05-25T13:00", "2024-05-25T14:00", "2024-05-25T15:00", "2024-05-25T16:00", "2024-05-25T17:00", "2024-05-25T18:00", "2024-05-25T19:00", "2024-05-25T20:00", "2024-05-25T21:00", "2024-05-25T22:00", "2024-05-25T23:00", "2024-05-26T00:00", "2024-05-26T01:00", "2024-05-26T02:00", "2024-05-26T03:00", "2024-05-26T04:00", "2024-05-26T05:00", "2024-05-26T06:00", "2024-05-26T07:00", "2024-05-26T08:00", "2024-05-26T09:00", "2024-05-26T10:00", "2024-05-26T11:00", "2024-05-26T12:00", "2024-05-26T13:00", "2024-05-26T14:00", "2024-05-26T15:00", "2024-05-26T16:00", "2024-05-26T17:00", "2024-05-26T18:00", "2024-05-26T19:00", "2024-05-26T20:00", "2024-05-26T21:00", "2024-05-26T22:00", "2024-05-26T23:00" ], + "temperature_2m": [ 16.9, 16.3, 15.9, 15.0, 14.6, 14.6, 14.3, 14.9, 14.7, 14.8, 15.1, 15.7, 16.4, 18.1, 19.1, 19.7, 19.8, 19.5, 19.3, 19.1, 18.4, 17.6, 16.7, 16.2, 15.9, 15.3, 14.3, 13.0, 11.8, 10.8, 10.4, 10.8, 11.6, 13.0, 14.3, 14.9, 15.2, 15.8, 16.6, 17.2, 17.5, 17.6, 17.4, 17.2, 16.7, 15.9, 15.0, 14.3, 13.7, 13.3, 12.8, 12.0, 11.4, 11.1, 11.2, 11.6, 12.4, 13.1, 13.8, 14.6, 15.9, 17.2, 18.3, 18.6, 18.9, 19.1, 19.1, 18.8, 18.2, 17.7, 16.8, 12.6, 12.2, 12.0, 11.8, 11.5, 11.2, 11.0, 11.3, 12.1, 13.1, 14.0, 14.8, 15.5, 16.3, 16.6, 17.0, 17.2, 17.4, 17.6, 17.4, 16.8, 15.9, 15.1, 14.3, 13.6, 13.0, 12.8, 12.7, 12.7, 12.6, 12.5, 12.7, 13.3, 14.2, 15.1, 16.1, 17.2, 18.1, 18.7, 19.1, 19.4, 19.6, 19.6, 19.3, 18.5, 17.3, 16.3, 15.6, 15.1, 14.7, 14.5, 14.5, 14.4, 14.1, 13.8, 13.7, 14.2, 15.0, 15.6, 20.1, 21.4, 22.5, 23.3, 24.0, 24.3, 24.2, 23.8, 23.2, 22.4, 21.3, 20.2, 19.0, 17.7, 16.6, 16.0, 15.7, 15.3, 14.5, 13.7, 13.2, 13.5, 14.3, 15.0, 15.6, 16.2, 16.6, 16.6, 16.4, 16.2, 16.1, 15.9, 15.5, 14.9, 14.2, 13.4, 12.6, 11.8 ] + }, + "daily_units": { + "time": "iso8601", + "weather_code": "wmo code", + "temperature_2m_max": "°C", + "temperature_2m_min": "°C" + }, + "daily": { + "time": [ "2024-05-20", "2024-05-21", "2024-05-22", "2024-05-23", "2024-05-24", "2024-05-25", "2024-05-26" ], + "weather_code": [ 3, 3, 0, 0, 3, 80, 3 ], + "temperature_2m_max": [ 19.8, 17.6, 19.1, 17.6, 19.6, 24.3, 16.6 ], + "temperature_2m_min": [ 14.3, 10.4, 11.1, 11.0, 12.5, 13.7, 11.8 ] + } +} \ No newline at end of file diff --git a/Source/Meadow.Foundation.Libraries_and_Frameworks/Serialization.MicroJson/Tests/MicroJson.Unit.Tests/test types/OpenMeteoTypes.cs b/Source/Meadow.Foundation.Libraries_and_Frameworks/Serialization.MicroJson/Tests/MicroJson.Unit.Tests/test types/OpenMeteoTypes.cs new file mode 100644 index 0000000000..48e98ff219 --- /dev/null +++ b/Source/Meadow.Foundation.Libraries_and_Frameworks/Serialization.MicroJson/Tests/MicroJson.Unit.Tests/test types/OpenMeteoTypes.cs @@ -0,0 +1,69 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Unit.Tests; + +public class MeteoResponse +{ + public float latitude { get; set; } + public float longitude { get; set; } + public float generationtime_ms { get; set; } + public int utc_offset_seconds { get; set; } + public string timezone { get; set; } + public string timezone_abbreviation { get; set; } + public float elevation { get; set; } + public Current_Units current_units { get; set; } + public Current current { get; set; } + public Hourly_Units hourly_units { get; set; } + public Hourly hourly { get; set; } + public Daily_Units daily_units { get; set; } + public Daily daily { get; set; } +} + +public class Current_Units +{ + public string time { get; set; } + public string interval { get; set; } + public string temperature_2m { get; set; } + public string relative_humidity_2m { get; set; } +} + +public class Current +{ + public string time { get; set; } + public int interval { get; set; } + public float temperature_2m { get; set; } + public int relative_humidity_2m { get; set; } +} + +public class Hourly_Units +{ + public string time { get; set; } + public string temperature_2m { get; set; } +} + +public class Hourly +{ + public string[] time { get; set; } + public float[] temperature_2m { get; set; } +} + +public class Daily_Units +{ + public string time { get; set; } + public string weather_code { get; set; } + public string temperature_2m_max { get; set; } + public string temperature_2m_min { get; set; } +} + +public class Daily +{ + public string[] time { get; set; } + public int[] weather_code { get; set; } + public float[] temperature_2m_max { get; set; } + public float[] temperature_2m_min { get; set; } +} \ No newline at end of file diff --git a/Source/Meadow.Foundation.Peripherals/Audio.Mp3.Yx5300/Driver/Audio.Mp3.Yx5300.csproj b/Source/Meadow.Foundation.Peripherals/Audio.Mp3.Yx5300/Driver/Audio.Mp3.Yx5300.csproj index d6e81629c2..8aeb423f37 100644 --- a/Source/Meadow.Foundation.Peripherals/Audio.Mp3.Yx5300/Driver/Audio.Mp3.Yx5300.csproj +++ b/Source/Meadow.Foundation.Peripherals/Audio.Mp3.Yx5300/Driver/Audio.Mp3.Yx5300.csproj @@ -22,6 +22,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/Audio.Mp3.Yx5300/Samples/Yx5300_Sample/Yx5300_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Audio.Mp3.Yx5300/Samples/Yx5300_Sample/Yx5300_Sample.csproj index 71e58ea28c..15e19ef18a 100644 --- a/Source/Meadow.Foundation.Peripherals/Audio.Mp3.Yx5300/Samples/Yx5300_Sample/Yx5300_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Audio.Mp3.Yx5300/Samples/Yx5300_Sample/Yx5300_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Audio.Radio.Tea5767/Driver/Audio.Radio.Tea5767.csproj b/Source/Meadow.Foundation.Peripherals/Audio.Radio.Tea5767/Driver/Audio.Radio.Tea5767.csproj index 3ae5f730e4..c00d8bb853 100644 --- a/Source/Meadow.Foundation.Peripherals/Audio.Radio.Tea5767/Driver/Audio.Radio.Tea5767.csproj +++ b/Source/Meadow.Foundation.Peripherals/Audio.Radio.Tea5767/Driver/Audio.Radio.Tea5767.csproj @@ -22,6 +22,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/Audio.Radio.Tea5767/Samples/Tea5767_Sample/Tea5767_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Audio.Radio.Tea5767/Samples/Tea5767_Sample/Tea5767_Sample.csproj index 7f1379531f..85e03314fb 100644 --- a/Source/Meadow.Foundation.Peripherals/Audio.Radio.Tea5767/Samples/Tea5767_Sample/Tea5767_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Audio.Radio.Tea5767/Samples/Tea5767_Sample/Tea5767_Sample.csproj @@ -9,9 +9,9 @@ App - + - + diff --git a/Source/Meadow.Foundation.Peripherals/Displays.AsciiConsole/Driver/Displays.AsciiConsole.csproj b/Source/Meadow.Foundation.Peripherals/Displays.AsciiConsole/Driver/Displays.AsciiConsole.csproj index 8a9c101d7e..3fb194df7d 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.AsciiConsole/Driver/Displays.AsciiConsole.csproj +++ b/Source/Meadow.Foundation.Peripherals/Displays.AsciiConsole/Driver/Displays.AsciiConsole.csproj @@ -22,6 +22,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/Displays.AsciiConsole/Samples/AsciiConsole_Sample/AsciiConsole_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Displays.AsciiConsole/Samples/AsciiConsole_Sample/AsciiConsole_Sample.csproj index 88bb67a0d6..c9555a5f92 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.AsciiConsole/Samples/AsciiConsole_Sample/AsciiConsole_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Displays.AsciiConsole/Samples/AsciiConsole_Sample/AsciiConsole_Sample.csproj @@ -9,8 +9,8 @@ - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Displays.Ch1115/Driver/Displays.Ch1115.csproj b/Source/Meadow.Foundation.Peripherals/Displays.Ch1115/Driver/Displays.Ch1115.csproj index 5923dffbc6..f75a62a91d 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.Ch1115/Driver/Displays.Ch1115.csproj +++ b/Source/Meadow.Foundation.Peripherals/Displays.Ch1115/Driver/Displays.Ch1115.csproj @@ -22,6 +22,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/Displays.Ch1115/Samples/Ch1115_Sample/Ch1115_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Displays.Ch1115/Samples/Ch1115_Sample/Ch1115_Sample.csproj index 24037f8a54..d2b46644e6 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.Ch1115/Samples/Ch1115_Sample/Ch1115_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Displays.Ch1115/Samples/Ch1115_Sample/Ch1115_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Displays.Gtk/Driver/Displays.Gtk.csproj b/Source/Meadow.Foundation.Peripherals/Displays.Gtk/Driver/Displays.Gtk.csproj index 7b307749fc..efe5850c51 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.Gtk/Driver/Displays.Gtk.csproj +++ b/Source/Meadow.Foundation.Peripherals/Displays.Gtk/Driver/Displays.Gtk.csproj @@ -29,6 +29,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/Displays.Lcd.CharacterDisplay/Driver/Displays.Lcd.CharacterDisplay.csproj b/Source/Meadow.Foundation.Peripherals/Displays.Lcd.CharacterDisplay/Driver/Displays.Lcd.CharacterDisplay.csproj index 38007c7b82..a0e968806d 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.Lcd.CharacterDisplay/Driver/Displays.Lcd.CharacterDisplay.csproj +++ b/Source/Meadow.Foundation.Peripherals/Displays.Lcd.CharacterDisplay/Driver/Displays.Lcd.CharacterDisplay.csproj @@ -22,6 +22,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/Displays.Lcd.CharacterDisplay/Samples/CharacterDisplay_Sample/CharacterDisplay_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Displays.Lcd.CharacterDisplay/Samples/CharacterDisplay_Sample/CharacterDisplay_Sample.csproj index 362a19f5f6..7f2479ba09 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.Lcd.CharacterDisplay/Samples/CharacterDisplay_Sample/CharacterDisplay_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Displays.Lcd.CharacterDisplay/Samples/CharacterDisplay_Sample/CharacterDisplay_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Displays.Led.FourDigitSevenSegment/Driver/Displays.Led.FourDigitSevenSegment.csproj b/Source/Meadow.Foundation.Peripherals/Displays.Led.FourDigitSevenSegment/Driver/Displays.Led.FourDigitSevenSegment.csproj index 96b56625c9..e45979decc 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.Led.FourDigitSevenSegment/Driver/Displays.Led.FourDigitSevenSegment.csproj +++ b/Source/Meadow.Foundation.Peripherals/Displays.Led.FourDigitSevenSegment/Driver/Displays.Led.FourDigitSevenSegment.csproj @@ -22,6 +22,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/Displays.Led.FourDigitSevenSegment/Samples/FourDigitSevenSegment_Sample/FourDigitSevenSegment_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Displays.Led.FourDigitSevenSegment/Samples/FourDigitSevenSegment_Sample/FourDigitSevenSegment_Sample.csproj index 2a19fed64b..8ae8407867 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.Led.FourDigitSevenSegment/Samples/FourDigitSevenSegment_Sample/FourDigitSevenSegment_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Displays.Led.FourDigitSevenSegment/Samples/FourDigitSevenSegment_Sample/FourDigitSevenSegment_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Displays.Led.FourteenSegment/Driver/Displays.Led.FourteenSegment.csproj b/Source/Meadow.Foundation.Peripherals/Displays.Led.FourteenSegment/Driver/Displays.Led.FourteenSegment.csproj index b74c5299fe..b5a4444ffa 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.Led.FourteenSegment/Driver/Displays.Led.FourteenSegment.csproj +++ b/Source/Meadow.Foundation.Peripherals/Displays.Led.FourteenSegment/Driver/Displays.Led.FourteenSegment.csproj @@ -22,6 +22,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/Displays.Led.FourteenSegment/Samples/FourteenSegment_Sample/FourteenSegment_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Displays.Led.FourteenSegment/Samples/FourteenSegment_Sample/FourteenSegment_Sample.csproj index f0ffb96a62..80788d338d 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.Led.FourteenSegment/Samples/FourteenSegment_Sample/FourteenSegment_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Displays.Led.FourteenSegment/Samples/FourteenSegment_Sample/FourteenSegment_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Displays.Led.SevenSegment/Driver/Displays.Led.SevenSegment.csproj b/Source/Meadow.Foundation.Peripherals/Displays.Led.SevenSegment/Driver/Displays.Led.SevenSegment.csproj index 9956895cc9..f0f917da89 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.Led.SevenSegment/Driver/Displays.Led.SevenSegment.csproj +++ b/Source/Meadow.Foundation.Peripherals/Displays.Led.SevenSegment/Driver/Displays.Led.SevenSegment.csproj @@ -22,6 +22,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/Displays.Led.SevenSegment/Samples/SevenSegment_Sample/SevenSegment_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Displays.Led.SevenSegment/Samples/SevenSegment_Sample/SevenSegment_Sample.csproj index 66d10039e7..e0a5f85467 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.Led.SevenSegment/Samples/SevenSegment_Sample/SevenSegment_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Displays.Led.SevenSegment/Samples/SevenSegment_Sample/SevenSegment_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Displays.Led.SixteenSegment/Driver/Displays.Led.SixteenSegment.csproj b/Source/Meadow.Foundation.Peripherals/Displays.Led.SixteenSegment/Driver/Displays.Led.SixteenSegment.csproj index 6b9c19e001..5e05e9c918 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.Led.SixteenSegment/Driver/Displays.Led.SixteenSegment.csproj +++ b/Source/Meadow.Foundation.Peripherals/Displays.Led.SixteenSegment/Driver/Displays.Led.SixteenSegment.csproj @@ -22,6 +22,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/Displays.Led.SixteenSegment/Samples/SixteenSegment_Sample/SixteenSegment_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Displays.Led.SixteenSegment/Samples/SixteenSegment_Sample/SixteenSegment_Sample.csproj index c73037e20d..55c39a81ae 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.Led.SixteenSegment/Samples/SixteenSegment_Sample/SixteenSegment_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Displays.Led.SixteenSegment/Samples/SixteenSegment_Sample/SixteenSegment_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Displays.Max7219/Driver/Displays.Max7219.csproj b/Source/Meadow.Foundation.Peripherals/Displays.Max7219/Driver/Displays.Max7219.csproj index f09055a6a8..93d10e8958 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.Max7219/Driver/Displays.Max7219.csproj +++ b/Source/Meadow.Foundation.Peripherals/Displays.Max7219/Driver/Displays.Max7219.csproj @@ -22,6 +22,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/Displays.Max7219/Samples/Max7219_8x8x4_Sample/Max7219_8x8x4_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Displays.Max7219/Samples/Max7219_8x8x4_Sample/Max7219_8x8x4_Sample.csproj index 018a71f507..837aa1fd15 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.Max7219/Samples/Max7219_8x8x4_Sample/Max7219_8x8x4_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Displays.Max7219/Samples/Max7219_8x8x4_Sample/Max7219_8x8x4_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Displays.Max7219/Samples/Max7219_8x8x4x2_Sample/Max7219_8x8x4x2_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Displays.Max7219/Samples/Max7219_8x8x4x2_Sample/Max7219_8x8x4x2_Sample.csproj index 018a71f507..837aa1fd15 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.Max7219/Samples/Max7219_8x8x4x2_Sample/Max7219_8x8x4x2_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Displays.Max7219/Samples/Max7219_8x8x4x2_Sample/Max7219_8x8x4x2_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Displays.Max7219/Samples/Max7219_Sample/Max7219_7Segment_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Displays.Max7219/Samples/Max7219_Sample/Max7219_7Segment_Sample.csproj index 018a71f507..837aa1fd15 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.Max7219/Samples/Max7219_Sample/Max7219_7Segment_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Displays.Max7219/Samples/Max7219_Sample/Max7219_7Segment_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Displays.Pcd8544/Driver/Displays.Pcd8544.csproj b/Source/Meadow.Foundation.Peripherals/Displays.Pcd8544/Driver/Displays.Pcd8544.csproj index bad6d4e1fc..8bac149791 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.Pcd8544/Driver/Displays.Pcd8544.csproj +++ b/Source/Meadow.Foundation.Peripherals/Displays.Pcd8544/Driver/Displays.Pcd8544.csproj @@ -22,6 +22,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/Displays.Pcd8544/Driver/Pcd8544.cs b/Source/Meadow.Foundation.Peripherals/Displays.Pcd8544/Driver/Pcd8544.cs index c912019315..c7e4ba6d70 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.Pcd8544/Driver/Pcd8544.cs +++ b/Source/Meadow.Foundation.Peripherals/Displays.Pcd8544/Driver/Pcd8544.cs @@ -83,11 +83,6 @@ public SpiClockConfiguration.Mode SpiBusMode /// protected Buffer1bpp imageBuffer; - /// - /// Buffer to hold internal command data to be sent over the SPI bus - /// - protected Memory commandBuffer; - /// /// Create a Pcd8544 object /// @@ -134,15 +129,17 @@ private void Initialize() dataCommandPort.State = false; - commandBuffer.Span[0] = 0x21; - commandBuffer.Span[1] = 0xBF; - commandBuffer.Span[2] = 0x04; - commandBuffer.Span[3] = 0x14; - commandBuffer.Span[4] = 0x0D; - commandBuffer.Span[5] = 0x20; - commandBuffer.Span[6] = 0x0C; + var commandBuffer = new byte[7]; - spiComms.Write(commandBuffer.Span[0..6]); + commandBuffer[0] = 0x21; + commandBuffer[1] = 0xBF; + commandBuffer[2] = 0x04; + commandBuffer[3] = 0x14; + commandBuffer[4] = 0x0D; + commandBuffer[5] = 0x20; + commandBuffer[6] = 0x0C; + + spiComms.Write(commandBuffer); dataCommandPort.State = true; @@ -228,9 +225,9 @@ public void InvertDisplay(bool inverse) { IsDisplayInverted = inverse; dataCommandPort.State = false; - commandBuffer.Span[0] = inverse ? (byte)0x0D : (byte)0x0C; - spiComms.Write(commandBuffer.Span[0]); + spiComms.Write(inverse ? (byte)0x0D : (byte)0x0C); + dataCommandPort.State = true; } diff --git a/Source/Meadow.Foundation.Peripherals/Displays.Pcd8544/Samples/Pcd8544_Sample/Pcd8544_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Displays.Pcd8544/Samples/Pcd8544_Sample/Pcd8544_Sample.csproj index d22bf1a4af..df9fd1d7fb 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.Pcd8544/Samples/Pcd8544_Sample/Pcd8544_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Displays.Pcd8544/Samples/Pcd8544_Sample/Pcd8544_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Displays.Sh110x/Driver/Displays.Sh110x.csproj b/Source/Meadow.Foundation.Peripherals/Displays.Sh110x/Driver/Displays.Sh110x.csproj index d9f10c2961..8eccc2e716 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.Sh110x/Driver/Displays.Sh110x.csproj +++ b/Source/Meadow.Foundation.Peripherals/Displays.Sh110x/Driver/Displays.Sh110x.csproj @@ -22,6 +22,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/Displays.Sh110x/Samples/Sh1106_Sample/Sh1106_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Displays.Sh110x/Samples/Sh1106_Sample/Sh1106_Sample.csproj index 93bd06799e..b8c349bc21 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.Sh110x/Samples/Sh1106_Sample/Sh1106_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Displays.Sh110x/Samples/Sh1106_Sample/Sh1106_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Displays.Sh110x/Samples/Sh1107_Sample/Sh1107_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Displays.Sh110x/Samples/Sh1107_Sample/Sh1107_Sample.csproj index 93bd06799e..b8c349bc21 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.Sh110x/Samples/Sh1107_Sample/Sh1107_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Displays.Sh110x/Samples/Sh1107_Sample/Sh1107_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Displays.Silk/Driver/Displays.Silk.csproj b/Source/Meadow.Foundation.Peripherals/Displays.Silk/Driver/Displays.Silk.csproj index 5846d4dbe5..a62b117fc2 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.Silk/Driver/Displays.Silk.csproj +++ b/Source/Meadow.Foundation.Peripherals/Displays.Silk/Driver/Displays.Silk.csproj @@ -23,13 +23,13 @@ - + - + diff --git a/Source/Meadow.Foundation.Peripherals/Displays.Silk/Driver/Readme.md b/Source/Meadow.Foundation.Peripherals/Displays.Silk/Driver/Readme.md index d09c03ac34..95a0a96501 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.Silk/Driver/Readme.md +++ b/Source/Meadow.Foundation.Peripherals/Displays.Silk/Driver/Readme.md @@ -18,11 +18,13 @@ You can install the library from within Visual studio using the the NuGet Packag ## Usage ```csharp -public class Program +public class Program { static SilkDisplay? display; static MicroGraphics graphics = default!; +static PixelBufferBase image = default!; + public static void Main() { Initialize(); @@ -40,27 +42,54 @@ public static void Initialize() CurrentFont = new Font16x24(), Stroke = 1 }; + + image = LoadJpeg() as PixelBufferBase; } public static void Run() { - graphics.Clear(); + Task.Run(() => + { + var grayImage = image.Convert(); + + var scaledImage = image.Resize(320, 320); - graphics.DrawText(10, 10, "Silk.NET", Color.White); + var rotatedImage = image.Rotate(new Meadow.Units.Angle(60)); - graphics.DrawText(10, 40, "1234567890!@#$%^&*(){}[],./<>?;':", Color.LawnGreen); - graphics.DrawText(10, 70, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", Color.Cyan); - graphics.DrawText(10, 100, "abcdefghijklmnopqrstuvwxyz", Color.Yellow); - graphics.DrawText(10, 130, "Temp: 21.5°C", Color.Orange); + graphics.Clear(); - graphics.DrawTriangle(10, 220, 50, 260, 10, 260, Color.Red); - graphics.DrawRectangle(20, 185, 80, 40, Color.Yellow, false); - graphics.DrawCircle(50, 240, 40, Color.Blue, false); + //draw the image centered + graphics.DrawBuffer((display!.Width - rotatedImage.Width) / 2, + (display!.Height - rotatedImage.Height) / 2, rotatedImage); - graphics.Show(); + graphics.Show(); + }); display!.Run(); } + +static IPixelBuffer LoadJpeg() +{ + var jpgData = LoadResource("maple.jpg"); + + var decoder = new JpegDecoder(); + var jpg = decoder.DecodeJpeg(jpgData); + + Console.WriteLine($"Jpeg decoded is {jpg.Length} bytes, W: {decoder.Width}, H: {decoder.Height}"); + + return new BufferRgb888(decoder.Width, decoder.Height, jpg); +} + +static byte[] LoadResource(string filename) +{ + var assembly = Assembly.GetExecutingAssembly(); + var resourceName = $"Silk_Image_Sample.{filename}"; + + using Stream stream = assembly.GetManifestResourceStream(resourceName); + using var ms = new MemoryStream(); + stream.CopyTo(ms); + return ms.ToArray(); +} } ``` ## How to Contribute diff --git a/Source/Meadow.Foundation.Peripherals/Displays.Silk/Driver/SilkDisplay.cs b/Source/Meadow.Foundation.Peripherals/Displays.Silk/Driver/SilkDisplay.cs index d219a740a9..78ba871acb 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.Silk/Driver/SilkDisplay.cs +++ b/Source/Meadow.Foundation.Peripherals/Displays.Silk/Driver/SilkDisplay.cs @@ -38,6 +38,11 @@ public class SilkDisplay : IResizablePixelDisplay, ITouchScreen /// public IPixelBuffer PixelBuffer => pixelBuffer; + /// + /// The frame buffer that's used to draw to the display + /// + private SkiaPixelBuffer? frameBuffer; + /// public ColorMode ColorMode => pixelBuffer.ColorMode; @@ -58,21 +63,20 @@ public class SilkDisplay : IResizablePixelDisplay, ITouchScreen /// /// Width of display in pixels /// Height of display in pixels - /// + /// The scale factor to visualize the display public SilkDisplay(int width = 800, int height = 600, float displayScale = 1.0f) { - this.displayScale = displayScale; - virtualWidth = (int)(width * displayScale); - virtualHeight = (int)(height * displayScale); - Initialize(virtualWidth, virtualHeight); + Initialize(width, height, displayScale); } /// public void Resize(int width, int height, float displayScale = 1) { pixelBuffer = new SkiaPixelBuffer(width, height); + frameBuffer = new SkiaPixelBuffer(width, height); this.displayScale = displayScale; + virtualWidth = (int)(width * displayScale); virtualHeight = (int)(height * displayScale); window.Size = new Vector2D(virtualWidth, virtualHeight); @@ -82,12 +86,11 @@ public void Resize(int width, int height, float displayScale = 1) CreateOrUpdateDrawingSurface(virtualWidth, virtualHeight); } - private void Initialize(int width, int height) + private void Initialize(int width, int height, float displayScale = 1) { - pixelBuffer = new SkiaPixelBuffer(width, height); + this.displayScale = displayScale; var options = WindowOptions.Default; - options.Size = new Vector2D(width, height); options.Title = "Meadow Desktop"; options.PreferredStencilBufferBits = 8; options.PreferredBitDepth = new Vector4D(8, 8, 8, 8); @@ -98,12 +101,12 @@ private void Initialize(int width, int height) window.Render += OnWindowRender; window.Initialize(); - WindowExtensions.Center(window); - grglInterface = GRGlInterface.Create(name => window.GLContext!.TryGetProcAddress(name, out var addr) ? addr : 0); grglInterface.Validate(); context = GRContext.CreateGl(grglInterface); CreateOrUpdateDrawingSurface(width, height); + + Resize(width, height, displayScale); } private void CreateOrUpdateDrawingSurface(int width, int height) @@ -161,11 +164,19 @@ private void OnWindowLoad() private void OnWindowRender(double obj) { - canvas.DrawBitmap(pixelBuffer.SKBitmap, - SKRect.Create(0, 0, Width, Height), - SKRect.Create(0, 0, virtualWidth, virtualHeight)); + if (frameBuffer == null) + { + return; + } - canvas.Flush(); + lock (frameBuffer) + { + canvas.DrawBitmap(frameBuffer.SKBitmap, + SKRect.Create(0, 0, Width, Height), + SKRect.Create(0, 0, virtualWidth, virtualHeight)); + + canvas.Flush(); + } } /// @@ -183,6 +194,15 @@ public void Run() /// public void Show() { + if (frameBuffer == null) + { + return; + } + + lock (frameBuffer) + { + frameBuffer?.WriteBuffer(0, 0, pixelBuffer); + } } /// @@ -204,6 +224,11 @@ public void Show(int left, int top, int right, int bottom) public void Clear(bool updateDisplay = false) { pixelBuffer.Clear(); + + if (updateDisplay) + { + Show(); + } } /// diff --git a/Source/Meadow.Foundation.Peripherals/Displays.Silk/Driver/SkiaPixelBuffer.cs b/Source/Meadow.Foundation.Peripherals/Displays.Silk/Driver/SkiaPixelBuffer.cs index 137f16ea76..c43e2c9d4c 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.Silk/Driver/SkiaPixelBuffer.cs +++ b/Source/Meadow.Foundation.Peripherals/Displays.Silk/Driver/SkiaPixelBuffer.cs @@ -5,7 +5,7 @@ namespace Meadow.Foundation.Displays; internal class SkiaPixelBuffer : IPixelBuffer { - public SKBitmap SKBitmap { get; } + public SKBitmap SKBitmap { get; private set; } public int Width => SKBitmap.Width; public int Height => SKBitmap.Height; @@ -48,7 +48,8 @@ public Color GetPixel(int x, int y) public void InvertPixel(int x, int y) { - throw new NotImplementedException(); + var px = SKBitmap.GetPixel(x, y); + SKBitmap.SetPixel(x, y, new SKColor((byte)~px.Red, (byte)~px.Green, (byte)~px.Blue)); } public void SetPixel(int x, int y, Color color) @@ -58,6 +59,12 @@ public void SetPixel(int x, int y, Color color) public void WriteBuffer(int originX, int originY, IPixelBuffer buffer) { + if (buffer is SkiaPixelBuffer skiaBuffer && originX == 0 && originY == 0) + { + skiaBuffer.SKBitmap.CopyTo(SKBitmap); + return; + } + for (var x = 0; x < buffer.Width; x++) { for (var y = 0; y < buffer.Height; y++) diff --git a/Source/Meadow.Foundation.Peripherals/Displays.Silk/Samples/Silk_Image_Sample/Program.cs b/Source/Meadow.Foundation.Peripherals/Displays.Silk/Samples/Silk_Image_Sample/Program.cs new file mode 100644 index 0000000000..8ac631789e --- /dev/null +++ b/Source/Meadow.Foundation.Peripherals/Displays.Silk/Samples/Silk_Image_Sample/Program.cs @@ -0,0 +1,86 @@ +using Meadow.Foundation.Displays; +using Meadow.Foundation.Graphics; +using Meadow.Foundation.Graphics.Buffers; +using Meadow.Peripherals.Displays; +using SimpleJpegDecoder; +using System.Reflection; + +namespace SilkDisplay_Image_Sample; + +// + +public class Program +{ + static SilkDisplay? display; + static MicroGraphics graphics = default!; + + static PixelBufferBase image = default!; + + public static void Main() + { + Initialize(); + Run(); + + Thread.Sleep(Timeout.Infinite); + } + + public static void Initialize() + { + display = new SilkDisplay(640, 480, displayScale: 1f); + + graphics = new MicroGraphics(display) + { + CurrentFont = new Font16x24(), + Stroke = 1 + }; + + image = LoadJpeg() as PixelBufferBase; + } + + public static void Run() + { + Task.Run(() => + { + var grayImage = image.Convert(); + + var scaledImage = image.Resize(320, 320); + + var rotatedImage = image.Rotate(new Meadow.Units.Angle(60)); + + graphics.Clear(); + + //draw the image centered + graphics.DrawBuffer((display!.Width - rotatedImage.Width) / 2, + (display!.Height - rotatedImage.Height) / 2, rotatedImage); + + graphics.Show(); + }); + + display!.Run(); + } + + static IPixelBuffer LoadJpeg() + { + var jpgData = LoadResource("maple.jpg"); + + var decoder = new JpegDecoder(); + var jpg = decoder.DecodeJpeg(jpgData); + + Console.WriteLine($"Jpeg decoded is {jpg.Length} bytes, W: {decoder.Width}, H: {decoder.Height}"); + + return new BufferRgb888(decoder.Width, decoder.Height, jpg); + } + + static byte[] LoadResource(string filename) + { + var assembly = Assembly.GetExecutingAssembly(); + var resourceName = $"Silk_Image_Sample.{filename}"; + + using Stream stream = assembly.GetManifestResourceStream(resourceName); + using var ms = new MemoryStream(); + stream.CopyTo(ms); + return ms.ToArray(); + } +} + +// \ No newline at end of file diff --git a/Source/Meadow.Foundation.Peripherals/Displays.Silk/Samples/Silk_Image_Sample/Silk_Image_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Displays.Silk/Samples/Silk_Image_Sample/Silk_Image_Sample.csproj new file mode 100644 index 0000000000..0cd18076b9 --- /dev/null +++ b/Source/Meadow.Foundation.Peripherals/Displays.Silk/Samples/Silk_Image_Sample/Silk_Image_Sample.csproj @@ -0,0 +1,22 @@ + + + Exe + net8.0 + enable + enable + 10.0 + + + + + + + + + + + + + + + diff --git a/Source/Meadow.Foundation.Peripherals/Displays.Silk/Samples/Silk_Image_Sample/maple.jpg b/Source/Meadow.Foundation.Peripherals/Displays.Silk/Samples/Silk_Image_Sample/maple.jpg new file mode 100644 index 0000000000..fc94652e3d Binary files /dev/null and b/Source/Meadow.Foundation.Peripherals/Displays.Silk/Samples/Silk_Image_Sample/maple.jpg differ diff --git a/Source/Meadow.Foundation.Peripherals/Displays.Silk/Samples/Silk_Sample/Program.cs b/Source/Meadow.Foundation.Peripherals/Displays.Silk/Samples/Silk_Sample/Program.cs index 1a5ace69da..c7f33b7e2b 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.Silk/Samples/Silk_Sample/Program.cs +++ b/Source/Meadow.Foundation.Peripherals/Displays.Silk/Samples/Silk_Sample/Program.cs @@ -6,7 +6,7 @@ namespace SilkDisplay_Sample; // -public class Program +public class Program { static SilkDisplay? display; static MicroGraphics graphics = default!; @@ -32,20 +32,42 @@ public static void Initialize() public static void Run() { - graphics.Clear(); + Task.Run(() => + { + int circleRadius = 40; + int circleSpeed = 4; + int x = circleRadius; + int y = circleRadius; + bool xDirection = true; + bool yDirection = true; + + while (true) + { + graphics.Clear(); + + graphics.DrawText(10, 10, "Silk.NET", Color.White); + + graphics.DrawText(10, 40, "1234567890!@#$%^&*(){}[],./<>?;':", Color.LawnGreen); + graphics.DrawText(10, 70, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", Color.Cyan); + graphics.DrawText(10, 100, "abcdefghijklmnopqrstuvwxyz", Color.Yellow); + graphics.DrawText(10, 130, "Temp: 21.5°C", Color.Orange); + + graphics.DrawTriangle(10, 220, 50, 260, 10, 260, Color.Red); + graphics.DrawRectangle(20, 185, 80, 40, Color.Yellow, false); - graphics.DrawText(10, 10, "Silk.NET", Color.White); + graphics.DrawCircle(x, y, circleRadius, Color.Blue, false); + graphics.Show(); - graphics.DrawText(10, 40, "1234567890!@#$%^&*(){}[],./<>?;':", Color.LawnGreen); - graphics.DrawText(10, 70, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", Color.Cyan); - graphics.DrawText(10, 100, "abcdefghijklmnopqrstuvwxyz", Color.Yellow); - graphics.DrawText(10, 130, "Temp: 21.5°C", Color.Orange); + x += xDirection ? circleSpeed : -circleSpeed; + y += yDirection ? circleSpeed : -circleSpeed; - graphics.DrawTriangle(10, 220, 50, 260, 10, 260, Color.Red); - graphics.DrawRectangle(20, 185, 80, 40, Color.Yellow, false); - graphics.DrawCircle(50, 240, 40, Color.Blue, false); + if (x > display!.Width - circleRadius) { xDirection = false; } + else if (x < circleRadius) { xDirection = true; } - graphics.Show(); + if (y > display!.Height - circleRadius) { yDirection = false; } + else if (y < circleRadius) { yDirection = true; } + } + }); display!.Run(); } diff --git a/Source/Meadow.Foundation.Peripherals/Displays.Silk/Samples/Silk_Sample/Silk_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Displays.Silk/Samples/Silk_Sample/Silk_Sample.csproj index 3c26a04547..12dbc14ce4 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.Silk/Samples/Silk_Sample/Silk_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Displays.Silk/Samples/Silk_Sample/Silk_Sample.csproj @@ -7,6 +7,6 @@ 10.0 - + diff --git a/Source/Meadow.Foundation.Peripherals/Displays.Ssd130x/Driver/Displays.Ssd130x.csproj b/Source/Meadow.Foundation.Peripherals/Displays.Ssd130x/Driver/Displays.Ssd130x.csproj index adbea14749..03a0d0d766 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.Ssd130x/Driver/Displays.Ssd130x.csproj +++ b/Source/Meadow.Foundation.Peripherals/Displays.Ssd130x/Driver/Displays.Ssd130x.csproj @@ -22,6 +22,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/Displays.Ssd130x/Samples/Ssd1039_3DCube_Sample/Ssd1039_3DCube_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Displays.Ssd130x/Samples/Ssd1039_3DCube_Sample/Ssd1039_3DCube_Sample.csproj index aff8b0d9f6..c7504661da 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.Ssd130x/Samples/Ssd1039_3DCube_Sample/Ssd1039_3DCube_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Displays.Ssd130x/Samples/Ssd1039_3DCube_Sample/Ssd1039_3DCube_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Displays.Ssd130x/Samples/Ssd1306_Sample/Ssd1306_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Displays.Ssd130x/Samples/Ssd1306_Sample/Ssd1306_Sample.csproj index aff8b0d9f6..c7504661da 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.Ssd130x/Samples/Ssd1306_Sample/Ssd1306_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Displays.Ssd130x/Samples/Ssd1306_Sample/Ssd1306_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Displays.Ssd130x/Samples/Ssd1309_Game_Sample/SnakeGame.cs b/Source/Meadow.Foundation.Peripherals/Displays.Ssd130x/Samples/Ssd1309_Game_Sample/SnakeGame.cs index 9f5ea2cb14..2547a1463b 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.Ssd130x/Samples/Ssd1309_Game_Sample/SnakeGame.cs +++ b/Source/Meadow.Foundation.Peripherals/Displays.Ssd130x/Samples/Ssd1309_Game_Sample/SnakeGame.cs @@ -72,7 +72,7 @@ public void Update() return; var head = new Point((Point)SnakePosition[0]); - var tail = new Point((Point)SnakePosition[SnakePosition.Count - 1]); + var tail = new Point((Point)SnakePosition[^1]); if (Direction == SnakeDirection.Left) head.X--; diff --git a/Source/Meadow.Foundation.Peripherals/Displays.Ssd130x/Samples/Ssd1309_Game_Sample/Ssd1309_Game_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Displays.Ssd130x/Samples/Ssd1309_Game_Sample/Ssd1309_Game_Sample.csproj index aff8b0d9f6..c7504661da 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.Ssd130x/Samples/Ssd1309_Game_Sample/Ssd1309_Game_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Displays.Ssd130x/Samples/Ssd1309_Game_Sample/Ssd1309_Game_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Displays.Ssd130x/Samples/Ssd1309_Sample/Ssd1309_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Displays.Ssd130x/Samples/Ssd1309_Sample/Ssd1309_Sample.csproj index aff8b0d9f6..c7504661da 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.Ssd130x/Samples/Ssd1309_Sample/Ssd1309_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Displays.Ssd130x/Samples/Ssd1309_Sample/Ssd1309_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Displays.Ssd1327/Driver/Displays.Ssd1327.csproj b/Source/Meadow.Foundation.Peripherals/Displays.Ssd1327/Driver/Displays.Ssd1327.csproj index 054c55bd32..bbb07ba940 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.Ssd1327/Driver/Displays.Ssd1327.csproj +++ b/Source/Meadow.Foundation.Peripherals/Displays.Ssd1327/Driver/Displays.Ssd1327.csproj @@ -22,6 +22,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/Displays.Ssd1327/Driver/Ssd1327.cs b/Source/Meadow.Foundation.Peripherals/Displays.Ssd1327/Driver/Ssd1327.cs index 16b655e1cf..35b3d4335b 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.Ssd1327/Driver/Ssd1327.cs +++ b/Source/Meadow.Foundation.Peripherals/Displays.Ssd1327/Driver/Ssd1327.cs @@ -108,6 +108,7 @@ public Ssd1327(ISpiBus spiBus, this.dataCommandPort = dataCommandPort; this.resetPort = resetPort; + this.chipSelectPort = chipSelectPort; spiComms = new SpiCommunications(spiBus, this.chipSelectPort = chipSelectPort, DefaultSpiBusSpeed, DefaultSpiBusMode); diff --git a/Source/Meadow.Foundation.Peripherals/Displays.Ssd1327/Samples/Ssd1327_Sample/Ssd1327_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Displays.Ssd1327/Samples/Ssd1327_Sample/Ssd1327_Sample.csproj index 3dcc12b50b..fd574029aa 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.Ssd1327/Samples/Ssd1327_Sample/Ssd1327_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Displays.Ssd1327/Samples/Ssd1327_Sample/Ssd1327_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Displays.St7565/Driver/Displays.St7565.csproj b/Source/Meadow.Foundation.Peripherals/Displays.St7565/Driver/Displays.St7565.csproj index c3e1059862..bc332736d0 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.St7565/Driver/Displays.St7565.csproj +++ b/Source/Meadow.Foundation.Peripherals/Displays.St7565/Driver/Displays.St7565.csproj @@ -22,6 +22,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/Displays.St7565/Samples/St7565_Sample/St7565_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Displays.St7565/Samples/St7565_Sample/St7565_Sample.csproj index 7eb711b47e..e149c0d836 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.St7565/Samples/St7565_Sample/St7565_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Displays.St7565/Samples/St7565_Sample/St7565_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Driver/Displays.TftSpi.csproj b/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Driver/Displays.TftSpi.csproj index 866b62ab7d..7e34a63759 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Driver/Displays.TftSpi.csproj +++ b/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Driver/Displays.TftSpi.csproj @@ -22,7 +22,7 @@ - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Driver/Drivers/Ili9341.cs b/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Driver/Drivers/Ili9341.cs index 7837301fbc..4dbe676558 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Driver/Drivers/Ili9341.cs +++ b/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Driver/Drivers/Ili9341.cs @@ -22,7 +22,7 @@ public class Ili9341 : TftSpiBase, IRotatableDisplay /// /// The color modes supported by the display /// - public override ColorMode SupportedColorModes => ColorMode.Format16bppRgb565 | ColorMode.Format12bppRgb444; + public override ColorMode SupportedColorModes => ColorMode.Format16bppRgb565 | ColorMode.Format12bppRgb444 | ColorMode.Format18bppRgb666; /// /// Create a new Ili9341 color display object @@ -75,7 +75,7 @@ protected override void Initialize() } else { - DelayMs(120); //Not sure if this is needed but can't hurt + DelayMs(120); // Not sure if this is needed but can't hurt } SendCommand(0xEF, new byte[] { 0x03, 0x80, 0x02 }); @@ -92,14 +92,19 @@ protected override void Initialize() SendCommand(ILI9341_VMCTR2, new byte[] { 0x86 }); SendCommand((byte)Register.MADCTL, new byte[] { (byte)(Register.MADCTL_MX | Register.MADCTL_BGR) }); - if (ColorMode == ColorMode.Format16bppRgb565) + switch (ColorMode) { - SendCommand((byte)Register.COLOR_MODE, new byte[] { 0x55 }); //color mode - 16bpp - } - else - { - SendCommand((byte)Register.COLOR_MODE, new byte[] { 0x53 }); //color mode - 12bpp + case ColorMode.Format16bppRgb565: + SendCommand((byte)Register.COLOR_MODE, new byte[] { 0x55 }); // Color mode - 16bpp + break; + case ColorMode.Format12bppRgb444: + SendCommand((byte)Register.COLOR_MODE, new byte[] { 0x53 }); // Color mode - 12bpp + break; + case ColorMode.Format18bppRgb666: + SendCommand((byte)Register.COLOR_MODE, new byte[] { 0x66 }); // Color mode - 18bpp + break; } + SendCommand((byte)Register.FRMCTR1, new byte[] { 0x00, 0x18 }); SendCommand(ILI9341_DFUNCTR, new byte[] { 0x08, 0x82, 0x27 }); SendCommand(0xF2, new byte[] { 0x00 }); @@ -164,4 +169,4 @@ public void SetRotation(RotationType rotation) static readonly byte ILI9341_GMCTRP1 = 0xE0; static readonly byte ILI9341_GMCTRN1 = 0xE1; } -} \ No newline at end of file +} diff --git a/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Driver/Drivers/St7789.cs b/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Driver/Drivers/St7789.cs index de36db7919..42a6b73b5b 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Driver/Drivers/St7789.cs +++ b/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Driver/Drivers/St7789.cs @@ -17,7 +17,7 @@ public class St7789 : TftSpiBase, IRotatableDisplay /// /// The color modes supported by the display /// - public override ColorMode SupportedColorModes => ColorMode.Format16bppRgb565 | ColorMode.Format12bppRgb444; + public override ColorMode SupportedColorModes => ColorMode.Format16bppRgb565 | ColorMode.Format12bppRgb444 | ColorMode.Format18bppRgb666; /// /// SPI bus speed @@ -111,11 +111,13 @@ protected override void Initialize() SendCommand(Register.SLPOUT); DelayMs(500); - SendCommand(Register.COLOR_MODE); // set color mode - 16 bit color (x55), 12 bit color (x53), 18 bit color (x56) + SendCommand(Register.COLOR_MODE); // set color mode - 16 bit color (x55), 12 bit color (x53), 18 bit color (x66) if (ColorMode == ColorMode.Format16bppRgb565) SendData(0x55); // 16-bit color RGB565 - else - SendData(0x53); //12-bit color RGB444 + else if (ColorMode == ColorMode.Format12bppRgb444) + SendData(0x53); // 12-bit color RGB444 + else if (ColorMode == ColorMode.Format18bppRgb666) + SendData(0x66); // 18-bit color RGB666 DelayMs(10); @@ -190,4 +192,4 @@ public void SetRotation(RotationType rotation) UpdateBuffer(); } } -} \ No newline at end of file +} diff --git a/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Driver/TftSpiBase.cs b/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Driver/TftSpiBase.cs index efd598bd2e..b550db2b87 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Driver/TftSpiBase.cs +++ b/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Driver/TftSpiBase.cs @@ -46,7 +46,7 @@ public abstract partial class TftSpiBase : IPixelDisplay, ISpiPeripheral, IDispo /// /// The default SPI bus speed for the device /// - public virtual Frequency DefaultSpiBusSpeed => new Frequency(12000, Frequency.UnitType.Kilohertz); + public virtual Frequency DefaultSpiBusSpeed => new(12000, Frequency.UnitType.Kilohertz); /// /// The SPI bus speed for the device @@ -223,7 +223,7 @@ public virtual void SetColorMode(ColorMode colorMode) if (imageBuffer.ColorMode != colorMode) { - CreateBuffer(colorMode, Width, Height); + CreateBuffer(colorMode, nativeWidth, nativeHeight); Initialize(); } } @@ -256,7 +256,10 @@ protected void CreateBuffer(ColorMode colorMode, int width, int height) { imageBuffer = new BufferRgb888(width, height); } - + else if (colorMode == ColorMode.Format18bppRgb666) + { + imageBuffer = new BufferRgb666(width, height); + } else if (colorMode == ColorMode.Format16bppRgb565) { imageBuffer = new BufferRgb565(width, height); @@ -420,6 +423,7 @@ public void Show(int left, int top, int right, int bottom) { if (PixelBuffer.ColorMode != ColorMode.Format12bppRgb444 && PixelBuffer.ColorMode != ColorMode.Format16bppRgb565 && + PixelBuffer.ColorMode != ColorMode.Format18bppRgb666 && PixelBuffer.ColorMode != ColorMode.Format24bppRgb888) { //should cover all of these displays but just in case @@ -444,16 +448,23 @@ public void Show(int left, int top, int right, int bottom) } } + int bytesPerPixel = PixelBuffer.BitDepth / 8; + + if (PixelBuffer.ColorMode == ColorMode.Format18bppRgb666) + { + bytesPerPixel = 3; + } + SetAddressWindow(left, top, right - 1, bottom - 1); - var len = (right - left) * PixelBuffer.BitDepth / 8; + var len = (right - left) * bytesPerPixel; dataCommandPort.State = Data; int sourceIndex; for (int y = top; y < bottom; y++) { - sourceIndex = ((y * Width) + left) * PixelBuffer.BitDepth / 8; + sourceIndex = (y * Width + left) * bytesPerPixel; spiDisplay.Bus.Exchange( chipSelectPort, diff --git a/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/Gc9a01_Sample/Gc9a01_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/Gc9a01_Sample/Gc9a01_Sample.csproj index fa4e552f39..415caffd46 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/Gc9a01_Sample/Gc9a01_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/Gc9a01_Sample/Gc9a01_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/Hx8357b_Sample/Hx8357b_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/Hx8357b_Sample/Hx8357b_Sample.csproj index fa4e552f39..415caffd46 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/Hx8357b_Sample/Hx8357b_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/Hx8357b_Sample/Hx8357b_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/Hx8357d_Sample/Hx8357d_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/Hx8357d_Sample/Hx8357d_Sample.csproj index fa4e552f39..415caffd46 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/Hx8357d_Sample/Hx8357d_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/Hx8357d_Sample/Hx8357d_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/Ili9163_Sample/Ili9163_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/Ili9163_Sample/Ili9163_Sample.csproj index fa4e552f39..415caffd46 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/Ili9163_Sample/Ili9163_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/Ili9163_Sample/Ili9163_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/Ili9341_Jpg_Sample/Ili9341_Jpg_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/Ili9341_Jpg_Sample/Ili9341_Jpg_Sample.csproj index 54c3e2432d..270807d0d2 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/Ili9341_Jpg_Sample/Ili9341_Jpg_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/Ili9341_Jpg_Sample/Ili9341_Jpg_Sample.csproj @@ -13,8 +13,8 @@ - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/Ili9341_Jpg_Sample/MeadowApp.cs b/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/Ili9341_Jpg_Sample/MeadowApp.cs index b7c9fba4e9..53e8fc3d5b 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/Ili9341_Jpg_Sample/MeadowApp.cs +++ b/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/Ili9341_Jpg_Sample/MeadowApp.cs @@ -1,6 +1,5 @@ using Meadow; using Meadow.Devices; -using Meadow.Foundation; using Meadow.Foundation.Displays; using Meadow.Foundation.Graphics; using Meadow.Foundation.Graphics.Buffers; diff --git a/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/Ili9341_Sample/Ili9341_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/Ili9341_Sample/Ili9341_Sample.csproj index fa4e552f39..415caffd46 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/Ili9341_Sample/Ili9341_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/Ili9341_Sample/Ili9341_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/Ili9481_Sample/Ili9481_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/Ili9481_Sample/Ili9481_Sample.csproj index fa4e552f39..415caffd46 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/Ili9481_Sample/Ili9481_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/Ili9481_Sample/Ili9481_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/Ili9486_Sample/Ili9486_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/Ili9486_Sample/Ili9486_Sample.csproj index fa4e552f39..415caffd46 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/Ili9486_Sample/Ili9486_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/Ili9486_Sample/Ili9486_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/Ili9488_Sample/Ili9488_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/Ili9488_Sample/Ili9488_Sample.csproj index fa4e552f39..415caffd46 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/Ili9488_Sample/Ili9488_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/Ili9488_Sample/Ili9488_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/Rm68140_Sample/Rm68140_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/Rm68140_Sample/Rm68140_Sample.csproj index fa4e552f39..415caffd46 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/Rm68140_Sample/Rm68140_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/Rm68140_Sample/Rm68140_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/S6D02A1_Sample/S6D02A1_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/S6D02A1_Sample/S6D02A1_Sample.csproj index fa4e552f39..415caffd46 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/S6D02A1_Sample/S6D02A1_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/S6D02A1_Sample/S6D02A1_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/ST7789_Sample/ST7789_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/ST7789_Sample/ST7789_Sample.csproj index fa4e552f39..415caffd46 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/ST7789_Sample/ST7789_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/ST7789_Sample/ST7789_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/Ssd1331_Sample/Ssd1331_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/Ssd1331_Sample/Ssd1331_Sample.csproj index fa4e552f39..415caffd46 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/Ssd1331_Sample/Ssd1331_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/Ssd1331_Sample/Ssd1331_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/Ssd1351_Sample/Ssd1351_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/Ssd1351_Sample/Ssd1351_Sample.csproj index fa4e552f39..415caffd46 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/Ssd1351_Sample/Ssd1351_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/Ssd1351_Sample/Ssd1351_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/St7735_Sample/St7735_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/St7735_Sample/St7735_Sample.csproj index fa4e552f39..415caffd46 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/St7735_Sample/St7735_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/St7735_Sample/St7735_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/St7796s_Sample/St7796s_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/St7796s_Sample/St7796s_Sample.csproj index fa4e552f39..415caffd46 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/St7796s_Sample/St7796s_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/St7796s_Sample/St7796s_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Displays.Tm1637/Driver/Displays.Tm1637.csproj b/Source/Meadow.Foundation.Peripherals/Displays.Tm1637/Driver/Displays.Tm1637.csproj index 4c4921390c..4b283b7517 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.Tm1637/Driver/Displays.Tm1637.csproj +++ b/Source/Meadow.Foundation.Peripherals/Displays.Tm1637/Driver/Displays.Tm1637.csproj @@ -22,6 +22,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/Displays.Tm1637/Samples/Tm1637_Sample/Tm1637_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Displays.Tm1637/Samples/Tm1637_Sample/Tm1637_Sample.csproj index c78f278e2c..636e9416eb 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.Tm1637/Samples/Tm1637_Sample/Tm1637_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Displays.Tm1637/Samples/Tm1637_Sample/Tm1637_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Displays.Uc1609c/Driver/Displays.Uc1609c.csproj b/Source/Meadow.Foundation.Peripherals/Displays.Uc1609c/Driver/Displays.Uc1609c.csproj index 2c64fbfd05..fe21881534 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.Uc1609c/Driver/Displays.Uc1609c.csproj +++ b/Source/Meadow.Foundation.Peripherals/Displays.Uc1609c/Driver/Displays.Uc1609c.csproj @@ -22,6 +22,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/Displays.Uc1609c/Driver/Uc1609c.cs b/Source/Meadow.Foundation.Peripherals/Displays.Uc1609c/Driver/Uc1609c.cs index 86fd81b0f1..d7672a8b77 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.Uc1609c/Driver/Uc1609c.cs +++ b/Source/Meadow.Foundation.Peripherals/Displays.Uc1609c/Driver/Uc1609c.cs @@ -111,6 +111,7 @@ public Uc1609c(ISpiBus spiBus, IDigitalOutputPort resetPort, int width = 128, int height = 64) { + this.chipSelectPort = chipSelectPort; this.dataCommandPort = dataCommandPort; this.resetPort = resetPort; diff --git a/Source/Meadow.Foundation.Peripherals/Displays.Uc1609c/Samples/Uc1609c_Sample/Uc1609c_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Displays.Uc1609c/Samples/Uc1609c_Sample/Uc1609c_Sample.csproj index d4cec0abc3..71e593799f 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.Uc1609c/Samples/Uc1609c_Sample/Uc1609c_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Displays.Uc1609c/Samples/Uc1609c_Sample/Uc1609c_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Displays.WinForms/Driver/Displays.WinForms.csproj b/Source/Meadow.Foundation.Peripherals/Displays.WinForms/Driver/Displays.WinForms.csproj index 91eed0deff..fe80d3c956 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.WinForms/Driver/Displays.WinForms.csproj +++ b/Source/Meadow.Foundation.Peripherals/Displays.WinForms/Driver/Displays.WinForms.csproj @@ -33,6 +33,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/Displays.WinForms/Samples/WinForms_Sample/WinForms_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Displays.WinForms/Samples/WinForms_Sample/WinForms_Sample.csproj index fbbd91b549..bb020cc28f 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.WinForms/Samples/WinForms_Sample/WinForms_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Displays.WinForms/Samples/WinForms_Sample/WinForms_Sample.csproj @@ -7,7 +7,7 @@ 10.0 - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Displays.ePaper/Driver/Displays.ePaper.csproj b/Source/Meadow.Foundation.Peripherals/Displays.ePaper/Driver/Displays.ePaper.csproj index 8b803cc889..70900600c3 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.ePaper/Driver/Displays.ePaper.csproj +++ b/Source/Meadow.Foundation.Peripherals/Displays.ePaper/Driver/Displays.ePaper.csproj @@ -22,6 +22,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/Displays.ePaper/Samples/IL0373_Sample/IL0373_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Displays.ePaper/Samples/IL0373_Sample/IL0373_Sample.csproj index cc1140e32e..ce34a2fee2 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.ePaper/Samples/IL0373_Sample/IL0373_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Displays.ePaper/Samples/IL0373_Sample/IL0373_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Displays.ePaper/Samples/IL0376F_Sample/IL0376F_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Displays.ePaper/Samples/IL0376F_Sample/IL0376F_Sample.csproj index cc1140e32e..ce34a2fee2 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.ePaper/Samples/IL0376F_Sample/IL0376F_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Displays.ePaper/Samples/IL0376F_Sample/IL0376F_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Displays.ePaper/Samples/IL0398_Sample/IL0398_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Displays.ePaper/Samples/IL0398_Sample/IL0398_Sample.csproj index cc1140e32e..ce34a2fee2 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.ePaper/Samples/IL0398_Sample/IL0398_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Displays.ePaper/Samples/IL0398_Sample/IL0398_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Displays.ePaper/Samples/IL3897_Sample/IL3897_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Displays.ePaper/Samples/IL3897_Sample/IL3897_Sample.csproj index cc1140e32e..ce34a2fee2 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.ePaper/Samples/IL3897_Sample/IL3897_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Displays.ePaper/Samples/IL3897_Sample/IL3897_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Displays.ePaper/Samples/IL91874V03_Sample/IL91874V03_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Displays.ePaper/Samples/IL91874V03_Sample/IL91874V03_Sample.csproj index cc1140e32e..ce34a2fee2 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.ePaper/Samples/IL91874V03_Sample/IL91874V03_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Displays.ePaper/Samples/IL91874V03_Sample/IL91874V03_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Displays.ePaper/Samples/IL91874_Sample/IL91874_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Displays.ePaper/Samples/IL91874_Sample/IL91874_Sample.csproj index cc1140e32e..ce34a2fee2 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.ePaper/Samples/IL91874_Sample/IL91874_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Displays.ePaper/Samples/IL91874_Sample/IL91874_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Displays.ePaper/Samples/SSD1608_Sample/SSD1608_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Displays.ePaper/Samples/SSD1608_Sample/SSD1608_Sample.csproj index cc1140e32e..ce34a2fee2 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.ePaper/Samples/SSD1608_Sample/SSD1608_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Displays.ePaper/Samples/SSD1608_Sample/SSD1608_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Displays.ePaper/Samples/SSD1680_Sample/SSD1680_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Displays.ePaper/Samples/SSD1680_Sample/SSD1680_Sample.csproj index cc1140e32e..ce34a2fee2 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.ePaper/Samples/SSD1680_Sample/SSD1680_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Displays.ePaper/Samples/SSD1680_Sample/SSD1680_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Displays.ePaper/Samples/SSD1681_Sample/SSD1681_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Displays.ePaper/Samples/SSD1681_Sample/SSD1681_Sample.csproj index cc1140e32e..ce34a2fee2 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.ePaper/Samples/SSD1681_Sample/SSD1681_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Displays.ePaper/Samples/SSD1681_Sample/SSD1681_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Displays.ePaper/Samples/UC8151C_Sample/UC8151C_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Displays.ePaper/Samples/UC8151C_Sample/UC8151C_Sample.csproj index cc1140e32e..ce34a2fee2 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.ePaper/Samples/UC8151C_Sample/UC8151C_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Displays.ePaper/Samples/UC8151C_Sample/UC8151C_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Displays.ePaperWaveShare/Driver/Displays.ePaperWaveShare.csproj b/Source/Meadow.Foundation.Peripherals/Displays.ePaperWaveShare/Driver/Displays.ePaperWaveShare.csproj index 3fa5022bdc..b1680de59f 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.ePaperWaveShare/Driver/Displays.ePaperWaveShare.csproj +++ b/Source/Meadow.Foundation.Peripherals/Displays.ePaperWaveShare/Driver/Displays.ePaperWaveShare.csproj @@ -22,6 +22,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/Displays.ePaperWaveShare/Samples/Epd5in65f_Sample/Epd5in65f_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Displays.ePaperWaveShare/Samples/Epd5in65f_Sample/Epd5in65f_Sample.csproj index 5737184f77..8e41df3840 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.ePaperWaveShare/Samples/Epd5in65f_Sample/Epd5in65f_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Displays.ePaperWaveShare/Samples/Epd5in65f_Sample/Epd5in65f_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Displays.ePaperWaveShare/Samples/EpdColor_Sample/EpdColor_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Displays.ePaperWaveShare/Samples/EpdColor_Sample/EpdColor_Sample.csproj index 5737184f77..8e41df3840 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.ePaperWaveShare/Samples/EpdColor_Sample/EpdColor_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Displays.ePaperWaveShare/Samples/EpdColor_Sample/EpdColor_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Displays.ePaperWaveShare/Samples/EpdMonochrome_Sample/EpdMonochrome_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Displays.ePaperWaveShare/Samples/EpdMonochrome_Sample/EpdMonochrome_Sample.csproj index 5737184f77..8e41df3840 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.ePaperWaveShare/Samples/EpdMonochrome_Sample/EpdMonochrome_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Displays.ePaperWaveShare/Samples/EpdMonochrome_Sample/EpdMonochrome_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/ICs.ADC.Ads1x15/Driver/ICs.ADC.Ads1x15.csproj b/Source/Meadow.Foundation.Peripherals/ICs.ADC.Ads1x15/Driver/ICs.ADC.Ads1x15.csproj index 1c440e4be1..b45edc9668 100644 --- a/Source/Meadow.Foundation.Peripherals/ICs.ADC.Ads1x15/Driver/ICs.ADC.Ads1x15.csproj +++ b/Source/Meadow.Foundation.Peripherals/ICs.ADC.Ads1x15/Driver/ICs.ADC.Ads1x15.csproj @@ -22,6 +22,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/ICs.ADC.Ads1x15/Samples/Ads1015_Sample/Ads1015_Sample.csproj b/Source/Meadow.Foundation.Peripherals/ICs.ADC.Ads1x15/Samples/Ads1015_Sample/Ads1015_Sample.csproj index eb40de29e6..75a781c58e 100644 --- a/Source/Meadow.Foundation.Peripherals/ICs.ADC.Ads1x15/Samples/Ads1015_Sample/Ads1015_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/ICs.ADC.Ads1x15/Samples/Ads1015_Sample/Ads1015_Sample.csproj @@ -6,7 +6,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/ICs.ADC.Ads1x15/Samples/Ads1115_Sample/Ads1115_Sample.csproj b/Source/Meadow.Foundation.Peripherals/ICs.ADC.Ads1x15/Samples/Ads1115_Sample/Ads1115_Sample.csproj index eb40de29e6..75a781c58e 100644 --- a/Source/Meadow.Foundation.Peripherals/ICs.ADC.Ads1x15/Samples/Ads1115_Sample/Ads1115_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/ICs.ADC.Ads1x15/Samples/Ads1115_Sample/Ads1115_Sample.csproj @@ -6,7 +6,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/ICs.ADCs.Mcp3xxx/Driver/ICs.ADC.Mcp3xxx.csproj b/Source/Meadow.Foundation.Peripherals/ICs.ADCs.Mcp3xxx/Driver/ICs.ADC.Mcp3xxx.csproj index cd87aee1a7..f1a5fe3eff 100644 --- a/Source/Meadow.Foundation.Peripherals/ICs.ADCs.Mcp3xxx/Driver/ICs.ADC.Mcp3xxx.csproj +++ b/Source/Meadow.Foundation.Peripherals/ICs.ADCs.Mcp3xxx/Driver/ICs.ADC.Mcp3xxx.csproj @@ -22,6 +22,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/ICs.ADCs.Mcp3xxx/Driver/Mcp3xxx.cs b/Source/Meadow.Foundation.Peripherals/ICs.ADCs.Mcp3xxx/Driver/Mcp3xxx.cs index 5ea1343599..46a9e322dd 100644 --- a/Source/Meadow.Foundation.Peripherals/ICs.ADCs.Mcp3xxx/Driver/Mcp3xxx.cs +++ b/Source/Meadow.Foundation.Peripherals/ICs.ADCs.Mcp3xxx/Driver/Mcp3xxx.cs @@ -38,7 +38,7 @@ public abstract partial class Mcp3xxx : IAnalogInputController, ISpiPeripheral, /// /// The default reference voltage for the device /// - public Voltage DefaultReferenceVoltage => 3.3.Volts(); + public Voltage DefaultReferenceVoltage => new Voltage(3.3); /// /// The SPI bus speed for the device diff --git a/Source/Meadow.Foundation.Peripherals/ICs.ADCs.Mcp3xxx/Samples/Mcp3001_Sample/Mcp3001_Sample.csproj b/Source/Meadow.Foundation.Peripherals/ICs.ADCs.Mcp3xxx/Samples/Mcp3001_Sample/Mcp3001_Sample.csproj index b37e67dbc6..27e094a1d1 100644 --- a/Source/Meadow.Foundation.Peripherals/ICs.ADCs.Mcp3xxx/Samples/Mcp3001_Sample/Mcp3001_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/ICs.ADCs.Mcp3xxx/Samples/Mcp3001_Sample/Mcp3001_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/ICs.ADCs.Mcp3xxx/Samples/Mcp3002_Sample/Mcp3002_Sample.csproj b/Source/Meadow.Foundation.Peripherals/ICs.ADCs.Mcp3xxx/Samples/Mcp3002_Sample/Mcp3002_Sample.csproj index b37e67dbc6..27e094a1d1 100644 --- a/Source/Meadow.Foundation.Peripherals/ICs.ADCs.Mcp3xxx/Samples/Mcp3002_Sample/Mcp3002_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/ICs.ADCs.Mcp3xxx/Samples/Mcp3002_Sample/Mcp3002_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/ICs.ADCs.Mcp3xxx/Samples/Mcp3004_Sample/Mcp3004_Sample.csproj b/Source/Meadow.Foundation.Peripherals/ICs.ADCs.Mcp3xxx/Samples/Mcp3004_Sample/Mcp3004_Sample.csproj index b37e67dbc6..27e094a1d1 100644 --- a/Source/Meadow.Foundation.Peripherals/ICs.ADCs.Mcp3xxx/Samples/Mcp3004_Sample/Mcp3004_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/ICs.ADCs.Mcp3xxx/Samples/Mcp3004_Sample/Mcp3004_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/ICs.ADCs.Mcp3xxx/Samples/Mcp3008_Sample/Mcp3008_Sample.csproj b/Source/Meadow.Foundation.Peripherals/ICs.ADCs.Mcp3xxx/Samples/Mcp3008_Sample/Mcp3008_Sample.csproj index b37e67dbc6..27e094a1d1 100644 --- a/Source/Meadow.Foundation.Peripherals/ICs.ADCs.Mcp3xxx/Samples/Mcp3008_Sample/Mcp3008_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/ICs.ADCs.Mcp3xxx/Samples/Mcp3008_Sample/Mcp3008_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/ICs.ADCs.Mcp3xxx/Samples/Mcp3201_Sample/Mcp3201_Sample.csproj b/Source/Meadow.Foundation.Peripherals/ICs.ADCs.Mcp3xxx/Samples/Mcp3201_Sample/Mcp3201_Sample.csproj index b37e67dbc6..27e094a1d1 100644 --- a/Source/Meadow.Foundation.Peripherals/ICs.ADCs.Mcp3xxx/Samples/Mcp3201_Sample/Mcp3201_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/ICs.ADCs.Mcp3xxx/Samples/Mcp3201_Sample/Mcp3201_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/ICs.ADCs.Mcp3xxx/Samples/Mcp3202_Sample/Mcp3202_Sample.csproj b/Source/Meadow.Foundation.Peripherals/ICs.ADCs.Mcp3xxx/Samples/Mcp3202_Sample/Mcp3202_Sample.csproj index b37e67dbc6..27e094a1d1 100644 --- a/Source/Meadow.Foundation.Peripherals/ICs.ADCs.Mcp3xxx/Samples/Mcp3202_Sample/Mcp3202_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/ICs.ADCs.Mcp3xxx/Samples/Mcp3202_Sample/Mcp3202_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/ICs.ADCs.Mcp3xxx/Samples/Mcp3204_Sample/Mcp3204_Sample.csproj b/Source/Meadow.Foundation.Peripherals/ICs.ADCs.Mcp3xxx/Samples/Mcp3204_Sample/Mcp3204_Sample.csproj index b37e67dbc6..27e094a1d1 100644 --- a/Source/Meadow.Foundation.Peripherals/ICs.ADCs.Mcp3xxx/Samples/Mcp3204_Sample/Mcp3204_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/ICs.ADCs.Mcp3xxx/Samples/Mcp3204_Sample/Mcp3204_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/ICs.ADCs.Mcp3xxx/Samples/Mcp3208_Sample/Mcp3208_Sample.csproj b/Source/Meadow.Foundation.Peripherals/ICs.ADCs.Mcp3xxx/Samples/Mcp3208_Sample/Mcp3208_Sample.csproj index b37e67dbc6..27e094a1d1 100644 --- a/Source/Meadow.Foundation.Peripherals/ICs.ADCs.Mcp3xxx/Samples/Mcp3208_Sample/Mcp3208_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/ICs.ADCs.Mcp3xxx/Samples/Mcp3208_Sample/Mcp3208_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/ICs.DAC.Mcp4728/Datasheet/MCP4728 Quad DAC.pdf b/Source/Meadow.Foundation.Peripherals/ICs.DAC.Mcp4728/Datasheet/MCP4728 Quad DAC.pdf new file mode 100644 index 0000000000..5af2512da4 Binary files /dev/null and b/Source/Meadow.Foundation.Peripherals/ICs.DAC.Mcp4728/Datasheet/MCP4728 Quad DAC.pdf differ diff --git a/Source/Meadow.Foundation.Peripherals/ICs.DAC.Mcp4728/Driver/ICs.DAC.Mcp4728.csproj b/Source/Meadow.Foundation.Peripherals/ICs.DAC.Mcp4728/Driver/ICs.DAC.Mcp4728.csproj new file mode 100644 index 0000000000..5c9fdcb5f6 --- /dev/null +++ b/Source/Meadow.Foundation.Peripherals/ICs.DAC.Mcp4728/Driver/ICs.DAC.Mcp4728.csproj @@ -0,0 +1,29 @@ + + + 1.8.0 + Readme.md + Apache-2.0 + true + Wilderness Labs, Inc + netstandard2.1 + Library + Mcp4728 + Wilderness Labs, Inc + http://developer.wildernesslabs.co/Meadow/Meadow.Foundation/ + Meadow.Foundation.ICs.DAC.Mcp4728 + icon.png + https://github.com/WildernessLabs/Meadow.Foundation + Meadow.Foundation,DAC,analog,digital,converter,Microchip,MCP4728 + true + Microchip MCP4728 I2C digital to analog converter + enable + 10.0 + + + + + + + + + diff --git a/Source/Meadow.Foundation.Peripherals/ICs.DAC.Mcp4728/Driver/Mcp4728.AnalogOutputPort.cs b/Source/Meadow.Foundation.Peripherals/ICs.DAC.Mcp4728/Driver/Mcp4728.AnalogOutputPort.cs new file mode 100644 index 0000000000..aeaba37cde --- /dev/null +++ b/Source/Meadow.Foundation.Peripherals/ICs.DAC.Mcp4728/Driver/Mcp4728.AnalogOutputPort.cs @@ -0,0 +1,141 @@ +using Meadow.Hardware; +using System; +using System.Threading.Tasks; +using Meadow.Units; + +namespace Meadow.Foundation.ICs.DAC; + +public partial class Mcp4728 +{ + /// + /// Enumeration for DAC Channel Names + /// + public enum DACChannel : byte + { + /// A Output Channel + ChannelA = 0, + /// B Output Channel + ChannelB = 1, + /// C Output Channel + ChannelC = 2, + /// D Output Channel + ChannelD = 3 + } + + /// + /// Enumeration for Channel settings + /// + [Flags] + public enum ChannelSettings : byte + { + /// External VRef + ExternalVRef = 0x00, + /// Internal VRef 2.048V + InternalVRef = 0x80, + /// Normal Operation + ModeNormal = 0x00, + /// PowerDown, 1kOhm load + ModePowerDown1k = 0x20, + /// PowerDown, 100kOhm load + ModePowerDown100k = 0x40, + /// PowerDown, 500kOhm load + ModePowerDown500k = 0x60, + /// 1x gain + OutputGain1x = 0x00, + /// 2x gain, only applies for Internal VRef + OutputGain2x = 0x10, + } + + /// + /// Represents an analog output port for interfacing with the Mcp4728 DAC. + /// + public class AnalogOutputPort : IAnalogOutputPort + { + private readonly Mcp4728 _controller; + private readonly DACChannel _channel; + + /// + public IAnalogChannelInfo Channel { get; } + + /// + public IPin Pin { get; } + + /// + /// Maximum Output value that can be used with this + /// + public uint MaxOutputValue => (uint)(1 << Channel.Precision) - 1; + + /// + /// Voltage reference of the + /// + public Units.Voltage VoltageReference { get; internal set; } + + /// + /// Voltage resolution of the + /// + public Units.Voltage VoltageResolution { get; internal set; } + + /// + /// Gets or sets the Channel Settings for the port + /// + public ChannelSettings Settings { get; set; } + + /// + /// Gets or sets whether the port has a buffered value (Defers update until commanded) + /// + public bool Buffered { get; set; } + + internal AnalogOutputPort(IPin pin, IAnalogChannelInfo channelDefinition, Mcp4728 controller, DACChannel hardwareChannel) + { + _controller = controller; + _channel = hardwareChannel; + + Channel = channelDefinition; + Pin = pin; + + Buffered = false; + } + + /// + public void Dispose() + { + // nothing to do + } + + /// + public Task GenerateOutput(uint digitalValue) + { + if (digitalValue > MaxOutputValue) + { + throw new ArgumentOutOfRangeException($"Port supports a maximum of {Channel.Precision} bits"); + } + + _controller.WriteOutput((ushort)digitalValue, _channel, Settings, Buffered); + + return Task.CompletedTask; + } + + /// + /// Instructs the IAnalogOutputPort to generate an analog output signal corresponding to the provided voltage value + /// + /// The target voltage output, which will be automatically adjusted to the nearest selectable value. + public Task GenerateOutput(Voltage voltageValue) + { + var digitalValue = Math.Round(voltageValue.Volts / VoltageResolution.Volts); + if (digitalValue < 0) + throw new ArgumentOutOfRangeException(nameof(voltageValue), "Port does not support negative output voltages."); + if (digitalValue > MaxOutputValue) + throw new ArgumentOutOfRangeException(nameof(voltageValue), voltageValue.Volts, "Port does not support requested output voltage."); + + return GenerateOutput((uint)digitalValue); + } + + /// + /// Turns off the output, setting the pin to high impedance + /// + public void HighZ() + { + _controller.WriteOutput(0, _channel, Settings | ChannelSettings.ModePowerDown100k, false); + } + } +} \ No newline at end of file diff --git a/Source/Meadow.Foundation.Peripherals/ICs.DAC.Mcp4728/Driver/Mcp4728.cs b/Source/Meadow.Foundation.Peripherals/ICs.DAC.Mcp4728/Driver/Mcp4728.cs new file mode 100644 index 0000000000..bac83651ba --- /dev/null +++ b/Source/Meadow.Foundation.Peripherals/ICs.DAC.Mcp4728/Driver/Mcp4728.cs @@ -0,0 +1,237 @@ +using System; +using Meadow.Hardware; +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using Meadow.Units; + +namespace Meadow.Foundation.ICs.DAC; + +/// +/// This class represents an MCP4728 quad digital-to-analog converter (DAC) and implements +/// the II2CPeripheral and IAnalogOutputController interfaces. +/// +public partial class Mcp4728 : II2cPeripheral, IAnalogOutputController +{ + private readonly II2cBus i2cBus; + private readonly byte i2cAddress; + + /// + /// The default I2C address for the peripheral + /// + public byte DefaultI2cAddress => (byte)Addresses.Default; + + /// + /// Default I2C Bus Speed to use for communication. + /// + public static I2cBusSpeed DefaultBusSpeed => I2cBusSpeed.Fast; + + /// + /// Initializes a new instance of the Mcp4728 class. + /// + /// The I2C bus. + /// The I2C bus address of the device. + public Mcp4728(II2cBus bus, byte address = (byte)Addresses.Default) + { + i2cBus = bus; + i2cAddress = address; + Pins = new PinDefinitions(this); + } + + /// + /// Valid I2C addresses for the device + /// + public enum Addresses : byte + { + /// Bus address 0x60 + Address0 = 0x60, + /// Bus address 0x61, which requires programming the address bits on the IC. + Address1 = 0x61, + /// Bus address 0x62, which requires programming the address bits on the IC. + Address2 = 0x62, + /// Bus address 0x63, which requires programming the address bits on the IC. + Address3 = 0x63, + /// Bus address 0x64, which requires programming the address bits on the IC. + Address4 = 0x64, + /// Bus address 0x65, which requires programming the address bits on the IC. + Address5 = 0x65, + /// Bus address 0x66, which requires programming the address bits on the IC. + Address6 = 0x66, + /// Bus address 0x67, which requires programming the address bits on the IC. + Address7 = 0x67, + /// Bus address by default + Default = Address0, + } + + /// + /// The pins + /// + public PinDefinitions Pins { get; } + + /// + /// Represents the pin definitions for the MCP4728 DAC. + /// + public class PinDefinitions : IPinDefinitions + { + /// + /// Analog-digital converter precision + /// + public virtual byte DACPrecisionBits => 12; + + /// + /// Collection of pins + /// + public IList AllPins { get; } = new List(); + + /// + /// The pin controller + /// + public IPinController? Controller { get; set; } + + /// + /// Create a new PinDefinitions object + /// + public PinDefinitions(Mcp4728 mcp) + { + Controller = mcp; + } + + /// + /// Channel A pin + /// + public IPin ChannelA => new Pin( + Controller, + "A", + DACChannel.ChannelA, + new List { + new AnalogChannelInfo("A", DACPrecisionBits, false, true), + } + ); + + /// + /// Channel B pin + /// + public IPin ChannelB => new Pin( + Controller, + "B", + DACChannel.ChannelB, + new List { + new AnalogChannelInfo("B", DACPrecisionBits, false, true), + } + ); + + /// + /// Channel C pin + /// + public IPin ChannelC => new Pin( + Controller, + "C", + DACChannel.ChannelC, + new List { + new AnalogChannelInfo("C", DACPrecisionBits, false, true), + } + ); + + /// + /// Channel D pin + /// + public IPin ChannelD => new Pin( + Controller, + "D", + DACChannel.ChannelD, + new List { + new AnalogChannelInfo("D", DACPrecisionBits, false, true), + } + ); + + /// + /// Get Enumerator + /// + public IEnumerator GetEnumerator() => AllPins.GetEnumerator(); + + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); + } + + private enum Commands : byte + { + MultiWrite = 0x40, + SequentialWrite = 0x50, + /// Set bits 2..1 to select channel. Set bit 0 to not update outputs immediately. + SingleWrite = 0x58, + } + + /// + /// Write output to chip + /// + /// analog value + /// channel number (enumeration) + /// combination of channel settings flags + /// true to hold the value until 'update output' command (LDAC pin low) + internal void WriteOutput(ushort value12Bit, DACChannel channel, ChannelSettings settings, bool bufferedInput) + { + Span data = stackalloc byte[] { + (byte)((byte)Commands.SingleWrite | ((byte)channel << 1) | (byte)(bufferedInput ? 0x01 : 0x00)), + (byte)(((value12Bit & 0xff00) >> 8) | (byte)settings), + (byte)(value12Bit & 0xff) + }; + + i2cBus.Write(i2cAddress, data); + } + + /// + public IAnalogOutputPort CreateAnalogOutputPort(IPin pin) + { + return CreateAnalogOutputPort(pin, false, false, false); + } + + /// + /// Creates an IAnalogOutputPort on the specified pin, with the specified settings. + /// + /// The pin on which to create the port + /// use the internal 2.048V reference for this analog output. + /// if using , also apply a 2x gain to the output. + /// if true, changes to the output are not applied until the LDAC pin is pulled low. + /// if not using , providing the external Vcc voltage will allow to be correctly calculated. If not provided, 3.3V is assumed. + public IAnalogOutputPort CreateAnalogOutputPort(IPin pin, bool internalVRef, bool gain2x, bool buffered = false, Voltage? vcc = default) + { + if (pin.Controller == null || !pin.Controller.Equals(this)) + { + throw new ArgumentException("The provided pin must be on this controller"); + } + var channelInfo = pin.SupportedChannels?.First(c => c is IAnalogChannelInfo) as IAnalogChannelInfo + ?? throw new ArgumentException("Pin does not support analog output"); + + ChannelSettings settings; + Voltage voltageResolution, voltageReference; + switch (internalVRef, gain2x) + { + case (internalVRef: true, gain2x: true): + settings = ChannelSettings.InternalVRef | ChannelSettings.OutputGain2x; + voltageReference = 2.048.Volts(); + voltageResolution = new Voltage(1, Voltage.UnitType.Millivolts); + break; + case (internalVRef: true, gain2x: false): + settings = ChannelSettings.InternalVRef; + voltageReference = 2.048.Volts(); + voltageResolution = new Voltage(0.5, Voltage.UnitType.Millivolts); + break; + default: + settings = ChannelSettings.ExternalVRef; + voltageReference = vcc ?? 3.3.Volts(); + voltageResolution = (voltageReference) / (1 << channelInfo.Precision); + break; + } + + return new AnalogOutputPort( + pin, + channelInfo, + this, + (DACChannel)(pin.Key)) + { + Buffered = buffered, + Settings = settings, + VoltageReference = voltageReference, + VoltageResolution = voltageResolution, + }; + } +} \ No newline at end of file diff --git a/Source/Meadow.Foundation.Peripherals/ICs.DAC.Mcp4728/Driver/Readme.md b/Source/Meadow.Foundation.Peripherals/ICs.DAC.Mcp4728/Driver/Readme.md new file mode 100644 index 0000000000..302276055f --- /dev/null +++ b/Source/Meadow.Foundation.Peripherals/ICs.DAC.Mcp4728/Driver/Readme.md @@ -0,0 +1,44 @@ +# Meadow.Foundation.ICs.DAC.Mcp4728 + +**Microchip MCP4728 I2C digital to analog converter** + +The **Mcp4728** library is included in the **Meadow.Foundation.ICs.DAC.Mcp4728** nuget package and is designed for the [Wilderness Labs](www.wildernesslabs.co) Meadow .NET IoT platform. + +This driver is part of the [Meadow.Foundation](https://developer.wildernesslabs.co/Meadow/Meadow.Foundation/) peripherals library, an open-source repository of drivers and libraries that streamline and simplify adding hardware to your C# .NET Meadow IoT applications. + +For more information on developing for Meadow, visit [developer.wildernesslabs.co](http://developer.wildernesslabs.co/). + +To view all Wilderness Labs open-source projects, including samples, visit [github.com/wildernesslabs](https://github.com/wildernesslabs/). + +## Installation + +You can install the library from within Visual studio using the the NuGet Package Manager or from the command line using the .NET CLI: + +`dotnet add package Meadow.Foundation.ICs.DAC.Mcp4728` +## How to Contribute + +- **Found a bug?** [Report an issue](https://github.com/WildernessLabs/Meadow_Issues/issues) +- Have a **feature idea or driver request?** [Open a new feature request](https://github.com/WildernessLabs/Meadow_Issues/issues) +- Want to **contribute code?** Fork the [Meadow.Foundation](https://github.com/WildernessLabs/Meadow.Foundation) repository and submit a pull request against the `develop` branch + + +## Need Help? + +If you have questions or need assistance, please join the Wilderness Labs [community on Slack](http://slackinvite.wildernesslabs.co/). +## About Meadow + +Meadow is a complete, IoT platform with defense-grade security that runs full .NET applications on embeddable microcontrollers and Linux single-board computers including Raspberry Pi and NVIDIA Jetson. + +### Build + +Use the full .NET platform and tooling such as Visual Studio and plug-and-play hardware drivers to painlessly build IoT solutions. + +### Connect + +Utilize native support for WiFi, Ethernet, and Cellular connectivity to send sensor data to the Cloud and remotely control your peripherals. + +### Deploy + +Instantly deploy and manage your fleet in the cloud for OtA, health-monitoring, logs, command + control, and enterprise backend integrations. + + diff --git a/Source/Meadow.Foundation.Peripherals/ICs.DAC.Mcp4728/Sample/Mcp4728_Sample.csproj b/Source/Meadow.Foundation.Peripherals/ICs.DAC.Mcp4728/Sample/Mcp4728_Sample.csproj new file mode 100644 index 0000000000..42a57ad11e --- /dev/null +++ b/Source/Meadow.Foundation.Peripherals/ICs.DAC.Mcp4728/Sample/Mcp4728_Sample.csproj @@ -0,0 +1,20 @@ + + + netstandard2.1 + true + Library + App + + + + + + + + Always + + + Always + + + diff --git a/Source/Meadow.Foundation.Peripherals/ICs.DAC.Mcp4728/Sample/MeadowApp.cs b/Source/Meadow.Foundation.Peripherals/ICs.DAC.Mcp4728/Sample/MeadowApp.cs new file mode 100644 index 0000000000..056b720248 --- /dev/null +++ b/Source/Meadow.Foundation.Peripherals/ICs.DAC.Mcp4728/Sample/MeadowApp.cs @@ -0,0 +1,56 @@ +using System; +using Meadow; +using Meadow.Units; +using Meadow.Devices; +using System.Threading.Tasks; +using Meadow.Foundation.ICs.DAC; +using Meadow.Hardware; + +namespace MeadowApp +{ + public class MeadowApp : App + { + // + + Mcp4728 mcp4728; + Mcp4728.AnalogOutputPort analogOutputPort; + IAnalogInputPort analogInputPort; + + public override Task Initialize() + { + Resolver.Log.Debug("Initialize..."); + + var bus = Device.CreateI2cBus(I2cBusSpeed.Fast); + mcp4728 = new Mcp4728(bus); + // This example requires the VA output of the Mcp4728 to be connected to the A0 analog input on the device. + analogOutputPort = mcp4728.CreateAnalogOutputPort(mcp4728.Pins.ChannelA) as Mcp4728.AnalogOutputPort; + analogInputPort = Device.CreateAnalogInputPort(Device.Pins.A00); + + Resolver.Log.Info($"--- MCP4728 Sample App ---"); + analogOutputPort?.HighZ(); + return Task.CompletedTask; + } + + public override Task Run() + { + Resolver.Log.Debug("Run..."); + + var centerValue = analogOutputPort.MaxOutputValue / 2.0; + + // Generate a sine wave and read it back using an analog input. + for (int angle = 0; angle < 360; angle+=5) + { + var value = (uint)(centerValue + (centerValue * Math.Sin(new Angle(angle).Radians))); + analogOutputPort.GenerateOutput(value); + var expected = value * analogOutputPort.VoltageResolution.Volts; + var actual = analogInputPort.Read().Result.Volts; + Resolver.Log.Info($"Expected: {expected:N3}, Actual: {actual:N3}"); + } + + analogOutputPort.HighZ(); + return Task.CompletedTask; + } + + // + } +} \ No newline at end of file diff --git a/Source/Meadow.Foundation.Peripherals/ICs.DAC.Mcp4728/Sample/meadow.config.yaml b/Source/Meadow.Foundation.Peripherals/ICs.DAC.Mcp4728/Sample/meadow.config.yaml new file mode 100644 index 0000000000..32363cb69c --- /dev/null +++ b/Source/Meadow.Foundation.Peripherals/ICs.DAC.Mcp4728/Sample/meadow.config.yaml @@ -0,0 +1,2 @@ +MonoControl: + Options: --jit \ No newline at end of file diff --git a/Source/Meadow.Foundation.Peripherals/ICs.DAC.Mcp4728/Sample/wifi.config.yaml b/Source/Meadow.Foundation.Peripherals/ICs.DAC.Mcp4728/Sample/wifi.config.yaml new file mode 100644 index 0000000000..6c48cc4e85 --- /dev/null +++ b/Source/Meadow.Foundation.Peripherals/ICs.DAC.Mcp4728/Sample/wifi.config.yaml @@ -0,0 +1,8 @@ +# Uncomment to set the default Wi-Fi credentials. (This file will be processed into secure storage on the ESP32 and then deleted from the device.) +# To learn more about these config options, including custom application configuration settings, check out the Application Settings Configuration documentation. +# http://developer.wildernesslabs.co/Meadow/Meadow.OS/Configuration/WiFi_Configuration/ + +# # To enable automatically connecting to a default network, make sure to enable the Coprocessor > AutomaticallyStartNetwork value in meadow.config.yaml. +#Credentials: +# Ssid: YourSSID +# Password: SSIDPassword diff --git a/Source/Meadow.Foundation.Peripherals/ICs.DAC.Mcp492x/Driver/ICs.DAC.Mcp492x.csproj b/Source/Meadow.Foundation.Peripherals/ICs.DAC.Mcp492x/Driver/ICs.DAC.Mcp492x.csproj index aa1189b3cf..3568c51e22 100644 --- a/Source/Meadow.Foundation.Peripherals/ICs.DAC.Mcp492x/Driver/ICs.DAC.Mcp492x.csproj +++ b/Source/Meadow.Foundation.Peripherals/ICs.DAC.Mcp492x/Driver/ICs.DAC.Mcp492x.csproj @@ -10,7 +10,7 @@ Mcp492x Wilderness Labs, Inc http://developer.wildernesslabs.co/Meadow/Meadow.Foundation/ - Meadow.Foundation.ICs.DAC.MCP492x + Meadow.Foundation.ICs.DAC.Mcp492x icon.png https://github.com/WildernessLabs/Meadow.Foundation Meadow.Foundation,DAC,analog,digital,converter,Microchip,MCP4921,MCP4922 @@ -22,6 +22,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/ICs.DAC.Mcp492x/Driver/Mcp492x.cs b/Source/Meadow.Foundation.Peripherals/ICs.DAC.Mcp492x/Driver/Mcp492x.cs index 241440978d..e562dae49c 100644 --- a/Source/Meadow.Foundation.Peripherals/ICs.DAC.Mcp492x/Driver/Mcp492x.cs +++ b/Source/Meadow.Foundation.Peripherals/ICs.DAC.Mcp492x/Driver/Mcp492x.cs @@ -96,7 +96,7 @@ public IAnalogOutputPort CreateAnalogOutputPort(IPin pin) return CreateAnalogOutputPort(pin, Gain.Gain1x, false); } - /// + /// public IAnalogOutputPort CreateAnalogOutputPort(IPin pin, Gain gain = Gain.Gain1x, bool bufferedInput = false) { if (pin.Controller == null || !pin.Controller.Equals(this)) diff --git a/Source/Meadow.Foundation.Peripherals/ICs.DAC.Mcp492x/Driver/Readme.md b/Source/Meadow.Foundation.Peripherals/ICs.DAC.Mcp492x/Driver/Readme.md index 5e250b1462..4a7e787f71 100644 --- a/Source/Meadow.Foundation.Peripherals/ICs.DAC.Mcp492x/Driver/Readme.md +++ b/Source/Meadow.Foundation.Peripherals/ICs.DAC.Mcp492x/Driver/Readme.md @@ -1,8 +1,8 @@ -# Meadow.Foundation.ICs.DAC.MCP492x +# Meadow.Foundation.ICs.DAC.Mcp492x **Microchip MCP4921 and MCP4922 SPI digital to analog converters** -The **Mcp492x** library is included in the **Meadow.Foundation.ICs.DAC.MCP492x** nuget package and is designed for the [Wilderness Labs](www.wildernesslabs.co) Meadow .NET IoT platform. +The **Mcp492x** library is included in the **Meadow.Foundation.ICs.DAC.Mcp492x** nuget package and is designed for the [Wilderness Labs](www.wildernesslabs.co) Meadow .NET IoT platform. This driver is part of the [Meadow.Foundation](https://developer.wildernesslabs.co/Meadow/Meadow.Foundation/) peripherals library, an open-source repository of drivers and libraries that streamline and simplify adding hardware to your C# .NET Meadow IoT applications. @@ -14,7 +14,7 @@ To view all Wilderness Labs open-source projects, including samples, visit [gith You can install the library from within Visual studio using the the NuGet Package Manager or from the command line using the .NET CLI: -`dotnet add package Meadow.Foundation.ICs.DAC.MCP492x` +`dotnet add package Meadow.Foundation.ICs.DAC.Mcp492x` ## How to Contribute - **Found a bug?** [Report an issue](https://github.com/WildernessLabs/Meadow_Issues/issues) diff --git a/Source/Meadow.Foundation.Peripherals/ICs.DigiPots.Ds3502/Driver/ICs.DigiPots.Ds3502.csproj b/Source/Meadow.Foundation.Peripherals/ICs.DigiPots.Ds3502/Driver/ICs.DigiPots.Ds3502.csproj index 0280924d4a..a9f729d651 100644 --- a/Source/Meadow.Foundation.Peripherals/ICs.DigiPots.Ds3502/Driver/ICs.DigiPots.Ds3502.csproj +++ b/Source/Meadow.Foundation.Peripherals/ICs.DigiPots.Ds3502/Driver/ICs.DigiPots.Ds3502.csproj @@ -22,6 +22,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/ICs.DigiPots.Ds3502/Samples/Ds3502_Sample/Ds3502_Sample.csproj b/Source/Meadow.Foundation.Peripherals/ICs.DigiPots.Ds3502/Samples/Ds3502_Sample/Ds3502_Sample.csproj index ba06523426..ae319fb914 100644 --- a/Source/Meadow.Foundation.Peripherals/ICs.DigiPots.Ds3502/Samples/Ds3502_Sample/Ds3502_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/ICs.DigiPots.Ds3502/Samples/Ds3502_Sample/Ds3502_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/ICs.DigiPots.Mcp4xxx/Driver/ICs.DigiPots.Mcp4xxx.csproj b/Source/Meadow.Foundation.Peripherals/ICs.DigiPots.Mcp4xxx/Driver/ICs.DigiPots.Mcp4xxx.csproj index 62fc474629..3e314e0fd2 100644 --- a/Source/Meadow.Foundation.Peripherals/ICs.DigiPots.Mcp4xxx/Driver/ICs.DigiPots.Mcp4xxx.csproj +++ b/Source/Meadow.Foundation.Peripherals/ICs.DigiPots.Mcp4xxx/Driver/ICs.DigiPots.Mcp4xxx.csproj @@ -22,6 +22,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/ICs.DigiPots.Mcp4xxx/Driver/Mcp4xxx.ResistorArray.cs b/Source/Meadow.Foundation.Peripherals/ICs.DigiPots.Mcp4xxx/Driver/Mcp4xxx.ResistorArray.cs index 56fc8c1201..98d0e8f878 100644 --- a/Source/Meadow.Foundation.Peripherals/ICs.DigiPots.Mcp4xxx/Driver/Mcp4xxx.ResistorArray.cs +++ b/Source/Meadow.Foundation.Peripherals/ICs.DigiPots.Mcp4xxx/Driver/Mcp4xxx.ResistorArray.cs @@ -41,7 +41,7 @@ public Resistance Resistance internal ResistorArray(Mcp4xxx parent, int index, ISpiCommunications spiComms) { - if (index < 0 && index > 1) throw new ArgumentException(); + if (index is < 0 or > 1) throw new ArgumentException(); _parent = parent; _index = index; diff --git a/Source/Meadow.Foundation.Peripherals/ICs.DigiPots.Mcp4xxx/Samples/Mcp4162_Sample/Mcp4162_Sample.csproj b/Source/Meadow.Foundation.Peripherals/ICs.DigiPots.Mcp4xxx/Samples/Mcp4162_Sample/Mcp4162_Sample.csproj index f08713019d..1997fb4478 100644 --- a/Source/Meadow.Foundation.Peripherals/ICs.DigiPots.Mcp4xxx/Samples/Mcp4162_Sample/Mcp4162_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/ICs.DigiPots.Mcp4xxx/Samples/Mcp4162_Sample/Mcp4162_Sample.csproj @@ -10,7 +10,7 @@ 10 - - + + diff --git a/Source/Meadow.Foundation.Peripherals/ICs.EEPROM.At24Cxx/Driver/At24Cxx.cs b/Source/Meadow.Foundation.Peripherals/ICs.EEPROM.At24Cxx/Driver/At24Cxx.cs index ed0dfbc515..60563505bf 100644 --- a/Source/Meadow.Foundation.Peripherals/ICs.EEPROM.At24Cxx/Driver/At24Cxx.cs +++ b/Source/Meadow.Foundation.Peripherals/ICs.EEPROM.At24Cxx/Driver/At24Cxx.cs @@ -64,12 +64,12 @@ private void CheckAddress(ushort address, ushort amount) if (address > MemorySize) { throw new ArgumentOutOfRangeException( - "address", "startAddress should be less than the amount of memory in the module"); + nameof(address), "startAddress should be less than the amount of memory in the module"); } if ((address + amount) > MemorySize) { throw new ArgumentOutOfRangeException( - "address", "startAddress + amount should be less than the amount of memory in the module"); + nameof(address), "startAddress + amount should be less than the amount of memory in the module"); } } diff --git a/Source/Meadow.Foundation.Peripherals/ICs.EEPROM.At24Cxx/Driver/ICs.EEPROM.At24Cxx.csproj b/Source/Meadow.Foundation.Peripherals/ICs.EEPROM.At24Cxx/Driver/ICs.EEPROM.At24Cxx.csproj index 2634385308..35e38fdb0c 100644 --- a/Source/Meadow.Foundation.Peripherals/ICs.EEPROM.At24Cxx/Driver/ICs.EEPROM.At24Cxx.csproj +++ b/Source/Meadow.Foundation.Peripherals/ICs.EEPROM.At24Cxx/Driver/ICs.EEPROM.At24Cxx.csproj @@ -23,6 +23,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/ICs.EEPROM.At24Cxx/Samples/At24Cxx_Sample/At24Cxx_Sample.csproj b/Source/Meadow.Foundation.Peripherals/ICs.EEPROM.At24Cxx/Samples/At24Cxx_Sample/At24Cxx_Sample.csproj index f819bd6bba..c84ca55e2e 100644 --- a/Source/Meadow.Foundation.Peripherals/ICs.EEPROM.At24Cxx/Samples/At24Cxx_Sample/At24Cxx_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/ICs.EEPROM.At24Cxx/Samples/At24Cxx_Sample/At24Cxx_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/ICs.FanControllers.Emc2101/Driver/ICs.FanControllers.Emc2101.csproj b/Source/Meadow.Foundation.Peripherals/ICs.FanControllers.Emc2101/Driver/ICs.FanControllers.Emc2101.csproj index 97b0fdcd4d..b1f80b709d 100644 --- a/Source/Meadow.Foundation.Peripherals/ICs.FanControllers.Emc2101/Driver/ICs.FanControllers.Emc2101.csproj +++ b/Source/Meadow.Foundation.Peripherals/ICs.FanControllers.Emc2101/Driver/ICs.FanControllers.Emc2101.csproj @@ -21,7 +21,7 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/ICs.FanControllers.Emc2101/Samples/Emc2101_Sample/Emc2101_Sample.csproj b/Source/Meadow.Foundation.Peripherals/ICs.FanControllers.Emc2101/Samples/Emc2101_Sample/Emc2101_Sample.csproj index 27889e666a..ef743fa45e 100644 --- a/Source/Meadow.Foundation.Peripherals/ICs.FanControllers.Emc2101/Samples/Emc2101_Sample/Emc2101_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/ICs.FanControllers.Emc2101/Samples/Emc2101_Sample/Emc2101_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.AnalogMux/Driver/ICs.IOExpanders.AnalogMux.csproj b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.AnalogMux/Driver/ICs.IOExpanders.AnalogMux.csproj index d8b5766037..4913582c65 100644 --- a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.AnalogMux/Driver/ICs.IOExpanders.AnalogMux.csproj +++ b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.AnalogMux/Driver/ICs.IOExpanders.AnalogMux.csproj @@ -22,6 +22,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.AnalogMux/Samples/Nxp74HC4051_Sample/Nxp74HC4051_Sample.csproj b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.AnalogMux/Samples/Nxp74HC4051_Sample/Nxp74HC4051_Sample.csproj index 27c07329e8..0ddd974e3c 100644 --- a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.AnalogMux/Samples/Nxp74HC4051_Sample/Nxp74HC4051_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.AnalogMux/Samples/Nxp74HC4051_Sample/Nxp74HC4051_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.As1115/Driver/ICs.IOExpanders.As1115.csproj b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.As1115/Driver/ICs.IOExpanders.As1115.csproj index 77135d5afd..eeceb57980 100644 --- a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.As1115/Driver/ICs.IOExpanders.As1115.csproj +++ b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.As1115/Driver/ICs.IOExpanders.As1115.csproj @@ -22,6 +22,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.As1115/Samples/As1115_Sample/As1115_Sample.csproj b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.As1115/Samples/As1115_Sample/As1115_Sample.csproj index 9cab203f31..89d39f78a8 100644 --- a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.As1115/Samples/As1115_Sample/As1115_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.As1115/Samples/As1115_Sample/As1115_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Cp2112/Driver/ICs.IOExpanders.Cp2112.csproj b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Cp2112/Driver/ICs.IOExpanders.Cp2112.csproj index 32a6232f61..d33d38ec46 100644 --- a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Cp2112/Driver/ICs.IOExpanders.Cp2112.csproj +++ b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Cp2112/Driver/ICs.IOExpanders.Cp2112.csproj @@ -23,6 +23,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Cp2112/Samples/Cp2112_Windows_Sample/Cp2112_Windows_Sample.csproj b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Cp2112/Samples/Cp2112_Windows_Sample/Cp2112_Windows_Sample.csproj index c1d86a342e..629dba7fb6 100644 --- a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Cp2112/Samples/Cp2112_Windows_Sample/Cp2112_Windows_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Cp2112/Samples/Cp2112_Windows_Sample/Cp2112_Windows_Sample.csproj @@ -17,7 +17,7 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ftxxxx/Driver/FtdiExpander.DigitalInputPort.cs b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ftxxxx/Driver/FtdiExpander.DigitalInputPort.cs new file mode 100644 index 0000000000..1f31e1503b --- /dev/null +++ b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ftxxxx/Driver/FtdiExpander.DigitalInputPort.cs @@ -0,0 +1,35 @@ +using Meadow.Hardware; +using System; + +namespace Meadow.Foundation.ICs.IOExpanders; + +public abstract partial class FtdiExpander +{ + public sealed class DigitalInputPort : DigitalInputPortBase + { + private FtdiExpander _expander; + private FtdiPin _pin; + + /// + public override ResistorMode Resistor { get; set; } + + internal DigitalInputPort(FtdiExpander expander, IPin pin, IDigitalChannelInfo channel, ResistorMode resistorMode) + : base(pin, channel) + { + Resistor = resistorMode; + + _expander = expander; + _pin = pin as FtdiPin ?? throw new ArgumentException("Invalid pin"); + } + + /// + public override bool State + { + get + { + var states = _expander.GetGpioStates(_pin.IsLowByte); + return (states & (byte)_pin.Key) != 0; + } + } + } +} \ No newline at end of file diff --git a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ftxxxx/Driver/FtdiExpander.DigitalOutputPort.cs b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ftxxxx/Driver/FtdiExpander.DigitalOutputPort.cs index b8be7d7cca..8279bcdfc9 100644 --- a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ftxxxx/Driver/FtdiExpander.DigitalOutputPort.cs +++ b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ftxxxx/Driver/FtdiExpander.DigitalOutputPort.cs @@ -15,6 +15,7 @@ internal DigitalOutputPort(FtdiExpander expander, IPin pin, IDigitalChannelInfo : base(pin, channel, initialState, initialOutputType) { _expander = expander; + _state = initialState; if (pin is FtdiPin p) { @@ -26,6 +27,7 @@ internal DigitalOutputPort(FtdiExpander expander, IPin pin, IDigitalChannelInfo } } + /// public override bool State { get => _state; diff --git a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ftxxxx/Driver/FtdiExpander.Ft232hI2cBus.cs b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ftxxxx/Driver/FtdiExpander.Ft232hI2cBus.cs index 0797c298ee..e487c89457 100644 --- a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ftxxxx/Driver/FtdiExpander.Ft232hI2cBus.cs +++ b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ftxxxx/Driver/FtdiExpander.Ft232hI2cBus.cs @@ -8,8 +8,6 @@ public abstract partial class FtdiExpander { public class Ft232hI2cBus : I2CBus { - private FtdiExpander _expander; - internal Ft232hI2cBus(FtdiExpander expander, I2cBusSpeed busSpeed) : base(expander, busSpeed) { diff --git a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ftxxxx/Driver/FtdiExpander.PinDefinitions.cs b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ftxxxx/Driver/FtdiExpander.PinDefinitions.cs index b47f20f9f0..4d3d2d8d8e 100644 --- a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ftxxxx/Driver/FtdiExpander.PinDefinitions.cs +++ b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ftxxxx/Driver/FtdiExpander.PinDefinitions.cs @@ -4,17 +4,6 @@ namespace Meadow.Foundation.ICs.IOExpanders; -public class FtdiPin : Pin -{ - public bool IsLowByte { get; set; } - - internal FtdiPin(bool isLowByte, IPinController? controller, string name, object key, IList? supportedChannels) - : base(controller, name, key, supportedChannels) - { - IsLowByte = isLowByte; - } -} - /// /// Represents the pin definitions for the Ft232h IC. /// @@ -299,7 +288,7 @@ protected void InitAllPins() AllPins.Add(D1); AllPins.Add(D2); AllPins.Add(D3); - AllPins.Add(D7); + AllPins.Add(D4); AllPins.Add(D5); AllPins.Add(D6); AllPins.Add(D7); diff --git a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ftxxxx/Driver/FtdiExpander.cs b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ftxxxx/Driver/FtdiExpander.cs index 9de7f9a81b..5b2b30252c 100644 --- a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ftxxxx/Driver/FtdiExpander.cs +++ b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ftxxxx/Driver/FtdiExpander.cs @@ -11,9 +11,7 @@ namespace Meadow.Foundation.ICs.IOExpanders; public abstract partial class FtdiExpander : IPinController, -// IDisposable, -// IDigitalInputOutputController, - IDigitalOutputController, + IDigitalInputOutputController, ISpiController, II2cController { @@ -30,7 +28,9 @@ public abstract partial class FtdiExpander : internal string Description { get; private set; } internal IntPtr Handle { get; private set; } + /// public abstract II2cBus CreateI2cBus(int channel = 0, I2cBusSpeed busSpeed = I2cBusSpeed.Standard); + /// public abstract ISpiBus CreateSpiBus(int channel, SpiClockConfiguration configuration); /// @@ -70,7 +70,16 @@ internal static FtdiExpander Create( Description = description, Handle = handle }, - FtDeviceType.Ft2232H => throw new NotImplementedException(), + FtDeviceType.Ft2232H => new Ft232h + { + Index = index, + Flags = flags, + ID = id, + LocID = locid, + SerialNumber = serialNumber, + Description = description, + Handle = handle + }, FtDeviceType.Ft4232H => throw new NotImplementedException(), _ => throw new NotSupportedException(), }; @@ -141,6 +150,17 @@ private uint GetAvailableBytes() return availableBytes; } + internal byte GetGpioStates(bool lowByte) + { + Span outBuffer = stackalloc byte[2]; + Span inBuffer = stackalloc byte[1]; + outBuffer[0] = (byte)(lowByte ? Native.FT_OPCODE.ReadDataBitsLowByte : Native.FT_OPCODE.ReadDataBitsHighByte); + outBuffer[1] = (byte)Native.FT_OPCODE.SendImmediate; + Write(outBuffer); + ReadInto(inBuffer); + return inBuffer[0]; + } + internal void SetGpioDirectionAndState(bool lowByte, byte direction, byte state) { Span outBuffer = stackalloc byte[3]; @@ -217,7 +237,7 @@ internal void Write(ReadOnlySpan data) /// public IDigitalOutputPort CreateDigitalOutputPort(IPin pin, bool initialState = false, OutputType initialOutputType = OutputType.PushPull) { - var p = pin as FtdiPin; + var p = pin as FtdiPin ?? throw new ArgumentException(); // TODO: make sure the pin isn't in use @@ -300,4 +320,41 @@ public ISpiBus CreateSpiBus(int channel = 0) { return CreateSpiBus(channel, new SpiClockConfiguration(1000000.Hertz())); } + + /// + public IDigitalInputPort CreateDigitalInputPort(IPin pin, ResistorMode resistorMode) + { + switch (resistorMode) + { + case ResistorMode.InternalPullUp: + case ResistorMode.InternalPullDown: + throw new Exception("Internal resistors are not supported"); + } + + var p = pin as FtdiPin ?? throw new ArgumentException(); + + // TODO: make sure the pin isn't in use + + if (p.IsLowByte) + { + // update the expanders direction mask to make this an output + GpioDirectionLow &= (byte)~(byte)pin.Key; + + SetGpioDirectionAndState( + p.IsLowByte, + GpioDirectionLow, + GpioStateLow); + } + else + { + GpioDirectionHigh &= (byte)~(byte)pin.Key; + + SetGpioDirectionAndState( + p.IsLowByte, + GpioDirectionHigh, + GpioStateHigh); + } + + return new DigitalInputPort(this, pin, (pin.SupportedChannels.First() as IDigitalChannelInfo)!, resistorMode); + } } diff --git a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ftxxxx/Driver/FtdiPin.cs b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ftxxxx/Driver/FtdiPin.cs new file mode 100644 index 0000000000..795373737a --- /dev/null +++ b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ftxxxx/Driver/FtdiPin.cs @@ -0,0 +1,27 @@ +using Meadow.Hardware; +using System.Collections.Generic; + +namespace Meadow.Foundation.ICs.IOExpanders; + +/// +/// Represents a single FTDI expander pin +/// +public class FtdiPin : Pin +{ + /// + /// Returns true if the pin is on the low byte of the expander, otherwise false + /// + public bool IsLowByte { get; internal set; } + + internal FtdiPin(bool isLowByte, IPinController? controller, string name, object key, IList? supportedChannels) + : base(controller, name, key, supportedChannels) + { + IsLowByte = isLowByte; + } + + /// + public override string ToString() + { + return $"{Name}"; + } +} diff --git a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ftxxxx/Driver/ICs.IOExpanders.Ftxxxx.csproj b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ftxxxx/Driver/ICs.IOExpanders.Ftxxxx.csproj index c4f4551f59..8c92cabbaa 100644 --- a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ftxxxx/Driver/ICs.IOExpanders.Ftxxxx.csproj +++ b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ftxxxx/Driver/ICs.IOExpanders.Ftxxxx.csproj @@ -22,7 +22,7 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ftxxxx/Samples/Ft232h_Sample/Ft232h_Sample.csproj b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ftxxxx/Samples/Ft232h_Sample/Ft232h_Sample.csproj index 78728f3e98..361ad5d4f7 100644 --- a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ftxxxx/Samples/Ft232h_Sample/Ft232h_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ftxxxx/Samples/Ft232h_Sample/Ft232h_Sample.csproj @@ -8,9 +8,9 @@ - - - + + + diff --git a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ht16k33/Driver/ICs.IOExpanders.Ht16k33.csproj b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ht16k33/Driver/ICs.IOExpanders.Ht16k33.csproj index 8f2b46fe27..15812f1b1c 100644 --- a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ht16k33/Driver/ICs.IOExpanders.Ht16k33.csproj +++ b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ht16k33/Driver/ICs.IOExpanders.Ht16k33.csproj @@ -22,6 +22,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ht16k33/Samples/Ht16k33_Character_Sample/Ht16k33_Character_Sample.csproj b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ht16k33/Samples/Ht16k33_Character_Sample/Ht16k33_Character_Sample.csproj index 72e8b7aa52..04b76a347d 100644 --- a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ht16k33/Samples/Ht16k33_Character_Sample/Ht16k33_Character_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ht16k33/Samples/Ht16k33_Character_Sample/Ht16k33_Character_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ht16k33/Samples/Ht16k33_Sample/Ht16k33_Sample.csproj b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ht16k33/Samples/Ht16k33_Sample/Ht16k33_Sample.csproj index 72e8b7aa52..04b76a347d 100644 --- a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ht16k33/Samples/Ht16k33_Sample/Ht16k33_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ht16k33/Samples/Ht16k33_Sample/Ht16k33_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Is31fl3731/Driver/ICs.IOExpanders.Is31fl3731.csproj b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Is31fl3731/Driver/ICs.IOExpanders.Is31fl3731.csproj index 0183070206..1f4746ab0a 100644 --- a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Is31fl3731/Driver/ICs.IOExpanders.Is31fl3731.csproj +++ b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Is31fl3731/Driver/ICs.IOExpanders.Is31fl3731.csproj @@ -22,6 +22,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Is31fl3731/Driver/Is31fl3731.cs b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Is31fl3731/Driver/Is31fl3731.cs index 83db675444..fcbb6da4fb 100644 --- a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Is31fl3731/Driver/Is31fl3731.cs +++ b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Is31fl3731/Driver/Is31fl3731.cs @@ -6,9 +6,9 @@ namespace Meadow.Foundation.ICs.IOExpanders { /// /// Represents the IS31FL3731 IC - /// The Is31fl3731 is a compact LED driver for 144 single LEDs + /// The IS31FL3731 is a compact LED driver for 144 single LEDs /// - /// Based on https://github.com/adafruit/Adafruit_IS31FL3731 + /// Based on https://github.com/adafruit/Adafruit_IS31FL3731 public partial class Is31fl3731 : II2cPeripheral { const byte RegConfig = 0x00; @@ -22,6 +22,9 @@ public partial class Is31fl3731 : II2cPeripheral const byte CommandRegister = 0xFD; const byte CommandFunctionReg = 0x0B; + const byte MaxFrames = 7; + const byte MaxLeds = 144; + /// /// The default I2C address for the peripheral /// @@ -53,23 +56,23 @@ public Is31fl3731(II2cBus i2cBus, byte address = (byte)Addresses.Default) /// public void Initialize() { - //Shutdown + // Shutdown WriteRegister(CommandFunctionReg, RegShutdown, 0x00); Thread.Sleep(10); - //Turn on + // Turn on WriteRegister(CommandFunctionReg, RegShutdown, 0x01); Thread.Sleep(10); WriteRegister(CommandFunctionReg, RegConfig, RegConfigPictureMode); Thread.Sleep(10); - //disable blink mode + // Disable blink mode WriteRegister(CommandFunctionReg, DisplayOptionRegister, 0x00); } /// - /// Set the LED state for all LED's in the current Frame + /// Set the LED state for all LEDs in the current Frame /// /// true = on, false = off public virtual void SetLedState(bool on) @@ -80,25 +83,15 @@ public virtual void SetLedState(bool on) /// /// Sets the state for all LEDs for the specified frame /// - /// + /// Frame number /// true = on, false = off public virtual void SetLedState(byte frame, bool on) { - if (frame < 0 || frame > 7) - { - throw new ArgumentOutOfRangeException(nameof(frame), $"{nameof(frame)} # has to be between 0 and 7"); - } + ValidateFrame(frame); for (byte i = 0x00; i <= 0x11; i++) { - if (on) - { - WriteRegister(frame, i, 0xFF); - } - else - { - WriteRegister(frame, i, 0x00); - } + WriteRegister(frame, i, on ? (byte)0xFF : (byte)0x00); } } @@ -121,32 +114,33 @@ protected virtual void WriteRegister(byte register, byte data) protected virtual void WriteRegister(byte frame, byte register, byte data) { SelectPage(frame); - i2cComms.WriteRegister(register, data); } + /// + /// Read a value from a register + /// + /// Register to read from + /// The data value read from the register + protected virtual byte ReadRegister(byte register) + { + return i2cComms.ReadRegister(register); + } + /// /// Enable/disable blink mode /// /// true = on, false = off - /// the blink duration + /// The blink duration public virtual void SetBlinkMode(bool enabled, byte period) { period = Math.Min(period, (byte)7); - if (enabled) - { - var data = (byte)(period | 0x08); - WriteRegister(CommandFunctionReg, DisplayOptionRegister, data); - } - else - { - WriteRegister(CommandFunctionReg, DisplayOptionRegister, 0x00); - } + WriteRegister(CommandFunctionReg, DisplayOptionRegister, enabled ? (byte)(period | 0x08) : (byte)0x00); } /// - /// Turn off all LEDs for the specified frame + /// Turn off all LEDs for the current frame /// public virtual void Clear() { @@ -156,15 +150,12 @@ public virtual void Clear() /// /// Turn off all LEDs for the specified frame /// - /// the frame to clear + /// The frame to clear public virtual void Clear(byte frame) { - if (frame < 0 || frame > 7) - { - throw new ArgumentOutOfRangeException(nameof(frame), $"{nameof(frame)} # has to be between 0 and 7"); - } + ValidateFrame(frame); - for (byte i = 0; i <= 144; i++) + for (byte i = 0; i < MaxLeds; i++) { SetLedPwm(frame, i, 0); } @@ -175,7 +166,7 @@ public virtual void Clear(byte frame) /// public virtual void ClearAllFrames() { - for (byte i = 0; i < 7; i++) + for (byte i = 0; i <= MaxFrames; i++) { Clear(i); } @@ -185,7 +176,7 @@ public virtual void ClearAllFrames() /// Set the PWM value for the specified LED /// /// The LED number - /// The pwm value 0-255 + /// The PWM value (0-255) public virtual void SetLedPwm(byte ledIndex, byte pwm) { SetLedPwm(Frame, ledIndex, pwm); @@ -194,29 +185,42 @@ public virtual void SetLedPwm(byte ledIndex, byte pwm) /// /// Set the PWM value for the specified LED /// - /// Frame number. 0-7 - /// The LED number. 0-144 - /// The pwm value 0-255 + /// Frame number (0-7) + /// The LED number (0-144) + /// The PWM value (0-255) public virtual void SetLedPwm(byte frame, byte ledIndex, byte brightness) { - if (frame < 0 || frame > 7) + ValidateFrame(frame); + if (ledIndex >= MaxLeds) return; + + WriteRegister(frame, (byte)(0x24 + ledIndex), brightness); + } + + /// + /// Get the PWM value for the specified LED + /// + /// Frame number (0-7) + /// The LED number (0-144) + /// The PWM value 0-255 + public virtual byte GetLedPwm(byte frame, byte ledIndex) + { + ValidateFrame(frame); + if (ledIndex >= MaxLeds) { - throw new ArgumentOutOfRangeException(nameof(frame), $"{nameof(frame)} # has to be between 0 and 7"); + throw new ArgumentOutOfRangeException(nameof(ledIndex), $"LED index must be between 0 and {MaxLeds - 1}"); } - if (ledIndex < 0 || ledIndex >= 144) { return; } - - WriteRegister(frame, (byte)(0x24 + ledIndex), brightness); + SelectPage(frame); + return ReadRegister((byte)(0x24 + ledIndex)); } /// /// Display the specified frame /// - /// The frame number. 0-7 + /// The frame number (0-7) public virtual void DisplayFrame(byte frame) { - frame = Math.Max(frame, (byte)0); - frame = Math.Min(frame, (byte)7); + frame = Math.Clamp(frame, (byte)0, MaxFrames); WriteRegister(CommandFunctionReg, PictureFrameReg, frame); } @@ -224,19 +228,15 @@ public virtual void DisplayFrame(byte frame) /// /// Sets the current frame. /// - /// The frame number. 0-7 + /// The frame number (0-7) public virtual void SetFrame(byte frame) { - if (frame < 0 || frame > 7) - { - throw new ArgumentOutOfRangeException(nameof(frame), $"{nameof(frame)} must be between 1 and 8"); - } - + ValidateFrame(frame); Frame = frame; } /// - /// Blink all LEDs for the current frame. Blink Mode muse be enabled + /// Blink all LEDs for the current frame - blink Mode must be enabled /// /// true = on, false = off public virtual void SetBlinkFunctionOnAllLeds(bool on) @@ -247,30 +247,31 @@ public virtual void SetBlinkFunctionOnAllLeds(bool on) /// /// Blink all the LEDs for the specified frame /// - /// frame # + /// Frame number /// true = on, false = off public virtual void SetBlinkFunctionOnAllLeds(byte frame, bool on) { for (byte j = 0x12; j <= 0x23; j++) { - if (on) - { - WriteRegister(frame, j, 0xFF); - } - else - { - WriteRegister(frame, j, 0x00); - } + WriteRegister(frame, j, on ? (byte)0xFF : (byte)0x00); } } /// /// Select the page/frame /// - /// page/frame # + /// Page/frame number protected virtual void SelectPage(byte page) { i2cComms.WriteRegister(CommandRegister, page); } + + private void ValidateFrame(byte frame) + { + if (frame < 0 || frame > MaxFrames) + { + throw new ArgumentOutOfRangeException(nameof(frame), $"{nameof(frame)} must be between 0 and {MaxFrames}"); + } + } } -} \ No newline at end of file +} diff --git a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Is31fl3731/Samples/Is31fl3731_Sample/Is31fl3731_Sample.csproj b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Is31fl3731/Samples/Is31fl3731_Sample/Is31fl3731_Sample.csproj index e0b163dd6e..7f771c40dd 100644 --- a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Is31fl3731/Samples/Is31fl3731_Sample/Is31fl3731_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Is31fl3731/Samples/Is31fl3731_Sample/Is31fl3731_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Mcp23xxx/Driver/ICs.IOExpanders.Mcp23xxx.csproj b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Mcp23xxx/Driver/ICs.IOExpanders.Mcp23xxx.csproj index 8f666d4635..b2fd7c9b73 100644 --- a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Mcp23xxx/Driver/ICs.IOExpanders.Mcp23xxx.csproj +++ b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Mcp23xxx/Driver/ICs.IOExpanders.Mcp23xxx.csproj @@ -22,6 +22,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Mcp23xxx/Samples/Mcp23008_Sample/Mcp23008_Sample.csproj b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Mcp23xxx/Samples/Mcp23008_Sample/Mcp23008_Sample.csproj index e3282f0101..8e2452f43d 100644 --- a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Mcp23xxx/Samples/Mcp23008_Sample/Mcp23008_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Mcp23xxx/Samples/Mcp23008_Sample/Mcp23008_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Mcp23xxx/Samples/Mcp23009_Sample/Mcp23009_Sample.csproj b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Mcp23xxx/Samples/Mcp23009_Sample/Mcp23009_Sample.csproj index e3282f0101..8e2452f43d 100644 --- a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Mcp23xxx/Samples/Mcp23009_Sample/Mcp23009_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Mcp23xxx/Samples/Mcp23009_Sample/Mcp23009_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Mcp23xxx/Samples/Mcp23017_Sample/Mcp23017_Sample.csproj b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Mcp23xxx/Samples/Mcp23017_Sample/Mcp23017_Sample.csproj index e3282f0101..8e2452f43d 100644 --- a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Mcp23xxx/Samples/Mcp23017_Sample/Mcp23017_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Mcp23xxx/Samples/Mcp23017_Sample/Mcp23017_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Mcp23xxx/Samples/Mcp23018_Sample/Mcp23018_Sample.csproj b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Mcp23xxx/Samples/Mcp23018_Sample/Mcp23018_Sample.csproj index e3282f0101..8e2452f43d 100644 --- a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Mcp23xxx/Samples/Mcp23018_Sample/Mcp23018_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Mcp23xxx/Samples/Mcp23018_Sample/Mcp23018_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Mcp23xxx/Samples/Mcp23s08_Sample/Mcp23s08_Sample.csproj b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Mcp23xxx/Samples/Mcp23s08_Sample/Mcp23s08_Sample.csproj index e3282f0101..8e2452f43d 100644 --- a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Mcp23xxx/Samples/Mcp23s08_Sample/Mcp23s08_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Mcp23xxx/Samples/Mcp23s08_Sample/Mcp23s08_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Mcp23xxx/Samples/Mcp23s09_Sample/Mcp23s09_Sample.csproj b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Mcp23xxx/Samples/Mcp23s09_Sample/Mcp23s09_Sample.csproj index e3282f0101..8e2452f43d 100644 --- a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Mcp23xxx/Samples/Mcp23s09_Sample/Mcp23s09_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Mcp23xxx/Samples/Mcp23s09_Sample/Mcp23s09_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Mcp23xxx/Samples/Mcp23s17_Sample/Mcp23s17_Sample.csproj b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Mcp23xxx/Samples/Mcp23s17_Sample/Mcp23s17_Sample.csproj index e3282f0101..8e2452f43d 100644 --- a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Mcp23xxx/Samples/Mcp23s17_Sample/Mcp23s17_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Mcp23xxx/Samples/Mcp23s17_Sample/Mcp23s17_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Mcp23xxx/Samples/Mcp23s18_Sample/Mcp23s18_Sample.csproj b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Mcp23xxx/Samples/Mcp23s18_Sample/Mcp23s18_Sample.csproj index e3282f0101..8e2452f43d 100644 --- a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Mcp23xxx/Samples/Mcp23s18_Sample/Mcp23s18_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Mcp23xxx/Samples/Mcp23s18_Sample/Mcp23s18_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Mcp23xxx/Samples/Mcp23x08_Input_Sample/Mcp23x08_Input_Sample.csproj b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Mcp23xxx/Samples/Mcp23x08_Input_Sample/Mcp23x08_Input_Sample.csproj index e3282f0101..8e2452f43d 100644 --- a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Mcp23xxx/Samples/Mcp23x08_Input_Sample/Mcp23x08_Input_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Mcp23xxx/Samples/Mcp23x08_Input_Sample/Mcp23x08_Input_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Mcp23xxx/Samples/Mcp23x17_Input_Sample/Mcp23x17_Input_Sample.csproj b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Mcp23xxx/Samples/Mcp23x17_Input_Sample/Mcp23x17_Input_Sample.csproj index e3282f0101..8e2452f43d 100644 --- a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Mcp23xxx/Samples/Mcp23x17_Input_Sample/Mcp23x17_Input_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Mcp23xxx/Samples/Mcp23x17_Input_Sample/Mcp23x17_Input_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Pca9671/Driver/ICs.IOExpanders.Pca9671.csproj b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Pca9671/Driver/ICs.IOExpanders.Pca9671.csproj index e3a35af4ce..c382f4d2e8 100644 --- a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Pca9671/Driver/ICs.IOExpanders.Pca9671.csproj +++ b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Pca9671/Driver/ICs.IOExpanders.Pca9671.csproj @@ -22,6 +22,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Pca9671/Samples/Pca9671_Sample/Pca9671_Sample.csproj b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Pca9671/Samples/Pca9671_Sample/Pca9671_Sample.csproj index 881069b8ad..5d321f8d19 100644 --- a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Pca9671/Samples/Pca9671_Sample/Pca9671_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Pca9671/Samples/Pca9671_Sample/Pca9671_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Pca9685/Driver/ICs.IOExpanders.Pca9685.csproj b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Pca9685/Driver/ICs.IOExpanders.Pca9685.csproj index 3960cf0e2a..b2842481d9 100644 --- a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Pca9685/Driver/ICs.IOExpanders.Pca9685.csproj +++ b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Pca9685/Driver/ICs.IOExpanders.Pca9685.csproj @@ -22,6 +22,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Pca9685/Driver/Pca9685.cs b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Pca9685/Driver/Pca9685.cs index a672856873..2676110d0d 100644 --- a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Pca9685/Driver/Pca9685.cs +++ b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Pca9685/Driver/Pca9685.cs @@ -102,9 +102,9 @@ public virtual void Initialize() /// IPwmPort public virtual IPwmPort CreatePwmPort(byte portNumber, float dutyCycle = 0.5f) { - if (portNumber < 0 || portNumber > 15) + if (portNumber is < 0 or > 15) { - throw new ArgumentException("Value must be between 0 and 15", "portNumber"); + throw new ArgumentException("Value must be between 0 and 15", nameof(portNumber)); } var pwmPort = new PwmPort(i2cBus, address, Led0OnL, frequency, portNumber, dutyCycle); @@ -119,19 +119,12 @@ public virtual IPwmPort CreatePwmPort(byte portNumber, float dutyCycle = 0.5f) /// true is on, false if off public virtual void SetPin(byte pin, bool on) { - if ((pin < 0) || (pin > 15)) + if (pin is < 0 or > 15) { throw new ArgumentException("PWM pin must be between 0 and 15"); } - if (on) - { - SetPwm(pin, 4096, 0); - } - else - { - SetPwm(pin, 0, 0); - } + SetPwm(pin, on ? 4096 : 0, 0); } /// @@ -143,19 +136,19 @@ public virtual void SetPin(byte pin, bool on) /// On parameter is an inverted pwm signal public virtual void SetPwm(byte pin, int on, int off) { - if (pin < 0 || pin > 15) + if (pin is < 0 or > 15) { - throw new ArgumentException("Value has to be between 0 and 15", "port"); + throw new ArgumentException("Value has to be between 0 and 15", nameof(pin)); } - if (on < 0 || on > 4096) + if (on is < 0 or > 4096) { - throw new ArgumentException("Value has to be between 0 and 4096", "on"); + throw new ArgumentException("Value has to be between 0 and 4096", nameof(on)); } - if (off < 0 || off > 4096) + if (off is < 0 or > 4096) { - throw new ArgumentException("Value has to be between 0 and 4096", "off"); + throw new ArgumentException("Value has to be between 0 and 4096", nameof(off)); } Write((byte)(Led0OnL + (4 * pin)), (byte)(on & 0xFF), (byte)(on >> 8), (byte)(off & 0xFF), (byte)(off >> 8)); diff --git a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Pca9685/Samples/Pca9685_Sample/Pca9685_Sample.csproj b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Pca9685/Samples/Pca9685_Sample/Pca9685_Sample.csproj index 94c8835bbc..49509fd089 100644 --- a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Pca9685/Samples/Pca9685_Sample/Pca9685_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Pca9685/Samples/Pca9685_Sample/Pca9685_Sample.csproj @@ -10,7 +10,7 @@ ICs.IOExpanders - - + + diff --git a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Pcx857x/Driver/ICs.IOExpanders.Pcx857x.csproj b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Pcx857x/Driver/ICs.IOExpanders.Pcx857x.csproj index 589e94f6a4..654a184014 100644 --- a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Pcx857x/Driver/ICs.IOExpanders.Pcx857x.csproj +++ b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Pcx857x/Driver/ICs.IOExpanders.Pcx857x.csproj @@ -22,6 +22,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Pcx857x/Samples/Pca8574_Sample/Pca8574_Sample.csproj b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Pcx857x/Samples/Pca8574_Sample/Pca8574_Sample.csproj index 08929a714c..e478a726b2 100644 --- a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Pcx857x/Samples/Pca8574_Sample/Pca8574_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Pcx857x/Samples/Pca8574_Sample/Pca8574_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Pcx857x/Samples/Pca8575_Sample/Pca8575_Sample.csproj b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Pcx857x/Samples/Pca8575_Sample/Pca8575_Sample.csproj index 08929a714c..e478a726b2 100644 --- a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Pcx857x/Samples/Pca8575_Sample/Pca8575_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Pcx857x/Samples/Pca8575_Sample/Pca8575_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Pcx857x/Samples/Pcf8574_Sample/Pcf8574_Sample.csproj b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Pcx857x/Samples/Pcf8574_Sample/Pcf8574_Sample.csproj index 08929a714c..e478a726b2 100644 --- a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Pcx857x/Samples/Pcf8574_Sample/Pcf8574_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Pcx857x/Samples/Pcf8574_Sample/Pcf8574_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Pcx857x/Samples/Pcf8575_Sample/Pcf8575_Sample.csproj b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Pcx857x/Samples/Pcf8575_Sample/Pcf8575_Sample.csproj index 08929a714c..e478a726b2 100644 --- a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Pcx857x/Samples/Pcf8575_Sample/Pcf8575_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Pcx857x/Samples/Pcf8575_Sample/Pcf8575_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Sc16is7x2/Driver/ICs.IOExpanders.Sc16is7x2.csproj b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Sc16is7x2/Driver/ICs.IOExpanders.Sc16is7x2.csproj index 17f51b5b51..05da40f358 100644 --- a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Sc16is7x2/Driver/ICs.IOExpanders.Sc16is7x2.csproj +++ b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Sc16is7x2/Driver/ICs.IOExpanders.Sc16is7x2.csproj @@ -22,6 +22,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Sc16is7x2/Samples/InterruptDrivenUart/InterruptDrivenUart/InterruptDrivenUart.csproj b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Sc16is7x2/Samples/InterruptDrivenUart/InterruptDrivenUart/InterruptDrivenUart.csproj index 369718eaf4..9bf64ec7a0 100644 --- a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Sc16is7x2/Samples/InterruptDrivenUart/InterruptDrivenUart/InterruptDrivenUart.csproj +++ b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Sc16is7x2/Samples/InterruptDrivenUart/InterruptDrivenUart/InterruptDrivenUart.csproj @@ -21,6 +21,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Sc16is7x2/Samples/Sc16is752_Sample/Sc16is752_Sample.csproj b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Sc16is7x2/Samples/Sc16is752_Sample/Sc16is752_Sample.csproj index d0a6099155..c62901f35e 100644 --- a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Sc16is7x2/Samples/Sc16is752_Sample/Sc16is752_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Sc16is7x2/Samples/Sc16is752_Sample/Sc16is752_Sample.csproj @@ -10,7 +10,7 @@ enable - - + + diff --git a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Sc16is7x2/Samples/Sc16is762_Sample/Sc16is762_Sample.csproj b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Sc16is7x2/Samples/Sc16is762_Sample/Sc16is762_Sample.csproj index d0a6099155..c62901f35e 100644 --- a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Sc16is7x2/Samples/Sc16is762_Sample/Sc16is762_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Sc16is7x2/Samples/Sc16is762_Sample/Sc16is762_Sample.csproj @@ -10,7 +10,7 @@ enable - - + + diff --git a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.SerialWombat/Driver/ICs.IOExpanders.SerialWombat.csproj b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.SerialWombat/Driver/ICs.IOExpanders.SerialWombat.csproj index 095e06110c..159ac68f43 100644 --- a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.SerialWombat/Driver/ICs.IOExpanders.SerialWombat.csproj +++ b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.SerialWombat/Driver/ICs.IOExpanders.SerialWombat.csproj @@ -22,8 +22,8 @@ - - - + + + diff --git a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.SerialWombat/Samples/Sw18AB_ADC_Sample/Sw18AB_ADC_Sample.csproj b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.SerialWombat/Samples/Sw18AB_ADC_Sample/Sw18AB_ADC_Sample.csproj index 36ea4908d7..cd0f342836 100644 --- a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.SerialWombat/Samples/Sw18AB_ADC_Sample/Sw18AB_ADC_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.SerialWombat/Samples/Sw18AB_ADC_Sample/Sw18AB_ADC_Sample.csproj @@ -17,7 +17,7 @@ - - + + diff --git a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.SerialWombat/Samples/Sw18AB_Core_Sample/Sw18AB_Core_Sample.csproj b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.SerialWombat/Samples/Sw18AB_Core_Sample/Sw18AB_Core_Sample.csproj index 46843435eb..c1926bdd5e 100644 --- a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.SerialWombat/Samples/Sw18AB_Core_Sample/Sw18AB_Core_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.SerialWombat/Samples/Sw18AB_Core_Sample/Sw18AB_Core_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.SerialWombat/Samples/Sw18AB_PWM_Sample/Sw18AB_PWM_Sample.csproj b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.SerialWombat/Samples/Sw18AB_PWM_Sample/Sw18AB_PWM_Sample.csproj index 46843435eb..c1926bdd5e 100644 --- a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.SerialWombat/Samples/Sw18AB_PWM_Sample/Sw18AB_PWM_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.SerialWombat/Samples/Sw18AB_PWM_Sample/Sw18AB_PWM_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.SerialWombat/Samples/Sw18AB_Sample/Sw18AB_Sample.csproj b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.SerialWombat/Samples/Sw18AB_Sample/Sw18AB_Sample.csproj index 46843435eb..c1926bdd5e 100644 --- a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.SerialWombat/Samples/Sw18AB_Sample/Sw18AB_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.SerialWombat/Samples/Sw18AB_Sample/Sw18AB_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.SerialWombat/Samples/Sw18AB_Ultrasonic_Sample/Sw18AB_Ultrasonic_Sample.csproj b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.SerialWombat/Samples/Sw18AB_Ultrasonic_Sample/Sw18AB_Ultrasonic_Sample.csproj index 36ea4908d7..cd0f342836 100644 --- a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.SerialWombat/Samples/Sw18AB_Ultrasonic_Sample/Sw18AB_Ultrasonic_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.SerialWombat/Samples/Sw18AB_Ultrasonic_Sample/Sw18AB_Ultrasonic_Sample.csproj @@ -17,7 +17,7 @@ - - + + diff --git a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.TCA9548A/Driver/ICs.IOExpanders.Tca9548a.csproj b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.TCA9548A/Driver/ICs.IOExpanders.Tca9548a.csproj index 14cc5d13df..2a1d12e7f6 100644 --- a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.TCA9548A/Driver/ICs.IOExpanders.Tca9548a.csproj +++ b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.TCA9548A/Driver/ICs.IOExpanders.Tca9548a.csproj @@ -22,6 +22,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.TCA9548A/Samples/Tca9548a_Sample/Tca9548a_Sample.csproj b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.TCA9548A/Samples/Tca9548a_Sample/Tca9548a_Sample.csproj index 2664cb1b02..c782747422 100644 --- a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.TCA9548A/Samples/Tca9548a_Sample/Tca9548a_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.TCA9548A/Samples/Tca9548a_Sample/Tca9548a_Sample.csproj @@ -10,8 +10,8 @@ ICs.IOExpanders - - - + + + diff --git a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.x74595/Driver/ICs.IOExpanders.x74595.csproj b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.x74595/Driver/ICs.IOExpanders.x74595.csproj index 8ac1fe4116..02eda3a9d0 100644 --- a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.x74595/Driver/ICs.IOExpanders.x74595.csproj +++ b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.x74595/Driver/ICs.IOExpanders.x74595.csproj @@ -22,6 +22,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.x74595/Samples/x74595_Sample/x74595_Sample.csproj b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.x74595/Samples/x74595_Sample/x74595_Sample.csproj index ede71ff0d4..5eebb12a82 100644 --- a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.x74595/Samples/x74595_Sample/x74595_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.x74595/Samples/x74595_Sample/x74595_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Leds.Apa102/Driver/Leds.Apa102.csproj b/Source/Meadow.Foundation.Peripherals/Leds.Apa102/Driver/Leds.Apa102.csproj index 91a65ea2e7..1025e46bc1 100644 --- a/Source/Meadow.Foundation.Peripherals/Leds.Apa102/Driver/Leds.Apa102.csproj +++ b/Source/Meadow.Foundation.Peripherals/Leds.Apa102/Driver/Leds.Apa102.csproj @@ -22,6 +22,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/Leds.Apa102/Samples/Apa102_Display_Sample/Apa102_Display_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Leds.Apa102/Samples/Apa102_Display_Sample/Apa102_Display_Sample.csproj index 31736d3f84..e6d46bda9a 100644 --- a/Source/Meadow.Foundation.Peripherals/Leds.Apa102/Samples/Apa102_Display_Sample/Apa102_Display_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Leds.Apa102/Samples/Apa102_Display_Sample/Apa102_Display_Sample.csproj @@ -9,8 +9,8 @@ App - - - + + + diff --git a/Source/Meadow.Foundation.Peripherals/Leds.Apa102/Samples/Apa102_Sample/Apa102_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Leds.Apa102/Samples/Apa102_Sample/Apa102_Sample.csproj index 16afe2430c..2b9a760bc9 100644 --- a/Source/Meadow.Foundation.Peripherals/Leds.Apa102/Samples/Apa102_Sample/Apa102_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Leds.Apa102/Samples/Apa102_Sample/Apa102_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Leds.Pca9633/Driver/Leds.Pca9633.csproj b/Source/Meadow.Foundation.Peripherals/Leds.Pca9633/Driver/Leds.Pca9633.csproj index 40f76fdaf1..cf297e4708 100644 --- a/Source/Meadow.Foundation.Peripherals/Leds.Pca9633/Driver/Leds.Pca9633.csproj +++ b/Source/Meadow.Foundation.Peripherals/Leds.Pca9633/Driver/Leds.Pca9633.csproj @@ -22,6 +22,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/Leds.Pca9633/Samples/Pca9633_Sample/Pca9633_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Leds.Pca9633/Samples/Pca9633_Sample/Pca9633_Sample.csproj index c26fff32f5..bcd3e57fc7 100644 --- a/Source/Meadow.Foundation.Peripherals/Leds.Pca9633/Samples/Pca9633_Sample/Pca9633_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Leds.Pca9633/Samples/Pca9633_Sample/Pca9633_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Leds.Ws2812/Driver/Leds.Ws2812.csproj b/Source/Meadow.Foundation.Peripherals/Leds.Ws2812/Driver/Leds.Ws2812.csproj index add8d2185c..89f69b0e62 100644 --- a/Source/Meadow.Foundation.Peripherals/Leds.Ws2812/Driver/Leds.Ws2812.csproj +++ b/Source/Meadow.Foundation.Peripherals/Leds.Ws2812/Driver/Leds.Ws2812.csproj @@ -24,6 +24,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/Leds.Ws2812/Samples/Ws2812_Sample/Ws2812_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Leds.Ws2812/Samples/Ws2812_Sample/Ws2812_Sample.csproj index 441e92e638..06a1629b10 100644 --- a/Source/Meadow.Foundation.Peripherals/Leds.Ws2812/Samples/Ws2812_Sample/Ws2812_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Leds.Ws2812/Samples/Ws2812_Sample/Ws2812_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Motors.ElectronicSpeedController/Driver/Motors.ElectronicSpeedController.csproj b/Source/Meadow.Foundation.Peripherals/Motors.ElectronicSpeedController/Driver/Motors.ElectronicSpeedController.csproj index 6d9c90257c..baec7eae74 100644 --- a/Source/Meadow.Foundation.Peripherals/Motors.ElectronicSpeedController/Driver/Motors.ElectronicSpeedController.csproj +++ b/Source/Meadow.Foundation.Peripherals/Motors.ElectronicSpeedController/Driver/Motors.ElectronicSpeedController.csproj @@ -22,6 +22,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/Motors.ElectronicSpeedController/Driver/Readme.md b/Source/Meadow.Foundation.Peripherals/Motors.ElectronicSpeedController/Driver/Readme.md index b9468ebf9b..3783477ed1 100644 --- a/Source/Meadow.Foundation.Peripherals/Motors.ElectronicSpeedController/Driver/Readme.md +++ b/Source/Meadow.Foundation.Peripherals/Motors.ElectronicSpeedController/Driver/Readme.md @@ -59,8 +59,8 @@ private void RotaryRotated(object sender, RotaryChangeResult e) private void DisplayPowerOnLed(float power) { // `0.0` - `1.0` - int r = (int)ExtensionMethods.Map(power, 0f, 1f, 0f, 255f); - int b = (int)ExtensionMethods.Map(power, 0f, 1f, 255f, 0f); + int r = (int)power.Map(0f, 1f, 0f, 255f); + int b = (int)power.Map(0f, 1f, 255f, 0f); var color = Color.FromRgb(r, 0, b); } diff --git a/Source/Meadow.Foundation.Peripherals/Motors.ElectronicSpeedController/Samples/ElectronicSpeedController_Sample/ElectronicSpeedController_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Motors.ElectronicSpeedController/Samples/ElectronicSpeedController_Sample/ElectronicSpeedController_Sample.csproj index 60d6835831..1f1cd73196 100644 --- a/Source/Meadow.Foundation.Peripherals/Motors.ElectronicSpeedController/Samples/ElectronicSpeedController_Sample/ElectronicSpeedController_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Motors.ElectronicSpeedController/Samples/ElectronicSpeedController_Sample/ElectronicSpeedController_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Motors.ElectronicSpeedController/Samples/ElectronicSpeedController_Sample/MeadowApp.cs b/Source/Meadow.Foundation.Peripherals/Motors.ElectronicSpeedController/Samples/ElectronicSpeedController_Sample/MeadowApp.cs index 1afdb35f7d..54242f9ca0 100644 --- a/Source/Meadow.Foundation.Peripherals/Motors.ElectronicSpeedController/Samples/ElectronicSpeedController_Sample/MeadowApp.cs +++ b/Source/Meadow.Foundation.Peripherals/Motors.ElectronicSpeedController/Samples/ElectronicSpeedController_Sample/MeadowApp.cs @@ -55,8 +55,8 @@ private void RotaryRotated(object sender, RotaryChangeResult e) private void DisplayPowerOnLed(float power) { // `0.0` - `1.0` - int r = (int)ExtensionMethods.Map(power, 0f, 1f, 0f, 255f); - int b = (int)ExtensionMethods.Map(power, 0f, 1f, 255f, 0f); + int r = (int)power.Map(0f, 1f, 0f, 255f); + int b = (int)power.Map(0f, 1f, 255f, 0f); var color = Color.FromRgb(r, 0, b); } diff --git a/Source/Meadow.Foundation.Peripherals/Motors.GpioStepper/Driver/Motors.GpioStepper.csproj b/Source/Meadow.Foundation.Peripherals/Motors.GpioStepper/Driver/Motors.GpioStepper.csproj index 1efb3759df..6e6a67a9af 100644 --- a/Source/Meadow.Foundation.Peripherals/Motors.GpioStepper/Driver/Motors.GpioStepper.csproj +++ b/Source/Meadow.Foundation.Peripherals/Motors.GpioStepper/Driver/Motors.GpioStepper.csproj @@ -22,6 +22,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/Motors.GpioStepper/Samples/GpioStepper_Sample/GpioStepper_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Motors.GpioStepper/Samples/GpioStepper_Sample/GpioStepper_Sample.csproj index 25dac4cc66..1ec5fd629a 100644 --- a/Source/Meadow.Foundation.Peripherals/Motors.GpioStepper/Samples/GpioStepper_Sample/GpioStepper_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Motors.GpioStepper/Samples/GpioStepper_Sample/GpioStepper_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Motors.Stepper.A4988/Driver/Motors.Stepper.A4988.csproj b/Source/Meadow.Foundation.Peripherals/Motors.Stepper.A4988/Driver/Motors.Stepper.A4988.csproj index 2934d1b6ff..6c5afb3a2c 100644 --- a/Source/Meadow.Foundation.Peripherals/Motors.Stepper.A4988/Driver/Motors.Stepper.A4988.csproj +++ b/Source/Meadow.Foundation.Peripherals/Motors.Stepper.A4988/Driver/Motors.Stepper.A4988.csproj @@ -22,6 +22,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/Motors.Stepper.A4988/Samples/A4988_Sample/A4988_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Motors.Stepper.A4988/Samples/A4988_Sample/A4988_Sample.csproj index 9b2ed1beca..2951b23017 100644 --- a/Source/Meadow.Foundation.Peripherals/Motors.Stepper.A4988/Samples/A4988_Sample/A4988_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Motors.Stepper.A4988/Samples/A4988_Sample/A4988_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Motors.Stepper.Uln2003/Driver/Motors.Stepper.Uln2003.csproj b/Source/Meadow.Foundation.Peripherals/Motors.Stepper.Uln2003/Driver/Motors.Stepper.Uln2003.csproj index 486f2a473f..10c377a1dd 100644 --- a/Source/Meadow.Foundation.Peripherals/Motors.Stepper.Uln2003/Driver/Motors.Stepper.Uln2003.csproj +++ b/Source/Meadow.Foundation.Peripherals/Motors.Stepper.Uln2003/Driver/Motors.Stepper.Uln2003.csproj @@ -22,6 +22,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/Motors.Stepper.Uln2003/Samples/Uln2003_Sample/Uln2003_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Motors.Stepper.Uln2003/Samples/Uln2003_Sample/Uln2003_Sample.csproj index 39a37871f1..2aff3b33a9 100644 --- a/Source/Meadow.Foundation.Peripherals/Motors.Stepper.Uln2003/Samples/Uln2003_Sample/Uln2003_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Motors.Stepper.Uln2003/Samples/Uln2003_Sample/Uln2003_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Motors.Tb67h420ftg/Driver/Motors.Tb67h420ftg.csproj b/Source/Meadow.Foundation.Peripherals/Motors.Tb67h420ftg/Driver/Motors.Tb67h420ftg.csproj index 4789900018..7bd1162412 100644 --- a/Source/Meadow.Foundation.Peripherals/Motors.Tb67h420ftg/Driver/Motors.Tb67h420ftg.csproj +++ b/Source/Meadow.Foundation.Peripherals/Motors.Tb67h420ftg/Driver/Motors.Tb67h420ftg.csproj @@ -24,6 +24,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/Motors.Tb67h420ftg/Samples/Tb67h420ftg_Encoder_Sample/Tb67h420ftg_Encoder_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Motors.Tb67h420ftg/Samples/Tb67h420ftg_Encoder_Sample/Tb67h420ftg_Encoder_Sample.csproj index cdc100747f..a5f0c2c10e 100644 --- a/Source/Meadow.Foundation.Peripherals/Motors.Tb67h420ftg/Samples/Tb67h420ftg_Encoder_Sample/Tb67h420ftg_Encoder_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Motors.Tb67h420ftg/Samples/Tb67h420ftg_Encoder_Sample/Tb67h420ftg_Encoder_Sample.csproj @@ -9,8 +9,8 @@ App - - - + + + diff --git a/Source/Meadow.Foundation.Peripherals/Motors.Tb67h420ftg/Samples/Tb67h420ftg_Sample/Tb67h420ftg_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Motors.Tb67h420ftg/Samples/Tb67h420ftg_Sample/Tb67h420ftg_Sample.csproj index 95b7784e9c..9b8793a2e1 100644 --- a/Source/Meadow.Foundation.Peripherals/Motors.Tb67h420ftg/Samples/Tb67h420ftg_Sample/Tb67h420ftg_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Motors.Tb67h420ftg/Samples/Tb67h420ftg_Sample/Tb67h420ftg_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/RTCs.Ds1307/Driver/Ds1307.cs b/Source/Meadow.Foundation.Peripherals/RTCs.Ds1307/Driver/Ds1307.cs index 82f2fdbec8..137e87b211 100644 --- a/Source/Meadow.Foundation.Peripherals/RTCs.Ds1307/Driver/Ds1307.cs +++ b/Source/Meadow.Foundation.Peripherals/RTCs.Ds1307/Driver/Ds1307.cs @@ -7,16 +7,15 @@ namespace Meadow.Foundation.RTCs /// /// Represents a DS1307 real-time clock /// - public partial class Ds1307 : II2cPeripheral + public partial class Ds1307 : II2cPeripheral, IRealTimeClock { /// /// The default I2C address for the peripheral /// public byte DefaultI2cAddress => (byte)Addresses.Default; - const int OriginYear = 1980; - - readonly II2cBus i2cBus; + private const int OriginYear = 1980; + private readonly II2cBus i2cBus; /// /// Create a new Ds1307 object @@ -67,7 +66,7 @@ public bool IsRunning /// Get the time from the real-time clock /// /// - public DateTime GetTime() + public DateTimeOffset GetTime() { var data = new byte[7]; i2cBus.Write((byte)Addresses.Default, new byte[] { 0 }); @@ -79,7 +78,7 @@ public DateTime GetTime() /// Set the time on the real-time clock /// /// The new time - public void SetTime(DateTime time) + public void SetTime(DateTimeOffset time) { var data = new List { 0 }; data.AddRange(ToRTCTime(time)); @@ -139,17 +138,17 @@ public void SquareWaveOutput(SquareWaveFrequency freq) i2cBus.Write((byte)Addresses.Default, new byte[] { 0x07, registerData }); //register and value } - static byte ToBCD(ushort i) + private static byte ToBCD(ushort i) { return (byte)((i % 10) + ((i / 10) * 0x10)); } - static ushort FromBCD(byte bcd) + private static ushort FromBCD(byte bcd) { return (ushort)(((bcd) & 0x0F) + (((bcd) >> 4) * 10)); } - static byte[] ToRTCTime(DateTime dt) + private static byte[] ToRTCTime(DateTimeOffset dt) { var data = new byte[7]; data[0] = ToBCD((ushort)dt.Second); @@ -162,7 +161,7 @@ static byte[] ToRTCTime(DateTime dt) return data; } - static DateTime FromRTCTime(byte[] rtcData) + private static DateTimeOffset FromRTCTime(byte[] rtcData) { try { // is the RTC in 12- or 24-hour mode? diff --git a/Source/Meadow.Foundation.Peripherals/RTCs.Ds1307/Driver/RTCs.Ds1307.csproj b/Source/Meadow.Foundation.Peripherals/RTCs.Ds1307/Driver/RTCs.Ds1307.csproj index 07123f5ad4..b72d90b565 100644 --- a/Source/Meadow.Foundation.Peripherals/RTCs.Ds1307/Driver/RTCs.Ds1307.csproj +++ b/Source/Meadow.Foundation.Peripherals/RTCs.Ds1307/Driver/RTCs.Ds1307.csproj @@ -15,13 +15,13 @@ http://developer.wildernesslabs.co/Meadow/Meadow.Foundation/ Meadow.Foundation.RTCs.Ds1307 https://github.com/WildernessLabs/Meadow.Foundation - Meadow, Meadow.Foundation, RTC + Meadow, Meadow.Foundation, RTC, DS1307 true DS1307 I2C real time clock - + diff --git a/Source/Meadow.Foundation.Peripherals/RTCs.Ds1307/Driver/Readme.md b/Source/Meadow.Foundation.Peripherals/RTCs.Ds1307/Driver/Readme.md index c7092ddb04..256bb6e27e 100644 --- a/Source/Meadow.Foundation.Peripherals/RTCs.Ds1307/Driver/Readme.md +++ b/Source/Meadow.Foundation.Peripherals/RTCs.Ds1307/Driver/Readme.md @@ -18,7 +18,7 @@ You can install the library from within Visual studio using the the NuGet Packag ## Usage ```csharp -Ds1307 rtc; +private Ds1307 rtc; public override Task Initialize() { @@ -31,7 +31,7 @@ public override Task Initialize() public override Task Run() { - var dateTime = new DateTime(); + var dateTime = new DateTimeOffset(); var running = rtc.IsRunning; Resolver.Log.Info($"{(running ? "is running" : "is not running")}"); diff --git a/Source/Meadow.Foundation.Peripherals/RTCs.Ds1307/Samples/Ds1307_Sample/Ds1307_Sample.csproj b/Source/Meadow.Foundation.Peripherals/RTCs.Ds1307/Samples/Ds1307_Sample/Ds1307_Sample.csproj index 8a8a9fec62..e06e05b34b 100644 --- a/Source/Meadow.Foundation.Peripherals/RTCs.Ds1307/Samples/Ds1307_Sample/Ds1307_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/RTCs.Ds1307/Samples/Ds1307_Sample/Ds1307_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/RTCs.Ds1307/Samples/Ds1307_Sample/MeadowApp.cs b/Source/Meadow.Foundation.Peripherals/RTCs.Ds1307/Samples/Ds1307_Sample/MeadowApp.cs index a7487eb431..8c59c6644b 100644 --- a/Source/Meadow.Foundation.Peripherals/RTCs.Ds1307/Samples/Ds1307_Sample/MeadowApp.cs +++ b/Source/Meadow.Foundation.Peripherals/RTCs.Ds1307/Samples/Ds1307_Sample/MeadowApp.cs @@ -10,7 +10,7 @@ public class MeadowApp : App { // - Ds1307 rtc; + private Ds1307 rtc; public override Task Initialize() { @@ -23,7 +23,7 @@ public override Task Initialize() public override Task Run() { - var dateTime = new DateTime(); + var dateTime = new DateTimeOffset(); var running = rtc.IsRunning; Resolver.Log.Info($"{(running ? "is running" : "is not running")}"); diff --git a/Source/Meadow.Foundation.Peripherals/RTCs.Ds323x/Datasheet/DS3232.pdf b/Source/Meadow.Foundation.Peripherals/RTCs.Ds323x/Datasheet/DS3232.pdf new file mode 100644 index 0000000000..185e9e2a2c Binary files /dev/null and b/Source/Meadow.Foundation.Peripherals/RTCs.Ds323x/Datasheet/DS3232.pdf differ diff --git a/Source/Meadow.Foundation.Peripherals/RTCs.Ds323x/Datasheet/DS3234.pdf b/Source/Meadow.Foundation.Peripherals/RTCs.Ds323x/Datasheet/DS3234.pdf deleted file mode 100644 index f6eae888c3..0000000000 Binary files a/Source/Meadow.Foundation.Peripherals/RTCs.Ds323x/Datasheet/DS3234.pdf and /dev/null differ diff --git a/Source/Meadow.Foundation.Peripherals/RTCs.Ds323x/Datasheet/DeadOn RTC - DS3234 Breakout-v11.pdf b/Source/Meadow.Foundation.Peripherals/RTCs.Ds323x/Datasheet/DeadOn RTC - DS3234 Breakout-v11.pdf deleted file mode 100644 index 5e2117b4ea..0000000000 Binary files a/Source/Meadow.Foundation.Peripherals/RTCs.Ds323x/Datasheet/DeadOn RTC - DS3234 Breakout-v11.pdf and /dev/null differ diff --git a/Source/Meadow.Foundation.Peripherals/RTCs.Ds323x/Driver/Ds3231.cs b/Source/Meadow.Foundation.Peripherals/RTCs.Ds323x/Driver/Drivers/Ds3231.cs similarity index 75% rename from Source/Meadow.Foundation.Peripherals/RTCs.Ds323x/Driver/Ds3231.cs rename to Source/Meadow.Foundation.Peripherals/RTCs.Ds323x/Driver/Drivers/Ds3231.cs index e6b29a0ea2..26538997e9 100644 --- a/Source/Meadow.Foundation.Peripherals/RTCs.Ds323x/Driver/Ds3231.cs +++ b/Source/Meadow.Foundation.Peripherals/RTCs.Ds323x/Driver/Drivers/Ds3231.cs @@ -3,12 +3,12 @@ namespace Meadow.Foundation.RTCs { /// - /// Create a new DS3231 Real Time Clock object. + /// Represents a Ds3231 real-time clock /// public partial class Ds3231 : Ds323x { /// - /// Create a new MAG3110 object using the default parameters for the component. + /// Create a new Ds3231 RTC object /// /// Digital pin connected to the alarm interrupt pin on the RTC. /// The I2C Bus the peripheral is connected to @@ -18,17 +18,16 @@ public Ds3231(II2cBus i2cBus, IPin? interruptPin = null, byte address = (byte)Ad { } /// - /// Create a new Ds3231 object using the default parameters for the component. + /// Create a new Ds3231 RTC object /// /// Address of the DS3231 (default = 0x68). /// The I2C Bus the peripheral is connected to /// Digital port connected to the alarm interrupt pin on the RTC. public Ds3231( II2cBus i2cBus, - IDigitalInterruptPort? interruptPort = null, - byte address = (byte)Addresses.Default) + IDigitalInterruptPort? interruptPort, + byte address) : base(new I2cCommunications(i2cBus, address), interruptPort) - { - } + { } } } \ No newline at end of file diff --git a/Source/Meadow.Foundation.Peripherals/RTCs.Ds323x/Driver/Drivers/Ds3232.cs b/Source/Meadow.Foundation.Peripherals/RTCs.Ds323x/Driver/Drivers/Ds3232.cs new file mode 100644 index 0000000000..4b30ba976b --- /dev/null +++ b/Source/Meadow.Foundation.Peripherals/RTCs.Ds323x/Driver/Drivers/Ds3232.cs @@ -0,0 +1,33 @@ +using Meadow.Hardware; + +namespace Meadow.Foundation.RTCs +{ + /// + /// Represents a Ds3232 real-time clock + /// + public partial class Ds3232 : Ds323x + { + /// + /// Create a new Ds3232 RTC object + /// + /// Digital pin connected to the alarm interrupt pin on the RTC. + /// The I2C Bus the peripheral is connected to + /// I2C Bus address of the peripheral + public Ds3232(II2cBus i2cBus, IPin? interruptPin = null, byte address = (byte)Addresses.Default) + : base(new I2cCommunications(i2cBus, address), interruptPin) + { } + + /// + /// Create a new Ds3232 RTC object + /// + /// Address of the DS3232 (default = 0x68). + /// The I2C Bus the peripheral is connected to + /// Digital port connected to the alarm interrupt pin on the RTC. + public Ds3232( + II2cBus i2cBus, + IDigitalInterruptPort? interruptPort = null, + byte address = (byte)Addresses.Default) + : base(new I2cCommunications(i2cBus, address), interruptPort) + { } + } +} \ No newline at end of file diff --git a/Source/Meadow.Foundation.Peripherals/RTCs.Ds323x/Driver/Ds323x.Registers.cs b/Source/Meadow.Foundation.Peripherals/RTCs.Ds323x/Driver/Ds323x.Registers.cs index bd95f825ab..299236b64b 100644 --- a/Source/Meadow.Foundation.Peripherals/RTCs.Ds323x/Driver/Ds323x.Registers.cs +++ b/Source/Meadow.Foundation.Peripherals/RTCs.Ds323x/Driver/Ds323x.Registers.cs @@ -1,31 +1,30 @@ -namespace Meadow.Foundation.RTCs +namespace Meadow.Foundation.RTCs; + +public partial class Ds323x { - public partial class Ds323x + /// + /// Register addresses in the sensor + /// + private static class Registers { - /// - /// Register addresses in the sensor - /// - static class Registers - { - public static readonly byte Seconds = 0x00; - public static readonly byte Minutes = 0x01; - public static readonly byte Hours = 0x02; - public static readonly byte Day = 0x03; - public static readonly byte Date = 0x04; - public static readonly byte Month = 0x05; - public static readonly byte Year = 0x06; - public static readonly byte Alarm1Seconds = 0x07; - public static readonly byte Alarm1Minutes = 0x08; - public static readonly byte Alarm1Hours = 0x09; - public static readonly byte Alarm1DayDate = 0x0a; - public static readonly byte Alarm2Minutes = 0x0b; - public static readonly byte Alarm2Hours = 0x0c; - public static readonly byte Alarm2DayDate = 0x0d; - public static readonly byte Control = 0x0e; - public static readonly byte ControlStatus = 0x0f; - public static readonly byte AgingOffset = 0x10; - public static readonly byte TemperatureMSB = 0x11; - public static readonly byte TemperatureLSB = 0x12; - } + public static readonly byte Seconds = 0x00; + public static readonly byte Minutes = 0x01; + public static readonly byte Hours = 0x02; + public static readonly byte Day = 0x03; + public static readonly byte Date = 0x04; + public static readonly byte Month = 0x05; + public static readonly byte Year = 0x06; + public static readonly byte Alarm1Seconds = 0x07; + public static readonly byte Alarm1Minutes = 0x08; + public static readonly byte Alarm1Hours = 0x09; + public static readonly byte Alarm1DayDate = 0x0a; + public static readonly byte Alarm2Minutes = 0x0b; + public static readonly byte Alarm2Hours = 0x0c; + public static readonly byte Alarm2DayDate = 0x0d; + public static readonly byte Control = 0x0e; + public static readonly byte ControlStatus = 0x0f; + public static readonly byte AgingOffset = 0x10; + public static readonly byte TemperatureMSB = 0x11; + public static readonly byte TemperatureLSB = 0x12; } } diff --git a/Source/Meadow.Foundation.Peripherals/RTCs.Ds323x/Driver/Ds323x.cs b/Source/Meadow.Foundation.Peripherals/RTCs.Ds323x/Driver/Ds323x.cs index 9e40d80e5d..8e15c1ac47 100644 --- a/Source/Meadow.Foundation.Peripherals/RTCs.Ds323x/Driver/Ds323x.cs +++ b/Source/Meadow.Foundation.Peripherals/RTCs.Ds323x/Driver/Ds323x.cs @@ -1,19 +1,28 @@ using Meadow.Foundation.Helpers; using Meadow.Hardware; +using Meadow.Units; using System; +using System.Threading.Tasks; namespace Meadow.Foundation.RTCs { /// - /// DS323X real-time clock + /// Base class for DS323x family of real-time clocks /// - public partial class Ds323x : II2cPeripheral, IDisposable + public partial class Ds323x : PollingSensorBase, IRealTimeClock, II2cPeripheral, IDisposable { /// /// The default I2C address for the peripheral /// public byte DefaultI2cAddress => (byte)Addresses.Default; + /// + public bool IsRunning + { + get => true; + set => throw new NotImplementedException(); + } + /// /// Is the object disposed /// @@ -74,68 +83,6 @@ public partial class Ds323x : II2cPeripheral, IDisposable private readonly Memory readBuffer; - /// - /// Create a new Ds323x object - /// - protected Ds323x(I2cCommunications i2cComms, IPin? interruptPin) - { - this.i2cComms = i2cComms; - - if (interruptPin != null) - { - var interruptPort = interruptPin.CreateDigitalInterruptPort(InterruptMode.EdgeFalling, ResistorMode.InternalPullUp, TimeSpan.FromMilliseconds(10), TimeSpan.FromMilliseconds(10)); - createdPort = true; - - Initialize(interruptPort); - } - - readBuffer = new byte[0x12]; - } - - /// - /// Create a new Ds323x object - /// - protected Ds323x(I2cCommunications i2cComms, IDigitalInterruptPort? interruptPort) - { - this.i2cComms = i2cComms; - - if (interruptPort != null) - { - Initialize(interruptPort); - } - } - - private void Initialize(IDigitalInterruptPort interruptPort) - { - switch (interruptPort.InterruptMode) - { - case InterruptMode.EdgeFalling: - case InterruptMode.EdgeBoth: - // we need a rising edge, so all good; - break; - default: - throw new DeviceConfigurationException("RTC alarms require a falling-edge enabled interrupt port"); - } - - InterruptPort = interruptPort; - InterruptPort.Changed += (s, cr) => - { - //Alarm interrupt has been raised, work out which one and raise the necessary event. - if ((alarm1Delegate != null) || (alarm2Delegate != null)) - { - var alarm = WhichAlarm; - if (((alarm == Alarm.Alarm1Raised) || (alarm == Alarm.BothAlarmsRaised)) && (alarm1Delegate != null)) - { - alarm1Delegate(this); - } - if (((alarm == Alarm.Alarm2Raised) || (alarm == Alarm.BothAlarmsRaised)) && (alarm2Delegate != null)) - { - alarm2Delegate(this); - } - } - }; - } - /// /// Delegate for the alarm events. /// @@ -188,33 +135,42 @@ public event AlarmRaised OnAlarm2Raised /// /// Get / Set the current date and time. /// - public DateTime CurrentDateTime + public DateTimeOffset CurrentDateTime { - get + get => GetTime(); + set => SetTime(value); + } + + /// + protected override Task ReadSensor() + { + var ctl = i2cComms.ReadRegister(Registers.Control); + ctl |= 1 << 5; + i2cComms.WriteRegister(Registers.Control, ctl); + + byte status; + + do { - var data = readBuffer.Span[0..DATE_TIME_REGISTERS_SIZE]; - i2cComms.ReadRegister(Registers.Seconds, data); - return DecodeDateTimeRegisters(data); - } - set + status = i2cComms.ReadRegister(Registers.ControlStatus); + } while ((status & (1 << 2)) != (1 << 2)); + + var data = readBuffer.Span[0..2]; + i2cComms.ReadRegister(Registers.TemperatureMSB, data); + if ((data[0] & 0x80) != 0) { - i2cComms.WriteRegister(Registers.Seconds, EncodeDateTimeRegisters(value)); + // negative + data[0] = (byte)(data[0] | ~((1 << 8) - 1)); } + + var temperature = 0.25 * (data[1] >> 6) + data[0]; + return Task.FromResult(new Temperature(temperature, Temperature.UnitType.Celsius)); } /// /// Get the current die temperature. /// - public Units.Temperature Temperature - { - get - { - var data = readBuffer.Span[0..2]; - i2cComms.ReadRegister(Registers.TemperatureMSB, data); - var temperature = (ushort)((data[0] << 2) | (data[1] >> 6)); - return new Units.Temperature(temperature * 0.25, Units.Temperature.UnitType.Celsius); - } - } + public Temperature Temperature => Conditions; /// /// I2C Communication bus used to communicate with the i2cComms @@ -279,12 +235,87 @@ protected Alarm WhichAlarm } /// - /// Decode the register contents and create a DateTime version of the - /// register contents. + /// Create a new Ds323x object + /// + protected Ds323x(I2cCommunications i2cComms, IPin? interruptPin) + { + this.i2cComms = i2cComms; + + if (interruptPin != null) + { + var interruptPort = interruptPin.CreateDigitalInterruptPort(InterruptMode.EdgeFalling, ResistorMode.InternalPullUp, TimeSpan.FromMilliseconds(10), TimeSpan.FromMilliseconds(10)); + createdPort = true; + + Initialize(interruptPort); + } + + readBuffer = new byte[0x12]; + } + + /// + /// Create a new Ds323x object + /// + protected Ds323x(I2cCommunications i2cComms, IDigitalInterruptPort? interruptPort) + { + this.i2cComms = i2cComms; + + if (interruptPort != null) + { + Initialize(interruptPort); + } + } + + private void Initialize(IDigitalInterruptPort interruptPort) + { + switch (interruptPort.InterruptMode) + { + case InterruptMode.EdgeFalling: + case InterruptMode.EdgeBoth: + // we need a rising edge, so all good; + break; + default: + throw new DeviceConfigurationException("RTC alarms require a falling-edge enabled interrupt port"); + } + + InterruptPort = interruptPort; + InterruptPort.Changed += (s, cr) => + { + //Alarm interrupt has been raised, work out which one and raise the necessary event. + if ((alarm1Delegate != null) || (alarm2Delegate != null)) + { + var alarm = WhichAlarm; + if (((alarm == Alarm.Alarm1Raised) || (alarm == Alarm.BothAlarmsRaised)) && (alarm1Delegate != null)) + { + alarm1Delegate(this); + } + if (((alarm == Alarm.Alarm2Raised) || (alarm == Alarm.BothAlarmsRaised)) && (alarm2Delegate != null)) + { + alarm2Delegate(this); + } + } + }; + } + + /// + public DateTimeOffset GetTime() + { + var data = readBuffer.Span[0..DATE_TIME_REGISTERS_SIZE]; + i2cComms.ReadRegister(Registers.Seconds, data); + return DecodeDateTimeRegisters(data); + } + + /// + public void SetTime(DateTimeOffset time) + { + i2cComms.WriteRegister(Registers.Seconds, EncodeDateTimeRegisters(time)); + } + + /// + /// Get the the date and time register contents /// /// Register contents. - /// DateTime object version of the data. - protected DateTime DecodeDateTimeRegisters(Span data) + /// DateTimeOffset object version of the data. + protected DateTimeOffset DecodeDateTimeRegisters(Span data) { var seconds = Converters.BCDToByte(data[0]); var minutes = Converters.BCDToByte(data[1]); @@ -310,7 +341,15 @@ protected DateTime DecodeDateTimeRegisters(Span data) { year += 100; } - return new DateTime(year, month, day, hour, minutes, seconds); + try + { + return new DateTime(year, month, day, hour, minutes, seconds); + } + catch + { + // uninitialized RTC will have zeros, which won't parse to a DateTimeOffset + return DateTime.MinValue; + } } /// @@ -318,7 +357,7 @@ protected DateTime DecodeDateTimeRegisters(Span data) /// /// DateTime object to encode. /// Bytes to send to the DS323x chip. - protected byte[] EncodeDateTimeRegisters(DateTime dt) + protected byte[] EncodeDateTimeRegisters(DateTimeOffset dt) { var data = new byte[7]; @@ -331,7 +370,7 @@ protected byte[] EncodeDateTimeRegisters(DateTime dt) if (dt.Year > 1999) { data[5] |= 0x80; - data[6] = Converters.ByteToBCD((byte)((dt.Year - 2000) & 0xff)); + data[6] = Converters.ByteToBCD((byte)((dt.Year - 2000) & 0xff)); } else { @@ -347,32 +386,7 @@ protected byte[] EncodeDateTimeRegisters(DateTime dt) /// Byte representation of the day of the week (Sunday = 1). protected byte DayOfWeekToByte(DayOfWeek day) { - byte result = 1; - switch (day) - { - case DayOfWeek.Sunday: - result = 1; - break; - case DayOfWeek.Monday: - result = 2; - break; - case DayOfWeek.Tuesday: - result = 3; - break; - case DayOfWeek.Wednesday: - result = 4; - break; - case DayOfWeek.Thursday: - result = 5; - break; - case DayOfWeek.Friday: - result = 6; - break; - case DayOfWeek.Saturday: - result = 7; - break; - } - return result; + return (byte)(day + 1); } /// @@ -381,7 +395,7 @@ protected byte DayOfWeekToByte(DayOfWeek day) /// Define the alarm to be set. /// Date and time for the alarm. /// Type of alarm to set. - public void SetAlarm(Alarm alarm, DateTime time, AlarmType type) + public void SetAlarm(Alarm alarm, DateTimeOffset time, AlarmType type) { byte[] data; var register = Registers.Alarm1Seconds; diff --git a/Source/Meadow.Foundation.Peripherals/RTCs.Ds323x/Driver/RTCs.Ds323x.csproj b/Source/Meadow.Foundation.Peripherals/RTCs.Ds323x/Driver/RTCs.Ds323x.csproj index 311778f5cb..f4e95fcf72 100644 --- a/Source/Meadow.Foundation.Peripherals/RTCs.Ds323x/Driver/RTCs.Ds323x.csproj +++ b/Source/Meadow.Foundation.Peripherals/RTCs.Ds323x/Driver/RTCs.Ds323x.csproj @@ -15,13 +15,13 @@ http://developer.wildernesslabs.co/Meadow/Meadow.Foundation/ Meadow.Foundation.RTCs.Ds323x https://github.com/WildernessLabs/Meadow.Foundation - Meadow.Foundation, RTC, Ds323x + Meadow.Foundation,RTC,Ds323x,DS3231,DS3232,DS3231M true - Ds323x I2C real time clock (DS3231) + Ds323x I2C family of real time clocks (DS3231, DS3231M, DS3232) - + diff --git a/Source/Meadow.Foundation.Peripherals/RTCs.Ds323x/Driver/Readme.md b/Source/Meadow.Foundation.Peripherals/RTCs.Ds323x/Driver/Readme.md index 2b6f9bd87c..e92baf0804 100644 --- a/Source/Meadow.Foundation.Peripherals/RTCs.Ds323x/Driver/Readme.md +++ b/Source/Meadow.Foundation.Peripherals/RTCs.Ds323x/Driver/Readme.md @@ -1,6 +1,6 @@ # Meadow.Foundation.RTCs.Ds323x -**Ds323x I2C real time clock (DS3231)** +**Ds323x I2C family of real time clocks (DS3231, DS3231M, DS3232)** The **Ds323x** library is included in the **Meadow.Foundation.RTCs.Ds323x** nuget package and is designed for the [Wilderness Labs](www.wildernesslabs.co) Meadow .NET IoT platform. @@ -20,6 +20,8 @@ You can install the library from within Visual studio using the the NuGet Packag ```csharp Ds3231 sensor; +readonly TimeSpan timezoneOffset = new TimeSpan(-7, 0, 0); + public override Task Initialize() { Resolver.Log.Info("Initialize..."); @@ -32,16 +34,16 @@ public override Task Initialize() public override Task Run() { - sensor.CurrentDateTime = new DateTime(2020, 1, 1); + sensor.CurrentDateTime = new DateTimeOffset(new DateTime(2024, 1, 1), timezoneOffset); Resolver.Log.Info($"Current time: {sensor.CurrentDateTime}"); Resolver.Log.Info($"Temperature: {sensor.Temperature}"); - sensor.ClearInterrupt(Ds323x.Alarm.BothAlarmsRaised); + sensor.ClearInterrupt(Ds3231.Alarm.BothAlarmsRaised); - sensor.SetAlarm(Ds323x.Alarm.Alarm1Raised, - new DateTime(2020, 1, 1, 1, 0, 0), - Ds323x.AlarmType.WhenSecondsMatch); + sensor.SetAlarm(Ds3231.Alarm.Alarm1Raised, + new DateTimeOffset(new DateTime(2024, 1, 1, 1, 0, 0), timezoneOffset), + Ds3231.AlarmType.WhenSecondsMatch); sensor.DisplayRegisters(); diff --git a/Source/Meadow.Foundation.Peripherals/RTCs.Ds323x/Samples/Ds323x_Sample/Ds323x_Sample.csproj b/Source/Meadow.Foundation.Peripherals/RTCs.Ds323x/Samples/Ds3231_Sample/Ds3231_Sample.csproj similarity index 87% rename from Source/Meadow.Foundation.Peripherals/RTCs.Ds323x/Samples/Ds323x_Sample/Ds323x_Sample.csproj rename to Source/Meadow.Foundation.Peripherals/RTCs.Ds323x/Samples/Ds3231_Sample/Ds3231_Sample.csproj index b943e7ce4b..c1b38c69a1 100644 --- a/Source/Meadow.Foundation.Peripherals/RTCs.Ds323x/Samples/Ds323x_Sample/Ds323x_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/RTCs.Ds323x/Samples/Ds3231_Sample/Ds3231_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/RTCs.Ds323x/Samples/Ds323x_Sample/MeadowApp.cs b/Source/Meadow.Foundation.Peripherals/RTCs.Ds323x/Samples/Ds3231_Sample/MeadowApp.cs similarity index 70% rename from Source/Meadow.Foundation.Peripherals/RTCs.Ds323x/Samples/Ds323x_Sample/MeadowApp.cs rename to Source/Meadow.Foundation.Peripherals/RTCs.Ds323x/Samples/Ds3231_Sample/MeadowApp.cs index 4fe9507ed5..f43f89799b 100644 --- a/Source/Meadow.Foundation.Peripherals/RTCs.Ds323x/Samples/Ds323x_Sample/MeadowApp.cs +++ b/Source/Meadow.Foundation.Peripherals/RTCs.Ds323x/Samples/Ds3231_Sample/MeadowApp.cs @@ -4,7 +4,7 @@ using System; using System.Threading.Tasks; -namespace RTCs.Ds323x_Sample +namespace RTCs.Ds3231_Sample { public class MeadowApp : App { @@ -12,6 +12,8 @@ public class MeadowApp : App Ds3231 sensor; + readonly TimeSpan timezoneOffset = new TimeSpan(-7, 0, 0); + public override Task Initialize() { Resolver.Log.Info("Initialize..."); @@ -24,16 +26,16 @@ public override Task Initialize() public override Task Run() { - sensor.CurrentDateTime = new DateTime(2020, 1, 1); + sensor.CurrentDateTime = new DateTimeOffset(new DateTime(2024, 1, 1), timezoneOffset); Resolver.Log.Info($"Current time: {sensor.CurrentDateTime}"); Resolver.Log.Info($"Temperature: {sensor.Temperature}"); - sensor.ClearInterrupt(Ds323x.Alarm.BothAlarmsRaised); + sensor.ClearInterrupt(Ds3231.Alarm.BothAlarmsRaised); - sensor.SetAlarm(Ds323x.Alarm.Alarm1Raised, - new DateTime(2020, 1, 1, 1, 0, 0), - Ds323x.AlarmType.WhenSecondsMatch); + sensor.SetAlarm(Ds3231.Alarm.Alarm1Raised, + new DateTimeOffset(new DateTime(2024, 1, 1, 1, 0, 0), timezoneOffset), + Ds3231.AlarmType.WhenSecondsMatch); sensor.DisplayRegisters(); diff --git a/Source/Meadow.Foundation.Peripherals/RTCs.Ds323x/Samples/Ds3232_Sample/Ds3232_Sample.csproj b/Source/Meadow.Foundation.Peripherals/RTCs.Ds323x/Samples/Ds3232_Sample/Ds3232_Sample.csproj new file mode 100644 index 0000000000..c1b38c69a1 --- /dev/null +++ b/Source/Meadow.Foundation.Peripherals/RTCs.Ds323x/Samples/Ds3232_Sample/Ds3232_Sample.csproj @@ -0,0 +1,15 @@ + + + https://github.com/WildernessLabs/Meadow.Foundation + Wilderness Labs, Inc + Wilderness Labs, Inc + true + netstandard2.1 + Library + App + + + + + + diff --git a/Source/Meadow.Foundation.Peripherals/RTCs.Ds323x/Samples/Ds3232_Sample/MeadowApp.cs b/Source/Meadow.Foundation.Peripherals/RTCs.Ds323x/Samples/Ds3232_Sample/MeadowApp.cs new file mode 100644 index 0000000000..424eb57511 --- /dev/null +++ b/Source/Meadow.Foundation.Peripherals/RTCs.Ds323x/Samples/Ds3232_Sample/MeadowApp.cs @@ -0,0 +1,54 @@ +using Meadow; +using Meadow.Devices; +using Meadow.Foundation.RTCs; +using System; +using System.Threading.Tasks; + +namespace RTCs.Ds3232_Sample +{ + public class MeadowApp : App + { + // + + Ds3232 sensor; + + readonly TimeSpan timezoneOffset = new TimeSpan(-7, 0, 0); + + public override Task Initialize() + { + Resolver.Log.Info("Initialize..."); + + sensor = new Ds3232(Device.CreateI2cBus(), Device.Pins.D06); + sensor.OnAlarm1Raised += Sensor_OnAlarm1Raised; + + return base.Initialize(); + } + + public override Task Run() + { + sensor.CurrentDateTime = new DateTimeOffset(new DateTime(2024, 1, 1), timezoneOffset); + + Resolver.Log.Info($"Current time: {sensor.CurrentDateTime}"); + Resolver.Log.Info($"Temperature: {sensor.Temperature}"); + + sensor.ClearInterrupt(Ds3232.Alarm.BothAlarmsRaised); + + sensor.SetAlarm(Ds3232.Alarm.Alarm1Raised, + new DateTimeOffset(new DateTime(2024, 1, 1, 1, 0, 0), timezoneOffset), + Ds3232.AlarmType.WhenSecondsMatch); + + sensor.DisplayRegisters(); + + return base.Run(); + } + + private void Sensor_OnAlarm1Raised(object sender) + { + var rtc = (Ds3232)sender; + Resolver.Log.Info("Alarm 1 has been activated: " + rtc.CurrentDateTime.ToString("dd MMM yyyy HH:mm:ss")); + rtc.ClearInterrupt(Ds323x.Alarm.Alarm1Raised); + } + + // + } +} \ No newline at end of file diff --git a/Source/Meadow.Foundation.Peripherals/RTCs.Pcf8523/Datasheet/PCF8523.pdf b/Source/Meadow.Foundation.Peripherals/RTCs.Pcf8523/Datasheet/PCF8523.pdf new file mode 100644 index 0000000000..7547867483 Binary files /dev/null and b/Source/Meadow.Foundation.Peripherals/RTCs.Pcf8523/Datasheet/PCF8523.pdf differ diff --git a/Source/Meadow.Foundation.Peripherals/RTCs.Pcf8523/Driver/Pcf8523.Enums.cs b/Source/Meadow.Foundation.Peripherals/RTCs.Pcf8523/Driver/Pcf8523.Enums.cs new file mode 100644 index 0000000000..2f732c385e --- /dev/null +++ b/Source/Meadow.Foundation.Peripherals/RTCs.Pcf8523/Driver/Pcf8523.Enums.cs @@ -0,0 +1,43 @@ +namespace Meadow.Foundation.RTCs; + +internal enum Registers : byte +{ + Control_1 = 0x00, + Control_2 = 0x01, + Control_3 = 0x02, + Seconds = 0x03, + Minutes = 0x04, + Hours = 0x05, + Days = 0x06, + Weekdays = 0x07, + Months = 0x08, + Years = 0x09, + MinuteAlarm = 0x0A, + HourAlarm = 0x0B, + DayAlarm = 0x0C, + Weekday_Alarm = 0x0D, + Offset = 0x0E, + Tmr_CLKOUT_ctrl = 0x0F, + Tmr_A_freq_ctrl = 0x10, + Tmr_A_reg = 0x11, + Tmr_B_freq_ctrl = 0x12, + Tmr_B_reg = 0x13, +} + +public partial class Pcf8523 +{ + /// + /// Valid I2C addresses for the sensor + /// + public enum Addresses : byte + { + /// + /// Bus address 0x68 + /// + Address_0x68 = 0x68, + /// + /// Default bus address + /// + Default = Address_0x68 + } +} \ No newline at end of file diff --git a/Source/Meadow.Foundation.Peripherals/RTCs.Pcf8523/Driver/Pcf8523.cs b/Source/Meadow.Foundation.Peripherals/RTCs.Pcf8523/Driver/Pcf8523.cs new file mode 100644 index 0000000000..d6a7e66981 --- /dev/null +++ b/Source/Meadow.Foundation.Peripherals/RTCs.Pcf8523/Driver/Pcf8523.cs @@ -0,0 +1,136 @@ +using Meadow.Hardware; +using System; + +namespace Meadow.Foundation.RTCs; + +/// +/// Represents a PCF8523 real-time clock +/// +public partial class Pcf8523 : II2cPeripheral, IRealTimeClock, IBatteryBackedPeripheral +{ + /// + /// The default I2C address for the peripheral + /// + public byte DefaultI2cAddress => (byte)Addresses.Default; + + private const int OriginYear = 1980; + private byte[] txBuffer = new byte[20]; + private byte[] rxBuffer = new byte[20]; + + private I2cCommunications i2CCommunications; + + /// + /// Creates a new Pcf8523 object + /// + /// The I2C bus + public Pcf8523(II2cBus i2cBus) + { + this.i2CCommunications = new I2cCommunications(i2cBus, (byte)Addresses.Default, 20); + Initialize(); + } + + private void Initialize() + { + // put the device into 24-hour mode + var reg = i2CCommunications.ReadRegister((byte)Registers.Control_1); + reg = (byte)(reg & ~(1 << 3)); + i2CCommunications.WriteRegister((byte)Registers.Control_1, reg); + + // make sure we're in battery state monitor mode, direct switching on + i2CCommunications.WriteRegister((byte)Registers.Control_3, 0x20); + } + + /// + /// Reads the battery low indicator register bit + /// + public bool IsBatteryLow() + { + var reg = i2CCommunications.ReadRegister((byte)Registers.Control_3); + var low = (reg & (1 << 2)) != 0; + return low; + } + + /// + public bool IsRunning + { + get + { + var reg = i2CCommunications.ReadRegister((byte)Registers.Control_1); + return (reg & (1 << 5)) == 0; + } + set + { + var reg = i2CCommunications.ReadRegister((byte)Registers.Control_1); + if (value) + { + reg = (byte)(reg & ~(1 << 5)); + } + else + { + reg = (byte)(reg | ~(1 << 5)); + } + i2CCommunications.WriteRegister((byte)Registers.Control_1, reg); + } + } + + /// + public DateTimeOffset GetTime() + { + // read 10 bytes + i2CCommunications.ReadRegister((byte)Registers.Control_1, rxBuffer.AsSpan()[..10]); + + return RTCTimeToDateTimeOffset(rxBuffer, 0x03); + } + + private DateTimeOffset RTCTimeToDateTimeOffset(Span rtcRegisters, int startOffset) + { + // TODO: check MSB of second register + // clock integrity is not guaranteed; oscillator has stopped or been interrupted + + var y = FromBCD(rtcRegisters[startOffset + 6]) + 2000; + var m = FromBCD(rtcRegisters[startOffset + 5]); + var dow = FromBCD(rtcRegisters[startOffset + 4]); + var d = FromBCD(rtcRegisters[startOffset + 3]); + var h = FromBCD(rtcRegisters[startOffset + 2]); + var min = FromBCD(rtcRegisters[startOffset + 1]); + var s = FromBCD((byte)(rtcRegisters[startOffset + 0] & 0x7f)); + + try + { + return new DateTime(y, m, d, h, min, s); + } + catch + { + return DateTimeOffset.MinValue; + } + } + + private void DateTimeOffsetToRTCTime(DateTimeOffset dt, Span destination, int offset) + { + destination[offset + 0] = ToBCD((ushort)dt.Second); + destination[offset + 1] = ToBCD((ushort)dt.Minute); + destination[offset + 2] = ToBCD((ushort)dt.Hour); + destination[offset + 3] = ToBCD((ushort)dt.Day); + destination[offset + 4] = ToBCD((ushort)(int)dt.DayOfWeek); + destination[offset + 5] = ToBCD((ushort)dt.Month); + destination[offset + 6] = ToBCD((ushort)(dt.Year - 2000)); + } + + /// + public void SetTime(DateTimeOffset time) + { + txBuffer[0] = (byte)Registers.Seconds; + DateTimeOffsetToRTCTime(time, txBuffer, 1); + i2CCommunications.Write(txBuffer); + } + + private static byte ToBCD(ushort i) + { + return (byte)((i % 10) + ((i / 10) * 0x10)); + } + + private static ushort FromBCD(byte bcd) + { + return (ushort)(((bcd) & 0x0F) + (((bcd) >> 4) * 10)); + } +} \ No newline at end of file diff --git a/Source/Meadow.Foundation.Peripherals/RTCs.Pcf8523/Driver/RTCs.Pcf8523.csproj b/Source/Meadow.Foundation.Peripherals/RTCs.Pcf8523/Driver/RTCs.Pcf8523.csproj new file mode 100644 index 0000000000..4eae261a97 --- /dev/null +++ b/Source/Meadow.Foundation.Peripherals/RTCs.Pcf8523/Driver/RTCs.Pcf8523.csproj @@ -0,0 +1,25 @@ + + + 1.11.0 + enable + 10.0 + Apache-2.0 + true + icon.png + Wilderness Labs, Inc + netstandard2.1 + Library + Pcf8523 + Wilderness Labs, Inc + http://developer.wildernesslabs.co/Meadow/Meadow.Foundation/ + Meadow.Foundation.RTCs.Pcf8523 + https://github.com/WildernessLabs/Meadow.Foundation + Meadow, Meadow.Foundation, RTC, Pcf8523 + true + Pcf8523 I2C real time clock + + + + + + diff --git a/Source/Meadow.Foundation.Peripherals/RTCs.Pcf8523/Driver/Readme.md b/Source/Meadow.Foundation.Peripherals/RTCs.Pcf8523/Driver/Readme.md new file mode 100644 index 0000000000..6eaaa26006 --- /dev/null +++ b/Source/Meadow.Foundation.Peripherals/RTCs.Pcf8523/Driver/Readme.md @@ -0,0 +1,85 @@ +# Meadow.Foundation.RTCs.Pcf8523 + +**Pcf8523 I2C real time clock** + +The **Pcf8523** library is included in the **Meadow.Foundation.RTCs.Pcf8523** nuget package and is designed for the [Wilderness Labs](www.wildernesslabs.co) Meadow .NET IoT platform. + +This driver is part of the [Meadow.Foundation](https://developer.wildernesslabs.co/Meadow/Meadow.Foundation/) peripherals library, an open-source repository of drivers and libraries that streamline and simplify adding hardware to your C# .NET Meadow IoT applications. + +For more information on developing for Meadow, visit [developer.wildernesslabs.co](http://developer.wildernesslabs.co/). + +To view all Wilderness Labs open-source projects, including samples, visit [github.com/wildernesslabs](https://github.com/wildernesslabs/). + +## Installation + +You can install the library from within Visual studio using the the NuGet Package Manager or from the command line using the .NET CLI: + +`dotnet add package Meadow.Foundation.RTCs.Pcf8523` +## Usage + +```csharp +private Pcf8523 rtc; + +public override Task Initialize() +{ + Resolver.Log.Info("Initializing..."); + + rtc = new Pcf8523(Device.CreateI2cBus()); + + return base.Initialize(); +} + +public override Task Run() +{ + var dateTime = new DateTimeOffset(); + var running = rtc.IsRunning; + + Resolver.Log.Info($"{(running ? "is running" : "is not running")}"); + + if (!running) + { + Resolver.Log.Info(" Starting RTC..."); + rtc.IsRunning = true; + } + + dateTime = rtc.GetTime(); + Resolver.Log.Info($" RTC current time is: {dateTime.ToString("MM/dd/yy HH:mm:ss")}"); + + Resolver.Log.Info($" Setting RTC to : {dateTime.ToString("MM/dd/yy HH:mm:ss")}"); + dateTime = new DateTime(2030, 2, 15); + rtc.SetTime(dateTime); + + dateTime = rtc.GetTime(); + Resolver.Log.Info($" RTC current time is: {dateTime.ToString("MM/dd/yy HH:mm:ss")}"); + + return base.Run(); +} + +``` +## How to Contribute + +- **Found a bug?** [Report an issue](https://github.com/WildernessLabs/Meadow_Issues/issues) +- Have a **feature idea or driver request?** [Open a new feature request](https://github.com/WildernessLabs/Meadow_Issues/issues) +- Want to **contribute code?** Fork the [Meadow.Foundation](https://github.com/WildernessLabs/Meadow.Foundation) repository and submit a pull request against the `develop` branch + + +## Need Help? + +If you have questions or need assistance, please join the Wilderness Labs [community on Slack](http://slackinvite.wildernesslabs.co/). +## About Meadow + +Meadow is a complete, IoT platform with defense-grade security that runs full .NET applications on embeddable microcontrollers and Linux single-board computers including Raspberry Pi and NVIDIA Jetson. + +### Build + +Use the full .NET platform and tooling such as Visual Studio and plug-and-play hardware drivers to painlessly build IoT solutions. + +### Connect + +Utilize native support for WiFi, Ethernet, and Cellular connectivity to send sensor data to the Cloud and remotely control your peripherals. + +### Deploy + +Instantly deploy and manage your fleet in the cloud for OtA, health-monitoring, logs, command + control, and enterprise backend integrations. + + diff --git a/Source/Meadow.Foundation.Peripherals/RTCs.Pcf8523/Samples/Pcf8523_Sample/MeadowApp.cs b/Source/Meadow.Foundation.Peripherals/RTCs.Pcf8523/Samples/Pcf8523_Sample/MeadowApp.cs new file mode 100644 index 0000000000..03f4eabc80 --- /dev/null +++ b/Source/Meadow.Foundation.Peripherals/RTCs.Pcf8523/Samples/Pcf8523_Sample/MeadowApp.cs @@ -0,0 +1,52 @@ +using Meadow; +using Meadow.Devices; +using Meadow.Foundation.RTCs; +using System; +using System.Threading.Tasks; + +namespace RTCs.Pcf8523_Sample +{ + public class MeadowApp : App + { + // + + private Pcf8523 rtc; + + public override Task Initialize() + { + Resolver.Log.Info("Initializing..."); + + rtc = new Pcf8523(Device.CreateI2cBus()); + + return base.Initialize(); + } + + public override Task Run() + { + var dateTime = new DateTimeOffset(); + var running = rtc.IsRunning; + + Resolver.Log.Info($"{(running ? "is running" : "is not running")}"); + + if (!running) + { + Resolver.Log.Info(" Starting RTC..."); + rtc.IsRunning = true; + } + + dateTime = rtc.GetTime(); + Resolver.Log.Info($" RTC current time is: {dateTime.ToString("MM/dd/yy HH:mm:ss")}"); + + Resolver.Log.Info($" Setting RTC to : {dateTime.ToString("MM/dd/yy HH:mm:ss")}"); + dateTime = new DateTime(2030, 2, 15); + rtc.SetTime(dateTime); + + dateTime = rtc.GetTime(); + Resolver.Log.Info($" RTC current time is: {dateTime.ToString("MM/dd/yy HH:mm:ss")}"); + + return base.Run(); + } + + // + } +} \ No newline at end of file diff --git a/Source/Meadow.Foundation.Peripherals/RTCs.Pcf8523/Samples/Pcf8523_Sample/Pcf8523_Sample.csproj b/Source/Meadow.Foundation.Peripherals/RTCs.Pcf8523/Samples/Pcf8523_Sample/Pcf8523_Sample.csproj new file mode 100644 index 0000000000..e853845a55 --- /dev/null +++ b/Source/Meadow.Foundation.Peripherals/RTCs.Pcf8523/Samples/Pcf8523_Sample/Pcf8523_Sample.csproj @@ -0,0 +1,15 @@ + + + https://github.com/WildernessLabs/Meadow.Foundation + Wilderness Labs, Inc + Wilderness Labs, Inc + true + netstandard2.1 + Library + App + + + + + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.AdafruitMPRLS/Driver/Sensors.Atmospheric.AdafruitMPRLS.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.AdafruitMPRLS/Driver/Sensors.Atmospheric.AdafruitMPRLS.csproj index 8de652edf5..4abd4414f7 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.AdafruitMPRLS/Driver/Sensors.Atmospheric.AdafruitMPRLS.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.AdafruitMPRLS/Driver/Sensors.Atmospheric.AdafruitMPRLS.csproj @@ -22,6 +22,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.AdafruitMPRLS/Samples/AdafruitMPRLS_Sample/AdafruitMPRLS_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.AdafruitMPRLS/Samples/AdafruitMPRLS_Sample/AdafruitMPRLS_Sample.csproj index 6fef156b11..35b9f5057d 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.AdafruitMPRLS/Samples/AdafruitMPRLS_Sample/AdafruitMPRLS_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.AdafruitMPRLS/Samples/AdafruitMPRLS_Sample/AdafruitMPRLS_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Ahtx0/Datasheet/Aosong_AHT10.pdf b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Ahtx0/Datasheet/Aosong_AHT10.pdf new file mode 100644 index 0000000000..391bd00a5d Binary files /dev/null and b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Ahtx0/Datasheet/Aosong_AHT10.pdf differ diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Ahtx0/Datasheet/Data-Sheet-AHT20-Humidity-and-Temperature-Sensor-ASAIR-V1.0.03.pdf b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Ahtx0/Datasheet/Data-Sheet-AHT20-Humidity-and-Temperature-Sensor-ASAIR-V1.0.03.pdf new file mode 100644 index 0000000000..86cc200770 Binary files /dev/null and b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Ahtx0/Datasheet/Data-Sheet-AHT20-Humidity-and-Temperature-Sensor-ASAIR-V1.0.03.pdf differ diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Ahtx0/Driver/Ahtx0.Addresses.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Ahtx0/Driver/Ahtx0.Addresses.cs new file mode 100644 index 0000000000..bcd53b5654 --- /dev/null +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Ahtx0/Driver/Ahtx0.Addresses.cs @@ -0,0 +1,23 @@ +namespace Meadow.Foundation.Sensors.Atmospheric; + +public partial class Ahtx0 +{ + /// + /// Valid I2C addresses for the sensor + /// + public enum Addresses : byte + { + /// + /// Bus address 0x38 + /// + Address_0x38 = 0x38, + /// + /// Bus address 0x39 + /// + Address_0x39 = 0x39, + /// + /// Default bus address + /// + Default = Address_0x38 + } +} diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Ahtx0/Driver/Ahtx0.Registers.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Ahtx0/Driver/Ahtx0.Registers.cs new file mode 100644 index 0000000000..c8277418d3 --- /dev/null +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Ahtx0/Driver/Ahtx0.Registers.cs @@ -0,0 +1,14 @@ +namespace Meadow.Foundation.Sensors.Atmospheric; + +public partial class Ahtx0 +{ + /// + /// Ahtx0 Commands + /// + internal enum Commands : byte + { + INITIALIZE = 0b111_0001, + TRIGGER_MEAS = 0b1010_1100, + SOFT_RESET = 0b1011_1010 + } +} diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Ahtx0/Driver/Ahtx0.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Ahtx0/Driver/Ahtx0.cs new file mode 100644 index 0000000000..be51cfb3f2 --- /dev/null +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Ahtx0/Driver/Ahtx0.cs @@ -0,0 +1,139 @@ +using Meadow.Hardware; +using Meadow.Peripherals.Sensors; +using Meadow.Peripherals.Sensors.Atmospheric; +using Meadow.Units; +using System; +using System.Threading.Tasks; + +namespace Meadow.Foundation.Sensors.Atmospheric; + + +/// +/// Ahtx0 Temperature sensor object +/// +public abstract partial class Ahtx0 : + ByteCommsSensorBase<(RelativeHumidity? Humidity, Units.Temperature? Temperature)>, + ITemperatureSensor, IHumiditySensor, II2cPeripheral +{ + private bool isInitialized = false; + + private event EventHandler> temperatureHandlers = default!; + private event EventHandler> humidityHandlers = default!; + + event EventHandler> ISamplingSensor.Updated + { + add => temperatureHandlers += value; + remove => temperatureHandlers -= value; + } + + event EventHandler> ISamplingSensor.Updated + { + add => humidityHandlers += value; + remove => humidityHandlers -= value; + } + + /// + /// The default I2C address for the peripheral + /// + public byte DefaultI2cAddress => (byte)Addresses.Default; + + /// + public Units.Temperature? Temperature { get; protected set; } + + /// + public Units.RelativeHumidity? Humidity { get; protected set; } + + /// + /// Create a new Ahtx0 object using the default configuration for the sensor + /// + /// The I2C bus + /// I2C address of the sensor + public Ahtx0(II2cBus i2cBus, byte address = (byte)Addresses.Default) + : base(i2cBus, address, readBufferSize: 7) + { + } + + /// + /// Raise all change events for subscribers + /// + /// humidity and temperature + protected override void RaiseEventsAndNotify(IChangeResult<(Units.RelativeHumidity? Humidity, Units.Temperature? Temperature)> changeResult) + { + if (changeResult.New.Humidity is { } humidity) + { + humidityHandlers?.Invoke(this, new ChangeResult(humidity, changeResult.Old?.Humidity)); + } + if (changeResult.New.Temperature is { } temperature) + { + temperatureHandlers?.Invoke(this, new ChangeResult(temperature, changeResult.Old?.Temperature)); + } + base.RaiseEventsAndNotify(changeResult); + } + + private async Task InitializeIfRequired() + { + if (isInitialized) { return; } + + BusComms.Write((byte)Commands.SOFT_RESET); + await Task.Delay(20); + + while (IsBusy()) + { + await Task.Delay(10); + } + + BusComms.Write(new byte[] { (byte)Commands.INITIALIZE, 0x08, 0x00 }); + + while (IsBusy()) + { + await Task.Delay(10); + } + + BusComms.Read(ReadBuffer.Span[0..1]); + + isInitialized = true; + } + + private bool IsBusy() + { + BusComms.Read(ReadBuffer.Span[0..1]); + return (ReadBuffer.Span[0] & 0x80) == 0x80; + } + + /// + /// Reads the humidity and temperature. + /// + protected override async Task<(Units.RelativeHumidity?, Units.Temperature?)> ReadSensor() + { + (Units.RelativeHumidity? Humidity, Units.Temperature? Temperature) conditions; + + await InitializeIfRequired(); + + BusComms.Write(new byte[] { (byte)Commands.TRIGGER_MEAS, 0x33, 0x00 }); + await Task.Delay(80); + + while (IsBusy()) + { + await Task.Delay(10); + } + + BusComms.Read(ReadBuffer.Span); + + var data = ReadBuffer.ToArray(); + Resolver.Log.Info(BitConverter.ToString(data)); + + var humidity = (data[1] << 12) | (data[2] << 4) | (data[3] >> 4); + conditions.Humidity = new RelativeHumidity((humidity / (double)0x100000) * 100d, RelativeHumidity.UnitType.Percent); + + var temp = ((data[3] & 0x0f) << 16) | (data[4] << 8) | data[5]; + conditions.Temperature = new Units.Temperature((temp / (double)0x100000) * 200d - 50d, Units.Temperature.UnitType.Celsius); + + return conditions; + } + + async Task ISensor.Read() + => (await Read()).Temperature!.Value; + + async Task ISensor.Read() + => (await Read()).Humidity!.Value; +} \ No newline at end of file diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Ahtx0/Driver/Drivers/Aht10.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Ahtx0/Driver/Drivers/Aht10.cs new file mode 100644 index 0000000000..b4592567c0 --- /dev/null +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Ahtx0/Driver/Drivers/Aht10.cs @@ -0,0 +1,19 @@ +using Meadow.Hardware; + +namespace Meadow.Foundation.Sensors.Atmospheric; + +/// +/// Aht10 Temperature sensor object +/// +public class Aht10 : Ahtx0 +{ + /// + /// Create a new Aht10 object using the default configuration for the sensor + /// + /// The I2C bus + /// I2C address of the sensor + public Aht10(II2cBus i2cBus, byte address = 56) + : base(i2cBus, address) + { + } +} diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Ahtx0/Driver/Drivers/Aht20.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Ahtx0/Driver/Drivers/Aht20.cs new file mode 100644 index 0000000000..37b4489d18 --- /dev/null +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Ahtx0/Driver/Drivers/Aht20.cs @@ -0,0 +1,19 @@ +using Meadow.Hardware; + +namespace Meadow.Foundation.Sensors.Atmospheric; + +/// +/// Aht20 Temperature sensor object +/// +public class Aht20 : Ahtx0 +{ + /// + /// Create a new Aht20 object using the default configuration for the sensor + /// + /// The I2C bus + /// I2C address of the sensor + public Aht20(II2cBus i2cBus, byte address = 56) + : base(i2cBus, address) + { + } +} diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Ahtx0/Driver/Readme.md b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Ahtx0/Driver/Readme.md new file mode 100644 index 0000000000..707976513c --- /dev/null +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Ahtx0/Driver/Readme.md @@ -0,0 +1,87 @@ +# Meadow.Foundation.Sensors.Atmospheric.Ahtx0 + +**AHTx0 I2C temperature and humidity sensors** + +The **Ahtx0** library is included in the **Meadow.Foundation.Sensors.Atmospheric.Ahtx0** nuget package and is designed for the [Wilderness Labs](www.wildernesslabs.co) Meadow .NET IoT platform. + +This driver is part of the [Meadow.Foundation](https://developer.wildernesslabs.co/Meadow/Meadow.Foundation/) peripherals library, an open-source repository of drivers and libraries that streamline and simplify adding hardware to your C# .NET Meadow IoT applications. + +For more information on developing for Meadow, visit [developer.wildernesslabs.co](http://developer.wildernesslabs.co/). + +To view all Wilderness Labs open-source projects, including samples, visit [github.com/wildernesslabs](https://github.com/wildernesslabs/). + +## Installation + +You can install the library from within Visual studio using the the NuGet Package Manager or from the command line using the .NET CLI: + +`dotnet add package Meadow.Foundation.Sensors.Atmospheric.Ahtx0` +## Usage + +```csharp +private Ahtx0 sensor; + +public override Task Initialize() +{ + Resolver.Log.Info("Initialize..."); + + // adjust the index to match your hardware configuration + var ft232 = FtdiExpanderCollection.Devices[0]; + + sensor = new Aht10(ft232.CreateI2cBus()); + + var consumer = Aht10.CreateObserver( + handler: (result) => + { + Resolver.Log.Info($"Observer: Temp changed by threshold; new temp: {result.New.Temperature?.Celsius:N2}C, old: {result.Old?.Temperature?.Celsius:N2}C"); + }, + filter: null + ); + sensor.Subscribe(consumer); + + (sensor as ITemperatureSensor).Updated += (sender, e) => + { + Resolver.Log.Info($"Temperature Updated: {e.New.Celsius:n2}C"); + }; + return Task.CompletedTask; +} + +public override async Task Run() +{ + if (sensor == null) { return; } + + var result = await sensor.Read(); + Resolver.Log.Info("Initial Readings:"); + Resolver.Log.Info($" Temperature: {result.Temperature?.Celsius:F1}°C"); + Resolver.Log.Info($" Relative Humidity: {result.Humidity:F1}%"); + + sensor.StartUpdating(TimeSpan.FromSeconds(1)); +} + +``` +## How to Contribute + +- **Found a bug?** [Report an issue](https://github.com/WildernessLabs/Meadow_Issues/issues) +- Have a **feature idea or driver request?** [Open a new feature request](https://github.com/WildernessLabs/Meadow_Issues/issues) +- Want to **contribute code?** Fork the [Meadow.Foundation](https://github.com/WildernessLabs/Meadow.Foundation) repository and submit a pull request against the `develop` branch + + +## Need Help? + +If you have questions or need assistance, please join the Wilderness Labs [community on Slack](http://slackinvite.wildernesslabs.co/). +## About Meadow + +Meadow is a complete, IoT platform with defense-grade security that runs full .NET applications on embeddable microcontrollers and Linux single-board computers including Raspberry Pi and NVIDIA Jetson. + +### Build + +Use the full .NET platform and tooling such as Visual Studio and plug-and-play hardware drivers to painlessly build IoT solutions. + +### Connect + +Utilize native support for WiFi, Ethernet, and Cellular connectivity to send sensor data to the Cloud and remotely control your peripherals. + +### Deploy + +Instantly deploy and manage your fleet in the cloud for OtA, health-monitoring, logs, command + control, and enterprise backend integrations. + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Ahtx0/Driver/Sensors.Atmospheric.Ahtx0.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Ahtx0/Driver/Sensors.Atmospheric.Ahtx0.csproj new file mode 100644 index 0000000000..069a7e83c4 --- /dev/null +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Ahtx0/Driver/Sensors.Atmospheric.Ahtx0.csproj @@ -0,0 +1,28 @@ + + + 1.11.0 + true + icon.png + Wilderness Labs, Inc + netstandard2.1 + Library + Ahtx0 + Wilderness Labs, Inc + http://developer.wildernesslabs.co/Meadow/Meadow.Foundation/ + Meadow.Foundation.Sensors.Atmospheric.Ahtx0 + https://github.com/WildernessLabs/Meadow.Foundation + Meadow.Foundation, Temperature, AHT10, AHT20 + true + AHTx0 I2C temperature and humidity sensors + enable + Meadow.Foundation.Sensors.Atmospheric + + + Apache-2.0 + 10.0 + + + + + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Ahtx0/Samples/Aht10_Desktop_Sample/Aht10_Desktop_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Ahtx0/Samples/Aht10_Desktop_Sample/Aht10_Desktop_Sample.csproj new file mode 100644 index 0000000000..39b353f0e9 --- /dev/null +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Ahtx0/Samples/Aht10_Desktop_Sample/Aht10_Desktop_Sample.csproj @@ -0,0 +1,16 @@ + + + + Exe + net8.0 + enable + 10 + + + + + + + + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Ahtx0/Samples/Aht10_Desktop_Sample/MeadowApp.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Ahtx0/Samples/Aht10_Desktop_Sample/MeadowApp.cs new file mode 100644 index 0000000000..cc41b8e2fe --- /dev/null +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Ahtx0/Samples/Aht10_Desktop_Sample/MeadowApp.cs @@ -0,0 +1,59 @@ +using Meadow; +using Meadow.Foundation.ICs.IOExpanders; +using Meadow.Foundation.Sensors.Atmospheric; +using Meadow.Peripherals.Sensors; +using System; +using System.Threading.Tasks; + +namespace Sensors.Temperature.Aht10_Sample; + +public class MeadowApp : App +{ + public static async Task Main(string[] args) + { + await MeadowOS.Start(args); + } + + // + + private Ahtx0 sensor; + + public override Task Initialize() + { + Resolver.Log.Info("Initialize..."); + + // adjust the index to match your hardware configuration + var ft232 = FtdiExpanderCollection.Devices[0]; + + sensor = new Aht10(ft232.CreateI2cBus()); + + var consumer = Aht10.CreateObserver( + handler: (result) => + { + Resolver.Log.Info($"Observer: Temp changed by threshold; new temp: {result.New.Temperature?.Celsius:N2}C, old: {result.Old?.Temperature?.Celsius:N2}C"); + }, + filter: null + ); + sensor.Subscribe(consumer); + + (sensor as ITemperatureSensor).Updated += (sender, e) => + { + Resolver.Log.Info($"Temperature Updated: {e.New.Celsius:n2}C"); + }; + return Task.CompletedTask; + } + + public override async Task Run() + { + if (sensor == null) { return; } + + var result = await sensor.Read(); + Resolver.Log.Info("Initial Readings:"); + Resolver.Log.Info($" Temperature: {result.Temperature?.Celsius:F1}°C"); + Resolver.Log.Info($" Relative Humidity: {result.Humidity:F1}%"); + + sensor.StartUpdating(TimeSpan.FromSeconds(1)); + } + + // +} \ No newline at end of file diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Ahtx0/Samples/Aht10_Sample/Aht10_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Ahtx0/Samples/Aht10_Sample/Aht10_Sample.csproj new file mode 100644 index 0000000000..fdd43f1206 --- /dev/null +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Ahtx0/Samples/Aht10_Sample/Aht10_Sample.csproj @@ -0,0 +1,16 @@ + + + https://github.com/WildernessLabs/Meadow.Foundation + Wilderness Labs, Inc + Wilderness Labs, Inc + true + netstandard2.1 + Library + App + 10 + + + + + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Ahtx0/Samples/Aht10_Sample/MeadowApp.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Ahtx0/Samples/Aht10_Sample/MeadowApp.cs new file mode 100644 index 0000000000..86ee81b3ac --- /dev/null +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Ahtx0/Samples/Aht10_Sample/MeadowApp.cs @@ -0,0 +1,58 @@ +using Meadow; +using Meadow.Devices; +using Meadow.Foundation.Sensors.Atmospheric; +using Meadow.Peripherals.Sensors; +using System; +using System.Threading.Tasks; + +namespace Sensors.Temperature.Aht10_Sample; + +public class FeatherV1App : MeadowApp { } +public class FeatherV2App : MeadowApp { } +public class CoreComputApp : MeadowApp { } + +public class MeadowApp : App + where T : F7MicroBase +{ + // + + private Ahtx0 sensor; + + public override Task Initialize() + { + Resolver.Log.Info("Initialize..."); + + sensor = new Aht10(Device.CreateI2cBus()); + + var consumer = Aht10.CreateObserver( + handler: (result) => + { + Resolver.Log.Info($"Observer: Temp changed by threshold; new temp: {result.New.Temperature?.Celsius:N2}C, old: {result.Old?.Temperature?.Celsius:N2}C"); + }, + filter: null + ); + sensor.Subscribe(consumer); + + (sensor as ITemperatureSensor).Updated += (sender, e) => + { + Resolver.Log.Info($"Temperature Updated: {e.New.Celsius:n2}C"); + }; + return Task.CompletedTask; + } + + public override async Task Run() + { + Resolver.Log.Info("Run..."); + + if (sensor == null) { return; } + + var result = await sensor.Read(); + Resolver.Log.Info("Initial Readings:"); + Resolver.Log.Info($" Temperature: {result.Temperature?.Celsius:F1}°C"); + Resolver.Log.Info($" Relative Humidity: {result.Humidity:F1}%"); + + sensor.StartUpdating(TimeSpan.FromSeconds(1)); + } + + // +} \ No newline at end of file diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Bh1900Nux/Driver/Sensors.Atmospheric.Bh1900Nux.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Bh1900Nux/Driver/Sensors.Atmospheric.Bh1900Nux.csproj index b8c45dd2f6..c84e23132b 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Bh1900Nux/Driver/Sensors.Atmospheric.Bh1900Nux.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Bh1900Nux/Driver/Sensors.Atmospheric.Bh1900Nux.csproj @@ -26,6 +26,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Bh1900Nux/Samples/Bh1900Nux_Sample/Bh1900Nux_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Bh1900Nux/Samples/Bh1900Nux_Sample/Bh1900Nux_Sample.csproj index a067fb1e7c..346a348d79 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Bh1900Nux/Samples/Bh1900Nux_Sample/Bh1900Nux_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Bh1900Nux/Samples/Bh1900Nux_Sample/Bh1900Nux_Sample.csproj @@ -12,7 +12,7 @@ 8.0 - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Bme68x/Driver/Sensors.Atmospheric.Bme68x.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Bme68x/Driver/Sensors.Atmospheric.Bme68x.csproj index dfed5802e7..306455cda3 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Bme68x/Driver/Sensors.Atmospheric.Bme68x.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Bme68x/Driver/Sensors.Atmospheric.Bme68x.csproj @@ -24,6 +24,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Bme68x/Samples/Bme680_Sample/Bme680_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Bme68x/Samples/Bme680_Sample/Bme680_Sample.csproj index 78cfc545e2..222662b249 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Bme68x/Samples/Bme680_Sample/Bme680_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Bme68x/Samples/Bme680_Sample/Bme680_Sample.csproj @@ -13,7 +13,7 @@ 8.0 - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Bme68x/Samples/Bme688_Sample/Bme688_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Bme68x/Samples/Bme688_Sample/Bme688_Sample.csproj index 78cfc545e2..222662b249 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Bme68x/Samples/Bme688_Sample/Bme688_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Bme68x/Samples/Bme688_Sample/Bme688_Sample.csproj @@ -13,7 +13,7 @@ 8.0 - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Bmp085/Driver/Sensors.Atmospheric.Bmp085.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Bmp085/Driver/Sensors.Atmospheric.Bmp085.csproj index c4cfa0fdff..20a86ae2da 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Bmp085/Driver/Sensors.Atmospheric.Bmp085.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Bmp085/Driver/Sensors.Atmospheric.Bmp085.csproj @@ -24,6 +24,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Bmp085/Samples/Bmp085_Sample/Bmp085_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Bmp085/Samples/Bmp085_Sample/Bmp085_Sample.csproj index 9a665f5054..efe445c20f 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Bmp085/Samples/Bmp085_Sample/Bmp085_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Bmp085/Samples/Bmp085_Sample/Bmp085_Sample.csproj @@ -11,7 +11,7 @@ 10.0 - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Bmp180/Driver/Sensors.Atmospheric.Bmp180.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Bmp180/Driver/Sensors.Atmospheric.Bmp180.csproj index f35c47eea0..c5b26cbe87 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Bmp180/Driver/Sensors.Atmospheric.Bmp180.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Bmp180/Driver/Sensors.Atmospheric.Bmp180.csproj @@ -22,6 +22,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Bmp180/Samples/Bmp180_Sample/Bmp180_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Bmp180/Samples/Bmp180_Sample/Bmp180_Sample.csproj index ee15da2291..3a012efde6 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Bmp180/Samples/Bmp180_Sample/Bmp180_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Bmp180/Samples/Bmp180_Sample/Bmp180_Sample.csproj @@ -10,7 +10,7 @@ 10.0 - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Bmx280/Driver/Sensors.Atmospheric.Bmx280.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Bmx280/Driver/Sensors.Atmospheric.Bmx280.csproj index b43988a05c..9a511279dd 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Bmx280/Driver/Sensors.Atmospheric.Bmx280.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Bmx280/Driver/Sensors.Atmospheric.Bmx280.csproj @@ -26,6 +26,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Bmx280/Samples/Bme280_Sample/Bme280_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Bmx280/Samples/Bme280_Sample/Bme280_Sample.csproj index 603cef6e23..1f9be65d25 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Bmx280/Samples/Bme280_Sample/Bme280_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Bmx280/Samples/Bme280_Sample/Bme280_Sample.csproj @@ -10,7 +10,7 @@ 10 - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Bmx280/Samples/Bme280_VB_Sample/Bme280_VB_Sample.vbproj b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Bmx280/Samples/Bme280_VB_Sample/Bme280_VB_Sample.vbproj index 6d1eb3cfe6..36bb4ef9dd 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Bmx280/Samples/Bme280_VB_Sample/Bme280_VB_Sample.vbproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Bmx280/Samples/Bme280_VB_Sample/Bme280_VB_Sample.vbproj @@ -6,7 +6,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Bmx280/Samples/Bmp280_Sample/Bmp280_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Bmx280/Samples/Bmp280_Sample/Bmp280_Sample.csproj index 68ae311dec..f40eb5d8d0 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Bmx280/Samples/Bmp280_Sample/Bmp280_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Bmx280/Samples/Bmp280_Sample/Bmp280_Sample.csproj @@ -12,7 +12,7 @@ 8.0 - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Ccs811/Driver/Sensors.Atmospheric.Ccs811.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Ccs811/Driver/Sensors.Atmospheric.Ccs811.csproj index bc18be8866..7bcf3eca17 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Ccs811/Driver/Sensors.Atmospheric.Ccs811.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Ccs811/Driver/Sensors.Atmospheric.Ccs811.csproj @@ -24,6 +24,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Ccs811/Samples/Ccs811_Sample/Ccs811_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Ccs811/Samples/Ccs811_Sample/Ccs811_Sample.csproj index 2be6af975a..367067be78 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Ccs811/Samples/Ccs811_Sample/Ccs811_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Ccs811/Samples/Ccs811_Sample/Ccs811_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Dhtxx/Driver/Sensors.Atmospheric.Dhtxx.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Dhtxx/Driver/Sensors.Atmospheric.Dhtxx.csproj index 9663c8e78c..9b7e253e0c 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Dhtxx/Driver/Sensors.Atmospheric.Dhtxx.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Dhtxx/Driver/Sensors.Atmospheric.Dhtxx.csproj @@ -24,6 +24,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Dhtxx/Samples/Dht10_Sample/Dht10_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Dhtxx/Samples/Dht10_Sample/Dht10_Sample.csproj index ee03762ea5..9beac7eb2b 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Dhtxx/Samples/Dht10_Sample/Dht10_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Dhtxx/Samples/Dht10_Sample/Dht10_Sample.csproj @@ -13,7 +13,7 @@ 8.0 - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Dhtxx/Samples/Dht12_Sample/Dht12_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Dhtxx/Samples/Dht12_Sample/Dht12_Sample.csproj index ee03762ea5..9beac7eb2b 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Dhtxx/Samples/Dht12_Sample/Dht12_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Dhtxx/Samples/Dht12_Sample/Dht12_Sample.csproj @@ -13,7 +13,7 @@ 8.0 - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Hc2/Driver/Hc2.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Hc2/Driver/Hc2.cs index 00f1ee36f8..05b9158873 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Hc2/Driver/Hc2.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Hc2/Driver/Hc2.cs @@ -31,7 +31,7 @@ event EventHandler> ISamplingSensor /// The current relative humidity /// - public Units.RelativeHumidity? Humidity { get; protected set; } + public Units.RelativeHumidity? Humidity => Conditions.Humidity; /// /// The current temperature diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Hc2/Driver/Sensors.Atmospheric.Hc2.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Hc2/Driver/Sensors.Atmospheric.Hc2.csproj index ac1e3f6677..57b5e8d0db 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Hc2/Driver/Sensors.Atmospheric.Hc2.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Hc2/Driver/Sensors.Atmospheric.Hc2.csproj @@ -24,6 +24,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Hc2/Samples/Hc2_Sample/Hc2_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Hc2/Samples/Hc2_Sample/Hc2_Sample.csproj index 316d41ec2b..869cf0e51b 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Hc2/Samples/Hc2_Sample/Hc2_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Hc2/Samples/Hc2_Sample/Hc2_Sample.csproj @@ -12,7 +12,7 @@ 10.0 - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Hih6130/Driver/Sensors.Atmospheric.Hih6130.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Hih6130/Driver/Sensors.Atmospheric.Hih6130.csproj index 611fdb0f32..1f65d8e00c 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Hih6130/Driver/Sensors.Atmospheric.Hih6130.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Hih6130/Driver/Sensors.Atmospheric.Hih6130.csproj @@ -22,6 +22,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Hih6130/Samples/Hih6130_Sample/Hih6130_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Hih6130/Samples/Hih6130_Sample/Hih6130_Sample.csproj index e71f61399c..6677a443fc 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Hih6130/Samples/Hih6130_Sample/Hih6130_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Hih6130/Samples/Hih6130_Sample/Hih6130_Sample.csproj @@ -11,7 +11,7 @@ 10.0 - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Htu2xd/Driver/Sensors.Atmospheric.Htux1d.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Htu2xd/Driver/Sensors.Atmospheric.Htux1d.csproj index 52abd238dc..7a20ae1332 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Htu2xd/Driver/Sensors.Atmospheric.Htux1d.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Htu2xd/Driver/Sensors.Atmospheric.Htux1d.csproj @@ -24,6 +24,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Htu2xd/Samples/Htu21d_Sample/Htu21d_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Htu2xd/Samples/Htu21d_Sample/Htu21d_Sample.csproj index e4d634890f..14a87d0898 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Htu2xd/Samples/Htu21d_Sample/Htu21d_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Htu2xd/Samples/Htu21d_Sample/Htu21d_Sample.csproj @@ -13,7 +13,7 @@ 9.0 - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Htu2xd/Samples/Htu31d_Sample/Htu31d_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Htu2xd/Samples/Htu31d_Sample/Htu31d_Sample.csproj index e4d634890f..14a87d0898 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Htu2xd/Samples/Htu31d_Sample/Htu31d_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Htu2xd/Samples/Htu31d_Sample/Htu31d_Sample.csproj @@ -13,7 +13,7 @@ 9.0 - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Mpl3115a2/Driver/Sensors.Atmospheric.Mpl3115a2.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Mpl3115a2/Driver/Sensors.Atmospheric.Mpl3115a2.csproj index c59bef6ec5..910426fecd 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Mpl3115a2/Driver/Sensors.Atmospheric.Mpl3115a2.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Mpl3115a2/Driver/Sensors.Atmospheric.Mpl3115a2.csproj @@ -23,6 +23,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Mpl3115a2/Samples/Mpl3115a2_Sample/Mpl3115a2_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Mpl3115a2/Samples/Mpl3115a2_Sample/Mpl3115a2_Sample.csproj index 37b02046ae..200e26b2f9 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Mpl3115a2/Samples/Mpl3115a2_Sample/Mpl3115a2_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Mpl3115a2/Samples/Mpl3115a2_Sample/Mpl3115a2_Sample.csproj @@ -11,7 +11,7 @@ 10.0 - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Ms5611/Driver/Sensors.Atmospheric.Ms5611.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Ms5611/Driver/Sensors.Atmospheric.Ms5611.csproj index 6b1d1e145f..231bd5c45f 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Ms5611/Driver/Sensors.Atmospheric.Ms5611.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Ms5611/Driver/Sensors.Atmospheric.Ms5611.csproj @@ -22,6 +22,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Ms5611/Samples/Ms5611_Sample/Ms5611_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Ms5611/Samples/Ms5611_Sample/Ms5611_Sample.csproj index 685ed8dcad..b30e89ca5c 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Ms5611/Samples/Ms5611_Sample/Ms5611_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Ms5611/Samples/Ms5611_Sample/Ms5611_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Sgp40/Driver/Readme.md b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Sgp40/Driver/Readme.md index 9ac1055c3e..1b9e54a05c 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Sgp40/Driver/Readme.md +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Sgp40/Driver/Readme.md @@ -37,17 +37,13 @@ public override Task Initialize() Resolver.Log.Warn("Self test failed"); } - var consumer = Sgp40.CreateObserver( - handler: result => - { - Resolver.Log.Info($"Observer: VOC changed by threshold; new index: {result.New}"); - }, - filter: result => - { - return Math.Abs(result.New - result.Old ?? 0) > 10; - } - ); - sensor.Subscribe(consumer); + var consumer = Sgp40.CreateObserver( + handler: result => + { + Resolver.Log.Info($"Observer: VOC changed by threshold; new index: {result.New}"); + }, + filter: result => Math.Abs(result.New - result.Old ?? 0) > 10); + sensor.Subscribe(consumer); sensor.Updated += (sender, result) => { diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Sgp40/Driver/Sensors.Atmospheric.Sgp40.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Sgp40/Driver/Sensors.Atmospheric.Sgp40.csproj index a49267077b..fd8ec8f3dc 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Sgp40/Driver/Sensors.Atmospheric.Sgp40.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Sgp40/Driver/Sensors.Atmospheric.Sgp40.csproj @@ -24,6 +24,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Sgp40/Samples/Sgp40_Sample/MeadowApp.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Sgp40/Samples/Sgp40_Sample/MeadowApp.cs index 042c1ccfff..dca799394d 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Sgp40/Samples/Sgp40_Sample/MeadowApp.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Sgp40/Samples/Sgp40_Sample/MeadowApp.cs @@ -29,17 +29,13 @@ public override Task Initialize() Resolver.Log.Warn("Self test failed"); } - var consumer = Sgp40.CreateObserver( - handler: result => - { - Resolver.Log.Info($"Observer: VOC changed by threshold; new index: {result.New}"); - }, - filter: result => - { - return Math.Abs(result.New - result.Old ?? 0) > 10; - } - ); - sensor.Subscribe(consumer); + var consumer = Sgp40.CreateObserver( + handler: result => + { + Resolver.Log.Info($"Observer: VOC changed by threshold; new index: {result.New}"); + }, + filter: result => Math.Abs(result.New - result.Old ?? 0) > 10); + sensor.Subscribe(consumer); sensor.Updated += (sender, result) => { diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Sgp40/Samples/Sgp40_Sample/Sgp40_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Sgp40/Samples/Sgp40_Sample/Sgp40_Sample.csproj index 3a2d9a72a4..7b10636d78 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Sgp40/Samples/Sgp40_Sample/Sgp40_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Sgp40/Samples/Sgp40_Sample/Sgp40_Sample.csproj @@ -11,7 +11,7 @@ 10.0 - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Sht31D/Driver/Sensors.Atmospheric.Sht31d.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Sht31D/Driver/Sensors.Atmospheric.Sht31d.csproj index c5734d72b5..d8b2d7b56f 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Sht31D/Driver/Sensors.Atmospheric.Sht31d.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Sht31D/Driver/Sensors.Atmospheric.Sht31d.csproj @@ -24,6 +24,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Sht31d/Samples/Sht31d_Sample/Sht31d_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Sht31d/Samples/Sht31d_Sample/Sht31d_Sample.csproj index a640ec255e..69e7ac6a78 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Sht31d/Samples/Sht31d_Sample/Sht31d_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Sht31d/Samples/Sht31d_Sample/Sht31d_Sample.csproj @@ -10,7 +10,7 @@ 10.0 - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Sht4x/Driver/Sensors.Atmospheric.Sht4x.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Sht4x/Driver/Sensors.Atmospheric.Sht4x.csproj index c95a45549d..147f1b5446 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Sht4x/Driver/Sensors.Atmospheric.Sht4x.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Sht4x/Driver/Sensors.Atmospheric.Sht4x.csproj @@ -24,6 +24,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Sht4x/Samples/Sht4x_Sample/Sht4x_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Sht4x/Samples/Sht4x_Sample/Sht4x_Sample.csproj index 52104bb086..ce634f08a0 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Sht4x/Samples/Sht4x_Sample/Sht4x_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Sht4x/Samples/Sht4x_Sample/Sht4x_Sample.csproj @@ -12,7 +12,7 @@ 9.0 - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Si70xx/Driver/Sensors.Atmospheric.Si70xx.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Si70xx/Driver/Sensors.Atmospheric.Si70xx.csproj index e4eb8846d4..a8ecc5d8c8 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Si70xx/Driver/Sensors.Atmospheric.Si70xx.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Si70xx/Driver/Sensors.Atmospheric.Si70xx.csproj @@ -22,6 +22,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Si70xx/Samples/Si70xx_Sample/Si70xx_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Si70xx/Samples/Si70xx_Sample/Si70xx_Sample.csproj index 77527179b6..99cc33172a 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Si70xx/Samples/Si70xx_Sample/Si70xx_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Si70xx/Samples/Si70xx_Sample/Si70xx_Sample.csproj @@ -11,7 +11,7 @@ 10.0 - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Th02/Driver/Sensors.Atmospheric.Th02.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Th02/Driver/Sensors.Atmospheric.Th02.csproj index f06f3b45ea..e403ab9e67 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Th02/Driver/Sensors.Atmospheric.Th02.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Th02/Driver/Sensors.Atmospheric.Th02.csproj @@ -24,6 +24,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Th02/Samples/Th02_Sample/Th02_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Th02/Samples/Th02_Sample/Th02_Sample.csproj index b5a45d07b8..935c198fda 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Th02/Samples/Th02_Sample/Th02_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Th02/Samples/Th02_Sample/Th02_Sample.csproj @@ -10,7 +10,7 @@ 10.0 - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Camera.Amg8833/Driver/Sensors.Camera.Amg8833.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Camera.Amg8833/Driver/Sensors.Camera.Amg8833.csproj index be1d809cfe..9de5175d53 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Camera.Amg8833/Driver/Sensors.Camera.Amg8833.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Camera.Amg8833/Driver/Sensors.Camera.Amg8833.csproj @@ -22,6 +22,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Camera.Amg8833/Samples/Amg8833_Sample/Amg8833_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Camera.Amg8833/Samples/Amg8833_Sample/Amg8833_Sample.csproj index 2cdcaeb23e..4ab67edf3e 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Camera.Amg8833/Samples/Amg8833_Sample/Amg8833_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Camera.Amg8833/Samples/Amg8833_Sample/Amg8833_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Camera.Mlx90640/Driver/Sensors.Camera.Mlx90640.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Camera.Mlx90640/Driver/Sensors.Camera.Mlx90640.csproj index b4585f9180..4cf23109ad 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Camera.Mlx90640/Driver/Sensors.Camera.Mlx90640.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Camera.Mlx90640/Driver/Sensors.Camera.Mlx90640.csproj @@ -22,6 +22,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Camera.Mlx90640/Samples/Mlx90640_Sample/Mlx90640_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Camera.Mlx90640/Samples/Mlx90640_Sample/Mlx90640_Sample.csproj index ff8d20d274..1340308920 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Camera.Mlx90640/Samples/Mlx90640_Sample/Mlx90640_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Camera.Mlx90640/Samples/Mlx90640_Sample/Mlx90640_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Camera.Vc0706/Driver/Sensors.Camera.Vc0706.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Camera.Vc0706/Driver/Sensors.Camera.Vc0706.csproj index 85a3c6d433..1cf7fad73b 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Camera.Vc0706/Driver/Sensors.Camera.Vc0706.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Camera.Vc0706/Driver/Sensors.Camera.Vc0706.csproj @@ -22,6 +22,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Camera.Vc0706/Samples/Vc0706_Sample/Vc0706_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Camera.Vc0706/Samples/Vc0706_Sample/Vc0706_Sample.csproj index ce67a17837..7cafd91ad6 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Camera.Vc0706/Samples/Vc0706_Sample/Vc0706_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Camera.Vc0706/Samples/Vc0706_Sample/Vc0706_Sample.csproj @@ -12,7 +12,7 @@ - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Distance.A02yyuw/Driver/A02yyuw.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Distance.A02yyuw/Driver/A02yyuw.cs index 5d9f3f1350..3118d2ec06 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Distance.A02yyuw/Driver/A02yyuw.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Distance.A02yyuw/Driver/A02yyuw.cs @@ -15,7 +15,7 @@ public class A02yyuw : PollingSensorBase, IRangeFinder, ISleepAwarePerip /// /// Distance from sensor to object /// - public Length? Distance { get; protected set; } + public Length? Distance => Conditions; /// /// Value returned when the sensor cannot determine the distance diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Distance.A02yyuw/Driver/Sensors.Distance.A02yyuw.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Distance.A02yyuw/Driver/Sensors.Distance.A02yyuw.csproj index 47d3be959c..9661f81470 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Distance.A02yyuw/Driver/Sensors.Distance.A02yyuw.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Distance.A02yyuw/Driver/Sensors.Distance.A02yyuw.csproj @@ -22,6 +22,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Distance.A02yyuw/Samples/A02yyuw_Sample/A02yyuw_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Distance.A02yyuw/Samples/A02yyuw_Sample/A02yyuw_Sample.csproj index e518268c06..c7293d9000 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Distance.A02yyuw/Samples/A02yyuw_Sample/A02yyuw_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Distance.A02yyuw/Samples/A02yyuw_Sample/A02yyuw_Sample.csproj @@ -6,7 +6,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Distance.Hcsr04/Driver/Sensors.Distance.Hcsr04.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Distance.Hcsr04/Driver/Sensors.Distance.Hcsr04.csproj index 566bae0eaa..4f64e6c59f 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Distance.Hcsr04/Driver/Sensors.Distance.Hcsr04.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Distance.Hcsr04/Driver/Sensors.Distance.Hcsr04.csproj @@ -22,6 +22,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Distance.Hcsr04/Samples/Hcsr04_Sample/Hcsr04_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Distance.Hcsr04/Samples/Hcsr04_Sample/Hcsr04_Sample.csproj index 6b41dc3372..466ec67898 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Distance.Hcsr04/Samples/Hcsr04_Sample/Hcsr04_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Distance.Hcsr04/Samples/Hcsr04_Sample/Hcsr04_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Distance.MaxBotix/Driver/Sensors.Distance.MaxBotix.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Distance.MaxBotix/Driver/Sensors.Distance.MaxBotix.csproj index a3ec8774b5..17a9b662d7 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Distance.MaxBotix/Driver/Sensors.Distance.MaxBotix.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Distance.MaxBotix/Driver/Sensors.Distance.MaxBotix.csproj @@ -22,6 +22,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Distance.MaxBotix/Samples/MaxBotix_Sample/MaxBotix_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Distance.MaxBotix/Samples/MaxBotix_Sample/MaxBotix_Sample.csproj index c2bb8d19ff..f5a852eccf 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Distance.MaxBotix/Samples/MaxBotix_Sample/MaxBotix_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Distance.MaxBotix/Samples/MaxBotix_Sample/MaxBotix_Sample.csproj @@ -6,7 +6,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Distance.Me007ys/Driver/Me007ys.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Distance.Me007ys/Driver/Me007ys.cs index 25281bcb32..4fe3dd97fa 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Distance.Me007ys/Driver/Me007ys.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Distance.Me007ys/Driver/Me007ys.cs @@ -15,7 +15,7 @@ public class Me007ys : PollingSensorBase, IRangeFinder, ISleepAwarePerip /// /// Distance from sensor to object /// - public Length? Distance { get; protected set; } + public Length? Distance => Conditions; /// /// Value returned when the sensor cannot determine the distance diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Distance.Me007ys/Driver/Sensors.Distance.Me007ys.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Distance.Me007ys/Driver/Sensors.Distance.Me007ys.csproj index c20229bd92..3710be80ec 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Distance.Me007ys/Driver/Sensors.Distance.Me007ys.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Distance.Me007ys/Driver/Sensors.Distance.Me007ys.csproj @@ -22,6 +22,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Distance.Me007ys/Samples/Me007ys_Sample/Me007ys_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Distance.Me007ys/Samples/Me007ys_Sample/Me007ys_Sample.csproj index d76a3085b5..2f02610b4d 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Distance.Me007ys/Samples/Me007ys_Sample/Me007ys_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Distance.Me007ys/Samples/Me007ys_Sample/Me007ys_Sample.csproj @@ -6,7 +6,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Distance.Vl53l0x/Driver/Sensors.Distance.Vl53l0x.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Distance.Vl53l0x/Driver/Sensors.Distance.Vl53l0x.csproj index fe38ee2ca5..ef2a3ab6b9 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Distance.Vl53l0x/Driver/Sensors.Distance.Vl53l0x.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Distance.Vl53l0x/Driver/Sensors.Distance.Vl53l0x.csproj @@ -22,6 +22,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Distance.Vl53l0x/Samples/Vl53l0x_Sample/Vl53l0x_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Distance.Vl53l0x/Samples/Vl53l0x_Sample/Vl53l0x_Sample.csproj index 65372696d8..f795f090bd 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Distance.Vl53l0x/Samples/Vl53l0x_Sample/Vl53l0x_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Distance.Vl53l0x/Samples/Vl53l0x_Sample/Vl53l0x_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.Ags01Db/Driver/Sensors.Environmental.Ags01Db.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.Ags01Db/Driver/Sensors.Environmental.Ags01Db.csproj index 8a810452b6..c6c6337e10 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.Ags01Db/Driver/Sensors.Environmental.Ags01Db.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.Ags01Db/Driver/Sensors.Environmental.Ags01Db.csproj @@ -22,6 +22,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.Ags01Db/Samples/Ags01Db_Sample/Ags01Db_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.Ags01Db/Samples/Ags01Db_Sample/Ags01Db_Sample.csproj index 2ac2df0086..a5cfba09e6 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.Ags01Db/Samples/Ags01Db_Sample/Ags01Db_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.Ags01Db/Samples/Ags01Db_Sample/Ags01Db_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.AtlasScientificGravityDOMeter/Driver/Sensors.Environmental.AtlasScientificGravityDOMeter.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.AtlasScientificGravityDOMeter/Driver/Sensors.Environmental.AtlasScientificGravityDOMeter.csproj index ceef609955..3b626216fb 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.AtlasScientificGravityDOMeter/Driver/Sensors.Environmental.AtlasScientificGravityDOMeter.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.AtlasScientificGravityDOMeter/Driver/Sensors.Environmental.AtlasScientificGravityDOMeter.csproj @@ -22,6 +22,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.AtlasScientificGravityDOMeter/Samples/AtlasScientificGravityDOMeter_Sample/AtlasScientificGravityDOMeter_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.AtlasScientificGravityDOMeter/Samples/AtlasScientificGravityDOMeter_Sample/AtlasScientificGravityDOMeter_Sample.csproj index ecf74cdbed..e7d188ae99 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.AtlasScientificGravityDOMeter/Samples/AtlasScientificGravityDOMeter_Sample/AtlasScientificGravityDOMeter_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.AtlasScientificGravityDOMeter/Samples/AtlasScientificGravityDOMeter_Sample/AtlasScientificGravityDOMeter_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.DFRobotGravityDOMeter/Driver/Sensors.Environmental.DFRobotGravityDOMeter.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.DFRobotGravityDOMeter/Driver/Sensors.Environmental.DFRobotGravityDOMeter.csproj index b0c00e6ab1..739c9e59ec 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.DFRobotGravityDOMeter/Driver/Sensors.Environmental.DFRobotGravityDOMeter.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.DFRobotGravityDOMeter/Driver/Sensors.Environmental.DFRobotGravityDOMeter.csproj @@ -22,6 +22,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.DFRobotGravityDOMeter/Samples/DFRobotGravityDOMeter_Sample/DFRobotGravityDOMeter_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.DFRobotGravityDOMeter/Samples/DFRobotGravityDOMeter_Sample/DFRobotGravityDOMeter_Sample.csproj index 3a8f59e13a..c81ceb6f9d 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.DFRobotGravityDOMeter/Samples/DFRobotGravityDOMeter_Sample/DFRobotGravityDOMeter_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.DFRobotGravityDOMeter/Samples/DFRobotGravityDOMeter_Sample/DFRobotGravityDOMeter_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.Ens160/Driver/Sensors.Environmental.Ens160.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.Ens160/Driver/Sensors.Environmental.Ens160.csproj index 07156f4973..34ae54b6d0 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.Ens160/Driver/Sensors.Environmental.Ens160.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.Ens160/Driver/Sensors.Environmental.Ens160.csproj @@ -22,6 +22,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.Ens160/Samples/Ens160_Sample/Ens160_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.Ens160/Samples/Ens160_Sample/Ens160_Sample.csproj index 951c662d8d..fbf2848c23 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.Ens160/Samples/Ens160_Sample/Ens160_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.Ens160/Samples/Ens160_Sample/Ens160_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.MiniPID2/Driver/Sensors.Environmental.MiniPID2.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.MiniPID2/Driver/Sensors.Environmental.MiniPID2.csproj index 9098aa5785..a5b798dbab 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.MiniPID2/Driver/Sensors.Environmental.MiniPID2.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.MiniPID2/Driver/Sensors.Environmental.MiniPID2.csproj @@ -22,6 +22,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.MiniPID2/Samples/MiniPID2_Sample/MiniPID2_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.MiniPID2/Samples/MiniPID2_Sample/MiniPID2_Sample.csproj index 8983fe9d62..783619e329 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.MiniPID2/Samples/MiniPID2_Sample/MiniPID2_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.MiniPID2/Samples/MiniPID2_Sample/MiniPID2_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.NextPm/Driver/CommandManager.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.NextPm/Driver/CommandManager.cs index 2308911940..7691bccffe 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.NextPm/Driver/CommandManager.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.NextPm/Driver/CommandManager.cs @@ -12,7 +12,7 @@ public static (int commandLength, int expectedResponseLength) GenerateCommand(Ne var payloadLength = 2; - if (payload != null && payload.Length > 0) + if (payload is { Length: > 0 }) { Array.Copy(payload, 0, buffer, 2, payload.Length); payloadLength += payload.Length; diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.NextPm/Driver/Sensors.Environmental.NextPm.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.NextPm/Driver/Sensors.Environmental.NextPm.csproj index ea088deefc..ef86fee464 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.NextPm/Driver/Sensors.Environmental.NextPm.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.NextPm/Driver/Sensors.Environmental.NextPm.csproj @@ -24,6 +24,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.NextPm/Samples/NextPm_Sample/NextPm_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.NextPm/Samples/NextPm_Sample/NextPm_Sample.csproj index a38af271e1..c6d9a79277 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.NextPm/Samples/NextPm_Sample/NextPm_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.NextPm/Samples/NextPm_Sample/NextPm_Sample.csproj @@ -6,7 +6,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.Pmsa003I/Driver/Sensors.Environmental.Pmsa003i.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.Pmsa003I/Driver/Sensors.Environmental.Pmsa003i.csproj index 1fba5af27d..955d720570 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.Pmsa003I/Driver/Sensors.Environmental.Pmsa003i.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.Pmsa003I/Driver/Sensors.Environmental.Pmsa003i.csproj @@ -22,6 +22,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.Pmsa003I/Samples/Pmsa003I_Sample/Pmsa003I_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.Pmsa003I/Samples/Pmsa003I_Sample/Pmsa003I_Sample.csproj index 6b115a875a..92369c0011 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.Pmsa003I/Samples/Pmsa003I_Sample/Pmsa003I_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.Pmsa003I/Samples/Pmsa003I_Sample/Pmsa003I_Sample.csproj @@ -6,7 +6,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.Scd30/Driver/Sensors.Environmental.Scd30.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.Scd30/Driver/Sensors.Environmental.Scd30.csproj index 29701eab8d..bba28d24ac 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.Scd30/Driver/Sensors.Environmental.Scd30.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.Scd30/Driver/Sensors.Environmental.Scd30.csproj @@ -25,6 +25,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.Scd30/Samples/Scd30_Sample/MeadowApp.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.Scd30/Samples/Scd30_Sample/MeadowApp.cs index 7353ad2d06..a3f3c3ce9d 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.Scd30/Samples/Scd30_Sample/MeadowApp.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.Scd30/Samples/Scd30_Sample/MeadowApp.cs @@ -7,7 +7,7 @@ namespace MeadowApp { // Change F7FeatherV2 to F7FeatherV1 for V1.x boards - public class MeadowApp : App + public class MeadowApp : App { // diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.Scd30/Samples/Scd30_Sample/Scd30_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.Scd30/Samples/Scd30_Sample/Scd30_Sample.csproj index 086ec2bbf6..00326b1864 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.Scd30/Samples/Scd30_Sample/Scd30_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.Scd30/Samples/Scd30_Sample/Scd30_Sample.csproj @@ -6,7 +6,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.Scd4x/Driver/Drivers/Scd40.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.Scd4x/Driver/Drivers/Scd40.cs index 14b6aedebb..ddbc7f794d 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.Scd4x/Driver/Drivers/Scd40.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.Scd4x/Driver/Drivers/Scd40.cs @@ -16,4 +16,4 @@ public Scd40(II2cBus i2cBus, byte address = (byte)Addresses.Default) : base(i2cBus, address) { } } -} +} \ No newline at end of file diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.Scd4x/Driver/Scd4xBase.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.Scd4x/Driver/Scd4xBase.cs index 8672f15e8e..11c54fbf48 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.Scd4x/Driver/Scd4xBase.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.Scd4x/Driver/Scd4xBase.cs @@ -92,9 +92,9 @@ public Task ReInitialize() } /// - /// Forced recalibration allows recalibration using an external CO2 reference + /// Forced calibration allows calibration using an external CO2 reference /// - public Task PerformForcedRecalibration() + public Task PerformForcedCalibration() { SendCommand(Commands.PerformForcedCalibration); return Task.Delay(400); @@ -213,16 +213,28 @@ private void SendCommand(Commands command) } /// - /// Get Scdx40 C02 Gas Concentration and + /// Get Scd4x C02 Gas Concentration and /// Update the Concentration property /// protected override async Task<(Concentration? Concentration, Units.Temperature? Temperature, RelativeHumidity? Humidity)> ReadSensor() { + bool isSampling = IsSampling; + + if (IsSampling == false) + { + StartUpdating(); + } + while (IsDataReady() == false) { await Task.Delay(500); } + if (isSampling == false) + { + StopUpdating(); + } + (Concentration Concentration, Units.Temperature Temperature, RelativeHumidity Humidity) conditions; SendCommand(Commands.ReadMeasurement); diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.Scd4x/Driver/Sensors.Environmental.Scd4x.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.Scd4x/Driver/Sensors.Environmental.Scd4x.csproj index 9857206643..4d47a115da 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.Scd4x/Driver/Sensors.Environmental.Scd4x.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.Scd4x/Driver/Sensors.Environmental.Scd4x.csproj @@ -22,6 +22,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.Scd4x/Samples/Scd40_Sample/Scd40_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.Scd4x/Samples/Scd40_Sample/Scd40_Sample.csproj index a8c2a05c0a..2b8061572b 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.Scd4x/Samples/Scd40_Sample/Scd40_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.Scd4x/Samples/Scd40_Sample/Scd40_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.Scd4x/Samples/Scd41_Sample/Scd41_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.Scd4x/Samples/Scd41_Sample/Scd41_Sample.csproj index a8c2a05c0a..2b8061572b 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.Scd4x/Samples/Scd41_Sample/Scd41_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.Scd4x/Samples/Scd41_Sample/Scd41_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.Y4000/Driver/Sensors.Environmental.Y4000.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.Y4000/Driver/Sensors.Environmental.Y4000.csproj index a23026b06e..d12f5c5139 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.Y4000/Driver/Sensors.Environmental.Y4000.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.Y4000/Driver/Sensors.Environmental.Y4000.csproj @@ -22,7 +22,7 @@ - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.Y4000/Samples/Y4000_Sample/Y4000_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.Y4000/Samples/Y4000_Sample/Y4000_Sample.csproj index 5892a17214..8383ecf6e7 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.Y4000/Samples/Y4000_Sample/Y4000_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.Y4000/Samples/Y4000_Sample/Y4000_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Gnss.Bg95M3/Driver/Sensors.Gnss.Bg95M3.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Gnss.Bg95M3/Driver/Sensors.Gnss.Bg95M3.csproj index 3fb7b6679d..0360f13010 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Gnss.Bg95M3/Driver/Sensors.Gnss.Bg95M3.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Gnss.Bg95M3/Driver/Sensors.Gnss.Bg95M3.csproj @@ -22,6 +22,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Gnss.Bg95M3/Samples/Bg95M3_Sample/Bg95M3_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Gnss.Bg95M3/Samples/Bg95M3_Sample/Bg95M3_Sample.csproj index c8901f75f6..3d0f79f3ee 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Gnss.Bg95M3/Samples/Bg95M3_Sample/Bg95M3_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Gnss.Bg95M3/Samples/Bg95M3_Sample/Bg95M3_Sample.csproj @@ -9,8 +9,8 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Gnss.Mt3339/Driver/Sensors.Gnss.Mt3339.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Gnss.Mt3339/Driver/Sensors.Gnss.Mt3339.csproj index d00f01b7a8..f5a8231982 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Gnss.Mt3339/Driver/Sensors.Gnss.Mt3339.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Gnss.Mt3339/Driver/Sensors.Gnss.Mt3339.csproj @@ -23,7 +23,7 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Gnss.Mt3339/Samples/Mt3339_Sample/Mt3339_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Gnss.Mt3339/Samples/Mt3339_Sample/Mt3339_Sample.csproj index 28b95e9b6d..612c484443 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Gnss.Mt3339/Samples/Mt3339_Sample/Mt3339_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Gnss.Mt3339/Samples/Mt3339_Sample/Mt3339_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Gnss.NeoM8/Driver/Sensors.Gnss.NeoM8.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Gnss.NeoM8/Driver/Sensors.Gnss.NeoM8.csproj index 69dfe15db5..1fd7ecfa6c 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Gnss.NeoM8/Driver/Sensors.Gnss.NeoM8.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Gnss.NeoM8/Driver/Sensors.Gnss.NeoM8.csproj @@ -22,6 +22,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Gnss.NeoM8/Samples/NeoM8_Sample/NeoM8_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Gnss.NeoM8/Samples/NeoM8_Sample/NeoM8_Sample.csproj index 0b8e040b21..ec07243abd 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Gnss.NeoM8/Samples/NeoM8_Sample/NeoM8_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Gnss.NeoM8/Samples/NeoM8_Sample/NeoM8_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Hid.ANONavigationEncoder/Driver/Sensors.Hid.ANONavigationEncoder.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Hid.ANONavigationEncoder/Driver/Sensors.Hid.ANONavigationEncoder.csproj index 0feed5a1f3..8837309213 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Hid.ANONavigationEncoder/Driver/Sensors.Hid.ANONavigationEncoder.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Hid.ANONavigationEncoder/Driver/Sensors.Hid.ANONavigationEncoder.csproj @@ -22,6 +22,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Hid.ANONavigationEncoder/Samples/ANONavigationEncoder_Sample/ANONavigationEncoder_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Hid.ANONavigationEncoder/Samples/ANONavigationEncoder_Sample/ANONavigationEncoder_Sample.csproj index 5aed4caedb..c54f860010 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Hid.ANONavigationEncoder/Samples/ANONavigationEncoder_Sample/ANONavigationEncoder_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Hid.ANONavigationEncoder/Samples/ANONavigationEncoder_Sample/ANONavigationEncoder_Sample.csproj @@ -6,7 +6,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Hid.As5013/Driver/Sensors.Hid.As5013.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Hid.As5013/Driver/Sensors.Hid.As5013.csproj index 5a670bdfa6..a840fc522c 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Hid.As5013/Driver/Sensors.Hid.As5013.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Hid.As5013/Driver/Sensors.Hid.As5013.csproj @@ -22,6 +22,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Hid.As5013/Samples/As5013_Sample/As5013_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Hid.As5013/Samples/As5013_Sample/As5013_Sample.csproj index fb22ad7bb1..c6b74d551f 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Hid.As5013/Samples/As5013_Sample/As5013_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Hid.As5013/Samples/As5013_Sample/As5013_Sample.csproj @@ -6,7 +6,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Hid.BBQ10Keyboard/Driver/Sensors.Hid.Bbq10Keyboard.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Hid.BBQ10Keyboard/Driver/Sensors.Hid.Bbq10Keyboard.csproj index 707d1717a5..bdefbd967d 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Hid.BBQ10Keyboard/Driver/Sensors.Hid.Bbq10Keyboard.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Hid.BBQ10Keyboard/Driver/Sensors.Hid.Bbq10Keyboard.csproj @@ -22,6 +22,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Hid.BBQ10Keyboard/Samples/Bbq10Keyboard_Sample/Bbq10Keyboard_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Hid.BBQ10Keyboard/Samples/Bbq10Keyboard_Sample/Bbq10Keyboard_Sample.csproj index 5230076bae..8951b2dd15 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Hid.BBQ10Keyboard/Samples/Bbq10Keyboard_Sample/Bbq10Keyboard_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Hid.BBQ10Keyboard/Samples/Bbq10Keyboard_Sample/Bbq10Keyboard_Sample.csproj @@ -6,7 +6,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Hid.Keyboard/Driver/Sensors.Hid.Keyboard.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Hid.Keyboard/Driver/Sensors.Hid.Keyboard.csproj index 45c2a7d91b..00bcdefee1 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Hid.Keyboard/Driver/Sensors.Hid.Keyboard.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Hid.Keyboard/Driver/Sensors.Hid.Keyboard.csproj @@ -22,6 +22,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Hid.Mpr121/Driver/Sensors.Hid.Mpr121.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Hid.Mpr121/Driver/Sensors.Hid.Mpr121.csproj index b96bbe1ce3..c139fa04ed 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Hid.Mpr121/Driver/Sensors.Hid.Mpr121.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Hid.Mpr121/Driver/Sensors.Hid.Mpr121.csproj @@ -22,6 +22,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Hid.Mpr121/Samples/Mpr121_Sample/Mpr121_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Hid.Mpr121/Samples/Mpr121_Sample/Mpr121_Sample.csproj index 93a9744f1c..ffb3bef322 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Hid.Mpr121/Samples/Mpr121_Sample/Mpr121_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Hid.Mpr121/Samples/Mpr121_Sample/Mpr121_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Hid.Tsc2004/Driver/Sensors.Hid.Tsc2004.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Hid.Tsc2004/Driver/Sensors.Hid.Tsc2004.csproj index 6580fbee62..b69eb6824a 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Hid.Tsc2004/Driver/Sensors.Hid.Tsc2004.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Hid.Tsc2004/Driver/Sensors.Hid.Tsc2004.csproj @@ -22,6 +22,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Hid.Tsc2004/Samples/Tsc2004_Sample/Tsc2004_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Hid.Tsc2004/Samples/Tsc2004_Sample/Tsc2004_Sample.csproj index 741986e56a..e68c7e312d 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Hid.Tsc2004/Samples/Tsc2004_Sample/Tsc2004_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Hid.Tsc2004/Samples/Tsc2004_Sample/Tsc2004_Sample.csproj @@ -6,7 +6,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Hid.WiiExtensionControllers/Driver/Sensors.Hid.WiiExtensionControllers.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Hid.WiiExtensionControllers/Driver/Sensors.Hid.WiiExtensionControllers.csproj index de130d9873..27ad981511 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Hid.WiiExtensionControllers/Driver/Sensors.Hid.WiiExtensionControllers.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Hid.WiiExtensionControllers/Driver/Sensors.Hid.WiiExtensionControllers.csproj @@ -22,6 +22,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Hid.WiiExtensionControllers/Samples/NesClassicController_Sample/NesClassicController_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Hid.WiiExtensionControllers/Samples/NesClassicController_Sample/NesClassicController_Sample.csproj index 8e17ae439c..ea5af25801 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Hid.WiiExtensionControllers/Samples/NesClassicController_Sample/NesClassicController_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Hid.WiiExtensionControllers/Samples/NesClassicController_Sample/NesClassicController_Sample.csproj @@ -6,7 +6,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Hid.WiiExtensionControllers/Samples/SnesClassicController_Sample/SnesClassicController_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Hid.WiiExtensionControllers/Samples/SnesClassicController_Sample/SnesClassicController_Sample.csproj index 8e17ae439c..ea5af25801 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Hid.WiiExtensionControllers/Samples/SnesClassicController_Sample/SnesClassicController_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Hid.WiiExtensionControllers/Samples/SnesClassicController_Sample/SnesClassicController_Sample.csproj @@ -6,7 +6,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Hid.WiiExtensionControllers/Samples/WiiClassicControllerPro_Sample/WiiClassicControllerPro_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Hid.WiiExtensionControllers/Samples/WiiClassicControllerPro_Sample/WiiClassicControllerPro_Sample.csproj index 8e17ae439c..ea5af25801 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Hid.WiiExtensionControllers/Samples/WiiClassicControllerPro_Sample/WiiClassicControllerPro_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Hid.WiiExtensionControllers/Samples/WiiClassicControllerPro_Sample/WiiClassicControllerPro_Sample.csproj @@ -6,7 +6,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Hid.WiiExtensionControllers/Samples/WiiClassicController_Sample/WiiClassicController_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Hid.WiiExtensionControllers/Samples/WiiClassicController_Sample/WiiClassicController_Sample.csproj index 8e17ae439c..ea5af25801 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Hid.WiiExtensionControllers/Samples/WiiClassicController_Sample/WiiClassicController_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Hid.WiiExtensionControllers/Samples/WiiClassicController_Sample/WiiClassicController_Sample.csproj @@ -6,7 +6,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Hid.WiiExtensionControllers/Samples/WiiNunchuck_Sample/WiiNunchuck_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Hid.WiiExtensionControllers/Samples/WiiNunchuck_Sample/WiiNunchuck_Sample.csproj index 8e17ae439c..ea5af25801 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Hid.WiiExtensionControllers/Samples/WiiNunchuck_Sample/WiiNunchuck_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Hid.WiiExtensionControllers/Samples/WiiNunchuck_Sample/WiiNunchuck_Sample.csproj @@ -6,7 +6,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Hid.Xpt2046/Driver/Sensors.Hid.Xpt2046.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Hid.Xpt2046/Driver/Sensors.Hid.Xpt2046.csproj index 43828d30c2..a8e0f97895 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Hid.Xpt2046/Driver/Sensors.Hid.Xpt2046.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Hid.Xpt2046/Driver/Sensors.Hid.Xpt2046.csproj @@ -22,6 +22,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Hid.Xpt2046/Driver/Xpt2046.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Hid.Xpt2046/Driver/Xpt2046.cs index 98bc62514a..fb2f06844b 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Hid.Xpt2046/Driver/Xpt2046.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Hid.Xpt2046/Driver/Xpt2046.cs @@ -5,238 +5,241 @@ using System.Linq; using System.Threading; -namespace Meadow.Foundation.Sensors.Hid +namespace Meadow.Foundation.Sensors.Hid; + +/// +/// Represents an XPT2046 4-wire touch screen controller +/// +public partial class Xpt2046 : ICalibratableTouchscreen { + /// + public event TouchEventHandler? TouchDown = null; + /// + public event TouchEventHandler? TouchUp = null; + /// + public event TouchEventHandler? TouchClick = null; + /// + public event TouchEventHandler? TouchMoved = null; + + private const int SamplePeriodMilliseconds = 100; + private const byte StartBit = 0x80; + + private readonly ISpiBus spiBus; + private readonly IDigitalInterruptPort touchInterrupt; + private readonly IDigitalOutputPort? chipSelect = null; + private Timer sampleTimer; + private bool isSampling = false; + private bool firstTouch = true; + private TouchPoint? lastTouchPosition; + private TouchPoint? penultimatePosition; + private float mX, mY, cX, cY; // linear calibration coefficeints + + /// + public RotationType Rotation { get; } + /// + public bool IsCalibrated { get; private set; } + + /// + public bool IsTouched => isSampling; + /// - /// Represents an XPT2046 4-wire touch screen controller + /// Creates an instance of an Xpt2046 /// - public partial class Xpt2046 : ICalibratableTouchscreen + /// The ISpiBus connected to the touchscreen controller + /// The interrupt port connected to the touchscreen controller + /// The chip select port for the touchscreen controller + /// The touchscreen rotation (not the display rotation) + public Xpt2046( + ISpiBus spiBus, + IDigitalInterruptPort touchInterrupt, + IDigitalOutputPort? chipSelect, + RotationType rotation = RotationType.Normal) { - /// - public event TouchEventHandler? TouchDown = null; - /// - public event TouchEventHandler? TouchUp = null; - /// - public event TouchEventHandler? TouchClick = null; - /// - public event TouchEventHandler? TouchMoved = null; - - private const int SamplePeriodMilliseconds = 100; - private const byte StartBit = 0x80; - - private readonly ISpiBus spiBus; - private readonly IDigitalInterruptPort touchInterrupt; - private readonly IDigitalOutputPort? chipSelect = null; - private Timer sampleTimer; - private bool isSampling = false; - private bool firstTouch = true; - private TouchPoint? lastTouchPosition; - private TouchPoint? penultimatePosition; - private float mX, mY, cX, cY; // linear calibration coefficeints - - /// - public RotationType Rotation { get; } - /// - public bool IsCalibrated { get; private set; } - - /// - public bool IsTouched => isSampling; - - /// - /// Creates an instance of an Xpt2046 - /// - /// The ISpiBus connected to the touchscreen controller - /// The interrupt port connected to the touchscreen controller - /// The chip select port for the touchscreen controller - /// The touchscreen rotation (not the display rotation) - public Xpt2046( - ISpiBus spiBus, - IDigitalInterruptPort touchInterrupt, - IDigitalOutputPort? chipSelect, - RotationType rotation = RotationType.Normal) + if (touchInterrupt.InterruptMode != InterruptMode.EdgeBoth) { - sampleTimer = new Timer(SampleTimerProc, null, -1, -1); + throw new ArgumentException("The interrupt port must be set to EdgeBoth"); + } - this.spiBus = spiBus; - this.touchInterrupt = touchInterrupt; - this.chipSelect = chipSelect; - Rotation = rotation; + sampleTimer = new Timer(SampleTimerProc, null, -1, -1); - touchInterrupt.Changed += OnTouchInterrupt; - } + this.spiBus = spiBus; + this.touchInterrupt = touchInterrupt; + this.chipSelect = chipSelect; + Rotation = rotation; + touchInterrupt.Changed += OnTouchInterrupt; + } - private TouchPoint ConvertRawToTouchPoint(ushort rawX, ushort rawY, ushort rawZ) + private TouchPoint ConvertRawToTouchPoint(ushort rawX, ushort rawY, ushort rawZ) + { + int x, y; + + // rotate + switch (Rotation) { - int x, y; + case RotationType._90Degrees: + x = 4095 - rawY; + y = rawX; + break; + case RotationType._180Degrees: + x = 4095 - rawX; + y = 4095 - rawY; + break; + case RotationType._270Degrees: + x = rawY; + y = 4095 - rawX; + break; + default: + x = rawX; + y = rawY; + break; + } - // rotate - switch (Rotation) - { - case RotationType._90Degrees: - x = 4095 - rawY; - y = rawX; - break; - case RotationType._180Degrees: - x = 4095 - rawX; - y = 4095 - rawY; - break; - case RotationType._270Degrees: - x = rawY; - y = 4095 - rawX; - break; - default: - x = rawX; - y = rawY; - break; - } + if (!IsCalibrated) + { + return TouchPoint.FromRawData(x, y, rawZ); + } - if (!IsCalibrated) - { - return TouchPoint.FromRawData(x, y, rawZ); - } + // scale for calibration + var scaledX = ((x * mX) + cX); + var scaledY = ((y * mY) + cY); - // scale for calibration - var scaledX = ((x * mX) + cX); - var scaledY = ((y * mY) + cY); + return TouchPoint.FromScreenData((int)scaledX, (int)scaledY, rawZ, rawX, rawY, rawZ); + } - return TouchPoint.FromScreenData((int)scaledX, (int)scaledY, rawZ, rawX, rawY, rawZ); + private void OnTouchInterrupt(object sender, DigitalPortResult e) + { + // high is not touched, low is touched + if (!isSampling) + { + sampleTimer.Change(0, -1); } + } - private void OnTouchInterrupt(object sender, DigitalPortResult e) + private void SampleTimerProc(object o) + { + if (touchInterrupt.State) { - // high is not touched, low is touched - if (!isSampling) + // the actual "last" reading for up is often garbage, so go back one before that if we have it + if (penultimatePosition != null) { - sampleTimer.Change(0, -1); + TouchUp?.Invoke(this, penultimatePosition.Value); } + else if (lastTouchPosition != null) + { + TouchUp?.Invoke(this, lastTouchPosition.Value); + } + isSampling = false; + firstTouch = true; + lastTouchPosition = null; + penultimatePosition = null; + return; } - private void SampleTimerProc(object o) + isSampling = true; + + var z = ReadZ(); + var x = ReadX(); + var y = ReadY(); + EnableIrq(); + + var position = ConvertRawToTouchPoint(x, y, z); + + try { - if (touchInterrupt.State) + if (firstTouch) { - // the actual "last" reading for up is often garbage, so go back one before that if we have it - if (penultimatePosition != null) - { - TouchUp?.Invoke(this, penultimatePosition.Value); - } - else if (lastTouchPosition != null) + firstTouch = false; + lastTouchPosition = position; + if (lastTouchPosition != null) { - TouchUp?.Invoke(this, lastTouchPosition.Value); + TouchDown?.Invoke(this, lastTouchPosition.Value); } - isSampling = false; - firstTouch = true; - lastTouchPosition = null; - penultimatePosition = null; - return; } - - isSampling = true; - - var z = ReadZ(); - var x = ReadX(); - var y = ReadY(); - EnableIrq(); - - var position = ConvertRawToTouchPoint(x, y, z); - - try + else { - if (firstTouch) + if (!position.Equals(lastTouchPosition)) { - firstTouch = false; + penultimatePosition = lastTouchPosition; lastTouchPosition = position; if (lastTouchPosition != null) { - TouchDown?.Invoke(this, lastTouchPosition.Value); - } - } - else - { - if (!position.Equals(lastTouchPosition)) - { - penultimatePosition = lastTouchPosition; - lastTouchPosition = position; - if (lastTouchPosition != null) - { - TouchMoved?.Invoke(this, lastTouchPosition.Value); - } + TouchMoved?.Invoke(this, lastTouchPosition.Value); } } } - catch (Exception ex) - { - Resolver.Log.Warn($"Touchscreen event handler error: {ex.Message}"); - // ignore any unhandled handler exceptions - } - - sampleTimer.Change(SamplePeriodMilliseconds, -1); } - - private ushort ReadX() + catch (Exception ex) { - return ReadChannel(Channel.X); + Resolver.Log.Warn($"Touchscreen event handler error: {ex.Message}"); + // ignore any unhandled handler exceptions } - private ushort ReadY() - { - return ReadChannel(Channel.Y); - } + sampleTimer.Change(SamplePeriodMilliseconds, -1); + } - private ushort ReadZ() - { - return ReadChannel(Channel.Z2); - } + private ushort ReadX() + { + return ReadChannel(Channel.X); + } - private void EnableIrq() - { - ReadChannel(Channel.Temp, PowerState.PowerDown); - } + private ushort ReadY() + { + return ReadChannel(Channel.Y); + } - private ushort ReadChannel(Channel channel, PowerState postSamplePowerState = PowerState.Adc, Mode mode = Mode.Bits_12, VoltageReference vref = VoltageReference.Differential) - { - Span txBuffer = stackalloc byte[3]; - Span rxBuffer = stackalloc byte[3]; + private ushort ReadZ() + { + return ReadChannel(Channel.Z2); + } - txBuffer[0] = (byte)(StartBit | (byte)channel | (byte)mode | (byte)vref | (byte)postSamplePowerState); + private void EnableIrq() + { + ReadChannel(Channel.Temp, PowerState.PowerDown); + } - spiBus.Exchange(chipSelect, txBuffer, rxBuffer); + private ushort ReadChannel(Channel channel, PowerState postSamplePowerState = PowerState.Adc, Mode mode = Mode.Bits_12, VoltageReference vref = VoltageReference.Differential) + { + Span txBuffer = stackalloc byte[3]; + Span rxBuffer = stackalloc byte[3]; - return (ushort)((rxBuffer[1] >> 3) << 8 | (rxBuffer[2] >> 3)); - } + txBuffer[0] = (byte)(StartBit | (byte)channel | (byte)mode | (byte)vref | (byte)postSamplePowerState); - /// - public void SetCalibrationData(IEnumerable data) + spiBus.Exchange(chipSelect, txBuffer, rxBuffer); + + return (ushort)((rxBuffer[1] >> 3) << 8 | (rxBuffer[2] >> 3)); + } + + /// + public void SetCalibrationData(IEnumerable data) + { + var points = data.ToArray(); + if (points.Length != 2) { throw new ArgumentException("This touchscreen requires exactly 2 calibration points"); } + + // basic point validation + if (points[1].RawX - points[0].RawX == 0 || + points[1].RawY - points[0].RawY == 0 || + points[1].ScreenX - points[0].ScreenX == 0 || + points[1].ScreenY - points[0].ScreenY == 0) { - var points = data.ToArray(); - if (points.Length != 2) { throw new ArgumentException("This touchscreen requires exactly 2 calibration points"); } - - // basic point validation - if (points[1].RawX - points[0].RawX == 0 || - points[1].RawY - points[0].RawY == 0 || - points[1].ScreenX - points[0].ScreenX == 0 || - points[1].ScreenY - points[0].ScreenY == 0) - { - throw new ArgumentOutOfRangeException("Invalid calibration data"); - } + throw new ArgumentOutOfRangeException("Invalid calibration data"); + } - // simple 2-point linear calibration (fine for small screens) + // simple 2-point linear calibration (fine for small screens) - mX = (points[1].ScreenX - points[0].ScreenX) / (float)(points[1].RawX - points[0].RawX); - cX = points[0].ScreenX - (points[0].RawX * mX); - mY = (points[1].ScreenY - points[0].ScreenY) / (float)(points[1].RawY - points[0].RawY); - cY = points[0].ScreenY - (points[0].RawY * mY); + mX = (points[1].ScreenX - points[0].ScreenX) / (float)(points[1].RawX - points[0].RawX); + cX = points[0].ScreenX - (points[0].RawX * mX); + mY = (points[1].ScreenY - points[0].ScreenY) / (float)(points[1].RawY - points[0].RawY); + cY = points[0].ScreenY - (points[0].RawY * mY); - IsCalibrated = true; - } + IsCalibrated = true; + } - private enum Channel : byte - { - Temp = 0x00, - X = 1 << 4, - Z1 = 3 << 4, - Z2 = 4 << 4, - Y = 5 << 4, - } + private enum Channel : byte + { + Temp = 0x00, + X = 1 << 4, + Z1 = 3 << 4, + Z2 = 4 << 4, + Y = 5 << 4, } } \ No newline at end of file diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Hid.Xpt2046/Samples/Xpt2046_Sample/Xpt2046_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Hid.Xpt2046/Samples/Xpt2046_Sample/Xpt2046_Sample.csproj index 2c537b558d..d9d07c7e91 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Hid.Xpt2046/Samples/Xpt2046_Sample/Xpt2046_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Hid.Xpt2046/Samples/Xpt2046_Sample/Xpt2046_Sample.csproj @@ -6,7 +6,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Light.Alspt19315C/Driver/Sensors.Light.Alspt19315C.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Light.Alspt19315C/Driver/Sensors.Light.Alspt19315C.csproj index 2a409358a6..7791a3dbd5 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Light.Alspt19315C/Driver/Sensors.Light.Alspt19315C.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Light.Alspt19315C/Driver/Sensors.Light.Alspt19315C.csproj @@ -22,6 +22,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Light.Alspt19315C/Samples/Alspt19315C_Sample/Alspt19315C_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Light.Alspt19315C/Samples/Alspt19315C_Sample/Alspt19315C_Sample.csproj index 361c7a7e2c..db4b1e410c 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Light.Alspt19315C/Samples/Alspt19315C_Sample/Alspt19315C_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Light.Alspt19315C/Samples/Alspt19315C_Sample/Alspt19315C_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Light.AnalogSolarIntensityGauge/Driver/Sensors.Light.AnalogSolarIntensityGauge.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Light.AnalogSolarIntensityGauge/Driver/Sensors.Light.AnalogSolarIntensityGauge.csproj index 6b928b570c..c7a353f6d4 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Light.AnalogSolarIntensityGauge/Driver/Sensors.Light.AnalogSolarIntensityGauge.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Light.AnalogSolarIntensityGauge/Driver/Sensors.Light.AnalogSolarIntensityGauge.csproj @@ -25,6 +25,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Light.AnalogSolarIntensityGauge/Samples/AnalogSolarIntensityGauge_Sample/AnalogSolarIntensityGauge_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Light.AnalogSolarIntensityGauge/Samples/AnalogSolarIntensityGauge_Sample/AnalogSolarIntensityGauge_Sample.csproj index 3be76b203b..badf79b94f 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Light.AnalogSolarIntensityGauge/Samples/AnalogSolarIntensityGauge_Sample/AnalogSolarIntensityGauge_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Light.AnalogSolarIntensityGauge/Samples/AnalogSolarIntensityGauge_Sample/AnalogSolarIntensityGauge_Sample.csproj @@ -6,7 +6,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Light.Bh1745/Driver/Sensors.Light.Bh1745.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Light.Bh1745/Driver/Sensors.Light.Bh1745.csproj index c310aa9335..2064121b43 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Light.Bh1745/Driver/Sensors.Light.Bh1745.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Light.Bh1745/Driver/Sensors.Light.Bh1745.csproj @@ -23,6 +23,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Light.Bh1745/Samples/Bh1745_Sample/Bh1745_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Light.Bh1745/Samples/Bh1745_Sample/Bh1745_Sample.csproj index 5192bb4cf1..e2761c9ab6 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Light.Bh1745/Samples/Bh1745_Sample/Bh1745_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Light.Bh1745/Samples/Bh1745_Sample/Bh1745_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Light.Bh1750/Driver/Bh1750.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Light.Bh1750/Driver/Bh1750.cs index f4279df3bd..ca7c083471 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Light.Bh1750/Driver/Bh1750.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Light.Bh1750/Driver/Bh1750.cs @@ -111,7 +111,7 @@ private TimeSpan GetMeasurementTime(MeasuringModes mode) } /// - /// Set BH1750FVI Light Transmittance + /// Set BH1750 Light Transmittance /// /// Light Transmittance, from 27.20% to 222.50% private void SetLightTransmittance(double transmittance) diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Light.Bh1750/Driver/Sensors.Light.Bh1750.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Light.Bh1750/Driver/Sensors.Light.Bh1750.csproj index b7a1e12a86..bb785847f2 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Light.Bh1750/Driver/Sensors.Light.Bh1750.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Light.Bh1750/Driver/Sensors.Light.Bh1750.csproj @@ -18,12 +18,11 @@ Meadow.Foundation,luminance,color,Light,Bh1750 true Bh1750 I2C luminance and color light sensor - Meadow.Foundation.Sensors.Light -{ + Meadow.Foundation.Sensors.Light - + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Light.Bh1750/Samples/Bh1750_Sample/Bh1750_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Light.Bh1750/Samples/Bh1750_Sample/Bh1750_Sample.csproj index 4a14349f46..437223b9b4 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Light.Bh1750/Samples/Bh1750_Sample/Bh1750_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Light.Bh1750/Samples/Bh1750_Sample/Bh1750_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Light.Max44009/Driver/Sensors.Light.Max44009.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Light.Max44009/Driver/Sensors.Light.Max44009.csproj index a4d36f4e58..c4b183a40f 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Light.Max44009/Driver/Sensors.Light.Max44009.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Light.Max44009/Driver/Sensors.Light.Max44009.csproj @@ -23,6 +23,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Light.Max44009/Samples/Max44009_Sample/Max44009_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Light.Max44009/Samples/Max44009_Sample/Max44009_Sample.csproj index bb7156d066..96dcb4874c 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Light.Max44009/Samples/Max44009_Sample/Max44009_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Light.Max44009/Samples/Max44009_Sample/Max44009_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Light.Si1145/Driver/Sensors.Light.Si1145.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Light.Si1145/Driver/Sensors.Light.Si1145.csproj index eb49f6c8ce..b6681b6d00 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Light.Si1145/Driver/Sensors.Light.Si1145.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Light.Si1145/Driver/Sensors.Light.Si1145.csproj @@ -23,6 +23,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Light.Si1145/Samples/Si1145_Sample/Si1145_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Light.Si1145/Samples/Si1145_Sample/Si1145_Sample.csproj index 8f196d329f..a496a927ca 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Light.Si1145/Samples/Si1145_Sample/Si1145_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Light.Si1145/Samples/Si1145_Sample/Si1145_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Light.Temt6000/Driver/Sensors.Light.Temt6000.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Light.Temt6000/Driver/Sensors.Light.Temt6000.csproj index 5bade29b93..40af84166b 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Light.Temt6000/Driver/Sensors.Light.Temt6000.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Light.Temt6000/Driver/Sensors.Light.Temt6000.csproj @@ -22,6 +22,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Light.Temt6000/Samples/Temt6000_Sample/Temt6000_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Light.Temt6000/Samples/Temt6000_Sample/Temt6000_Sample.csproj index 6779078c3a..cb9275ac79 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Light.Temt6000/Samples/Temt6000_Sample/Temt6000_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Light.Temt6000/Samples/Temt6000_Sample/Temt6000_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Light.Tsl2591/Driver/Sensors.Light.Tsl2591.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Light.Tsl2591/Driver/Sensors.Light.Tsl2591.csproj index fa35c1d25f..a7b30158c0 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Light.Tsl2591/Driver/Sensors.Light.Tsl2591.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Light.Tsl2591/Driver/Sensors.Light.Tsl2591.csproj @@ -22,6 +22,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Light.Tsl2591/Driver/Tsl2591.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Light.Tsl2591/Driver/Tsl2591.cs index ec787bdf23..706fd5204b 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Light.Tsl2591/Driver/Tsl2591.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Light.Tsl2591/Driver/Tsl2591.cs @@ -15,7 +15,7 @@ namespace Meadow.Foundation.Sensors.Light /// public partial class Tsl2591 : ByteCommsSensorBase<(Illuminance? FullSpectrum, Illuminance? Infrared, Illuminance? VisibleLight, Illuminance? Integrated)>, - ILightSensor, IDisposable, IPowerControllablePeripheral + ILightSensor, IPowerControllablePeripheral { /// /// Raised when Full Spectrum Illuminance value changes diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Light.Tsl2591/Samples/Tsl2591_Sample/Tsl2591_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Light.Tsl2591/Samples/Tsl2591_Sample/Tsl2591_Sample.csproj index c23e99e347..fa9206617d 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Light.Tsl2591/Samples/Tsl2591_Sample/Tsl2591_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Light.Tsl2591/Samples/Tsl2591_Sample/Tsl2591_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Light.Veml7700/Driver/Sensors.Light.Veml7700.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Light.Veml7700/Driver/Sensors.Light.Veml7700.csproj index 9d46f4549d..f03d0254da 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Light.Veml7700/Driver/Sensors.Light.Veml7700.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Light.Veml7700/Driver/Sensors.Light.Veml7700.csproj @@ -23,6 +23,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Light.Veml7700/Driver/Veml7700.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Light.Veml7700/Driver/Veml7700.cs index ecc7259f46..5e023c3665 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Light.Veml7700/Driver/Veml7700.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Light.Veml7700/Driver/Veml7700.cs @@ -22,12 +22,12 @@ public partial class Veml7700 : ByteCommsSensorBase, /// public event EventHandler RangeExceededLow = default!; - ushort config; + private ushort config; /// /// Luminosity reading from the TSL2561 sensor. /// - public Illuminance? Illuminance { get; protected set; } + public Illuminance? Illuminance => Conditions; /// /// Sensor types Data source @@ -51,16 +51,16 @@ public Veml7700(II2cBus i2cBus) { } - int gain = 3; - int integrationTime = 0; - bool firstRead = true; - bool outOfRange = false; + private int gain = 3; + private int integrationTime = 0; + private bool firstRead = true; + private bool outOfRange = false; /// /// Reads data from the sensor /// /// The latest sensor reading - protected async override Task ReadSensor() + protected override async Task ReadSensor() { Illuminance illuminance = new Illuminance(0); @@ -92,6 +92,7 @@ protected async override Task ReadSensor() if (++integrationTime >= 4) { // everything is maxed out + integrationTime = 3; RangeExceededHigh?.Invoke(this, EventArgs.Empty); outOfRange = true; } @@ -113,6 +114,7 @@ protected async override Task ReadSensor() // we're at max gain, have to slow integration time if (--integrationTime <= -2) { + integrationTime = -2; RangeExceededLow?.Invoke(this, EventArgs.Empty); outOfRange = true; } @@ -224,6 +226,15 @@ private async Task SetIntegrationTime(int it) { ushort cfg; + if (it < -2) + { + it = -2; + } + else if (it > 3) + { + it = 3; + } + // bits 6-9 cfg = (ushort)(config & ~0x03C0); // clear bits diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Light.Veml7700/Samples/Veml7700_Sample/Veml7700_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Light.Veml7700/Samples/Veml7700_Sample/Veml7700_Sample.csproj index ab2e2f2a40..0f365fcddb 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Light.Veml7700/Samples/Veml7700_Sample/Veml7700_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Light.Veml7700/Samples/Veml7700_Sample/Veml7700_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.LoadCell.Hx711/Driver/Sensors.LoadCell.Hx711.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.LoadCell.Hx711/Driver/Sensors.LoadCell.Hx711.csproj index 245a4ce5cd..5c29e73a90 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.LoadCell.Hx711/Driver/Sensors.LoadCell.Hx711.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.LoadCell.Hx711/Driver/Sensors.LoadCell.Hx711.csproj @@ -24,6 +24,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.LoadCell.Hx711/Samples/Hx711_Sample/Hx711_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.LoadCell.Hx711/Samples/Hx711_Sample/Hx711_Sample.csproj index e164d8c933..496b9ffb6d 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.LoadCell.Hx711/Samples/Hx711_Sample/Hx711_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.LoadCell.Hx711/Samples/Hx711_Sample/Hx711_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.LoadCell.Nau7802/Driver/Sensors.LoadCell.Nau7802.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.LoadCell.Nau7802/Driver/Sensors.LoadCell.Nau7802.csproj index a9c9b67703..7d5aac4466 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.LoadCell.Nau7802/Driver/Sensors.LoadCell.Nau7802.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.LoadCell.Nau7802/Driver/Sensors.LoadCell.Nau7802.csproj @@ -24,6 +24,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.LoadCell.Nau7802/Samples/Nau7802_Sample/Nau7802_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.LoadCell.Nau7802/Samples/Nau7802_Sample/Nau7802_Sample.csproj index 0e4738a459..1c1522b0c5 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.LoadCell.Nau7802/Samples/Nau7802_Sample/Nau7802_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.LoadCell.Nau7802/Samples/Nau7802_Sample/Nau7802_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Moisture.Capacitive/Driver/Sensors.Moisture.Capacitive.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Moisture.Capacitive/Driver/Sensors.Moisture.Capacitive.csproj index 8eea43138e..4c7b340dfb 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Moisture.Capacitive/Driver/Sensors.Moisture.Capacitive.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Moisture.Capacitive/Driver/Sensors.Moisture.Capacitive.csproj @@ -24,6 +24,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Moisture.Capacitive/Samples/Capacitive_Sample/Capacitive_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Moisture.Capacitive/Samples/Capacitive_Sample/Capacitive_Sample.csproj index 6822a96cd9..663a42ab37 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Moisture.Capacitive/Samples/Capacitive_Sample/Capacitive_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Moisture.Capacitive/Samples/Capacitive_Sample/Capacitive_Sample.csproj @@ -12,7 +12,7 @@ 9.0 - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Moisture.Fc28/Driver/Fc28.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Moisture.Fc28/Driver/Fc28.cs index b31f5afdc6..ae46d5affb 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Moisture.Fc28/Driver/Fc28.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Moisture.Fc28/Driver/Fc28.cs @@ -24,7 +24,7 @@ public class Fc28 : PollingSensorBase, IMoistureSensor, IDisposable /// /// Last value read from the moisture sensor /// - public double? Moisture { get; protected set; } + public double? Moisture => Conditions; /// /// Voltage value of most dry soil - default is 0 volts diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Moisture.Fc28/Driver/Sensors.Moisture.Fc28.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Moisture.Fc28/Driver/Sensors.Moisture.Fc28.csproj index 164421aab7..0c221a1734 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Moisture.Fc28/Driver/Sensors.Moisture.Fc28.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Moisture.Fc28/Driver/Sensors.Moisture.Fc28.csproj @@ -24,6 +24,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Moisture.Fc28/Samples/Fc28_Sample/Fc28_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Moisture.Fc28/Samples/Fc28_Sample/Fc28_Sample.csproj index 8a5aba4dd3..fe07dba36f 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Moisture.Fc28/Samples/Fc28_Sample/Fc28_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Moisture.Fc28/Samples/Fc28_Sample/Fc28_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Adxl3xx/Datasheet/ADXL343.pdf b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Adxl3xx/Datasheet/ADXL343.pdf new file mode 100644 index 0000000000..6f1663825a Binary files /dev/null and b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Adxl3xx/Datasheet/ADXL343.pdf differ diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Adxl3xx/Driver/Drivers/Adxl343.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Adxl3xx/Driver/Drivers/Adxl343.cs new file mode 100644 index 0000000000..a8f5cb26a3 --- /dev/null +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Adxl3xx/Driver/Drivers/Adxl343.cs @@ -0,0 +1,231 @@ +using Meadow.Foundation.Helpers; +using Meadow.Hardware; +using Meadow.Peripherals.Sensors.Motion; +using Meadow.Units; +using System; +using System.Threading.Tasks; + +namespace Meadow.Foundation.Sensors.Motion +{ + /// + /// Driver for the ADXL343 triple axis accelerometer + /// +/- 16g + /// + public partial class Adxl343 : ByteCommsSensorBase, IAccelerometer, II2cPeripheral + { + /// + /// The default I2C address for the peripheral + /// + public byte DefaultI2cAddress => (byte)Addresses.Default; + + readonly double ADXL343_MG2G_MULTIPLIER = 0.004; + + /// + /// Minimum value that can be used for the update interval when the + /// sensor is being configured to generate interrupts + /// + public const ushort MinimumPollingPeriod = 100; + + /// + /// Current acceleration + /// + public Acceleration3D? Acceleration3D => Conditions; + + /// + /// Values stored in this register are automatically added to the X reading + /// + /// + /// Scale factor is 15.6 mg/LSB so 0x7f represents an offset of 2g + /// + public sbyte OffsetX + { + get => (sbyte)ReadRegister(Register.OFFSET_X); + set => WriteRegister(Register.OFFSET_X, (byte)value); + } + + /// + /// Values stored in this register are automatically added to the Y reading + /// + /// + /// Scale factor is 15.6 mg/LSB so 0x7f represents an offset of 2g + /// + public sbyte OffsetY + { + get => (sbyte)ReadRegister(Register.OFFSET_Y); + set => WriteRegister(Register.OFFSET_Y, (byte)value); + } + + /// + /// Values stored in this register are automatically added to the Z reading + /// + /// + /// Scale factor is 15.6 mg/LSB so 0x7f represents an offset of 2g + /// + public sbyte OffsetZ + { + get => (sbyte)ReadRegister(Register.OFFSET_Z); + set => WriteRegister(Register.OFFSET_Z, (byte)value); + } + + /// + /// Create a new instance of the ADXL343 communicating over the I2C interface + /// + /// Address of the I2C sensor + /// I2C bus + public Adxl343(II2cBus i2cBus, Addresses address = Addresses.Default) + : this(i2cBus, (byte)address) + { + } + + /// + /// Create a new instance of the ADXL343 communicating over the I2C interface + /// + /// Address of the I2C sensor + /// I2C bus + public Adxl343(II2cBus i2cBus, byte address) + : base(i2cBus, address) + { + var deviceID = ReadRegister(Register.DEVICE_ID); + + if (deviceID != 0xe5) + { + throw new Exception("Invalid device ID."); + } + } + + /// + /// Read sensor + /// + /// Current acceleration + protected override Task ReadSensor() + { + BusComms.ReadRegister((byte)Register.DATAX0, ReadBuffer.Span[0..6]); + + var conditions = new Acceleration3D( + new Acceleration(ADXL343_MG2G_MULTIPLIER * (short)(ReadBuffer.Span[0] + (ReadBuffer.Span[1] << 8)), Acceleration.UnitType.Gravity), + new Acceleration(ADXL343_MG2G_MULTIPLIER * (short)(ReadBuffer.Span[2] + (ReadBuffer.Span[3] << 8)), Acceleration.UnitType.Gravity), + new Acceleration(ADXL343_MG2G_MULTIPLIER * (short)(ReadBuffer.Span[4] + (ReadBuffer.Span[5] << 8)), Acceleration.UnitType.Gravity)); + + return Task.FromResult(conditions); + } + + /// + /// Set the PowerControl register (see pages 25 and 26 of the data sheet) + /// + /// Link the activity and inactivity events + /// Enable / disable auto sleep when the activity and inactivity are linked + /// Enable or disable measurements (turn on or off) + /// Put the part to sleep (true) or run in normal more (false) + /// Frequency of measurements when the part is in sleep mode + public void SetPowerState(bool linkActivityAndInactivity, bool autoSleep, bool measuring, bool sleep, Frequencies frequency) + { + byte data = 0; + if (linkActivityAndInactivity) + { + data |= 0x20; + } + if (autoSleep) + { + data |= 0x10; + } + if (measuring) + { + data |= 0x08; + } + if (sleep) + { + data |= 0x40; + } + data |= (byte)frequency; + + WriteRegister(Register.POWER_CONTROL, data); + } + + /// + /// Configure the data format (see pages 26 and 27 of the data sheet). + /// + /// Put the device into self test mode when true + /// Use 3-wire SPI (true) or 4-wire SPI (false) + /// + /// Set to full resolution (true) or 10-bit mode using the range determined by the range + /// parameter (false). + /// + /// Left-justified when true, right justified with sign extension when false + /// Set the range of the sensor to 2g, 4g, 8g or 16g + /// + /// The range of the sensor is determined by the following table: + /// 0: +/- 2g + /// 1: +/- 4g + /// 2: +/- 8g + /// 3: +/ 16g + /// + public void SetDataFormat(bool selfTest, bool spiMode, bool fullResolution, bool justification, GForceRanges range) + { + byte data = 0; + if (selfTest) + { + data |= 0x80; + } + if (spiMode) + { + data |= 0x40; + } + if (fullResolution) + { + data |= 0x04; + } + if (justification) + { + data |= 0x02; + } + data |= (byte)range; + + WriteRegister(Register.DATA_FORMAT, data); + } + + /// + /// Set the data rate and low power mode for the sensor. + /// + /// Data rate for the sensor + /// + /// Setting this to true will enter low power mode (note measurement will encounter more noise in + /// this mode). + /// + public void SetDataRate(byte dataRate, bool lowPower) + { + if (dataRate > 0xff) + { + throw new ArgumentOutOfRangeException(nameof(dataRate), "Data rate should be in the range 0-15 inclusive"); + } + + var data = dataRate; + + if (lowPower) + { + data |= 0x10; + } + + WriteRegister(Register.DATA_RATE, data); + } + + private void WriteRegister(Register register, byte value) + { + BusComms.WriteRegister((byte)register, value); + } + + private byte ReadRegister(Register register) + { + return BusComms.ReadRegister((byte)register); + } + + /// + /// Dump the registers to the debug output stream. + /// + public void DisplayRegisters() + { + byte[] registerData = new byte[29]; + BusComms.ReadRegister((byte)Register.TAP_THRESHOLD, registerData); + DebugInformation.DisplayRegisters((byte)Register.TAP_THRESHOLD, registerData); + } + } +} \ No newline at end of file diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Adxl3xx/Driver/Drivers/Adxl343_Extras/Adxl343.Addresses.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Adxl3xx/Driver/Drivers/Adxl343_Extras/Adxl343.Addresses.cs new file mode 100644 index 0000000000..6ad0753074 --- /dev/null +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Adxl3xx/Driver/Drivers/Adxl343_Extras/Adxl343.Addresses.cs @@ -0,0 +1,24 @@ +namespace Meadow.Foundation.Sensors.Motion +{ + public partial class Adxl343 + { + /// + /// Valid I2C addresses for the sensor + /// + public enum Addresses : byte + { + /// + /// Bus address 0x53 + /// + Address_0x53 = 0x53, + /// + /// Bus address 0x1D + /// + Address_0x1D = 0x1D, + /// + /// Bus address 0x53 + /// + Default = Address_0x53 + } + } +} \ No newline at end of file diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Adxl3xx/Driver/Drivers/Adxl343_Extras/Adxl343.Frequencies.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Adxl3xx/Driver/Drivers/Adxl343_Extras/Adxl343.Frequencies.cs new file mode 100644 index 0000000000..5f79186f3f --- /dev/null +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Adxl3xx/Driver/Drivers/Adxl343_Extras/Adxl343.Frequencies.cs @@ -0,0 +1,31 @@ +namespace Meadow.Foundation.Sensors.Motion +{ + public partial class Adxl343 + { + /// + /// Frequency of the sensor readings when the device is in sleep mode. + /// + /// + /// See page 26 of the data sheet + /// + public enum Frequencies : byte + { + /// + /// 8hz + /// + EightHz = 0x00, + /// + /// 4hz + /// + FourHz = 0x01, + /// + /// 2hz + /// + TwoHz = 0x02, + /// + /// 1hz + /// + OneHz = 0x03, + } + } +} \ No newline at end of file diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Adxl3xx/Driver/Drivers/Adxl343_Extras/Adxl343.GForceRanges.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Adxl3xx/Driver/Drivers/Adxl343_Extras/Adxl343.GForceRanges.cs new file mode 100644 index 0000000000..5f8a3e9a07 --- /dev/null +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Adxl3xx/Driver/Drivers/Adxl343_Extras/Adxl343.GForceRanges.cs @@ -0,0 +1,28 @@ +namespace Meadow.Foundation.Sensors.Motion +{ + public partial class Adxl343 + { + /// + /// GForce range + /// + public enum GForceRanges : byte + { + /// + /// 2x gravity + /// + TwoG = 0x00, + /// + /// 4x gravity + /// + FourG = 0x01, + /// + /// 8x gravity + /// + EightG = 0x02, + /// + /// 16x gravity + /// + SixteenG = 0x03 + } + } +} \ No newline at end of file diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Adxl3xx/Driver/Drivers/Adxl343_Extras/Adxl343.Registers.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Adxl3xx/Driver/Drivers/Adxl343_Extras/Adxl343.Registers.cs new file mode 100644 index 0000000000..9343db028a --- /dev/null +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Adxl3xx/Driver/Drivers/Adxl343_Extras/Adxl343.Registers.cs @@ -0,0 +1,46 @@ + +namespace Meadow.Foundation.Sensors.Motion +{ + public partial class Adxl343 + { + /// + /// Control registers for the ADXL345 chip. + /// + /// + /// Taken from table 19 on page 23 of the data sheet. + /// + private enum Register : byte + { + DEVICE_ID = 0x00, + TAP_THRESHOLD = 0x1D, + OFFSET_X = 0x1E, + OFFSET_Y = 0x1F, + OFFSET_Z = 0x20, + TAP_DURATION = 0x21, + TAP_LATENCY = 0x22, + TAP_WINDOW = 0x23, + ACTIVITY_THRESHOLD = 0x24, + INACTIVITY_THRESHOLD = 0x25, + INACTIVITY_TIME = 0x26, + ACTIVITY_INACTIVITY_CONTROL = 0x27, + FREEFALL_THRESHOLD = 0x28, + FREEFALL_TIME = 0x29, + TAP_AXES = 0x2A, + TAP_ACTIVITY_STATUS = 0x2B, + DATA_RATE = 0x2C, + POWER_CONTROL = 0x2D, + INTERRUPT_ENABLE = 0x2E, + INTERRUPT_MAP = 0x2F, + INTERRUPT_SOURCE = 0x30, + DATA_FORMAT = 0x31, + DATAX0 = 0x32, + DATAX1 = 0x33, + DATAY0 = 0x33, + DATAY1 = 0x34, + DATAZ0 = 0x36, + DATAZ1 = 0x37, + FIFO_CONTROL = 0x38, + FIFO_STATUS = 0x39, + } + } +} \ No newline at end of file diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Adxl3xx/Driver/Drivers/Adxl345.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Adxl3xx/Driver/Drivers/Adxl345.cs index d2ac0ab408..e43829d576 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Adxl3xx/Driver/Drivers/Adxl345.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Adxl3xx/Driver/Drivers/Adxl345.cs @@ -99,7 +99,7 @@ public Adxl345(II2cBus i2cBus, byte address) /// Current acceleration protected override Task ReadSensor() { - BusComms.ReadRegister((byte)Register.X0, ReadBuffer.Span[0..6]); + BusComms.ReadRegister((byte)Register.DATAX0, ReadBuffer.Span[0..6]); var conditions = new Acceleration3D( new Acceleration(ADXL345_MG2G_MULTIPLIER * (short)(ReadBuffer.Span[0] + (ReadBuffer.Span[1] << 8)), Acceleration.UnitType.Gravity), diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Adxl3xx/Driver/Drivers/Adxl345_Extras/Adxl345.Addresses.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Adxl3xx/Driver/Drivers/Adxl345_Extras/Adxl345.Addresses.cs index b975a00da4..074d516c5c 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Adxl3xx/Driver/Drivers/Adxl345_Extras/Adxl345.Addresses.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Adxl3xx/Driver/Drivers/Adxl345_Extras/Adxl345.Addresses.cs @@ -21,4 +21,4 @@ public enum Addresses : byte Default = Address_0x53 } } -} +} \ No newline at end of file diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Adxl3xx/Driver/Drivers/Adxl345_Extras/Adxl345.Frequencies.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Adxl3xx/Driver/Drivers/Adxl345_Extras/Adxl345.Frequencies.cs index 24baa4f8f1..27d87e134f 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Adxl3xx/Driver/Drivers/Adxl345_Extras/Adxl345.Frequencies.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Adxl3xx/Driver/Drivers/Adxl345_Extras/Adxl345.Frequencies.cs @@ -28,4 +28,4 @@ public enum Frequencies : byte OneHz = 0x03, } } -} +} \ No newline at end of file diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Adxl3xx/Driver/Drivers/Adxl345_Extras/Adxl345.GForceRanges.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Adxl3xx/Driver/Drivers/Adxl345_Extras/Adxl345.GForceRanges.cs index 9aa871a44c..7dc9a4c203 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Adxl3xx/Driver/Drivers/Adxl345_Extras/Adxl345.GForceRanges.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Adxl3xx/Driver/Drivers/Adxl345_Extras/Adxl345.GForceRanges.cs @@ -25,4 +25,4 @@ public enum GForceRanges : byte SixteenG = 0x03 } } -} +} \ No newline at end of file diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Adxl3xx/Driver/Drivers/Adxl345_Extras/Adxl345.Registers.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Adxl3xx/Driver/Drivers/Adxl345_Extras/Adxl345.Registers.cs index e5adce0eb6..49ec040e74 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Adxl3xx/Driver/Drivers/Adxl345_Extras/Adxl345.Registers.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Adxl3xx/Driver/Drivers/Adxl345_Extras/Adxl345.Registers.cs @@ -11,36 +11,36 @@ public partial class Adxl345 /// private enum Register : byte { - ACTIVITY_INACTIVITY_CONTROL = 0x27, - ACTIVITY_THRESHOLD = 0x24, - DATA_FORMAT = 0x31, - DATA_RATE = 0x2c, DEVICE_ID = 0x00, - FIFO_CONTROL = 0x38, - FIFO_STATUS = 0x39, - FREEFALL_THRESHOLD = 0x28, - FREEFALL_TIME = 0x29, - INACTIVITY_THRESHOLD = 0x25, - INACTIVITY_TIME = 0x26, - INTERRUPT_ENABLE = 0x2e, - INTERRUPT_MAP = 0x2f, - INTERRUPT_SOURCE = 0x30, - OFFSET_X = 0x1e, - OFFSET_Y = 0x1f, + TAP_THRESHOLD = 0x1D, + OFFSET_X = 0x1E, + OFFSET_Y = 0x1F, OFFSET_Z = 0x20, - POWER_CONTROL = 0x2d, - TAP_ACTIVITY_STATUS = 0x2a, - TAP_AXES = 0x2a, TAP_DURATION = 0x21, TAP_LATENCY = 0x22, - TAP_THRESHOLD = 0x1d, TAP_WINDOW = 0x23, - X0 = 0x32, - X1 = 0x33, - Y0 = 0x33, - Y1 = 0x34, - Z0 = 0x36, - Z1 = 0x37 + ACTIVITY_THRESHOLD = 0x24, + INACTIVITY_THRESHOLD = 0x25, + INACTIVITY_TIME = 0x26, + ACTIVITY_INACTIVITY_CONTROL = 0x27, + FREEFALL_THRESHOLD = 0x28, + FREEFALL_TIME = 0x29, + TAP_AXES = 0x2A, + TAP_ACTIVITY_STATUS = 0x2B, + DATA_RATE = 0x2C, + POWER_CONTROL = 0x2D, + INTERRUPT_ENABLE = 0x2E, + INTERRUPT_MAP = 0x2F, + INTERRUPT_SOURCE = 0x30, + DATA_FORMAT = 0x31, + DATAX0 = 0x32, + DATAX1 = 0x33, + DATAY0 = 0x33, + DATAY1 = 0x34, + DATAZ0 = 0x36, + DATAZ1 = 0x37, + FIFO_CONTROL = 0x38, + FIFO_STATUS = 0x39, } } -} +} \ No newline at end of file diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Adxl3xx/Driver/Readme.md b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Adxl3xx/Driver/Readme.md index 7097ff170e..942af3ba86 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Adxl3xx/Driver/Readme.md +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Adxl3xx/Driver/Readme.md @@ -1,6 +1,6 @@ # Meadow.Foundation.Sensors.Motion.Adxl3xx -**ADXL3xx Analog and I2C 3-axis accelerometers (ADXL335, ADXL345, ADXL337, ADXL362, ADXL377)** +**ADXL3xx Analog and I2C 3-axis accelerometers (ADXL335, ADXL343, ADXL345, ADXL337, ADXL362, ADXL377)** The **Adxl3xx** library is included in the **Meadow.Foundation.Sensors.Motion.Adxl3xx** nuget package and is designed for the [Wilderness Labs](www.wildernesslabs.co) Meadow .NET IoT platform. diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Adxl3xx/Driver/Sensors.Motion.Adxl3xx.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Adxl3xx/Driver/Sensors.Motion.Adxl3xx.csproj index 135577a361..c06328f0ee 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Adxl3xx/Driver/Sensors.Motion.Adxl3xx.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Adxl3xx/Driver/Sensors.Motion.Adxl3xx.csproj @@ -15,13 +15,13 @@ http://developer.wildernesslabs.co/Meadow/Meadow.Foundation/ Meadow.Foundation.Sensors.Motion.Adxl3xx https://github.com/WildernessLabs/Meadow.Foundation - Meadow.Foundation,ADXL335,ADXL345,ADXL337,ADXL362,ADXL377,Accelerometer,Motion,3-axis + Meadow.Foundation,ADXL335,ADXL343,ADXL345,ADXL337,ADXL362,ADXL377,Accelerometer,Motion,3-axis true - ADXL3xx Analog and I2C 3-axis accelerometers (ADXL335, ADXL345, ADXL337, ADXL362, ADXL377) + ADXL3xx Analog and I2C 3-axis accelerometers (ADXL335, ADXL343, ADXL345, ADXL337, ADXL362, ADXL377) - + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Adxl3xx/Samples/Adxl335_Sample/Adxl335_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Adxl3xx/Samples/Adxl335_Sample/Adxl335_Sample.csproj index 2c2cd18a18..19c17bf538 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Adxl3xx/Samples/Adxl335_Sample/Adxl335_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Adxl3xx/Samples/Adxl335_Sample/Adxl335_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Adxl3xx/Samples/Adxl337_Sample/Adxl337_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Adxl3xx/Samples/Adxl337_Sample/Adxl337_Sample.csproj index 2c2cd18a18..19c17bf538 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Adxl3xx/Samples/Adxl337_Sample/Adxl337_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Adxl3xx/Samples/Adxl337_Sample/Adxl337_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Adxl3xx/Samples/Adxl343_Sample/Adxl343_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Adxl3xx/Samples/Adxl343_Sample/Adxl343_Sample.csproj new file mode 100644 index 0000000000..2d1b0c9ebd --- /dev/null +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Adxl3xx/Samples/Adxl343_Sample/Adxl343_Sample.csproj @@ -0,0 +1,15 @@ + + + https://github.com/WildernessLabs/Meadow.Foundation + Wilderness Labs, Inc + Wilderness Labs, Inc + true + netstandard2.1 + Library + App + + + + + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Adxl3xx/Samples/Adxl343_Sample/MeadowApp.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Adxl3xx/Samples/Adxl343_Sample/MeadowApp.cs new file mode 100644 index 0000000000..e7ca1f9664 --- /dev/null +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Adxl3xx/Samples/Adxl343_Sample/MeadowApp.cs @@ -0,0 +1,46 @@ +using Meadow; +using Meadow.Devices; +using Meadow.Foundation.Sensors.Motion; +using System; +using System.Threading.Tasks; + +namespace Sensors.Motion.Adxl343_Sample +{ + public class MeadowApp : App + { + // + + Adxl343 sensor; + + public override Task Initialize() + { + Resolver.Log.Info("Initialize..."); + + sensor = new Adxl343(Device.CreateI2cBus(), Adxl343.Addresses.Default); + sensor.SetPowerState(false, false, true, false, Adxl343.Frequencies.TwoHz); + + // classical .NET events can also be used: + sensor.Updated += (sender, result) => + { + Resolver.Log.Info($"Accel: [X:{result.New.X.MetersPerSecondSquared:N2}," + + $"Y:{result.New.Y.MetersPerSecondSquared:N2}," + + $"Z:{result.New.Z.MetersPerSecondSquared:N2} (m/s^2)]"); + }; + + return Task.CompletedTask; + } + + public async override Task Run() + { + var result = await sensor.Read(); + Resolver.Log.Info("Initial Readings:"); + Resolver.Log.Info($"Accel: [X:{result.X.MetersPerSecondSquared:N2}," + + $"Y:{result.Y.MetersPerSecondSquared:N2}," + + $"Z:{result.Z.MetersPerSecondSquared:N2} (m/s^2)]"); + + sensor.StartUpdating(TimeSpan.FromMilliseconds(500)); + } + + // + } +} \ No newline at end of file diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Adxl3xx/Samples/Adxl345_Sample/Adxl345_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Adxl3xx/Samples/Adxl345_Sample/Adxl345_Sample.csproj index cc2bc85fdb..2d1b0c9ebd 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Adxl3xx/Samples/Adxl345_Sample/Adxl345_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Adxl3xx/Samples/Adxl345_Sample/Adxl345_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Adxl3xx/Samples/Adxl345_Sample/MeadowApp.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Adxl3xx/Samples/Adxl345_Sample/MeadowApp.cs index 89b5c80740..84b9c20afa 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Adxl3xx/Samples/Adxl345_Sample/MeadowApp.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Adxl3xx/Samples/Adxl345_Sample/MeadowApp.cs @@ -40,5 +40,7 @@ public async override Task Run() sensor.StartUpdating(TimeSpan.FromMilliseconds(500)); } + + // } } \ No newline at end of file diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Adxl3xx/Samples/Adxl362_Sample/Adxl362_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Adxl3xx/Samples/Adxl362_Sample/Adxl362_Sample.csproj index cc2bc85fdb..2d1b0c9ebd 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Adxl3xx/Samples/Adxl362_Sample/Adxl362_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Adxl3xx/Samples/Adxl362_Sample/Adxl362_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Adxl3xx/Samples/Adxl377_Sample/Adxl377_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Adxl3xx/Samples/Adxl377_Sample/Adxl377_Sample.csproj index 2c2cd18a18..19c17bf538 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Adxl3xx/Samples/Adxl377_Sample/Adxl377_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Adxl3xx/Samples/Adxl377_Sample/Adxl377_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Apds9960/Driver/Sensors.Motion.Apds9960.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Apds9960/Driver/Sensors.Motion.Apds9960.csproj index 3bc2911726..0f394669f4 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Apds9960/Driver/Sensors.Motion.Apds9960.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Apds9960/Driver/Sensors.Motion.Apds9960.csproj @@ -23,6 +23,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Apds9960/Samples/Apds9960_Sample/Apds9960_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Apds9960/Samples/Apds9960_Sample/Apds9960_Sample.csproj index 05dc90c3e9..d056811ab6 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Apds9960/Samples/Apds9960_Sample/Apds9960_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Apds9960/Samples/Apds9960_Sample/Apds9960_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Bmi270/Driver/Sensors.Motion.Bmi270.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Bmi270/Driver/Sensors.Motion.Bmi270.csproj index 6fdd7343fe..8e9e0d87a2 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Bmi270/Driver/Sensors.Motion.Bmi270.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Bmi270/Driver/Sensors.Motion.Bmi270.csproj @@ -23,6 +23,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Bmi270/Samples/Bmi270_Sample/Bmi270_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Bmi270/Samples/Bmi270_Sample/Bmi270_Sample.csproj index 9cdb936a93..b606b8e84f 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Bmi270/Samples/Bmi270_Sample/Bmi270_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Bmi270/Samples/Bmi270_Sample/Bmi270_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Bno055/Driver/Sensors.Motion.Bno055.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Bno055/Driver/Sensors.Motion.Bno055.csproj index 97938b71f6..5ef7da650a 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Bno055/Driver/Sensors.Motion.Bno055.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Bno055/Driver/Sensors.Motion.Bno055.csproj @@ -23,6 +23,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Bno055/Samples/Bno055_Sample/Bno055_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Bno055/Samples/Bno055_Sample/Bno055_Sample.csproj index 9d7e3761af..bb5a1636e2 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Bno055/Samples/Bno055_Sample/Bno055_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Bno055/Samples/Bno055_Sample/Bno055_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Hcsens0040/Driver/Sensors.Motion.Hcsens0040.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Hcsens0040/Driver/Sensors.Motion.Hcsens0040.csproj index 68ff1b3507..f85706cb5e 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Hcsens0040/Driver/Sensors.Motion.Hcsens0040.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Hcsens0040/Driver/Sensors.Motion.Hcsens0040.csproj @@ -22,6 +22,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Hcsens0040/Samples/Hcsens0040_Sample/Hcsens0040_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Hcsens0040/Samples/Hcsens0040_Sample/Hcsens0040_Sample.csproj index 2c6c307b80..ec0d9a25c2 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Hcsens0040/Samples/Hcsens0040_Sample/Hcsens0040_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Hcsens0040/Samples/Hcsens0040_Sample/Hcsens0040_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Hmc5883/Driver/Sensors.Motion.Hmc5883.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Hmc5883/Driver/Sensors.Motion.Hmc5883.csproj index ae572f5378..764d1185da 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Hmc5883/Driver/Sensors.Motion.Hmc5883.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Hmc5883/Driver/Sensors.Motion.Hmc5883.csproj @@ -23,6 +23,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Hmc5883/Samples/Hmc5883_Sample/Hmc5883_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Hmc5883/Samples/Hmc5883_Sample/Hmc5883_Sample.csproj index 798679edef..fe80eb13f0 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Hmc5883/Samples/Hmc5883_Sample/Hmc5883_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Hmc5883/Samples/Hmc5883_Sample/Hmc5883_Sample.csproj @@ -12,7 +12,7 @@ 9.0 - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Hmc5883/Samples/Qmc5883_Sample/Qmc5883_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Hmc5883/Samples/Qmc5883_Sample/Qmc5883_Sample.csproj index 798679edef..fe80eb13f0 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Hmc5883/Samples/Qmc5883_Sample/Qmc5883_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Hmc5883/Samples/Qmc5883_Sample/Qmc5883_Sample.csproj @@ -12,7 +12,7 @@ 9.0 - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Lis2Mdl/Driver/Sensors.Motion.Lis2Mdl.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Lis2Mdl/Driver/Sensors.Motion.Lis2Mdl.csproj index 6f3ae082b4..b3c2401e41 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Lis2Mdl/Driver/Sensors.Motion.Lis2Mdl.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Lis2Mdl/Driver/Sensors.Motion.Lis2Mdl.csproj @@ -23,6 +23,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Lis2Mdl/Samples/Lis2Mdl_Sample/Lis2Mdl_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Lis2Mdl/Samples/Lis2Mdl_Sample/Lis2Mdl_Sample.csproj index 85210c6654..f09d2850c0 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Lis2Mdl/Samples/Lis2Mdl_Sample/Lis2Mdl_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Lis2Mdl/Samples/Lis2Mdl_Sample/Lis2Mdl_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Lis3Mdl/Driver/Sensors.Motion.Lis3Mdl.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Lis3Mdl/Driver/Sensors.Motion.Lis3Mdl.csproj index 9c229afab2..8046681c83 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Lis3Mdl/Driver/Sensors.Motion.Lis3Mdl.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Lis3Mdl/Driver/Sensors.Motion.Lis3Mdl.csproj @@ -23,6 +23,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Lis3Mdl/Samples/Lis3Mdl_Sample/Lis3Mdl_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Lis3Mdl/Samples/Lis3Mdl_Sample/Lis3Mdl_Sample.csproj index bfb0518924..c471098f87 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Lis3Mdl/Samples/Lis3Mdl_Sample/Lis3Mdl_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Lis3Mdl/Samples/Lis3Mdl_Sample/Lis3Mdl_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Lsm303agr/Driver/Sensors.Motion.Lsm303agr.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Lsm303agr/Driver/Sensors.Motion.Lsm303agr.csproj index 9b0a035213..240e8bf0fd 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Lsm303agr/Driver/Sensors.Motion.Lsm303agr.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Lsm303agr/Driver/Sensors.Motion.Lsm303agr.csproj @@ -23,6 +23,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Lsm303agr/Samples/Lsm303agr_Sample/Lsm303agr_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Lsm303agr/Samples/Lsm303agr_Sample/Lsm303agr_Sample.csproj index 1407302b70..892a276c44 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Lsm303agr/Samples/Lsm303agr_Sample/Lsm303agr_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Lsm303agr/Samples/Lsm303agr_Sample/Lsm303agr_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Lsm6Dsox/Driver/Sensors.Motion.Lsm6Dsox.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Lsm6Dsox/Driver/Sensors.Motion.Lsm6Dsox.csproj index 5859bc2b4a..8bbb1f24a7 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Lsm6Dsox/Driver/Sensors.Motion.Lsm6Dsox.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Lsm6Dsox/Driver/Sensors.Motion.Lsm6Dsox.csproj @@ -23,6 +23,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Lsm6Dsox/Samples/Lsm6Dsox_Sample/Lsm6Dsox_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Lsm6Dsox/Samples/Lsm6Dsox_Sample/Lsm6Dsox_Sample.csproj index 35b883c242..da9da1c179 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Lsm6Dsox/Samples/Lsm6Dsox_Sample/Lsm6Dsox_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Lsm6Dsox/Samples/Lsm6Dsox_Sample/Lsm6Dsox_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Mag3110/Driver/Sensors.Motion.Mag3110.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Mag3110/Driver/Sensors.Motion.Mag3110.csproj index bc8dfe0f3f..1782fef8e8 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Mag3110/Driver/Sensors.Motion.Mag3110.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Mag3110/Driver/Sensors.Motion.Mag3110.csproj @@ -23,6 +23,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Mag3110/Samples/Mag3110_Sample/Mag3110_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Mag3110/Samples/Mag3110_Sample/Mag3110_Sample.csproj index 79bd0e3331..f3bbe46671 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Mag3110/Samples/Mag3110_Sample/Mag3110_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Mag3110/Samples/Mag3110_Sample/Mag3110_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Mma7660fc/Driver/Sensors.Motion.Mma7660fc.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Mma7660fc/Driver/Sensors.Motion.Mma7660fc.csproj index 4f1f2d6e91..850ea11062 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Mma7660fc/Driver/Sensors.Motion.Mma7660fc.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Mma7660fc/Driver/Sensors.Motion.Mma7660fc.csproj @@ -22,6 +22,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Mma7660fc/Samples/Mma7660fc_Sample/Mma7660fc_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Mma7660fc/Samples/Mma7660fc_Sample/Mma7660fc_Sample.csproj index 578a32ab55..81f27fd15e 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Mma7660fc/Samples/Mma7660fc_Sample/Mma7660fc_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Mma7660fc/Samples/Mma7660fc_Sample/Mma7660fc_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Mmc5603/Driver/Sensors.Motion.Mmc5603.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Mmc5603/Driver/Sensors.Motion.Mmc5603.csproj index 7594b1329d..26a976520e 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Mmc5603/Driver/Sensors.Motion.Mmc5603.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Mmc5603/Driver/Sensors.Motion.Mmc5603.csproj @@ -23,6 +23,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Mmc5603/Samples/Mmc5603_Sample/Mmc5603_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Mmc5603/Samples/Mmc5603_Sample/Mmc5603_Sample.csproj index 5d448d8cb6..be6442e93b 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Mmc5603/Samples/Mmc5603_Sample/Mmc5603_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Mmc5603/Samples/Mmc5603_Sample/Mmc5603_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Mpu6050/Driver/Sensors.Motion.Mpu6050.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Mpu6050/Driver/Sensors.Motion.Mpu6050.csproj index 0b7da2a5f1..50b482a2ab 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Mpu6050/Driver/Sensors.Motion.Mpu6050.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Mpu6050/Driver/Sensors.Motion.Mpu6050.csproj @@ -23,6 +23,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Mpu6050/Samples/Mpu6050_Sample/Mpu6050_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Mpu6050/Samples/Mpu6050_Sample/Mpu6050_Sample.csproj index 321c8998c3..3980d16adb 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Mpu6050/Samples/Mpu6050_Sample/Mpu6050_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Mpu6050/Samples/Mpu6050_Sample/Mpu6050_Sample.csproj @@ -12,7 +12,7 @@ 8.0 - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.ParallaxPir/Driver/Sensors.Motion.ParallaxPir.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.ParallaxPir/Driver/Sensors.Motion.ParallaxPir.csproj index 8a3d296f12..045976287d 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.ParallaxPir/Driver/Sensors.Motion.ParallaxPir.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.ParallaxPir/Driver/Sensors.Motion.ParallaxPir.csproj @@ -22,6 +22,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.ParallaxPir/Samples/ParallaxPir_Sample/ParallaxPir_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.ParallaxPir/Samples/ParallaxPir_Sample/ParallaxPir_Sample.csproj index 56c6fc468c..441c8d0cfc 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.ParallaxPir/Samples/ParallaxPir_Sample/ParallaxPir_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.ParallaxPir/Samples/ParallaxPir_Sample/ParallaxPir_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Power.CurrentTransducer/Driver/Sensors.Power.CurrentTransducer.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Power.CurrentTransducer/Driver/Sensors.Power.CurrentTransducer.csproj index 898f362d0e..3196f4d8d5 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Power.CurrentTransducer/Driver/Sensors.Power.CurrentTransducer.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Power.CurrentTransducer/Driver/Sensors.Power.CurrentTransducer.csproj @@ -24,6 +24,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Power.CurrentTransducer/Samples/CurrentTransducer_Sample/CurrentTransducer_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Power.CurrentTransducer/Samples/CurrentTransducer_Sample/CurrentTransducer_Sample.csproj index 94709ca510..35afe41446 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Power.CurrentTransducer/Samples/CurrentTransducer_Sample/CurrentTransducer_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Power.CurrentTransducer/Samples/CurrentTransducer_Sample/CurrentTransducer_Sample.csproj @@ -11,7 +11,7 @@ enable - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Power.Ina2xx/Driver/Sensors.Power.Ina2xx.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Power.Ina2xx/Driver/Sensors.Power.Ina2xx.csproj index 0f35fb059f..eac343be95 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Power.Ina2xx/Driver/Sensors.Power.Ina2xx.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Power.Ina2xx/Driver/Sensors.Power.Ina2xx.csproj @@ -26,6 +26,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Power.Ina2xx/Samples/Ina219_Sample/Ina219_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Power.Ina2xx/Samples/Ina219_Sample/Ina219_Sample.csproj index 71be628ba8..b5a7e8a283 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Power.Ina2xx/Samples/Ina219_Sample/Ina219_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Power.Ina2xx/Samples/Ina219_Sample/Ina219_Sample.csproj @@ -6,7 +6,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Power.Ina2xx/Samples/Ina228_Sample/Ina228_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Power.Ina2xx/Samples/Ina228_Sample/Ina228_Sample.csproj index 71be628ba8..b5a7e8a283 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Power.Ina2xx/Samples/Ina228_Sample/Ina228_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Power.Ina2xx/Samples/Ina228_Sample/Ina228_Sample.csproj @@ -6,7 +6,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Power.Ina2xx/Samples/Ina260_Sample/Ina260_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Power.Ina2xx/Samples/Ina260_Sample/Ina260_Sample.csproj index e22f2e344d..08e4b2ed00 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Power.Ina2xx/Samples/Ina260_Sample/Ina260_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Power.Ina2xx/Samples/Ina260_Sample/Ina260_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Radio.Rfid.IDxxLA/Driver/Sensors.Radio.Rfid.IDxxLA.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Radio.Rfid.IDxxLA/Driver/Sensors.Radio.Rfid.IDxxLA.csproj index 3e1c46755c..c3820e65b9 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Radio.Rfid.IDxxLA/Driver/Sensors.Radio.Rfid.IDxxLA.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Radio.Rfid.IDxxLA/Driver/Sensors.Radio.Rfid.IDxxLA.csproj @@ -22,6 +22,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Radio.Rfid.IDxxLA/Samples/IDxxLA_Sample/IDxxLA_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Radio.Rfid.IDxxLA/Samples/IDxxLA_Sample/IDxxLA_Sample.csproj index 0037527201..2329e6a561 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Radio.Rfid.IDxxLA/Samples/IDxxLA_Sample/IDxxLA_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Radio.Rfid.IDxxLA/Samples/IDxxLA_Sample/IDxxLA_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Sound.Ky038/Driver/Sensors.Sound.Ky038.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Sound.Ky038/Driver/Sensors.Sound.Ky038.csproj index 6f959497f8..223cc23907 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Sound.Ky038/Driver/Sensors.Sound.Ky038.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Sound.Ky038/Driver/Sensors.Sound.Ky038.csproj @@ -22,6 +22,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Sound.Ky038/Samples/Ky038_Sample/Ky038_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Sound.Ky038/Samples/Ky038_Sample/Ky038_Sample.csproj index e3c34d30eb..d6245f0eaf 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Sound.Ky038/Samples/Ky038_Sample/Ky038_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Sound.Ky038/Samples/Ky038_Sample/Ky038_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Adt7410/Datasheet/adt7410.pdf b/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Adt7410/Datasheet/adt7410.pdf new file mode 100644 index 0000000000..fa2d75c98e Binary files /dev/null and b/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Adt7410/Datasheet/adt7410.pdf differ diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Adt7410/Driver/Adt7410.Addresses.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Adt7410/Driver/Adt7410.Addresses.cs new file mode 100644 index 0000000000..d8e94a9823 --- /dev/null +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Adt7410/Driver/Adt7410.Addresses.cs @@ -0,0 +1,20 @@ +namespace Meadow.Foundation.Sensors.Temperature +{ + public partial class Adt7410 + { + /// + /// Valid I2C addresses for the sensor + /// + public enum Addresses : byte + { + /// + /// Bus address 0x48 + /// + Address_0x48 = 0x48, + /// + /// Default bus address + /// + Default = Address_0x48 + } + } +} \ No newline at end of file diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Adt7410/Driver/Adt7410.Registers.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Adt7410/Driver/Adt7410.Registers.cs new file mode 100644 index 0000000000..fd456ba97e --- /dev/null +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Adt7410/Driver/Adt7410.Registers.cs @@ -0,0 +1,47 @@ +namespace Meadow.Foundation.Sensors.Temperature +{ + public partial class Adt7410 + { + /// + /// Enumeration of register addresses for the ADT7410 temperature sensor. + /// + public enum Registers : byte + { + /// + /// Temperature MSB Register. + /// Contains the most significant byte of the temperature data. + /// + TEMPMSB = 0x00, + + /// + /// Temperature LSB Register. + /// Contains the least significant byte of the temperature data. + /// + TEMPLSB = 0x01, + + /// + /// Status Register. + /// Provides the current status of the sensor, including flags for various error conditions. + /// + STATUS = 0x02, + + /// + /// Configuration Register. + /// Used for configuring the sensor, such as setting the resolution and operating mode. + /// + CONFIG = 0x03, + + /// + /// ID Register. + /// Contains the identification value of the sensor, typically used to verify the sensor model. + /// + ID = 0x0B, + + /// + /// Reset Register. + /// Writing to this register will reset the sensor to its default state. + /// + RESET = 0x2F + } + } +} \ No newline at end of file diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Adt7410/Driver/Adt7410.Resolution.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Adt7410/Driver/Adt7410.Resolution.cs new file mode 100644 index 0000000000..02e51c230d --- /dev/null +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Adt7410/Driver/Adt7410.Resolution.cs @@ -0,0 +1,21 @@ +namespace Meadow.Foundation.Sensors.Temperature +{ + public partial class Adt7410 + { + /// + /// Indicate the resolution of the sensor + /// + public enum Resolution : byte + { + /// + /// Operate in 16-bit mode + /// + Resolution16Bits, + + /// + /// Operate in 13-bit mode + /// + Resolution13Bits + } + } +} \ No newline at end of file diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Adt7410/Driver/Adt7410.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Adt7410/Driver/Adt7410.cs new file mode 100644 index 0000000000..0501d9cf6b --- /dev/null +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Adt7410/Driver/Adt7410.cs @@ -0,0 +1,98 @@ +using Meadow.Hardware; +using Meadow.Peripherals.Sensors; +using System.Threading.Tasks; + +namespace Meadow.Foundation.Sensors.Temperature +{ + /// + /// Adt7410 Temperature sensor object + /// + public partial class Adt7410 : ByteCommsSensorBase, + ITemperatureSensor, II2cPeripheral + { + /// + /// The default I2C address for the peripheral + /// + public byte DefaultI2cAddress => (byte)Addresses.Default; + + /// + /// The temperature from the last reading + /// + public Units.Temperature? Temperature => Conditions; + + /// + /// Get / set the resolution of the sensor + /// + public Resolution SensorResolution + { + get => _sensorResolution; + set + { + BusComms?.ReadRegister((byte)Registers.CONFIG, ReadBuffer.Span); + + if (value == Resolution.Resolution16Bits) + { + ReadBuffer.Span[1] |= 0x80; + } + else + { + ReadBuffer.Span[0] &= 0x7F; + } + + BusComms?.WriteRegister((byte)Registers.CONFIG, ReadBuffer.Span); + _sensorResolution = value; + } + } + + /// + /// Backing variable for the SensorResolution property + /// + private Resolution _sensorResolution; + + /// + /// Create a new Adt7410 object using the default configuration for the sensor + /// + /// The I2CBus + /// I2C address of the sensor + public Adt7410(II2cBus i2cBus, byte address = (byte)Addresses.Default) + : base(i2cBus, address, readBufferSize: 2, writeBufferSize: 3) + { + BusComms?.ReadRegister(0x01, ReadBuffer.Span); + + _sensorResolution = (ReadBuffer.Span[0] & 0x80) > 0 ? + Resolution.Resolution16Bits : Resolution.Resolution13Bits; + } + + /// + /// Update the Temperature property + /// + protected override Task ReadSensor() + { + ushort rawValue = BusComms!.ReadRegisterAsUShort((byte)Registers.TEMPMSB, ByteOrder.BigEndian); + int signedValue; + + if (_sensorResolution == Resolution.Resolution13Bits) + { + rawValue >>= 3; + signedValue = rawValue; + + if ((rawValue & 0x1000) == 0x1000) + { + signedValue -= 8192; + } + } + else + { + signedValue = rawValue; + if ((rawValue & 0x8000) == 0x8000) + { + signedValue -= 65536; + } + } + + var degreesPerBit = _sensorResolution == Resolution.Resolution16Bits ? 0.0078125 : 0.0625; + + return Task.FromResult(new Units.Temperature(signedValue * degreesPerBit, Units.Temperature.UnitType.Celsius)); + } + } +} \ No newline at end of file diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Adt7410/Driver/Readme.md b/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Adt7410/Driver/Readme.md new file mode 100644 index 0000000000..32e9052f05 --- /dev/null +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Adt7410/Driver/Readme.md @@ -0,0 +1,82 @@ +# Meadow.Foundation.Sensors.Temperature.Adt7410 + +**Adt7410 I2C temperature sensor** + +The **Adt7410** library is included in the **Meadow.Foundation.Sensors.Temperature.Adt7410** nuget package and is designed for the [Wilderness Labs](www.wildernesslabs.co) Meadow .NET IoT platform. + +This driver is part of the [Meadow.Foundation](https://developer.wildernesslabs.co/Meadow/Meadow.Foundation/) peripherals library, an open-source repository of drivers and libraries that streamline and simplify adding hardware to your C# .NET Meadow IoT applications. + +For more information on developing for Meadow, visit [developer.wildernesslabs.co](http://developer.wildernesslabs.co/). + +To view all Wilderness Labs open-source projects, including samples, visit [github.com/wildernesslabs](https://github.com/wildernesslabs/). + +## Installation + +You can install the library from within Visual studio using the the NuGet Package Manager or from the command line using the .NET CLI: + +`dotnet add package Meadow.Foundation.Sensors.Temperature.Adt7410` +## Usage + +```csharp +Adt7410 adt7410; + +public override Task Initialize() +{ + Resolver.Log.Info("Initialize..."); + + adt7410 = new Adt7410(Device.CreateI2cBus()); + adt7410.SensorResolution = Adt7410.Resolution.Resolution13Bits; + + var consumer = Adt7410.CreateObserver( + handler: result => + { + Resolver.Log.Info($"Temperature New {result.New.Celsius:N2}C, Old {result.Old?.Celsius:N2}C"); + }, + filter: null + ); + adt7410.Subscribe(consumer); + + adt7410.Updated += (object sender, IChangeResult e) => + { + Resolver.Log.Info($"Temperature Updated: {e.New.Celsius:N2}C"); + }; + + return Task.CompletedTask; +} + +public override async Task Run() +{ + var temp = await adt7410.Read(); + Resolver.Log.Info($"Current temperature: {temp.Celsius}C"); + + adt7410.StartUpdating(TimeSpan.FromSeconds(1)); +} + +``` +## How to Contribute + +- **Found a bug?** [Report an issue](https://github.com/WildernessLabs/Meadow_Issues/issues) +- Have a **feature idea or driver request?** [Open a new feature request](https://github.com/WildernessLabs/Meadow_Issues/issues) +- Want to **contribute code?** Fork the [Meadow.Foundation](https://github.com/WildernessLabs/Meadow.Foundation) repository and submit a pull request against the `develop` branch + + +## Need Help? + +If you have questions or need assistance, please join the Wilderness Labs [community on Slack](http://slackinvite.wildernesslabs.co/). +## About Meadow + +Meadow is a complete, IoT platform with defense-grade security that runs full .NET applications on embeddable microcontrollers and Linux single-board computers including Raspberry Pi and NVIDIA Jetson. + +### Build + +Use the full .NET platform and tooling such as Visual Studio and plug-and-play hardware drivers to painlessly build IoT solutions. + +### Connect + +Utilize native support for WiFi, Ethernet, and Cellular connectivity to send sensor data to the Cloud and remotely control your peripherals. + +### Deploy + +Instantly deploy and manage your fleet in the cloud for OtA, health-monitoring, logs, command + control, and enterprise backend integrations. + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Adt7410/Driver/Sensors.Temperature.Adt7410.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Adt7410/Driver/Sensors.Temperature.Adt7410.csproj new file mode 100644 index 0000000000..8b0c77c633 --- /dev/null +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Adt7410/Driver/Sensors.Temperature.Adt7410.csproj @@ -0,0 +1,30 @@ + + + 1.11.0 + true + icon.png + Wilderness Labs, Inc + netstandard2.1 + Library + Adt7410 + Wilderness Labs, Inc + http://developer.wildernesslabs.co/Meadow/Meadow.Foundation/ + Meadow.Foundation.Sensors.Temperature.Adt7410 + https://github.com/WildernessLabs/Meadow.Foundation + Meadow.Foundation,Temperature,Adt7410 + true + Adt7410 I2C temperature sensor + enable + Meadow.Foundation.Sensors.Temperature + + + Readme.md + Apache-2.0 + 10.0 + + + + + + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Adt7410/Samples/Adt7410_Sample/Adt7410_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Adt7410/Samples/Adt7410_Sample/Adt7410_Sample.csproj new file mode 100644 index 0000000000..a849b76bc0 --- /dev/null +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Adt7410/Samples/Adt7410_Sample/Adt7410_Sample.csproj @@ -0,0 +1,15 @@ + + + https://github.com/WildernessLabs/Meadow.Foundation + Wilderness Labs, Inc + Wilderness Labs, Inc + true + netstandard2.1 + Library + App + + + + + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Adt7410/Samples/Adt7410_Sample/MeadowApp.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Adt7410/Samples/Adt7410_Sample/MeadowApp.cs new file mode 100644 index 0000000000..1af66597cf --- /dev/null +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Adt7410/Samples/Adt7410_Sample/MeadowApp.cs @@ -0,0 +1,49 @@ +using Meadow; +using Meadow.Devices; +using Meadow.Foundation.Sensors.Temperature; +using System; +using System.Threading.Tasks; + +namespace Sensors.Temperature.Adt7410_Sample +{ + public class MeadowApp : App + { + // + + Adt7410 adt7410; + + public override Task Initialize() + { + Resolver.Log.Info("Initialize..."); + + adt7410 = new Adt7410(Device.CreateI2cBus()); + adt7410.SensorResolution = Adt7410.Resolution.Resolution13Bits; + + var consumer = Adt7410.CreateObserver( + handler: result => + { + Resolver.Log.Info($"Temperature New {result.New.Celsius:N2}C, Old {result.Old?.Celsius:N2}C"); + }, + filter: null + ); + adt7410.Subscribe(consumer); + + adt7410.Updated += (object sender, IChangeResult e) => + { + Resolver.Log.Info($"Temperature Updated: {e.New.Celsius:N2}C"); + }; + + return Task.CompletedTask; + } + + public override async Task Run() + { + var temp = await adt7410.Read(); + Resolver.Log.Info($"Current temperature: {temp.Celsius}C"); + + adt7410.StartUpdating(TimeSpan.FromSeconds(1)); + } + + // + } +} \ No newline at end of file diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Lm75/Driver/Lm75.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Lm75/Driver/Lm75.cs index 34fbb58354..4db3933d7e 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Lm75/Driver/Lm75.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Lm75/Driver/Lm75.cs @@ -6,7 +6,7 @@ namespace Meadow.Foundation.Sensors.Temperature { /// - /// TMP102 Temperature sensor object + /// LM75 Temperature sensor object /// public partial class Lm75 : ByteCommsSensorBase, ITemperatureSensor, II2cPeripheral @@ -19,10 +19,10 @@ public partial class Lm75 : ByteCommsSensorBase, /// /// The Temperature value from the last reading /// - public Units.Temperature? Temperature { get; protected set; } + public Units.Temperature? Temperature => Conditions; /// - /// Create a new TMP102 object using the default configuration for the sensor + /// Create a new LM75 object using the default configuration for the sensor /// /// The I2C bus /// I2C address of the sensor diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Lm75/Driver/Sensors.Temperature.Lm75.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Lm75/Driver/Sensors.Temperature.Lm75.csproj index e607eb4fab..c322ebaeb9 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Lm75/Driver/Sensors.Temperature.Lm75.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Lm75/Driver/Sensors.Temperature.Lm75.csproj @@ -25,6 +25,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Lm75/Samples/Lm75_Sample/Lm75_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Lm75/Samples/Lm75_Sample/Lm75_Sample.csproj index 08a56abe28..614fc4ce1b 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Lm75/Samples/Lm75_Sample/Lm75_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Lm75/Samples/Lm75_Sample/Lm75_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Mcp960x/Driver/Mcp960x.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Mcp960x/Driver/Mcp960x.cs index 1e0727d363..4c20dd4e35 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Mcp960x/Driver/Mcp960x.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Mcp960x/Driver/Mcp960x.cs @@ -43,12 +43,12 @@ event EventHandler> ISamplingSensor /// The Hot Temperature value from the last reading /// - public Units.Temperature? TemperatureHot { get; protected set; } + public Units.Temperature? TemperatureHot => Conditions.TemperatureHot; /// /// The Cold Temperature value from the last reading /// - public Units.Temperature? TemperatureCold { get; protected set; } + public Units.Temperature? TemperatureCold => Conditions.TemperatureCold; /// /// Create a new Mcp960x object using the default configuration for the sensor diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Mcp960x/Driver/Sensors.Temperature.Mcp960x.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Mcp960x/Driver/Sensors.Temperature.Mcp960x.csproj index a4710cf240..c58160079f 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Mcp960x/Driver/Sensors.Temperature.Mcp960x.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Mcp960x/Driver/Sensors.Temperature.Mcp960x.csproj @@ -25,6 +25,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Mcp960x/Samples/Mcp9600_Sample/Mcp9600_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Mcp960x/Samples/Mcp9600_Sample/Mcp9600_Sample.csproj index 0b12231375..fee7fc434f 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Mcp960x/Samples/Mcp9600_Sample/Mcp9600_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Mcp960x/Samples/Mcp9600_Sample/Mcp9600_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Mcp960x/Samples/Mcp9601_Sample/Mcp9601_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Mcp960x/Samples/Mcp9601_Sample/Mcp9601_Sample.csproj index 0b12231375..fee7fc434f 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Mcp960x/Samples/Mcp9601_Sample/Mcp9601_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Mcp960x/Samples/Mcp9601_Sample/Mcp9601_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Mcp9808/Driver/Mcp9808.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Mcp9808/Driver/Mcp9808.cs index 21e8dbfa9a..a91c82798b 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Mcp9808/Driver/Mcp9808.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Mcp9808/Driver/Mcp9808.cs @@ -16,9 +16,9 @@ public partial class Mcp9808 : ByteCommsSensorBase, public byte DefaultI2cAddress => (byte)Addresses.Default; /// - /// The temperature, in degrees celsius (°C), from the last reading. + /// The current temperature /// - public Units.Temperature? Temperature { get; protected set; } + public Units.Temperature? Temperature => Conditions; /// /// Creates a new Mcp9808 object diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Mcp9808/Driver/Sensors.Temperature.Mcp9808.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Mcp9808/Driver/Sensors.Temperature.Mcp9808.csproj index 4e43692566..e8efd64e49 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Mcp9808/Driver/Sensors.Temperature.Mcp9808.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Mcp9808/Driver/Sensors.Temperature.Mcp9808.csproj @@ -22,6 +22,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Mcp9808/Samples/Mcp9808_Sample/Mcp9808_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Mcp9808/Samples/Mcp9808_Sample/Mcp9808_Sample.csproj index b57eb345ea..87cc2755b6 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Mcp9808/Samples/Mcp9808_Sample/Mcp9808_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Mcp9808/Samples/Mcp9808_Sample/Mcp9808_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Pct2075/Driver/Sensors.Temperature.Pct2075.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Pct2075/Driver/Sensors.Temperature.Pct2075.csproj index a8450814da..b21106080e 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Pct2075/Driver/Sensors.Temperature.Pct2075.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Pct2075/Driver/Sensors.Temperature.Pct2075.csproj @@ -25,6 +25,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Pct2075/Samples/Pct2075_Sample/Pct2075_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Pct2075/Samples/Pct2075_Sample/Pct2075_Sample.csproj index 2318e8c6a2..bff75504cb 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Pct2075/Samples/Pct2075_Sample/Pct2075_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Pct2075/Samples/Pct2075_Sample/Pct2075_Sample.csproj @@ -10,7 +10,7 @@ 10.0 - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Thermistor/Driver/Sensors.Temperature.Thermistor.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Thermistor/Driver/Sensors.Temperature.Thermistor.csproj index a3310436e9..c7e9ef03a4 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Thermistor/Driver/Sensors.Temperature.Thermistor.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Thermistor/Driver/Sensors.Temperature.Thermistor.csproj @@ -25,6 +25,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Thermistor/Driver/Thermistor.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Thermistor/Driver/Thermistor.cs index 1eaad2d6ba..d100480e04 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Thermistor/Driver/Thermistor.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Thermistor/Driver/Thermistor.cs @@ -15,7 +15,7 @@ namespace Meadow.Foundation.Sensors.Temperature /// | /// +---[ TM ]--- < GND /// - public abstract class Thermistor : SamplingSensorBase, ITemperatureSensor + public abstract class Thermistor : PollingSensorBase, ITemperatureSensor { /// /// The analog input port used to determine output voltage of the voltage divider circuit @@ -38,8 +38,6 @@ protected Thermistor(IAnalogInputPort analogInput) { AnalogInputPort = analogInput; AnalogInputPort.StartUpdating(); - - Updated += (s, e) => TemperatureUpdated?.Invoke(this, e); } /// @@ -51,6 +49,8 @@ public override void StartUpdating(TimeSpan? updateInterval = null) IsSampling = true; AnalogInputPort.StartUpdating(updateInterval); } + + base.StartUpdating(updateInterval); } /// @@ -62,16 +62,13 @@ public override void StopUpdating() IsSampling = false; AnalogInputPort.StopUpdating(); } + + base.StopUpdating(); } /// /// The temperature from the last reading /// - public Units.Temperature? Temperature { get; protected set; } - - /// - /// Raised when the temperature is updated - /// - public event EventHandler> TemperatureUpdated = default!; + public Units.Temperature? Temperature => Conditions; } } \ No newline at end of file diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Thermistor/Samples/Thermistor_Sample/Thermistor_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Thermistor/Samples/Thermistor_Sample/Thermistor_Sample.csproj index 2b26a86b92..4e43ff4830 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Thermistor/Samples/Thermistor_Sample/Thermistor_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Thermistor/Samples/Thermistor_Sample/Thermistor_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Tmp102/Driver/Sensors.Temperature.Tmp102.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Tmp102/Driver/Sensors.Temperature.Tmp102.csproj index ff72c29154..b7a6240c78 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Tmp102/Driver/Sensors.Temperature.Tmp102.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Tmp102/Driver/Sensors.Temperature.Tmp102.csproj @@ -25,6 +25,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Tmp102/Driver/Tmp102.Resolution.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Tmp102/Driver/Tmp102.Resolution.cs index 8c93a9a5e8..d84a78ad30 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Tmp102/Driver/Tmp102.Resolution.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Tmp102/Driver/Tmp102.Resolution.cs @@ -17,6 +17,5 @@ public enum Resolution : byte /// Resolution13Bits } - } -} +} \ No newline at end of file diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Tmp102/Driver/Tmp102.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Tmp102/Driver/Tmp102.cs index cb156d2d09..6adc702481 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Tmp102/Driver/Tmp102.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Tmp102/Driver/Tmp102.cs @@ -47,7 +47,7 @@ public Resolution SensorResolution /// /// The temperature from the last reading /// - public Units.Temperature? Temperature { get; protected set; } + public Units.Temperature? Temperature => Conditions; /// /// Create a new TMP102 object using the default configuration for the sensor @@ -55,7 +55,7 @@ public Resolution SensorResolution /// The I2CBus /// I2C address of the sensor public Tmp102(II2cBus i2cBus, byte address = (byte)Addresses.Default) - : base(i2cBus, address, readBufferSize: 2, writeBufferSize: 2) + : base(i2cBus, address, readBufferSize: 2, writeBufferSize: 3) { BusComms?.ReadRegister(0x01, ReadBuffer.Span); _sensorResolution = (ReadBuffer.Span[1] & 0x10) > 0 ? diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Tmp102/Samples/Tmp102_Sample/MeadowApp.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Tmp102/Samples/Tmp102_Sample/MeadowApp.cs index f9d45862fb..a851a2412a 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Tmp102/Samples/Tmp102_Sample/MeadowApp.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Tmp102/Samples/Tmp102_Sample/MeadowApp.cs @@ -6,9 +6,6 @@ namespace Sensors.Temperature.Tmp102_Sample { - // TODO: This sample needs a rewrite. See the other atmospheric samples for - // an example of the sample pattern. - public class MeadowApp : App { // diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Tmp102/Samples/Tmp102_Sample/Tmp102_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Tmp102/Samples/Tmp102_Sample/Tmp102_Sample.csproj index debb9d4746..8b0d3ecd5d 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Tmp102/Samples/Tmp102_Sample/Tmp102_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Tmp102/Samples/Tmp102_Sample/Tmp102_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Weather.SwitchingAnemometer/Driver/Sensors.Weather.SwitchingAnemometer.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Weather.SwitchingAnemometer/Driver/Sensors.Weather.SwitchingAnemometer.csproj index 731dc39ca8..c5fdc0356f 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Weather.SwitchingAnemometer/Driver/Sensors.Weather.SwitchingAnemometer.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Weather.SwitchingAnemometer/Driver/Sensors.Weather.SwitchingAnemometer.csproj @@ -24,6 +24,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Weather.SwitchingAnemometer/Driver/SwitchingAnemometer.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Weather.SwitchingAnemometer/Driver/SwitchingAnemometer.cs index 2b474a2599..69d8e6dda3 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Weather.SwitchingAnemometer/Driver/SwitchingAnemometer.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Weather.SwitchingAnemometer/Driver/SwitchingAnemometer.cs @@ -17,7 +17,7 @@ public class SwitchingAnemometer : PollingSensorBase, IAnemometer, IDispo /// /// The current wind speed /// - public Speed? WindSpeed { get; protected set; } + public Speed? WindSpeed => Conditions; /// /// Time to wait if no events come in to register a zero speed wind diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Weather.SwitchingAnemometer/Samples/SwitchingAnemometer_Sample/SwitchingAnemometer_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Weather.SwitchingAnemometer/Samples/SwitchingAnemometer_Sample/SwitchingAnemometer_Sample.csproj index b2666d8508..bb973eb1be 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Weather.SwitchingAnemometer/Samples/SwitchingAnemometer_Sample/SwitchingAnemometer_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Weather.SwitchingAnemometer/Samples/SwitchingAnemometer_Sample/SwitchingAnemometer_Sample.csproj @@ -11,7 +11,7 @@ - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Weather.SwitchingRainGauge/Driver/Sensors.Weather.SwitchingRainGauge.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Weather.SwitchingRainGauge/Driver/Sensors.Weather.SwitchingRainGauge.csproj index ff773c90c9..d0124d6455 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Weather.SwitchingRainGauge/Driver/Sensors.Weather.SwitchingRainGauge.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Weather.SwitchingRainGauge/Driver/Sensors.Weather.SwitchingRainGauge.csproj @@ -22,6 +22,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Weather.SwitchingRainGauge/Samples/SwitchingRainGauge_Sample/SwitchingRainGauge_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Weather.SwitchingRainGauge/Samples/SwitchingRainGauge_Sample/SwitchingRainGauge_Sample.csproj index 849ece8e3f..ebdead2dc1 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Weather.SwitchingRainGauge/Samples/SwitchingRainGauge_Sample/SwitchingRainGauge_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Weather.SwitchingRainGauge/Samples/SwitchingRainGauge_Sample/SwitchingRainGauge_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Weather.WindVane/Driver/Sensors.Weather.WindVane.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Weather.WindVane/Driver/Sensors.Weather.WindVane.csproj index 6546e80c0a..53b805049f 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Weather.WindVane/Driver/Sensors.Weather.WindVane.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Weather.WindVane/Driver/Sensors.Weather.WindVane.csproj @@ -22,6 +22,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Weather.WindVane/Samples/WindVane_Sample/WindVane_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Weather.WindVane/Samples/WindVane_Sample/WindVane_Sample.csproj index f271557c09..6422dac0d3 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Weather.WindVane/Samples/WindVane_Sample/WindVane_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Weather.WindVane/Samples/WindVane_Sample/WindVane_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Servos.ServoCore/Driver/ContinuousRotationServoBase.cs b/Source/Meadow.Foundation.Peripherals/Servos.ServoCore/Driver/ContinuousRotationServoBase.cs index 050ae2f392..52a91ae31e 100644 --- a/Source/Meadow.Foundation.Peripherals/Servos.ServoCore/Driver/ContinuousRotationServoBase.cs +++ b/Source/Meadow.Foundation.Peripherals/Servos.ServoCore/Driver/ContinuousRotationServoBase.cs @@ -9,7 +9,7 @@ namespace Meadow.Foundation.Servos public abstract class ContinuousRotationServoBase : ServoBase, IContinuousRotationServo { /// - /// Gets the current rotation direction. + /// Gets the current rotation direction /// public RotationDirection CurrentDirection { get; protected set; } = RotationDirection.None; @@ -35,9 +35,9 @@ public ContinuousRotationServoBase(IPwmPort pwm, ServoConfig config) /// 0.0 to 1.0 (0% to 100%). public void Rotate(RotationDirection direction, float speed) { - if (speed < 0 || speed > 1) + if (speed is < 0 or > 1) { - throw new ArgumentOutOfRangeException("speed", "speed must be 0.0 - 1.0."); + throw new ArgumentOutOfRangeException(nameof(speed), "speed must be 0.0 - 1.0."); } // calculate the appropriate pulse duration for the speed and direction diff --git a/Source/Meadow.Foundation.Peripherals/Servos.ServoCore/Driver/ServoBase.cs b/Source/Meadow.Foundation.Peripherals/Servos.ServoCore/Driver/ServoBase.cs index b03ceecdda..f381d530ff 100644 --- a/Source/Meadow.Foundation.Peripherals/Servos.ServoCore/Driver/ServoBase.cs +++ b/Source/Meadow.Foundation.Peripherals/Servos.ServoCore/Driver/ServoBase.cs @@ -8,12 +8,12 @@ namespace Meadow.Foundation.Servos public abstract class ServoBase : IServo { /// - /// Gets the PWM port used to drive the Servo + /// Gets the PWM port used to drive the servo /// protected IPwmPort PwmPort { get; } /// - /// Gets the ServoConfig that describes this servo. + /// Gets the ServoConfig that describes this servo /// public ServoConfig Config { get; protected set; } diff --git a/Source/Meadow.Foundation.Peripherals/Servos.ServoCore/Driver/Servos.ServoCore.csproj b/Source/Meadow.Foundation.Peripherals/Servos.ServoCore/Driver/Servos.ServoCore.csproj index 2067f7f69a..4be768d85e 100644 --- a/Source/Meadow.Foundation.Peripherals/Servos.ServoCore/Driver/Servos.ServoCore.csproj +++ b/Source/Meadow.Foundation.Peripherals/Servos.ServoCore/Driver/Servos.ServoCore.csproj @@ -24,6 +24,6 @@ - + diff --git a/Source/Meadow.Foundation.Peripherals/Servos.ServoCore/Samples/ServoCore_Sample/ServoCore_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Servos.ServoCore/Samples/ServoCore_Sample/ServoCore_Sample.csproj index ed9c619a4b..57bb688867 100644 --- a/Source/Meadow.Foundation.Peripherals/Servos.ServoCore/Samples/ServoCore_Sample/ServoCore_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Servos.ServoCore/Samples/ServoCore_Sample/ServoCore_Sample.csproj @@ -9,7 +9,7 @@ App - - + + diff --git a/Source/Meadow.Foundation.sln b/Source/Meadow.Foundation.sln index 4af3b44e51..11d6dd0ff0 100644 --- a/Source/Meadow.Foundation.sln +++ b/Source/Meadow.Foundation.sln @@ -343,8 +343,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sensors.Light.Temt6000", "M EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Temt6000_Sample", "Meadow.Foundation.Peripherals\Sensors.Light.Temt6000\Samples\Temt6000_Sample\Temt6000_Sample.csproj", "{E05DC818-719E-4EB5-AF5F-A6C9C3C9D01B}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ds323x_Sample", "Meadow.Foundation.Peripherals\RTCs.Ds323x\Samples\Ds323x_Sample\Ds323x_Sample.csproj", "{A059BFE2-87FD-482C-B1DC-5C8023C79DA0}" -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "At24Cxx_Sample", "Meadow.Foundation.Peripherals\ICs.EEPROM.At24Cxx\Samples\At24Cxx_Sample\At24Cxx_Sample.csproj", "{9AF786F5-B6CA-490B-9926-2CCA9CFF1431}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Ms5611", "Ms5611", "{3FF07962-C887-495B-9B0E-EA2313B1F4AE}" @@ -1321,8 +1319,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Pcf8574_Sample", "Meadow.Fo EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Pcf8575_Sample", "Meadow.Foundation.Peripherals\ICs.IOExpanders.Pcx857x\Samples\Pcf8575_Sample\Pcf8575_Sample.csproj", "{97A8C2BD-3259-4A7A-B8F5-B08C001865D4}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ili9488Charts_Sample", "Meadow.Foundation.Libraries_and_Frameworks\Graphics.MicroLayout\Samples\Ili9488Charts_Sample\Ili9488Charts_Sample.csproj", "{8343269F-3016-4C34-AFC0-278013305E77}" -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HMI_Sample", "Meadow.Foundation.Libraries_and_Frameworks\Graphics.MicroLayout\Samples\HMI_Sample\HMI_Sample.csproj", "{04979CBD-EAEE-4802-810D-B4F1FD69131F}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TextDisplayMenuTft_Sample", "Meadow.Foundation.Libraries_and_Frameworks\Displays.TextDisplayMenu\Samples\TextDisplayMenuTft_Sample\TextDisplayMenuTft_Sample.csproj", "{89A32F78-E00E-4F0E-B802-389C5C893B91}" @@ -1435,6 +1431,14 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Samples", "Samples", "{FC2E EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Pct2075_Sample", "Meadow.Foundation.Peripherals\Sensors.Temperature.Pct2075\Samples\Pct2075_Sample\Pct2075_Sample.csproj", "{2B29B1A8-8903-4335-A5CC-6FFBD9069C2D}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Mcp4728", "Mcp4728", "{15184F80-6B76-4C34-8405-233F6347F636}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ICs.DAC.Mcp4728", "Meadow.Foundation.Peripherals\ICs.DAC.Mcp4728\Driver\ICs.DAC.Mcp4728.csproj", "{8BDA078E-1762-4215-98AB-6374A0FEC4A2}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Samples", "Samples", "{0EA7D8F6-856A-4357-BBDB-CD43324920D9}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Mcp4728_Sample", "Meadow.Foundation.Peripherals\ICs.DAC.Mcp4728\Sample\Mcp4728_Sample.csproj", "{B2E4607B-AB07-4667-9A07-9368286E4EA4}" +EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Touchscreen", "Touchscreen", "{B773E1A0-FA17-4D5A-BAF9-29CA3CF00789}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Xpt2046", "Xpt2046", "{FB71B923-4A40-4C68-BEA9-846A57813ED2}" @@ -1491,6 +1495,36 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Samples", "Samples", "{3D09 EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Silk_Sample", "Meadow.Foundation.Peripherals\Displays.Silk\Samples\Silk_Sample\Silk_Sample.csproj", "{5500B380-D815-4911-A30A-1DFB311F60BB}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Adt7410", "Adt7410", "{40E30114-4639-4F9F-9936-12E169B6E955}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Samples", "Samples", "{5200F1B2-C218-4CF8-B9AB-876AF244B839}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sensors.Temperature.Adt7410", "Meadow.Foundation.Peripherals\Sensors.Temperature.Adt7410\Driver\Sensors.Temperature.Adt7410.csproj", "{940EEEA3-64F8-48D4-9568-8C9487C22876}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Adt7410_Sample", "Meadow.Foundation.Peripherals\Sensors.Temperature.Adt7410\Samples\Adt7410_Sample\Adt7410_Sample.csproj", "{9C465F6E-AE56-48AB-8ABE-CE8428599D07}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Adxl343_Sample", "Meadow.Foundation.Peripherals\Sensors.Motion.Adxl3xx\Samples\Adxl343_Sample\Adxl343_Sample.csproj", "{C10E05C3-5E2D-4334-BDCF-5D3A5748C882}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ds3231_Sample", "Meadow.Foundation.Peripherals\RTCs.Ds323x\Samples\Ds3231_Sample\Ds3231_Sample.csproj", "{06A16755-8494-481E-B6F6-B983B1C4AB74}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ds3232_Sample", "Meadow.Foundation.Peripherals\RTCs.Ds323x\Samples\Ds3232_Sample\Ds3232_Sample.csproj", "{98BECE8D-19EA-44BB-9055-6524E500CF8D}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ListBox_Sample", "Meadow.Foundation.Libraries_and_Frameworks\Graphics.MicroLayout\Samples\ListBox_Sample\ListBox_Sample.csproj", "{99DE1F8B-7D07-41C7-83A1-DA878AFF67E8}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Charts_Sample", "Meadow.Foundation.Libraries_and_Frameworks\Graphics.MicroLayout\Samples\Charts_Sample\Charts_Sample.csproj", "{71AA2CAB-BB32-48CD-B711-50CD13104C76}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Ahtx0", "Ahtx0", "{F93B0027-D970-47A2-8D97-F132AE1BE609}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Samples", "Samples", "{AE9AD583-1709-434D-9C7E-FE776B2005F0}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sensors.Atmospheric.Ahtx0", "Meadow.Foundation.Peripherals\Sensors.Atmospheric.Ahtx0\Driver\Sensors.Atmospheric.Ahtx0.csproj", "{E92014B1-100A-40A7-998F-CE712777FE02}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Aht10_Sample", "Meadow.Foundation.Peripherals\Sensors.Atmospheric.Ahtx0\Samples\Aht10_Sample\Aht10_Sample.csproj", "{EA7B5437-D3CD-4996-9DB7-09E6DCB1D6EA}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Aht10_Desktop_Sample", "Meadow.Foundation.Peripherals\Sensors.Atmospheric.Ahtx0\Samples\Aht10_Desktop_Sample\Aht10_Desktop_Sample.csproj", "{C1AF868A-B1FF-4DE6-985B-07E2916A0325}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Silk_Image_Sample", "Meadow.Foundation.Peripherals\Displays.Silk\Samples\Silk_Image_Sample\Silk_Image_Sample.csproj", "{226E85FE-EB1A-46E9-B91A-50BC183F4BF3}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -1865,10 +1899,6 @@ Global {E05DC818-719E-4EB5-AF5F-A6C9C3C9D01B}.Debug|Any CPU.Build.0 = Debug|Any CPU {E05DC818-719E-4EB5-AF5F-A6C9C3C9D01B}.Release|Any CPU.ActiveCfg = Release|Any CPU {E05DC818-719E-4EB5-AF5F-A6C9C3C9D01B}.Release|Any CPU.Build.0 = Release|Any CPU - {A059BFE2-87FD-482C-B1DC-5C8023C79DA0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {A059BFE2-87FD-482C-B1DC-5C8023C79DA0}.Debug|Any CPU.Build.0 = Debug|Any CPU - {A059BFE2-87FD-482C-B1DC-5C8023C79DA0}.Release|Any CPU.ActiveCfg = Release|Any CPU - {A059BFE2-87FD-482C-B1DC-5C8023C79DA0}.Release|Any CPU.Build.0 = Release|Any CPU {9AF786F5-B6CA-490B-9926-2CCA9CFF1431}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {9AF786F5-B6CA-490B-9926-2CCA9CFF1431}.Debug|Any CPU.Build.0 = Debug|Any CPU {9AF786F5-B6CA-490B-9926-2CCA9CFF1431}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -3325,10 +3355,6 @@ Global {97A8C2BD-3259-4A7A-B8F5-B08C001865D4}.Release|Any CPU.ActiveCfg = Release|Any CPU {97A8C2BD-3259-4A7A-B8F5-B08C001865D4}.Release|Any CPU.Build.0 = Release|Any CPU {97A8C2BD-3259-4A7A-B8F5-B08C001865D4}.Release|Any CPU.Deploy.0 = Release|Any CPU - {8343269F-3016-4C34-AFC0-278013305E77}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {8343269F-3016-4C34-AFC0-278013305E77}.Debug|Any CPU.Build.0 = Debug|Any CPU - {8343269F-3016-4C34-AFC0-278013305E77}.Release|Any CPU.ActiveCfg = Release|Any CPU - {8343269F-3016-4C34-AFC0-278013305E77}.Release|Any CPU.Build.0 = Release|Any CPU {04979CBD-EAEE-4802-810D-B4F1FD69131F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {04979CBD-EAEE-4802-810D-B4F1FD69131F}.Debug|Any CPU.Build.0 = Debug|Any CPU {04979CBD-EAEE-4802-810D-B4F1FD69131F}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -3495,6 +3521,18 @@ Global {2B29B1A8-8903-4335-A5CC-6FFBD9069C2D}.Release|Any CPU.ActiveCfg = Release|Any CPU {2B29B1A8-8903-4335-A5CC-6FFBD9069C2D}.Release|Any CPU.Build.0 = Release|Any CPU {2B29B1A8-8903-4335-A5CC-6FFBD9069C2D}.Release|Any CPU.Deploy.0 = Release|Any CPU + {8BDA078E-1762-4215-98AB-6374A0FEC4A2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8BDA078E-1762-4215-98AB-6374A0FEC4A2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8BDA078E-1762-4215-98AB-6374A0FEC4A2}.Debug|Any CPU.Deploy.0 = Debug|Any CPU + {8BDA078E-1762-4215-98AB-6374A0FEC4A2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8BDA078E-1762-4215-98AB-6374A0FEC4A2}.Release|Any CPU.Build.0 = Release|Any CPU + {8BDA078E-1762-4215-98AB-6374A0FEC4A2}.Release|Any CPU.Deploy.0 = Release|Any CPU + {B2E4607B-AB07-4667-9A07-9368286E4EA4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B2E4607B-AB07-4667-9A07-9368286E4EA4}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B2E4607B-AB07-4667-9A07-9368286E4EA4}.Debug|Any CPU.Deploy.0 = Debug|Any CPU + {B2E4607B-AB07-4667-9A07-9368286E4EA4}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B2E4607B-AB07-4667-9A07-9368286E4EA4}.Release|Any CPU.Build.0 = Release|Any CPU + {B2E4607B-AB07-4667-9A07-9368286E4EA4}.Release|Any CPU.Deploy.0 = Release|Any CPU {C399419B-04D5-40A2-9501-F21DEDAF3EC6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {C399419B-04D5-40A2-9501-F21DEDAF3EC6}.Debug|Any CPU.Build.0 = Debug|Any CPU {C399419B-04D5-40A2-9501-F21DEDAF3EC6}.Debug|Any CPU.Deploy.0 = Debug|Any CPU @@ -3587,6 +3625,50 @@ Global {5500B380-D815-4911-A30A-1DFB311F60BB}.Debug|Any CPU.Build.0 = Debug|Any CPU {5500B380-D815-4911-A30A-1DFB311F60BB}.Release|Any CPU.ActiveCfg = Release|Any CPU {5500B380-D815-4911-A30A-1DFB311F60BB}.Release|Any CPU.Build.0 = Release|Any CPU + {940EEEA3-64F8-48D4-9568-8C9487C22876}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {940EEEA3-64F8-48D4-9568-8C9487C22876}.Debug|Any CPU.Build.0 = Debug|Any CPU + {940EEEA3-64F8-48D4-9568-8C9487C22876}.Release|Any CPU.ActiveCfg = Release|Any CPU + {940EEEA3-64F8-48D4-9568-8C9487C22876}.Release|Any CPU.Build.0 = Release|Any CPU + {9C465F6E-AE56-48AB-8ABE-CE8428599D07}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9C465F6E-AE56-48AB-8ABE-CE8428599D07}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9C465F6E-AE56-48AB-8ABE-CE8428599D07}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9C465F6E-AE56-48AB-8ABE-CE8428599D07}.Release|Any CPU.Build.0 = Release|Any CPU + {C10E05C3-5E2D-4334-BDCF-5D3A5748C882}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C10E05C3-5E2D-4334-BDCF-5D3A5748C882}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C10E05C3-5E2D-4334-BDCF-5D3A5748C882}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C10E05C3-5E2D-4334-BDCF-5D3A5748C882}.Release|Any CPU.Build.0 = Release|Any CPU + {06A16755-8494-481E-B6F6-B983B1C4AB74}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {06A16755-8494-481E-B6F6-B983B1C4AB74}.Debug|Any CPU.Build.0 = Debug|Any CPU + {06A16755-8494-481E-B6F6-B983B1C4AB74}.Release|Any CPU.ActiveCfg = Release|Any CPU + {06A16755-8494-481E-B6F6-B983B1C4AB74}.Release|Any CPU.Build.0 = Release|Any CPU + {98BECE8D-19EA-44BB-9055-6524E500CF8D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {98BECE8D-19EA-44BB-9055-6524E500CF8D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {98BECE8D-19EA-44BB-9055-6524E500CF8D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {98BECE8D-19EA-44BB-9055-6524E500CF8D}.Release|Any CPU.Build.0 = Release|Any CPU + {99DE1F8B-7D07-41C7-83A1-DA878AFF67E8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {99DE1F8B-7D07-41C7-83A1-DA878AFF67E8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {99DE1F8B-7D07-41C7-83A1-DA878AFF67E8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {99DE1F8B-7D07-41C7-83A1-DA878AFF67E8}.Release|Any CPU.Build.0 = Release|Any CPU + {71AA2CAB-BB32-48CD-B711-50CD13104C76}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {71AA2CAB-BB32-48CD-B711-50CD13104C76}.Debug|Any CPU.Build.0 = Debug|Any CPU + {71AA2CAB-BB32-48CD-B711-50CD13104C76}.Release|Any CPU.ActiveCfg = Release|Any CPU + {71AA2CAB-BB32-48CD-B711-50CD13104C76}.Release|Any CPU.Build.0 = Release|Any CPU + {E92014B1-100A-40A7-998F-CE712777FE02}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E92014B1-100A-40A7-998F-CE712777FE02}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E92014B1-100A-40A7-998F-CE712777FE02}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E92014B1-100A-40A7-998F-CE712777FE02}.Release|Any CPU.Build.0 = Release|Any CPU + {EA7B5437-D3CD-4996-9DB7-09E6DCB1D6EA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {EA7B5437-D3CD-4996-9DB7-09E6DCB1D6EA}.Debug|Any CPU.Build.0 = Debug|Any CPU + {EA7B5437-D3CD-4996-9DB7-09E6DCB1D6EA}.Release|Any CPU.ActiveCfg = Release|Any CPU + {EA7B5437-D3CD-4996-9DB7-09E6DCB1D6EA}.Release|Any CPU.Build.0 = Release|Any CPU + {C1AF868A-B1FF-4DE6-985B-07E2916A0325}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C1AF868A-B1FF-4DE6-985B-07E2916A0325}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C1AF868A-B1FF-4DE6-985B-07E2916A0325}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C1AF868A-B1FF-4DE6-985B-07E2916A0325}.Release|Any CPU.Build.0 = Release|Any CPU + {226E85FE-EB1A-46E9-B91A-50BC183F4BF3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {226E85FE-EB1A-46E9-B91A-50BC183F4BF3}.Debug|Any CPU.Build.0 = Debug|Any CPU + {226E85FE-EB1A-46E9-B91A-50BC183F4BF3}.Release|Any CPU.ActiveCfg = Release|Any CPU + {226E85FE-EB1A-46E9-B91A-50BC183F4BF3}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -3759,7 +3841,6 @@ Global {3DAA8F7C-7F99-4515-9467-CC88D1D92145} = {606456FE-9938-47EB-9327-001915575421} {CC00EF84-5144-4FFC-B194-56086D47BFAB} = {606456FE-9938-47EB-9327-001915575421} {E05DC818-719E-4EB5-AF5F-A6C9C3C9D01B} = {3DAA8F7C-7F99-4515-9467-CC88D1D92145} - {A059BFE2-87FD-482C-B1DC-5C8023C79DA0} = {C32CCF68-5D86-4337-BF37-4053C7F01848} {9AF786F5-B6CA-490B-9926-2CCA9CFF1431} = {671D7B77-DEBE-416D-818D-99411DF479AC} {3FF07962-C887-495B-9B0E-EA2313B1F4AE} = {DB3AAEB4-38A5-4A85-AEB4-F4FCCDA12188} {8C890579-33B9-4DE8-98B4-52B3E5893F8C} = {3FF07962-C887-495B-9B0E-EA2313B1F4AE} @@ -4247,7 +4328,6 @@ Global {59E30BBD-0A80-44E9-B38A-A0D401F25677} = {DD6634D3-A451-4C3E-A971-010FA021B6AA} {73A7EBC9-DE59-4DC1-AE11-27E168DCDDC6} = {DD6634D3-A451-4C3E-A971-010FA021B6AA} {97A8C2BD-3259-4A7A-B8F5-B08C001865D4} = {DD6634D3-A451-4C3E-A971-010FA021B6AA} - {8343269F-3016-4C34-AFC0-278013305E77} = {E762EEFF-E646-4517-BAE6-4E23A34854DC} {04979CBD-EAEE-4802-810D-B4F1FD69131F} = {E762EEFF-E646-4517-BAE6-4E23A34854DC} {89A32F78-E00E-4F0E-B802-389C5C893B91} = {E9BE2E5E-D4A3-484A-BBE8-DC6715B1E2C8} {45C6AAB8-2F59-4A35-9764-356D148A887A} = {A1917BD0-881F-4775-88D9-38D42D448CF5} @@ -4304,6 +4384,10 @@ Global {3C999A94-227A-470F-935E-966E375E40BB} = {7471C6BF-1995-4E56-91E9-86DAAA46C386} {FC2EEFA9-030B-4EF0-AFB7-1CC61876D1EE} = {7471C6BF-1995-4E56-91E9-86DAAA46C386} {2B29B1A8-8903-4335-A5CC-6FFBD9069C2D} = {FC2EEFA9-030B-4EF0-AFB7-1CC61876D1EE} + {15184F80-6B76-4C34-8405-233F6347F636} = {45C6AAB8-2F59-4A35-9764-356D148A887A} + {8BDA078E-1762-4215-98AB-6374A0FEC4A2} = {15184F80-6B76-4C34-8405-233F6347F636} + {0EA7D8F6-856A-4357-BBDB-CD43324920D9} = {15184F80-6B76-4C34-8405-233F6347F636} + {B2E4607B-AB07-4667-9A07-9368286E4EA4} = {0EA7D8F6-856A-4357-BBDB-CD43324920D9} {B773E1A0-FA17-4D5A-BAF9-29CA3CF00789} = {818BF624-10A7-45B2-9BEE-4C411CD9CA06} {FB71B923-4A40-4C68-BEA9-846A57813ED2} = {B773E1A0-FA17-4D5A-BAF9-29CA3CF00789} {C399419B-04D5-40A2-9501-F21DEDAF3EC6} = {FB71B923-4A40-4C68-BEA9-846A57813ED2} @@ -4332,6 +4416,21 @@ Global {37F84366-1DC7-4DDF-8C33-6A45219F4882} = {0E913C73-609E-40D7-949C-553615CD13B8} {3D090B0B-F863-4B8A-942C-89ED6C71BFF2} = {0E913C73-609E-40D7-949C-553615CD13B8} {5500B380-D815-4911-A30A-1DFB311F60BB} = {3D090B0B-F863-4B8A-942C-89ED6C71BFF2} + {40E30114-4639-4F9F-9936-12E169B6E955} = {DBC6C89D-A932-4F99-9382-7405A0045988} + {5200F1B2-C218-4CF8-B9AB-876AF244B839} = {40E30114-4639-4F9F-9936-12E169B6E955} + {940EEEA3-64F8-48D4-9568-8C9487C22876} = {40E30114-4639-4F9F-9936-12E169B6E955} + {9C465F6E-AE56-48AB-8ABE-CE8428599D07} = {5200F1B2-C218-4CF8-B9AB-876AF244B839} + {C10E05C3-5E2D-4334-BDCF-5D3A5748C882} = {4660F8A6-3E4A-47D3-BBFE-5CC06AEE7E4D} + {06A16755-8494-481E-B6F6-B983B1C4AB74} = {C32CCF68-5D86-4337-BF37-4053C7F01848} + {98BECE8D-19EA-44BB-9055-6524E500CF8D} = {C32CCF68-5D86-4337-BF37-4053C7F01848} + {99DE1F8B-7D07-41C7-83A1-DA878AFF67E8} = {E762EEFF-E646-4517-BAE6-4E23A34854DC} + {71AA2CAB-BB32-48CD-B711-50CD13104C76} = {E762EEFF-E646-4517-BAE6-4E23A34854DC} + {F93B0027-D970-47A2-8D97-F132AE1BE609} = {DB3AAEB4-38A5-4A85-AEB4-F4FCCDA12188} + {AE9AD583-1709-434D-9C7E-FE776B2005F0} = {F93B0027-D970-47A2-8D97-F132AE1BE609} + {E92014B1-100A-40A7-998F-CE712777FE02} = {F93B0027-D970-47A2-8D97-F132AE1BE609} + {EA7B5437-D3CD-4996-9DB7-09E6DCB1D6EA} = {AE9AD583-1709-434D-9C7E-FE776B2005F0} + {C1AF868A-B1FF-4DE6-985B-07E2916A0325} = {AE9AD583-1709-434D-9C7E-FE776B2005F0} + {226E85FE-EB1A-46E9-B91A-50BC183F4BF3} = {3D090B0B-F863-4B8A-942C-89ED6C71BFF2} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {AF7CA16F-8C38-4546-87A2-5DAAF58A1520}