diff --git a/README.md b/README.md index 9d7e93db8d..d6eaa5e4c8 100644 --- a/README.md +++ b/README.md @@ -27,9 +27,11 @@ Meadow.Foundation makes the task of building connected things easy with Meadow b Meadow.Foundation is currently split into multiple GitHub repos: 1. [Meadow.Foundation](https://github.com/WildernessLabs/Meadow.Foundation/) which contains the majority of the peripheral and library source code -2. [Meadow.Foundation.Featherwings](https://github.com/WildernessLabs/Meadow.Foundation.Featherwings/) contains drivers for hardware that conforms to the [Adafruit Featherwing](https://learn.adafruit.com/adafruit-feather/) form factor -3. [Meadow.Foundation.Grove](https://github.com/WildernessLabs/Meadow.Foundation.Grove/) contains drivers for [Seeed Studio Grove](https://www.seeedstudio.com/grove.html) modular hardware peripherals -4. [Meadow.Foundation.MikroBus](https://github.com/WildernessLabs/Meadow.Foundation.mikrobus/) contains drivers for [MikroElektronika](https://www.mikroe.com/click) mikroBUS Click Boards +2. [Meadow.Foundation.CompositeDevices]([https://github.com/WildernessLabs/Meadow.Foundation.Featherwings/](https://github.com/wildernesslabs/meadow.foundation.compositedevices)) contains drivers for devices that combine multiple peripherals or leverage additional onboard microcontrollers +3. [Meadow.Foundation.Featherwings](https://github.com/WildernessLabs/Meadow.Foundation.Featherwings/) contains drivers for hardware that conforms to the [Adafruit Featherwing](https://learn.adafruit.com/adafruit-feather/) form factor +4. [Meadow.Foundation.Grove](https://github.com/WildernessLabs/Meadow.Foundation.Grove/) contains drivers for [Seeed Studio Grove](https://www.seeedstudio.com/grove.html) modular hardware peripherals +5. [Meadow.Foundation.MBus](https://github.com/WildernessLabs/Meadow.Foundation.MBus/) contains drivers for M-Bus peripherals +6. [Meadow.Foundation.MikroBus](https://github.com/WildernessLabs/Meadow.Foundation.mikrobus/) contains drivers for [MikroElektronika](https://www.mikroe.com/click) mikroBUS Click Boards ## Repository Branches @@ -80,7 +82,7 @@ Meadow.Foundation, is open source and community powered. We love pull requests, ## License -Copyright 2019-2023, Wilderness Labs Inc. +Copyright 2019-2024, Wilderness Labs Inc. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -96,4 +98,4 @@ Copyright 2019-2023, Wilderness Labs Inc. ## Author Credits -Authors: Bryan Costanich, Mark Stevens, Adrian Stevens, Jorge Ramirez, Brian Kim, Frank Krueger, Craig Dunn \ No newline at end of file +Authors: Bryan Costanich, Mark Stevens, Adrian Stevens, Jorge Ramirez, Brian Kim, Frank Krueger, Craig Dunn 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 5f3acef651..55bd0f3e4e 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,8 +9,8 @@ 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 5f3acef651..55bd0f3e4e 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,8 +9,8 @@ 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 5f3acef651..55bd0f3e4e 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,8 +9,8 @@ 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 dea5b7314e..91ea8b27ad 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,8 +9,8 @@ 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 3648f23776..975997052d 100644 --- a/Source/Meadow.Foundation.Core.Samples/Leds.Led_Sample/MeadowApp.cs +++ b/Source/Meadow.Foundation.Core.Samples/Leds.Led_Sample/MeadowApp.cs @@ -1,6 +1,7 @@ using Meadow; using Meadow.Devices; using Meadow.Foundation.Leds; +using Meadow.Peripherals.Leds; using System; using System.Collections.Generic; using System.Threading.Tasks; 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 5f3acef651..55bd0f3e4e 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,8 +9,8 @@ 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 5f3acef651..55bd0f3e4e 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,8 +9,8 @@ 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 5f3acef651..55bd0f3e4e 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,8 +9,8 @@ App - - + + diff --git a/Source/Meadow.Foundation.Core.Samples/Leds.PwmLed_Sample/MeadowApp.cs b/Source/Meadow.Foundation.Core.Samples/Leds.PwmLed_Sample/MeadowApp.cs index c1e511c8a9..c78c4db869 100644 --- a/Source/Meadow.Foundation.Core.Samples/Leds.PwmLed_Sample/MeadowApp.cs +++ b/Source/Meadow.Foundation.Core.Samples/Leds.PwmLed_Sample/MeadowApp.cs @@ -1,6 +1,7 @@ using Meadow; using Meadow.Devices; using Meadow.Foundation.Leds; +using Meadow.Peripherals.Leds; using Meadow.Units; using System; using System.Collections.Generic; 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 5f3acef651..55bd0f3e4e 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,8 +9,8 @@ App - - + + diff --git a/Source/Meadow.Foundation.Core.Samples/Leds.RgbLed_Sample/MeadowApp.cs b/Source/Meadow.Foundation.Core.Samples/Leds.RgbLed_Sample/MeadowApp.cs index e5ecbdae97..8261beb1cb 100644 --- a/Source/Meadow.Foundation.Core.Samples/Leds.RgbLed_Sample/MeadowApp.cs +++ b/Source/Meadow.Foundation.Core.Samples/Leds.RgbLed_Sample/MeadowApp.cs @@ -1,6 +1,7 @@ using Meadow; using Meadow.Devices; using Meadow.Foundation.Leds; +using Meadow.Peripherals.Leds; using System; using System.Collections.Generic; using System.Threading.Tasks; 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 5f3acef651..55bd0f3e4e 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,8 +9,8 @@ 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 5f3acef651..55bd0f3e4e 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,8 +9,8 @@ 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 f264a9840c..90390e3ffb 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,8 +10,8 @@ 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 5f3acef651..55bd0f3e4e 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,8 +9,8 @@ App - - + + diff --git a/Source/Meadow.Foundation.Core.Samples/Relays.Relay_Sample/MeadowApp.cs b/Source/Meadow.Foundation.Core.Samples/Relays.Relay_Sample/MeadowApp.cs index 5055a8ee33..e867b38b84 100644 --- a/Source/Meadow.Foundation.Core.Samples/Relays.Relay_Sample/MeadowApp.cs +++ b/Source/Meadow.Foundation.Core.Samples/Relays.Relay_Sample/MeadowApp.cs @@ -1,6 +1,7 @@ using Meadow; using Meadow.Devices; using Meadow.Foundation.Relays; +using Meadow.Peripherals.Relays; using System.Threading; using System.Threading.Tasks; @@ -23,14 +24,16 @@ public override Task Initialize() public override Task Run() { - var state = false; - while (true) { - state = !state; - - Resolver.Log.Info($"- State: {state}"); - relay.IsOn = state; + var newState = relay.State switch + { + RelayState.Open => RelayState.Closed, + _ => RelayState.Open + }; + + Resolver.Log.Info($"- State: {newState}"); + relay.State = newState; Thread.Sleep(500); } 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 5f3acef651..55bd0f3e4e 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,8 +9,8 @@ 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 5f3acef651..55bd0f3e4e 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,8 +9,8 @@ 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 5f3acef651..55bd0f3e4e 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,8 +9,8 @@ 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 5f3acef651..55bd0f3e4e 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,8 +9,8 @@ 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 7a3acd0052..7ff6551de1 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,8 +13,8 @@ 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 5f3acef651..55bd0f3e4e 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,8 +9,8 @@ App - - + + diff --git a/Source/Meadow.Foundation.Core.Samples/Sensors.Light.AnalogLightSensor_Sample/MeadowApp.cs b/Source/Meadow.Foundation.Core.Samples/Sensors.Light.AnalogLightSensor_Sample/MeadowApp.cs index 79deb20d7e..1a537f350d 100644 --- a/Source/Meadow.Foundation.Core.Samples/Sensors.Light.AnalogLightSensor_Sample/MeadowApp.cs +++ b/Source/Meadow.Foundation.Core.Samples/Sensors.Light.AnalogLightSensor_Sample/MeadowApp.cs @@ -39,7 +39,7 @@ public override Task Initialize() analogLightSensor.Subscribe(consumer); // classical .NET events can also be used: - analogLightSensor.IlluminanceUpdated += (sender, result) => + analogLightSensor.Updated += (sender, result) => Resolver.Log.Info($"Lux changed: {result.New.Lux:N2} lux, old: {result.Old?.Lux:N2} lux"); //==== One-off reading use case/pattern 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 0894d3722a..de117fbde6 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,8 +14,8 @@ - - + + 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 a03599c60c..9ba036baa7 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,8 +11,8 @@ - - + + 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 a03599c60c..9ba036baa7 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,8 +11,8 @@ - - + + 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 5f3acef651..55bd0f3e4e 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,8 +9,8 @@ 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 5f3acef651..55bd0f3e4e 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,8 +9,8 @@ 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 5f3acef651..55bd0f3e4e 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,8 +9,8 @@ App - - + + diff --git a/Source/Meadow.Foundation.Core.Samples/Sensors.Temperature.AnalogTemperature_Sample/MeadowApp.cs b/Source/Meadow.Foundation.Core.Samples/Sensors.Temperature.AnalogTemperature_Sample/MeadowApp.cs index 28406ea4b6..a8e8d3e70d 100644 --- a/Source/Meadow.Foundation.Core.Samples/Sensors.Temperature.AnalogTemperature_Sample/MeadowApp.cs +++ b/Source/Meadow.Foundation.Core.Samples/Sensors.Temperature.AnalogTemperature_Sample/MeadowApp.cs @@ -41,7 +41,7 @@ public override Task Initialize() analogTemperature.Subscribe(consumer); // classical .NET events can also be used: - analogTemperature.TemperatureUpdated += (sender, result) => + analogTemperature.Updated += (sender, result) => { Resolver.Log.Info($"Temp Changed, temp: {result.New.Celsius:N2}C, old: {result.Old?.Celsius:N2}C"); }; 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 0894d3722a..de117fbde6 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,8 +14,8 @@ - - + + diff --git a/Source/Meadow.Foundation.Core/Color.cs b/Source/Meadow.Foundation.Core/Color.cs deleted file mode 100644 index 5313f1b0ca..0000000000 --- a/Source/Meadow.Foundation.Core/Color.cs +++ /dev/null @@ -1,605 +0,0 @@ -using System; - -namespace Meadow.Foundation -{ - /// - /// 32bit color struct - /// - public struct Color - { - /// - /// Default color - black with 0 alpha - /// - public static Color Default - { - get { return new Color(0, 0, 0, 0); } - } - - /// - /// Get the 4bpp grayscale value for current color - /// - public readonly byte Color4bppGray => (byte)((byte)(0.2989 * R + 0.5870 * G + 0.114 * B) >> 4); - - /// - /// Get the 8bpp grayscale value for current color - /// - public readonly byte Color8bppGray => (byte)(0.2989 * R + 0.5870 * G + 0.114 * B); - - /// - /// Get the 8bpp (332) color value for current color - /// - public readonly byte Color8bppRgb332 => (byte)((R & 0b11100000) | (G & 0b1110000) >> 3 | ((B & 0b11000000) >> 6)); - - /// - /// Get the 12bpp (444) color value for current color - /// - public readonly ushort Color12bppRgb444 => - (ushort)(((R & 0b11110000) << 4) | (G & 0b11110000) | ((B & 0b11110000) >> 4)); - - /// - /// Get the 16bpp (565) color value for current color - /// - public readonly ushort Color16bppRgb565 => - (ushort)(((R & 0b11111000) << 8) | ((G & 0b11111100) << 3) | (B >> 3)); - - /// - /// Get the 1bpp (on or off) value for current color - /// - public readonly bool Color1bpp => R > 0 || G > 0 || B > 0; - - /// - /// Current alpha value (0-255) - /// - public byte A { get; private set; } - - /// - /// Current red value (0-255) - /// - public byte R { get; private set; } - - /// - /// Current green value (0-255) - /// - public byte G { get; private set; } - - /// - /// Current blue value (0-255) - /// - public byte B { get; private set; } - - /// - /// Hue of current color (0-360.0) - /// - public double Hue - { - get - { - if (hue == -1) - { - ConvertToHsb(R, G, B, out hue, out saturation, out brightness); - } - return hue; - } - } - double hue; - - /// - /// Saturation of color (0-1.0) - /// - public double Saturation - { - get - { - if (saturation == -1) - { - ConvertToHsb(R, G, B, out hue, out saturation, out brightness); - } - return saturation; - } - } - double saturation; - - /// - /// Brightness of color (0-1.0) - /// - public double Brightness - { - get - { - if (brightness == -1) - { - ConvertToHsb(R, G, B, out hue, out saturation, out brightness); - } - return brightness; - } - } - double brightness; - - /// - /// Create a color struct - /// - /// red component of color - /// green component of color - /// blue component of color - /// transparency of color - public Color(byte red, byte green, byte blue, byte alpha = 255) - { - R = red; - G = green; - B = blue; - A = alpha; - - hue = saturation = brightness = -1; - } - - /// - /// Create a color struct - convenience ctor for doubles - prefer byte version - /// - /// red component of color - /// green component of color - /// blue component of color - public Color(double red, double green, double blue) : - this((byte)(red * 255), (byte)(green * 255), (byte)(blue * 255), 1) - { - } - - /// - /// Create a color struct - /// - /// hue of color - /// saturation of color - /// brightness of color - /// alpha (transparency) of color - - public Color(double hue, double saturation, double brightness, byte alpha = 255) - { - Converters.HslToRgb(hue * 360, saturation, brightness, out double red, out double green, out double blue); - - R = (byte)(255 * red); - G = (byte)(255 * green); - B = (byte)(255 * blue); - A = alpha; - - this.hue = hue; - this.saturation = saturation; - this.brightness = brightness; - } - - /// - /// Create a new color struct from current color with new brightness - /// - /// brightness of new color (0-1.0) - /// new color object - public Color WithBrightness(double brightness) - { - return new Color(Hue, Saturation, brightness, A); - } - - /// - /// Create a new color struct from current color with new hue - /// - /// hue of new color (0-360.0) - /// new color object - public Color WithHue(double hue) - { - return new Color(hue, Saturation, Brightness, A); - } - - /// - /// Create a new color structs from current color with new saturation - /// - /// saturation of new color (0-1.0) - /// new color object - public Color WithSaturation(double saturation) - { - return new Color(Hue, saturation, Brightness, A); - } - - static void ConvertToHsb(byte r, byte g, byte b, out double h, out double s, out double l) - { - ConvertToHsb(r / 255.0, g / 255.0, b / 255.0, out h, out s, out l); - } - - static void ConvertToHsb(double r, double g, double b, out double h, out double s, out double l) - { - double v = (double)Math.Max(r, g); - v = (double)Math.Max(v, b); - - double m = (double)Math.Min(r, g); - m = (double)Math.Min(m, b); - - l = (m + v) / 2.0f; - if (l <= 0.0) - { - h = s = l = 0; - return; - } - double vm = v - m; - s = vm; - - if (s > 0.0) - { - s /= l <= 0.5f ? v + m : 2.0f - v - m; - } - else - { - h = 0; - s = 0; - return; - } - - double r2 = (v - r) / vm; - double g2 = (v - g) / vm; - double b2 = (v - b) / vm; - - if (r == v) - { - h = g == m ? 5.0f + b2 : 1.0f - g2; - } - else if (g == v) - { - h = b == m ? 1.0f + r2 : 3.0f - b2; - } - else - { - h = r == m ? 3.0f + g2 : 5.0f - r2; - } - h /= 6.0f; - } - - /// - /// Equality operator - /// - /// left color value - /// right color value - /// true if equal - public static bool operator ==(Color color1, Color color2) - { - return EqualsInner(color1, color2); - } - - /// - /// Not equals operator - /// - /// left color value - /// right color value - /// true if not equals - public static bool operator !=(Color color1, Color color2) - { - return !EqualsInner(color1, color2); - } - - /// - /// Get hash of color - /// - /// hash as 32bit int - public override readonly int GetHashCode() - { - return HashCode.Combine(R, G, B, A); - } - - /// - /// Compare two color structs for equality - /// - /// - /// true if equals - public override readonly bool Equals(object obj) - { - if (obj is Color color) - { - return EqualsInner(this, color); - } - return base.Equals(obj); - } - - /// - /// Compare two color structs for equality - /// - /// - /// true if equals - public readonly bool Equals(Color other) - { - return EqualsInner(this, other); - } - - static bool EqualsInner(Color color1, Color color2) - { - return color1.R == color2.R && color1.G == color2.G && color1.B == color2.B && color1.A == color2.A; - } - - /// - /// Convert color to string - /// - /// string representing color - public override string ToString() - { - return "[Color: A={" + A + "}, R={" + R + "}, G={" + G + "}, B={" + B + "}, Hue={" + Hue + "}, Saturation={" + Saturation + "}, Brightness={" + Brightness + "}]"; - } - - static uint ToHex(char c) - { - ushort x = c; - if (x >= '0' && x <= '9') - { - return (uint)(x - '0'); - } - - x |= 0x20; - if (x >= 'a' && x <= 'f') - { - return (uint)(x - 'a' + 10); - } - return 0; - } - - static uint ToHexD(char c) - { - var j = ToHex(c); - return (j << 4) | j; - } - - /// - /// Create a color object from a hex string - /// - /// string hex value - /// new color object - public static Color FromHex(string hex) - { - // Undefined - if (hex.Length < 3) - { - return Default; - } - int idx = (hex[0] == '#') ? 1 : 0; - - switch (hex.Length - idx) - { - case 3: //#rgb => ffrrggbb - var t1 = ToHexD(hex[idx++]); - var t2 = ToHexD(hex[idx++]); - var t3 = ToHexD(hex[idx]); - - return FromRgb((byte)t1, (byte)t2, (byte)t3); - - case 4: //#argb => aarrggbb - var f1 = ToHexD(hex[idx++]); - var f2 = ToHexD(hex[idx++]); - var f3 = ToHexD(hex[idx++]); - var f4 = ToHexD(hex[idx]); - return FromRgba((byte)f2, (byte)f3, (byte)f4, (byte)f1); - - case 6: //#rrggbb => ffrrggbb - return FromRgb((byte)(ToHex(hex[idx++]) << 4 | ToHex(hex[idx++])), - (byte)(ToHex(hex[idx++]) << 4 | ToHex(hex[idx++])), - (byte)(ToHex(hex[idx++]) << 4 | ToHex(hex[idx]))); - - case 8: //#aarrggbb - var a1 = ToHex(hex[idx++]) << 4 | ToHex(hex[idx++]); - return FromRgba((byte)(ToHex(hex[idx++]) << 4 | ToHex(hex[idx++])), - (byte)(ToHex(hex[idx++]) << 4 | ToHex(hex[idx++])), - (byte)(ToHex(hex[idx++]) << 4 | ToHex(hex[idx])), - (byte)a1); - - default: //everything else will result in unexpected results - return Default; - } - } - - /// - /// Create a color object from a 32bit unsigned int - /// - /// color value - 8 bits red, 8 bits green, 8 bits blue, 8 bits alpha - /// new color object - public static Color FromUint(uint argb) - { - return FromRgba((byte)((argb & 0x00ff0000) >> 0x10), (byte)((argb & 0x0000ff00) >> 0x8), (byte)(argb & 0x000000ff), (byte)((argb & 0xff000000) >> 0x18)); - } - - /// - /// Create a new color object - /// - /// red component of color (0-255) - /// green component of color (0-255) - /// blue component of color (0-255) - /// alpha of color (0-255) - /// new color object - public static Color FromRgba(byte r, byte g, byte b, byte a) - { - return new Color(r, g, b, a); - } - /// - /// Create a new color object - /// - /// red component of color (0-255) - /// green component of color (0-255) - /// blue component of color (0-255) - - public static Color FromRgb(byte r, byte g, byte b) - { - return FromRgba(r, g, b, 255); - } - - /// - /// Create a new color object - /// - /// red component of color (0-1) - /// green component of color (0-1) - /// blue component of color (0-1) - /// alpha of color (0-1) - /// new color object - public static Color FromRgba(double r, double g, double b, double a) - { - return new Color((byte)(r * 255), (byte)(g * 255), (byte)(b * 255), (byte)(a * 255)); - } - - /// - /// Create a new color object - /// - /// red component of color (0-1) - /// green component of color (0-1) - /// blue component of color (0-1) - /// new color object - public static Color FromRgb(double r, double g, double b) - { - return FromRgba(r, g, b, 1f); - } - - /// - /// Create a new color object - /// - /// hue of color (0-360) - /// saturation of color (0-1) - /// brightness of color (0-1) - /// alpha of color (0-1) - /// new color object - public static Color FromHsba(double h, double s, double b, double a = 1.0) - { - return new Color(h, s, b, (byte)(a * 255)); - } - - // matches colors in WPF's System.Windows.Media.Colors -#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member - public static readonly Color AliceBlue = FromRgb(240, 248, 255); - public static readonly Color AntiqueWhite = FromRgb(250, 235, 215); - public static readonly Color Aqua = FromRgb(0, 255, 255); - public static readonly Color Aquamarine = FromRgb(127, 255, 212); - public static readonly Color Azure = FromRgb(240, 255, 255); - public static readonly Color Beige = FromRgb(245, 245, 220); - public static readonly Color Bisque = FromRgb(255, 228, 196); - public static readonly Color Black = FromRgb(0, 0, 0); - public static readonly Color BlanchedAlmond = FromRgb(255, 235, 205); - public static readonly Color Blue = FromRgb(0, 0, 255); - public static readonly Color BlueViolet = FromRgb(138, 43, 226); - public static readonly Color Brown = FromRgb(165, 42, 42); - public static readonly Color BurlyWood = FromRgb(222, 184, 135); - public static readonly Color CadetBlue = FromRgb(95, 158, 160); - public static readonly Color Chartreuse = FromRgb(127, 255, 0); - public static readonly Color Chocolate = FromRgb(210, 105, 30); - public static readonly Color Coral = FromRgb(255, 127, 80); - public static readonly Color CornflowerBlue = FromRgb(100, 149, 237); - public static readonly Color Cornsilk = FromRgb(255, 248, 220); - public static readonly Color Crimson = FromRgb(220, 20, 60); - public static readonly Color Cyan = FromRgb(0, 255, 255); - public static readonly Color DarkBlue = FromRgb(0, 0, 139); - public static readonly Color DarkCyan = FromRgb(0, 139, 139); - public static readonly Color DarkGoldenrod = FromRgb(184, 134, 11); - public static readonly Color DarkGray = FromRgb(169, 169, 169); - public static readonly Color DarkGreen = FromRgb(0, 100, 0); - public static readonly Color DarkKhaki = FromRgb(189, 183, 107); - public static readonly Color DarkMagenta = FromRgb(139, 0, 139); - public static readonly Color DarkOliveGreen = FromRgb(85, 107, 47); - public static readonly Color DarkOrange = FromRgb(255, 140, 0); - public static readonly Color DarkOrchid = FromRgb(153, 50, 204); - public static readonly Color DarkRed = FromRgb(139, 0, 0); - public static readonly Color DarkSalmon = FromRgb(233, 150, 122); - public static readonly Color DarkSeaGreen = FromRgb(143, 188, 143); - public static readonly Color DarkSlateBlue = FromRgb(72, 61, 139); - public static readonly Color DarkSlateGray = FromRgb(47, 79, 79); - public static readonly Color DarkTurquoise = FromRgb(0, 206, 209); - public static readonly Color DarkViolet = FromRgb(148, 0, 211); - public static readonly Color DeepPink = FromRgb(255, 20, 147); - public static readonly Color DeepSkyBlue = FromRgb(0, 191, 255); - public static readonly Color DimGray = FromRgb(105, 105, 105); - public static readonly Color DodgerBlue = FromRgb(30, 144, 255); - public static readonly Color Firebrick = FromRgb(178, 34, 34); - public static readonly Color FloralWhite = FromRgb(255, 250, 240); - public static readonly Color ForestGreen = FromRgb(34, 139, 34); - public static readonly Color Fuchsia = FromRgb(255, 0, 255); - public static readonly Color Gainsboro = FromRgb(220, 220, 220); - public static readonly Color GhostWhite = FromRgb(248, 248, 255); - public static readonly Color Gold = FromRgb(255, 215, 0); - public static readonly Color Goldenrod = FromRgb(218, 165, 32); - public static readonly Color Gray = FromRgb(128, 128, 128); - public static readonly Color Green = FromRgb(0, 128, 0); - public static readonly Color GreenYellow = FromRgb(173, 255, 47); - public static readonly Color Honeydew = FromRgb(240, 255, 240); - public static readonly Color HotPink = FromRgb(255, 105, 180); - public static readonly Color IndianRed = FromRgb(205, 92, 92); - public static readonly Color Indigo = FromRgb(75, 0, 130); - public static readonly Color Ivory = FromRgb(255, 255, 240); - public static readonly Color Khaki = FromRgb(240, 230, 140); - public static readonly Color Lavender = FromRgb(230, 230, 250); - public static readonly Color LavenderBlush = FromRgb(255, 240, 245); - public static readonly Color LawnGreen = FromRgb(124, 252, 0); - public static readonly Color LemonChiffon = FromRgb(255, 250, 205); - public static readonly Color LightBlue = FromRgb(173, 216, 230); - public static readonly Color LightCoral = FromRgb(240, 128, 128); - public static readonly Color LightCyan = FromRgb(224, 255, 255); - public static readonly Color LightGoldenrodYellow = FromRgb(250, 250, 210); - public static readonly Color LightGray = FromRgb(211, 211, 211); - public static readonly Color LightGreen = FromRgb(144, 238, 144); - public static readonly Color LightPink = FromRgb(255, 182, 193); - public static readonly Color LightSalmon = FromRgb(255, 160, 122); - public static readonly Color LightSeaGreen = FromRgb(32, 178, 170); - public static readonly Color LightSkyBlue = FromRgb(135, 206, 250); - public static readonly Color LightSlateGray = FromRgb(119, 136, 153); - public static readonly Color LightSteelBlue = FromRgb(176, 196, 222); - public static readonly Color LightYellow = FromRgb(255, 255, 224); - public static readonly Color Lime = FromRgb(0, 255, 0); - public static readonly Color LimeGreen = FromRgb(50, 205, 50); - public static readonly Color Linen = FromRgb(250, 240, 230); - public static readonly Color Magenta = FromRgb(255, 0, 255); - public static readonly Color Maroon = FromRgb(128, 0, 0); - public static readonly Color MediumAquamarine = FromRgb(102, 205, 170); - public static readonly Color MediumBlue = FromRgb(0, 0, 205); - public static readonly Color MediumOrchid = FromRgb(186, 85, 211); - public static readonly Color MediumPurple = FromRgb(147, 112, 219); - public static readonly Color MediumSeaGreen = FromRgb(60, 179, 113); - public static readonly Color MediumSlateBlue = FromRgb(123, 104, 238); - public static readonly Color MediumSpringGreen = FromRgb(0, 250, 154); - public static readonly Color MediumTurquoise = FromRgb(72, 209, 204); - public static readonly Color MediumVioletRed = FromRgb(199, 21, 133); - public static readonly Color MidnightBlue = FromRgb(25, 25, 112); - public static readonly Color MintCream = FromRgb(245, 255, 250); - public static readonly Color MistyRose = FromRgb(255, 228, 225); - public static readonly Color Moccasin = FromRgb(255, 228, 181); - public static readonly Color NavajoWhite = FromRgb(255, 222, 173); - public static readonly Color Navy = FromRgb(0, 0, 128); - public static readonly Color OldLace = FromRgb(253, 245, 230); - public static readonly Color Olive = FromRgb(128, 128, 0); - public static readonly Color OliveDrab = FromRgb(107, 142, 35); - public static readonly Color Orange = FromRgb(255, 165, 0); - public static readonly Color OrangeRed = FromRgb(255, 69, 0); - public static readonly Color Orchid = FromRgb(218, 112, 214); - public static readonly Color PaleGoldenrod = FromRgb(238, 232, 170); - public static readonly Color PaleGreen = FromRgb(152, 251, 152); - public static readonly Color PaleTurquoise = FromRgb(175, 238, 238); - public static readonly Color PaleVioletRed = FromRgb(219, 112, 147); - public static readonly Color PapayaWhip = FromRgb(255, 239, 213); - public static readonly Color PeachPuff = FromRgb(255, 218, 185); - public static readonly Color Peru = FromRgb(205, 133, 63); - public static readonly Color Pink = FromRgb(255, 192, 203); - public static readonly Color Plum = FromRgb(221, 160, 221); - public static readonly Color PowderBlue = FromRgb(176, 224, 230); - public static readonly Color Purple = FromRgb(128, 0, 128); - public static readonly Color Red = FromRgb(255, 0, 0); - public static readonly Color RosyBrown = FromRgb(188, 143, 143); - public static readonly Color RoyalBlue = FromRgb(65, 105, 225); - public static readonly Color SaddleBrown = FromRgb(139, 69, 19); - public static readonly Color Salmon = FromRgb(250, 128, 114); - public static readonly Color SandyBrown = FromRgb(244, 164, 96); - public static readonly Color SeaGreen = FromRgb(46, 139, 87); - public static readonly Color SeaShell = FromRgb(255, 245, 238); - public static readonly Color Sienna = FromRgb(160, 82, 45); - public static readonly Color Silver = FromRgb(192, 192, 192); - public static readonly Color SkyBlue = FromRgb(135, 206, 235); - public static readonly Color SlateBlue = FromRgb(106, 90, 205); - public static readonly Color SlateGray = FromRgb(112, 128, 144); - public static readonly Color Snow = FromRgb(255, 250, 250); - public static readonly Color SpringGreen = FromRgb(0, 255, 127); - public static readonly Color SteelBlue = FromRgb(70, 130, 180); - public static readonly Color Tan = FromRgb(210, 180, 140); - public static readonly Color Teal = FromRgb(0, 128, 128); - public static readonly Color Thistle = FromRgb(216, 191, 216); - public static readonly Color Tomato = FromRgb(255, 99, 71); - public static readonly Color Transparent = FromRgba(255, 255, 255, 0); - public static readonly Color Turquoise = FromRgb(64, 224, 208); - public static readonly Color Violet = FromRgb(238, 130, 238); - public static readonly Color Wheat = FromRgb(245, 222, 179); - public static readonly Color White = FromRgb(255, 255, 255); - public static readonly Color WhiteSmoke = FromRgb(245, 245, 245); - public static readonly Color Yellow = FromRgb(255, 255, 0); - public static readonly Color YellowGreen = FromRgb(154, 205, 50); -#pragma warning restore CS1591 // Missing XML comment for publicly visible type or member - } -} \ No newline at end of file diff --git a/Source/Meadow.Foundation.Core/Communications/ByteCommsSensorBase.cs b/Source/Meadow.Foundation.Core/Communications/ByteCommsSensorBase.cs index bc94576649..eaee13a5be 100644 --- a/Source/Meadow.Foundation.Core/Communications/ByteCommsSensorBase.cs +++ b/Source/Meadow.Foundation.Core/Communications/ByteCommsSensorBase.cs @@ -37,7 +37,7 @@ protected ByteCommsSensorBase( II2cBus i2cBus, byte address, int readBufferSize = 8, int writeBufferSize = 8) { - BusComms = new I2cCommunications(i2cBus, address, readBufferSize, writeBufferSize); + BusComms = new I2cCommunications(i2cBus, address, writeBufferSize); Init(readBufferSize, writeBufferSize); } @@ -60,17 +60,7 @@ protected ByteCommsSensorBase( int writeBufferSize = 8, ChipSelectMode chipSelectMode = ChipSelectMode.ActiveLow) { - BusComms = new SpiCommunications(spiBus, chipSelect, busSpeed, busMode, readBufferSize, writeBufferSize, chipSelectMode); - Init(readBufferSize, writeBufferSize); - } - - /// - /// ByteCommsSensorBase abstract ctor with no bus - /// - /// Read buffer size - /// Write buffer size - protected ByteCommsSensorBase(int readBufferSize = 8, int writeBufferSize = 8) - { + BusComms = new SpiCommunications(spiBus, chipSelect, busSpeed, busMode, writeBufferSize, chipSelectMode); Init(readBufferSize, writeBufferSize); } diff --git a/Source/Meadow.Foundation.Core/Communications/I2cCommunications.cs b/Source/Meadow.Foundation.Core/Communications/I2cCommunications.cs index 9526ca5f65..0fe460d561 100644 --- a/Source/Meadow.Foundation.Core/Communications/I2cCommunications.cs +++ b/Source/Meadow.Foundation.Core/Communications/I2cCommunications.cs @@ -1,6 +1,7 @@ -using System; +using Meadow.Hardware; +using System; -namespace Meadow.Hardware +namespace Meadow.Foundation { /// /// Helper class for I2C communications, handles registers, endian, etc. @@ -33,14 +34,13 @@ public class I2cCommunications : II2cCommunications /// /// The II2cBus used for communication with the peripheral /// The address of the peripheral on the I2C bus - /// The size of the buffer used for reading data from the peripheral. Defaults to 8 bytes /// The size of the buffer used for writing data to the peripheral. Defaults to 8 bytes - public I2cCommunications(II2cBus bus, byte peripheralAddress, int readBufferSize = 8, int writeBufferSize = 8) + public I2cCommunications(II2cBus bus, byte peripheralAddress, int writeBufferSize = 8) { Bus = bus; Address = peripheralAddress; WriteBuffer = new byte[writeBufferSize]; - ReadBuffer = new byte[readBufferSize]; + ReadBuffer = new byte[2]; } /// diff --git a/Source/Meadow.Foundation.Core/Communications/SpiCommunications.cs b/Source/Meadow.Foundation.Core/Communications/SpiCommunications.cs index 100948a335..f82c4ed7f9 100644 --- a/Source/Meadow.Foundation.Core/Communications/SpiCommunications.cs +++ b/Source/Meadow.Foundation.Core/Communications/SpiCommunications.cs @@ -1,7 +1,8 @@ -using Meadow.Units; +using Meadow.Hardware; +using Meadow.Units; using System; -namespace Meadow.Hardware +namespace Meadow.Foundation { /// /// Helper class for SPI communications, handles registers, endian, etc. @@ -52,7 +53,6 @@ public class SpiCommunications : ISpiCommunications /// The chip select port /// The SPI bus speed /// The SPI bus mode (0-3) - /// The size of the read buffer in bytes /// The size of the write buffer in bytes /// The chip select mode, active high or active low public SpiCommunications( @@ -60,7 +60,7 @@ public SpiCommunications( IDigitalOutputPort? chipSelect, Frequency busSpeed, SpiClockConfiguration.Mode busMode = SpiClockConfiguration.Mode.Mode0, - int readBufferSize = 8, int writeBufferSize = 8, + int writeBufferSize = 8, ChipSelectMode csMode = ChipSelectMode.ActiveLow) { Bus = bus; @@ -69,7 +69,7 @@ public SpiCommunications( ChipSelect = chipSelect; chipSelectMode = csMode; WriteBuffer = new byte[writeBufferSize]; - ReadBuffer = new byte[readBufferSize]; + ReadBuffer = new byte[2]; // de-assert the chip select if (chipSelect != null) diff --git a/Source/Meadow.Foundation.Core/Extensions/ColorExtensions.cs b/Source/Meadow.Foundation.Core/Extensions/ColorExtensions.cs deleted file mode 100644 index 94eda5c061..0000000000 --- a/Source/Meadow.Foundation.Core/Extensions/ColorExtensions.cs +++ /dev/null @@ -1,48 +0,0 @@ -namespace Meadow.Foundation -{ - /// - /// Static class for color extension methods - /// - public static class ColorExtensions - { - /// - /// Takes Hue, Saturation and Value and returns a Color object - /// - /// - /// - /// - /// - /// - /// A Color object - public static Color FromAhsv(this Color color, double alpha, double hue, double saturation, double value) - { - Converters.HsvToRgb(hue, saturation, value, out double red, out double green, out double blue); - - return new Color((byte)(red * 255), (byte)(green * 255), (byte)(blue * 255), (byte)(alpha * 255)); - } - - /// - /// Blend a new color with the current color - /// - /// The source color - /// The color to blend - /// The ratio of the blend color to source color - /// The resulting blended color - public static Color Blend(this Color color, Color blendColor, double ratio) - { - if (ratio == 0) - { - return color; - } - if (ratio == 1) - { - return blendColor; - } - - byte r = (byte)(color.R * (1 - ratio) + blendColor.R * ratio); - byte g = (byte)(color.G * (1 - ratio) + blendColor.G * ratio); - byte b = (byte)(color.B * (1 - ratio) + blendColor.B * ratio); - return Color.FromRgb(r, g, b); - } - } -} \ No newline at end of file diff --git a/Source/Meadow.Foundation.Core/Helpers/Checksum.cs b/Source/Meadow.Foundation.Core/Helpers/Checksum.cs deleted file mode 100644 index 5d375fe135..0000000000 --- a/Source/Meadow.Foundation.Core/Helpers/Checksum.cs +++ /dev/null @@ -1,112 +0,0 @@ -using System; -using System.Text; - -namespace Meadow.Foundation.Helpers -{ - /// - /// Provide CRC and checksum methods - /// - public class Checksum - { - #region Member variables / fields - - /// - /// Lookup table for the polynomial CRC 8 method. - /// - private static byte[]? _lookupTable = null; - - /// - /// When the _lookupTable is not null then _polynomial will contain the - /// value of the byte used to generate the lookup table for the PolynomialCRC8 - /// method. - /// - private static byte _polynomial; - - #endregion Member variables / fields - - #region Methods - - /// - /// Calculate a checksum for the string by XORing the bytes in the string. - /// - /// String to calculate the checksum for. - /// XOR checksum for the sting. - public static byte XOR(string data) - { - return XOR(Encoding.UTF8.GetBytes(data)); - } - - /// - /// Generate a checksum by XORing all of the data in the array. - /// - /// Data to calculate the checksum for. - /// XOR Checksum of the array of bytes. - public static byte XOR(byte[] data) - { - byte checksum = 0; - for (var index = 0; index < data.Length; index++) - { - checksum ^= data[index]; - } - return checksum; - } - - /// - /// Generate the lookup table for the PolynomialCRC method. - /// - private static byte[] PopulateLookupTable(byte polynomial) - { - _lookupTable = new byte[256]; - - for (int outer = 0; outer < 256; outer++) - { - int temp = outer; - for (int inner = 0; inner < 8; inner++) - { - if ((temp & 0x80) != 0) - { - temp = (temp << 1) ^ polynomial; - } - else - { - temp <<= 1; - } - } - _lookupTable[outer] = (byte)temp; - } - _polynomial = polynomial; - - return _lookupTable; - } - - /// - /// Calculate the 8-bit CRC using the specified polynomial. - /// - /// Data bytes to generate a CRC for. - /// Polynomial byte to use in the CRC calculation. - public static byte PolynomialCRC(byte[] data, byte polynomial) - { - if ((data == null) || (data.Length == 0)) - { - throw new ArgumentException("data", "PolynomialCRC: Data to CRC is invalid."); - } - if (_lookupTable == null) - { - _lookupTable = PopulateLookupTable(polynomial); - } - else if (_polynomial != polynomial) - { - _lookupTable = PopulateLookupTable(polynomial); - } - - byte crc = 0; - foreach (byte b in data) - { - crc = _lookupTable[crc ^ b]; - } - return crc; - } - - #endregion Methods - } -} \ No newline at end of file diff --git a/Source/Meadow.Foundation.Core/Helpers/Converters.cs b/Source/Meadow.Foundation.Core/Helpers/Converters.cs index 1a85ee2e27..adc08ca99b 100644 --- a/Source/Meadow.Foundation.Core/Helpers/Converters.cs +++ b/Source/Meadow.Foundation.Core/Helpers/Converters.cs @@ -34,210 +34,5 @@ public static byte ByteToBCD(byte v) result += (v % 10); return (byte)(result & 0xff); } - - /// - /// HSL to RGB - /// - /// Hue in degrees (0-359°) - /// Saturation - /// Brightness value - /// The red component (0-1) - /// The green component (0-1) - /// The blue component (0-1) - public static void HslToRgb(double hue, double saturation, double lightness, out double r, out double g, out double b) - { - double h = hue; - double R, G, B; - - // hue parameter checking/fixing - if (h < 0) - { - h = 0; - } - else if (h > 360) - { - h %= 360; - } - - //default to gray - R = G = B = lightness; - - var v = (lightness <= 0.5) ? - (lightness * (1.0 + saturation)) : - (lightness + saturation - lightness * saturation); - - if (v > 0) - { - double m; - double l = lightness; - double sv; - int sextant; - double fract, vsf, mid1, mid2; - - m = l + l - v; - sv = (v - m) / v; - h /= 60.0; - sextant = (int)h; - fract = h - sextant; - vsf = v * sv * fract; - mid1 = m + vsf; - mid2 = v - vsf; - switch (sextant) - { - case 0: - R = v; - G = mid1; - B = m; - break; - case 1: - R = mid2; - G = v; - B = m; - break; - case 2: - R = m; - G = v; - B = mid1; - break; - case 3: - R = m; - G = mid2; - B = v; - break; - case 4: - R = mid1; - G = m; - B = v; - break; - case 5: - R = v; - G = m; - B = mid2; - break; - } - } - - r = Clamp(R); - g = Clamp(G); - b = Clamp(B); - } - - /// - /// HSV to RGB - /// - /// Hue in degrees (0-359°) - /// Saturation - /// Brightness value - /// The red component (0-1) - /// The green component (0-1) - /// The blue component (0-1) - public static void HsvToRgb(double hue, double saturation, double brightValue, out double r, out double g, out double b) - { - double H = hue; - double R, G, B; - - // hue parameter checking/fixing - if (H < 0) - { - H = 0; - } - else if (H > 360) - { - H %= 360; - } - - // if Brightness is turned off, then everything is zero. - if (brightValue <= 0) - { - R = G = B = 0; - } - - // if saturation is turned off, then there is no color/hue. it's grayscale. - else if (saturation <= 0) - { - R = G = B = brightValue; - } - else // if we got here, then there is a color to create. - { - double hf = H / 60.0; - int i = (int)Math.Floor(hf); - double f = hf - i; - double pv = brightValue * (1 - saturation); - double qv = brightValue * (1 - saturation * f); - double tv = brightValue * (1 - saturation * (1 - f)); - - switch (i) - { - - // Red Dominant - case 0: - R = brightValue; - G = tv; - B = pv; - break; - - // Green Dominant - case 1: - R = qv; - G = brightValue; - B = pv; - break; - case 2: - R = pv; - G = brightValue; - B = tv; - break; - - // Blue Dominant - case 3: - R = pv; - G = qv; - B = brightValue; - break; - case 4: - R = tv; - G = pv; - B = brightValue; - break; - - // Red Red Dominant - case 5: - R = brightValue; - G = pv; - B = qv; - break; - - // In case the math is out of bounds, this is a fix. - case 6: - R = brightValue; - G = tv; - B = pv; - break; - case -1: - R = brightValue; - G = pv; - B = qv; - break; - - // If the color is not defined, go grayscale - default: - R = G = B = brightValue; - break; - } - } - r = Clamp(R); - g = Clamp(G); - b = Clamp(B); - } - - /// - /// Clamp a value to 0 to 1 - /// - static double Clamp(double i) - { - if (i < 0) return 0; - if (i > 1) return 1; - return i; - } } } \ No newline at end of file diff --git a/Source/Meadow.Foundation.Core/Leds/RgbLed.Animations.cs b/Source/Meadow.Foundation.Core/Leds/RgbLed.Animations.cs index 32d8d23e83..e3f6a47805 100644 --- a/Source/Meadow.Foundation.Core/Leds/RgbLed.Animations.cs +++ b/Source/Meadow.Foundation.Core/Leds/RgbLed.Animations.cs @@ -1,4 +1,5 @@ -using System; +using Meadow.Peripherals.Leds; +using System; using System.Threading; using System.Threading.Tasks; @@ -14,9 +15,7 @@ public partial class RgbLed private Task? animationTask = null; private CancellationTokenSource? cancellationTokenSource = null; - /// - /// Stops the current LED animation - /// + /// public async Task StopAnimation() { if (animationTask != null) @@ -28,29 +27,19 @@ public async Task StopAnimation() } } - /// - /// Start the Blink animation which sets turns the LED on and off on an interval of 1 second (500ms on, 500ms off) - /// + /// public Task StartBlink() { return StartBlink(TimeSpan.FromMilliseconds(500), TimeSpan.FromMilliseconds(500)); } - /// - /// Start the Blink animation which sets turns the LED on and off on an interval of 1 second (500ms on, 500ms off) - /// - /// The LED color + /// public Task StartBlink(RgbLedColors color) { return StartBlink(color, TimeSpan.FromMilliseconds(500), TimeSpan.FromMilliseconds(500)); } - /// - /// Start the Blink animation which sets turns the LED on and off with the specified durations and color - /// - /// The LED color - /// The duration the LED stays on - /// The duration the LED stays off + /// public async Task StartBlink( RgbLedColors color, TimeSpan onDuration, @@ -63,11 +52,7 @@ public async Task StartBlink( await StartBlink(onDuration, offDuration); } - /// - /// Start the Blink animation which sets turns the LED on and off with the specified durations and current color - /// - /// The duration the LED stays on - /// The duration the LED stays off + /// public async Task StartBlink(TimeSpan onDuration, TimeSpan offDuration) { await StopAnimation(); @@ -92,4 +77,4 @@ public async Task StartBlink(TimeSpan onDuration, TimeSpan offDuration) } } } -} +} \ No newline at end of file diff --git a/Source/Meadow.Foundation.Core/Leds/RgbLed.cs b/Source/Meadow.Foundation.Core/Leds/RgbLed.cs index 10826c0379..03f6fc2fae 100644 --- a/Source/Meadow.Foundation.Core/Leds/RgbLed.cs +++ b/Source/Meadow.Foundation.Core/Leds/RgbLed.cs @@ -1,13 +1,16 @@ using Meadow.Hardware; using Meadow.Peripherals.Leds; +using System; namespace Meadow.Foundation.Leds { /// /// Represents an RGB LED /// - public partial class RgbLed : IRgbLed + public partial class RgbLed : IRgbLed, IDisposable { + readonly bool createdPorts = false; + /// /// The current LED color /// @@ -43,6 +46,11 @@ public bool IsOn } bool isOn; + /// + /// Is the object disposed + /// + public bool IsDisposed { get; private set; } + /// /// Create instance of RgbLed /// @@ -60,7 +68,9 @@ public RgbLed( greenPin.CreateDigitalOutputPort(), bluePin.CreateDigitalOutputPort(), commonType) - { } + { + createdPorts = true; + } /// /// Create instance of RgbLed @@ -81,10 +91,7 @@ public RgbLed( Common = commonType; } - /// - /// Sets the current color of the LED. - /// - /// The color value + /// public void SetColor(RgbLedColors color) { Color = color; @@ -148,5 +155,31 @@ protected void UpdateLed(bool isOn) BluePort.State = !onState; } } + + /// + public void Dispose() + { + Dispose(disposing: true); + GC.SuppressFinalize(this); + } + + /// + /// Dispose of the object + /// + /// Is disposing + public virtual void Dispose(bool disposing) + { + if (!IsDisposed) + { + if (disposing && createdPorts) + { + RedPort.Dispose(); + GreenPort.Dispose(); + BluePort.Dispose(); + } + + IsDisposed = true; + } + } } } \ No newline at end of file diff --git a/Source/Meadow.Foundation.Core/Leds/RgbLedColors.cs b/Source/Meadow.Foundation.Core/Leds/RgbLedColors.cs deleted file mode 100644 index fa731d899f..0000000000 --- a/Source/Meadow.Foundation.Core/Leds/RgbLedColors.cs +++ /dev/null @@ -1,41 +0,0 @@ -namespace Meadow.Foundation.Leds -{ - /// - /// Colors for RGB Led - /// - public enum RgbLedColors - { - /// - /// Red (red LED only) - /// - Red, - /// - /// Green (green LED only) - /// - Green, - /// - /// Blue (blue LED only) - /// - Blue, - /// - /// Yellow (red and green LEDs) - /// - Yellow, - /// - /// Magenta (blue and red LEDs) - /// - Magenta, - /// - /// Cyan (blue and green LEDs) - /// - Cyan, - /// - /// White (red, green and blue LEDs) - /// - White, - /// - /// Count of colors - /// - count, - } -} \ No newline at end of file diff --git a/Source/Meadow.Foundation.Core/Leds/RgbPwmLed.Animations.cs b/Source/Meadow.Foundation.Core/Leds/RgbPwmLed.Animations.cs index 395a74217f..194cf32547 100644 --- a/Source/Meadow.Foundation.Core/Leds/RgbPwmLed.Animations.cs +++ b/Source/Meadow.Foundation.Core/Leds/RgbPwmLed.Animations.cs @@ -14,9 +14,7 @@ public partial class RgbPwmLed private Task? animationTask = null; private CancellationTokenSource? cancellationTokenSource = null; - /// - /// Stops the current LED animation - /// + /// public async Task StopAnimation() { if (animationTask != null) @@ -28,24 +26,13 @@ public async Task StopAnimation() } } - /// - /// Start the Blink animation which sets the brightness of the LED alternating between a low and high brightness - /// On an interval of 1 second (500ms on, 500ms off) - /// - /// The maximum brightness of the animation - /// The minimum brightness of the animation + /// public Task StartBlink(float highBrightness = 1f, float lowBrightness = 0f) { return StartBlink(TimeSpan.FromMilliseconds(500), TimeSpan.FromMilliseconds(500), highBrightness, lowBrightness); } - /// - /// Start the Blink animation which sets the brightness of the LED alternating between a low and high brightness - /// On an interval of 1 second (500ms on, 500ms off) - /// - /// The LED color - /// The maximum brightness of the animation - /// The minimum brightness of the animation + /// public Task StartBlink( Color color, float highBrightness = 1f, @@ -54,39 +41,7 @@ public Task StartBlink( return StartBlink(color, TimeSpan.FromMilliseconds(500), TimeSpan.FromMilliseconds(500), highBrightness, lowBrightness); } - /// - /// Start the Blink animation which sets the brightness of the LED alternating between a low and high brightness setting, using the durations provided. - /// - /// The LED color - /// The duration the LED stays on - /// The duration the LED stays off - /// The maximum brightness of the animation - /// The minimum brightness of the animation - - public async Task StartBlink( - Color color, - TimeSpan onDuration, - TimeSpan offDuration, - float highBrightness = 1f, - float lowBrightness = 0f) - { - ValidateBrightness(highBrightness, lowBrightness); - - await StopAnimation(); - - SetColor(color); - - await StartBlink(onDuration, offDuration, highBrightness, lowBrightness); - } - - /// - /// Start the Blink animation which sets the brightness of the LED alternating between a low and high brightness setting, using the durations provided. - /// - /// The duration the LED stays on - /// The duration the LED stays off - /// The maximum brightness of the animation - /// The minimum brightness of the animation - + /// public async Task StartBlink( TimeSpan onDuration, TimeSpan offDuration, @@ -117,24 +72,30 @@ public async Task StartBlink( } } - /// - /// Start the Pulse animation which gradually alternates the brightness of the LED between a low and high brightness setting - /// with a cycle time of 600ms - /// - /// The maximum brightness of the animation - /// The minimum brightness of the animation + /// + public async Task StartBlink( + Color color, + TimeSpan onDuration, + TimeSpan offDuration, + float highBrightness = 1f, + float lowBrightness = 0f) + { + ValidateBrightness(highBrightness, lowBrightness); + + await StopAnimation(); + + SetColor(color); + + await StartBlink(onDuration, offDuration, highBrightness, lowBrightness); + } + + /// public Task StartPulse(float highBrightness = 1, float lowBrightness = 0.15F) { return StartPulse(TimeSpan.FromMilliseconds(600), highBrightness, lowBrightness); } - /// - /// Start the Pulse animation which gradually alternates the brightness of the LED between a low and high brightness setting - /// with a cycle time of 600ms - /// - /// The LED color - /// The maximum brightness of the animation - /// The minimum brightness of the animation + /// public Task StartPulse( Color color, float highBrightness = 1, @@ -143,13 +104,7 @@ public Task StartPulse( return StartPulse(color, TimeSpan.FromMilliseconds(600), highBrightness, lowBrightness); } - /// - /// Start the Pulse animation which gradually alternates the brightness of the LED between a low and high brightness setting, using the durations provided. - /// - /// The LED color - /// The pulse animation duration - /// The maximum brightness of the animation - /// The minimum brightness of the animation + /// public async Task StartPulse( Color color, TimeSpan pulseDuration, @@ -165,12 +120,7 @@ public async Task StartPulse( await StartPulse(pulseDuration, highBrightness, lowBrightness); } - /// - /// Start the Pulse animation which gradually alternates the brightness of the LED between a low and high brightness setting, using the durations provided. - /// - /// The pulse animation duration - /// The maximum brightness of the animation - /// The minimum brightness of the animation + /// public async Task StartPulse( TimeSpan pulseDuration, float highBrightness = 1, diff --git a/Source/Meadow.Foundation.Core/Leds/RgbPwmLed.cs b/Source/Meadow.Foundation.Core/Leds/RgbPwmLed.cs index 6f4f9b709b..52813eed51 100644 --- a/Source/Meadow.Foundation.Core/Leds/RgbPwmLed.cs +++ b/Source/Meadow.Foundation.Core/Leds/RgbPwmLed.cs @@ -8,8 +8,10 @@ namespace Meadow.Foundation.Leds /// /// Represents a Pulse-Width-Modulation (PWM) controlled RGB LED /// - public partial class RgbPwmLed : IRgbPwmLed + public partial class RgbPwmLed : IRgbPwmLed, IDisposable { + readonly bool createdPorts = false; + static readonly Frequency DefaultFrequency = new Frequency(200, Frequency.UnitType.Hertz); readonly float DEFAULT_DUTY_CYCLE = 0f; @@ -28,9 +30,7 @@ public partial class RgbPwmLed : IRgbPwmLed /// public Voltage MIN_FORWARD_VOLTAGE => new Voltage(0); - /// - /// Turns on LED with current color or turns it off - /// + /// public bool IsOn { get => isOn; @@ -47,9 +47,7 @@ public bool IsOn /// public Color Color { get; protected set; } = Color.White; - /// - /// The brightness value assigned to the LED - /// + /// public float Brightness { get; protected set; } = 1f; /// @@ -87,6 +85,11 @@ public bool IsOn /// public Voltage BlueForwardVoltage { get; protected set; } + /// + /// Is the object disposed + /// + public bool IsDisposed { get; private set; } + /// /// Create instance of RgbPwmLed /// @@ -134,35 +137,9 @@ public RgbPwmLed( greenPwmPin.CreatePwmPort(DefaultFrequency), bluePwmPin.CreatePwmPort(DefaultFrequency), commonType) - { } - - /// - /// Create instance of RgbPwmLed - /// - /// The PWM pin for the red LED - /// The PWM pin for the green LED - /// The PWM pin for the blue LED - /// The forward voltage for the red LED - /// The forward voltage for the green LED - /// The forward voltage for the blue LED - /// Common anode or common cathode - public RgbPwmLed( - IPin redPwmPin, - IPin greenPwmPin, - IPin bluePwmPin, - Voltage redLedForwardVoltage, - Voltage greenLedForwardVoltage, - Voltage blueLedForwardVoltage, - CommonType commonType = CommonType.CommonCathode) : - this( - redPwmPin.CreatePwmPort(DefaultFrequency), - greenPwmPin.CreatePwmPort(DefaultFrequency), - bluePwmPin.CreatePwmPort(DefaultFrequency), - redLedForwardVoltage, - greenLedForwardVoltage, - blueLedForwardVoltage, - commonType) - { } + { + createdPorts = true; + } /// /// Create instance of RgbPwmLed @@ -202,6 +179,36 @@ public RgbPwmLed( ResetPwmPorts(); } + /// + /// Create instance of RgbPwmLed + /// + /// The PWM pin for the red LED + /// The PWM pin for the green LED + /// The PWM pin for the blue LED + /// The forward voltage for the red LED + /// The forward voltage for the green LED + /// The forward voltage for the blue LED + /// Common anode or common cathode + public RgbPwmLed( + IPin redPwmPin, + IPin greenPwmPin, + IPin bluePwmPin, + Voltage redLedForwardVoltage, + Voltage greenLedForwardVoltage, + Voltage blueLedForwardVoltage, + CommonType commonType = CommonType.CommonCathode) : + this( + redPwmPin.CreatePwmPort(DefaultFrequency), + greenPwmPin.CreatePwmPort(DefaultFrequency), + bluePwmPin.CreatePwmPort(DefaultFrequency), + redLedForwardVoltage, + greenLedForwardVoltage, + blueLedForwardVoltage, + commonType) + { + createdPorts = true; + } + /// /// Validates forward voltages to ensure they're within the range MIN_FORWARD_VOLTAGE to MAX_FORWARD_VOLTAGE /// @@ -258,11 +265,7 @@ public void SetBrightness(float brightness) SetColor(Color, brightness); } - /// - /// Sets the current color of the LED - /// - /// The LED color - /// Valid values are from 0 to 1, inclusive + /// public void SetColor(Color color, float brightness = 1) { if (color == Color && brightness == Brightness) @@ -277,5 +280,31 @@ public void SetColor(Color color, float brightness = 1) GreenPwm.DutyCycle = (float)(Color.G / 255.0 * maxGreenDutyCycle * brightness); BluePwm.DutyCycle = (float)(Color.B / 255.0 * maxBlueDutyCycle * brightness); } + + /// + public void Dispose() + { + Dispose(disposing: true); + GC.SuppressFinalize(this); + } + + /// + /// Dispose of the object + /// + /// Is disposing + public virtual void Dispose(bool disposing) + { + if (!IsDisposed) + { + if (disposing && createdPorts) + { + RedPwm.Dispose(); + GreenPwm.Dispose(); + BluePwm.Dispose(); + } + + IsDisposed = true; + } + } } } \ No newline at end of file diff --git a/Source/Meadow.Foundation.Core/Meadow.Foundation.Core.csproj b/Source/Meadow.Foundation.Core/Meadow.Foundation.Core.csproj index 46615403a2..33fdb48b8a 100644 --- a/Source/Meadow.Foundation.Core/Meadow.Foundation.Core.csproj +++ b/Source/Meadow.Foundation.Core/Meadow.Foundation.Core.csproj @@ -12,7 +12,7 @@ icon.png https://github.com/WildernessLabs/Meadow.Foundation Meadow, Meadow.Foundation - 0.33.1 + 1.7.0 true true Meadow.Foundation @@ -23,10 +23,10 @@ 10.0 - + - + diff --git a/Source/Meadow.Foundation.Core/Relays/Relay.cs b/Source/Meadow.Foundation.Core/Relays/Relay.cs index c343a05daf..b0159df78c 100644 --- a/Source/Meadow.Foundation.Core/Relays/Relay.cs +++ b/Source/Meadow.Foundation.Core/Relays/Relay.cs @@ -9,8 +9,11 @@ namespace Meadow.Foundation.Relays /// public class Relay : IRelay { + private RelayState _state; + private readonly bool _closedValue = true; + /// - public event EventHandler OnRelayChanged = default!; + public event EventHandler OnChanged = default!; /// /// Returns digital output port @@ -25,18 +28,21 @@ public class Relay : IRelay /// /// Whether or not the relay is on. Setting this property will turn it on or off. /// - public bool IsOn + public RelayState State { - get => isOn; + get => _state; set { - isOn = value; - DigitalOut.State = isOn ? onValue : !onValue; - OnRelayChanged?.Invoke(this, isOn); + _state = value; + DigitalOut.State = State switch + { + RelayState.Open => !_closedValue, + _ => _closedValue + }; + + OnChanged?.Invoke(this, State); } } - bool isOn = false; - readonly bool onValue = true; /// /// Creates a new Relay on an IDigitalOutputPort. @@ -58,7 +64,7 @@ public Relay(IDigitalOutputPort port, RelayType type = RelayType.NormallyOpen) { // if it's normally closed, we have to invert the "on" value Type = type; - onValue = Type != RelayType.NormallyClosed; + _closedValue = Type != RelayType.NormallyClosed; DigitalOut = port; } @@ -68,7 +74,11 @@ public Relay(IDigitalOutputPort port, RelayType type = RelayType.NormallyOpen) /// public void Toggle() { - IsOn = !IsOn; + State = State switch + { + RelayState.Open => RelayState.Closed, + _ => RelayState.Open, + }; } } } \ No newline at end of file diff --git a/Source/Meadow.Foundation.Core/Sensors/Buttons/PollingPushButton.cs b/Source/Meadow.Foundation.Core/Sensors/Buttons/PollingPushButton.cs index fd679a6db6..e1fb851dab 100644 --- a/Source/Meadow.Foundation.Core/Sensors/Buttons/PollingPushButton.cs +++ b/Source/Meadow.Foundation.Core/Sensors/Buttons/PollingPushButton.cs @@ -22,17 +22,16 @@ public class PollingPushButton : PushButtonBase protected CancellationTokenSource? ctsPolling; /// - /// Creates PushButton with an input pin + /// Creates PollingPushButton with an input pin /// /// The pin connected to the button /// The resistor mode public PollingPushButton(IPin inputPin, ResistorMode resistorMode = ResistorMode.InternalPullUp) : this(inputPin.CreateDigitalInputPort(resistorMode), resistorMode) - { - } + { } /// - /// Creates PushButton with a pre-configured input port + /// Creates PollingPushButton with a pre-configured input port /// /// The input port connected to the button /// /// The resistor mode diff --git a/Source/Meadow.Foundation.Core/Sensors/Buttons/PushButton.cs b/Source/Meadow.Foundation.Core/Sensors/Buttons/PushButton.cs index 215c6cad4b..6f2d9ebd4f 100644 --- a/Source/Meadow.Foundation.Core/Sensors/Buttons/PushButton.cs +++ b/Source/Meadow.Foundation.Core/Sensors/Buttons/PushButton.cs @@ -67,7 +67,7 @@ public PushButton(IDigitalInterruptPort inputPort) { DigitalIn = inputPort; - LongClickedThreshold = DefaultLongPressThreshold; + LongClickedThreshold = DefaultLongClickThreshold; DigitalIn.Changed += DigitalInChanged; } diff --git a/Source/Meadow.Foundation.Core/Sensors/Buttons/PushButtonBase.cs b/Source/Meadow.Foundation.Core/Sensors/Buttons/PushButtonBase.cs index 472998b0fa..3d3667ce5d 100644 --- a/Source/Meadow.Foundation.Core/Sensors/Buttons/PushButtonBase.cs +++ b/Source/Meadow.Foundation.Core/Sensors/Buttons/PushButtonBase.cs @@ -11,9 +11,9 @@ namespace Meadow.Foundation.Sensors.Buttons public abstract class PushButtonBase : IButton, IDisposable { /// - /// Default threshold for LongPress events + /// Default threshold for LongClicked events /// - public static readonly TimeSpan DefaultLongPressThreshold = TimeSpan.FromMilliseconds(500); + public static readonly TimeSpan DefaultLongClickThreshold = TimeSpan.FromMilliseconds(500); /// /// Raised when a press starts @@ -26,12 +26,12 @@ public abstract class PushButtonBase : IButton, IDisposable public event EventHandler PressEnded = default!; /// - /// Raised when the button is released after a press + /// Raised when the button is released after being pressed (for shorter than LongClickedThreshold, if set) /// public event EventHandler Clicked = default!; /// - /// Raised when the button is pressed for LongClickedThreshold or longer and then releases + /// Raised when the button is released after being pressed for longer than LongClickedThreshold /// public event EventHandler LongClicked = default!; @@ -52,9 +52,9 @@ public abstract class PushButtonBase : IButton, IDisposable protected IDigitalInputPort DigitalIn { get; private set; } /// - /// The minimum duration for a long press + /// The minimum duration for a long press. Defaults to /// - public TimeSpan LongClickedThreshold { get; set; } = TimeSpan.Zero; + public TimeSpan LongClickedThreshold { get; set; } = DefaultLongClickThreshold; /// /// Initializes a new instance of the PushButtonBase class with the specified digital input port @@ -62,7 +62,6 @@ public abstract class PushButtonBase : IButton, IDisposable /// The digital input port to associate with the push button protected PushButtonBase(IDigitalInputPort inputPort) { - LongClickedThreshold = DefaultLongPressThreshold; DigitalIn = inputPort; } @@ -131,7 +130,7 @@ protected virtual void RaiseClicked() /// protected virtual void RaisePressStarted() { - PressStarted?.Invoke(this, new EventArgs()); + PressStarted?.Invoke(this, EventArgs.Empty); } /// @@ -139,7 +138,7 @@ protected virtual void RaisePressStarted() /// protected virtual void RaisePressEnded() { - PressEnded?.Invoke(this, new EventArgs()); + PressEnded?.Invoke(this, EventArgs.Empty); } /// @@ -147,7 +146,7 @@ protected virtual void RaisePressEnded() /// protected virtual void RaiseLongClicked() { - LongClicked?.Invoke(this, new EventArgs()); + LongClicked?.Invoke(this, EventArgs.Empty); } /// diff --git a/Source/Meadow.Foundation.Core/Sensors/Light/AnalogLightSensor.cs b/Source/Meadow.Foundation.Core/Sensors/Light/AnalogLightSensor.cs index 7d52f8a0ff..0e858a2116 100644 --- a/Source/Meadow.Foundation.Core/Sensors/Light/AnalogLightSensor.cs +++ b/Source/Meadow.Foundation.Core/Sensors/Light/AnalogLightSensor.cs @@ -17,11 +17,6 @@ public partial class AnalogLightSensor /// protected IAnalogInputPort AnalogInputPort { get; } - /// - /// Raised when the value of the reading changes. - /// - public event EventHandler> IlluminanceUpdated = default!; - /// /// Illuminance sensor calibration /// @@ -125,16 +120,6 @@ public override void StopUpdating() AnalogInputPort.StopUpdating(); } - /// - /// Notify subscribers of IlluminanceUpdated event handler - /// - /// Change result with old and new Illuminance - protected override void RaiseEventsAndNotify(IChangeResult changeResult) - { - IlluminanceUpdated?.Invoke(this, changeResult); - base.RaiseEventsAndNotify(changeResult); - } - /// /// Converts a voltage value to a level in centimeters, based on the current /// calibration values. diff --git a/Source/Meadow.Foundation.Core/Sensors/Temperature/AnalogTemperature.cs b/Source/Meadow.Foundation.Core/Sensors/Temperature/AnalogTemperature.cs index a318cc5363..8ac8a0e6a7 100644 --- a/Source/Meadow.Foundation.Core/Sensors/Temperature/AnalogTemperature.cs +++ b/Source/Meadow.Foundation.Core/Sensors/Temperature/AnalogTemperature.cs @@ -32,11 +32,6 @@ namespace Meadow.Foundation.Sensors.Temperature /// public partial class AnalogTemperature : SamplingSensorBase, ITemperatureSensor, IDisposable { - /// - /// Raised when the value of the reading changes. - /// - public event EventHandler> TemperatureUpdated = default!; - /// /// AnalogInputPort connected to temperature sensor /// @@ -252,16 +247,6 @@ public override void StopUpdating() } } - /// - /// Method to notify subscribers to TemperatureUpdated event handler - /// - /// - protected override void RaiseEventsAndNotify(IChangeResult changeResult) - { - TemperatureUpdated?.Invoke(this, changeResult); - base.RaiseEventsAndNotify(changeResult); - } - /// /// Converts voltage to Temperature /// diff --git a/Source/Meadow.Foundation.Core/Simulation/SimulatedRelay.cs b/Source/Meadow.Foundation.Core/Simulation/SimulatedRelay.cs new file mode 100644 index 0000000000..fa9f91c0b1 --- /dev/null +++ b/Source/Meadow.Foundation.Core/Simulation/SimulatedRelay.cs @@ -0,0 +1,98 @@ +using Meadow.Peripherals.Relays; +using Meadow.Peripherals.Sensors; +using System; +using System.Threading; + +namespace Meadow.Foundation.Relays; + +/// +/// Represents a simulated relay that implements both IRelay and ISimulatedSensor interfaces. +/// +public class SimulatedRelay : IRelay, ISimulatedSensor +{ + private RelayState _state; + private Timer? _simulationTimer; + + /// + public event EventHandler OnChanged = default!; + + /// + public RelayType Type => RelayType.NormallyOpen; + + /// + /// Gets the name of the Relay + /// + public string Name { get; } + + /// + /// Initializes a new instance of the SimulatedRelay class with a specified name. + /// + /// The name of the simulated relay. + public SimulatedRelay(string name) + { + Name = name; + } + + /// + public RelayState State + { + get => _state; + set + { + if (value == _state) return; + _state = value; + OnChanged?.Invoke(this, State); + } + } + + /// + public SimulationBehavior[] SupportedBehaviors => new SimulationBehavior[] { SimulationBehavior.Sawtooth }; + /// + public Type ValueType => typeof(bool); + + /// + public void Toggle() + { + State = State switch + { + RelayState.Open => RelayState.Closed, + _ => RelayState.Open, + }; + } + + /// + public void SetSensorValue(object value) + { + if (value is bool b) + { + State = b switch + { + true => RelayState.Closed, + _ => RelayState.Open + }; + } + else if (value is RelayState s) + { + State = s; + } + else + { + throw new ArgumentException($"Expected a parameter of type '{ValueType.Name}' but received a '{value.GetType().Name}'"); + } + } + + /// + public void StartSimulation(SimulationBehavior behavior) + { + if (_simulationTimer == null) + { + _simulationTimer = new Timer((o) => + { + Toggle(); + }, + null, + TimeSpan.FromSeconds(5), + TimeSpan.FromSeconds(5)); + } + } +} diff --git a/Source/Meadow.Foundation.Core/Simulation/SimulatedTemperatureSensor.cs b/Source/Meadow.Foundation.Core/Simulation/SimulatedTemperatureSensor.cs new file mode 100644 index 0000000000..781a7ddb46 --- /dev/null +++ b/Source/Meadow.Foundation.Core/Simulation/SimulatedTemperatureSensor.cs @@ -0,0 +1,165 @@ +using Meadow.Hardware; +using Meadow.Peripherals.Sensors; +using System; +using System.Threading; +using System.Threading.Tasks; + +namespace Meadow.Foundation.Sensors; + +/// +/// Represents a simulated temperature sensor that implements both ITemperatureSensor and ISimulatedSensor interfaces. +/// +public class SimulatedTemperatureSensor : ITemperatureSensor, ISimulatedSensor +{ + private readonly Random _random = new(); + private Units.Temperature? _temperature; + private readonly Units.Temperature? _minTemperature; + private readonly Units.Temperature? _maxTemperature; + private SimulationBehavior _behavior; + private int _sawtoothDirection = 1; + private Timer? _reportTimer; + private Timer? _simulationTimer; + + /// + public event EventHandler> Updated = default!; + /// + public SimulationBehavior[] SupportedBehaviors => new SimulationBehavior[] { SimulationBehavior.RandomWalk, SimulationBehavior.Sawtooth }; + /// + public Type ValueType => typeof(Units.Temperature); + /// + 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 digital interrupt port used for incrementing the temperature. + /// The digital interrupt port used for decrementing the temperature. + public SimulatedTemperatureSensor( + Units.Temperature initialTemperature, + IDigitalInterruptPort incrementPort, + IDigitalInterruptPort decrementPort) + { + _temperature = initialTemperature; + + incrementPort.Changed += (s, e) => + { + Temperature = new Units.Temperature(Temperature!.Value.Fahrenheit + 0.5, Meadow.Units.Temperature.UnitType.Fahrenheit); + }; + decrementPort.Changed += (s, e) => + { + Temperature = new Units.Temperature(Temperature!.Value.Fahrenheit - 0.5, Meadow.Units.Temperature.UnitType.Fahrenheit); + }; + } + + /// + /// 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 SimulatedTemperatureSensor( + Units.Temperature initialTemperature, + Units.Temperature minimumTemperature, + Units.Temperature maximumTemperature, + SimulationBehavior behavior = SimulationBehavior.RandomWalk) + { + _temperature = initialTemperature; + _minTemperature = minimumTemperature; + _maxTemperature = maximumTemperature; + + StartSimulation(behavior); + } + + private void SimulationProc(object? o) + { + var delta = _behavior switch + { + SimulationBehavior.RandomWalk => _random.Next(-10, 10) / 10d, + _ => 0.1 * _sawtoothDirection + }; + + if (_temperature == null) return; + + var newTemp = _temperature.Value.Celsius + delta; + if ((newTemp < _minTemperature!.Value.Celsius) || + (newTemp > _maxTemperature!.Value.Celsius)) + { + newTemp = _temperature.Value.Celsius - delta; + _sawtoothDirection *= -1; + } + + Temperature = new Units.Temperature(newTemp, Meadow.Units.Temperature.UnitType.Celsius); + } + + private void ReportTimerProc(object? o) + { + Updated?.Invoke(this, new ChangeResult(this.Temperature!.Value, this.Temperature!.Value)); + } + + /// + public Units.Temperature? Temperature + { + get => _temperature; + private set + { + if (value == Temperature) return; + + if (value != null) + { + var previous = _temperature; + _temperature = value; + Updated?.Invoke(this, new ChangeResult(Temperature!.Value, previous)); + } + } + } + + /// + public Task Read() + { + return Task.FromResult(Temperature ?? Units.Temperature.AbsoluteZero); + } + + /// + /// 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 Units.Temperature temperature) + { + Temperature = temperature; + } + 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.FromSeconds(1)); + } +} 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 5ec116e7a7..af2a2b392c 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 @@ -15,13 +15,13 @@ icon.png https://github.com/WildernessLabs/Meadow.Foundation Meadow,Meadow.Foundation,Audio,Songs,Tone,Tones,Music,Sound,Effects - 0.1.0 + 1.7.0 true Lightweight single-voice sound effect and music player designed for embedded applications - + - + 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 51f6b9bf5b..2eeaf30982 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,8 +9,8 @@ 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 2a58d75a66..4a9e1dfa7e 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 @@ -15,13 +15,13 @@ icon.png https://github.com/WildernessLabs/Meadow.Foundation Meadow.Foundation, DataLoggers, Adafruit IO - 0.5.53 + 1.7.0 true Driver for the Adafruit IO data logging system - + - + 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 fb06a18b6e..a7e0ca36b3 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 @@ -15,13 +15,13 @@ icon.png https://github.com/WildernessLabs/Meadow.Foundation Meadow.Foundation, DataLoggers, SensorReading - 0.5.48 + 1.7.0 true SensorReading class for Meadow Foundation data loggers - + - + 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 fe629c7644..42050badca 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 @@ -15,13 +15,13 @@ icon.png https://github.com/WildernessLabs/Meadow.Foundation Meadow.Foundation, DataLoggers, ThingSpeak - 0.5.48 + 1.7.0 true Driver for the ThingSpeak data logging system - + - + diff --git a/Source/Meadow.Foundation.Libraries_and_Frameworks/Displays.TextDisplayMenu/Driver/BaseClasses/InputBase.cs b/Source/Meadow.Foundation.Libraries_and_Frameworks/Displays.TextDisplayMenu/Driver/BaseClasses/InputBase.cs index 5f69e8f3e5..751178f507 100644 --- a/Source/Meadow.Foundation.Libraries_and_Frameworks/Displays.TextDisplayMenu/Driver/BaseClasses/InputBase.cs +++ b/Source/Meadow.Foundation.Libraries_and_Frameworks/Displays.TextDisplayMenu/Driver/BaseClasses/InputBase.cs @@ -10,7 +10,7 @@ public abstract class InputBase : IMenuInputItem /// /// The ITextDisplay object /// - protected ITextDisplay display; + protected ITextDisplay display = default!; /// /// Is the item initialized diff --git a/Source/Meadow.Foundation.Libraries_and_Frameworks/Displays.TextDisplayMenu/Driver/BaseClasses/TimeBase.cs b/Source/Meadow.Foundation.Libraries_and_Frameworks/Displays.TextDisplayMenu/Driver/BaseClasses/TimeBase.cs index 6961d304d3..c63050a14f 100644 --- a/Source/Meadow.Foundation.Libraries_and_Frameworks/Displays.TextDisplayMenu/Driver/BaseClasses/TimeBase.cs +++ b/Source/Meadow.Foundation.Libraries_and_Frameworks/Displays.TextDisplayMenu/Driver/BaseClasses/TimeBase.cs @@ -10,7 +10,7 @@ public abstract class TimeBase : InputBase /// /// Value for each time part /// - protected int[] timeParts; + protected int[] timeParts = new int[0]; /// /// The current position 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 2ab844ba3e..216867952b 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 @@ -15,14 +15,14 @@ icon.png https://github.com/WildernessLabs/Meadow.Foundation Meadow, Meadow.Foundation, Display, Text, Menu - 0.1.50 + 1.7.0 true Text based stack navigation and editor for pixel and character displays - + - + diff --git a/Source/Meadow.Foundation.Libraries_and_Frameworks/Displays.TextDisplayMenu/Driver/InputTypes/Date.cs b/Source/Meadow.Foundation.Libraries_and_Frameworks/Displays.TextDisplayMenu/Driver/InputTypes/Date.cs index ba36f0bafd..3400cfc491 100644 --- a/Source/Meadow.Foundation.Libraries_and_Frameworks/Displays.TextDisplayMenu/Driver/InputTypes/Date.cs +++ b/Source/Meadow.Foundation.Libraries_and_Frameworks/Displays.TextDisplayMenu/Driver/InputTypes/Date.cs @@ -7,7 +7,7 @@ namespace Meadow.Foundation.Displays.UI.InputTypes /// public class Date : InputBase { - int[] dateParts; + int[] dateParts = new int[0]; byte position = 0; /// diff --git a/Source/Meadow.Foundation.Libraries_and_Frameworks/Displays.TextDisplayMenu/Driver/InputTypes/ListBase.cs b/Source/Meadow.Foundation.Libraries_and_Frameworks/Displays.TextDisplayMenu/Driver/InputTypes/ListBase.cs index 6c1dd39fdc..f656ccfd1e 100644 --- a/Source/Meadow.Foundation.Libraries_and_Frameworks/Displays.TextDisplayMenu/Driver/InputTypes/ListBase.cs +++ b/Source/Meadow.Foundation.Libraries_and_Frameworks/Displays.TextDisplayMenu/Driver/InputTypes/ListBase.cs @@ -10,7 +10,7 @@ public abstract class ListBase : InputBase /// /// List of choices for the input /// - protected string[] choices; + protected string[] choices = new string[0]; /// /// Selected index in the list diff --git a/Source/Meadow.Foundation.Libraries_and_Frameworks/Displays.TextDisplayMenu/Driver/TextDisplayMenu.cs b/Source/Meadow.Foundation.Libraries_and_Frameworks/Displays.TextDisplayMenu/Driver/TextDisplayMenu.cs index f330b4c0fc..a201db7a24 100644 --- a/Source/Meadow.Foundation.Libraries_and_Frameworks/Displays.TextDisplayMenu/Driver/TextDisplayMenu.cs +++ b/Source/Meadow.Foundation.Libraries_and_Frameworks/Displays.TextDisplayMenu/Driver/TextDisplayMenu.cs @@ -354,11 +354,11 @@ public bool Select() MenuItem menuItem = currentMenuPage.MenuItems[pos]; // go to the submenu if children are present - if (menuItem.HasSubItems) + if (menuItem != null && menuItem.HasSubItems) { pageStack?.Push(currentMenuPage); // currentMenuPage = child.SubMenu; - currentMenuPage = CreateMenuPage(menuItem.SubItems, true); + currentMenuPage = CreateMenuPage(menuItem.SubItems!, true); ShowCurrentPage(); return true; } @@ -402,7 +402,7 @@ public bool Select() currentInputItem.Init(display); } - currentInputItem?.GetInput(menuItem.Id, menuItem.Value); + currentInputItem?.GetInput(menuItem.Id, menuItem.Value!); return true; } else 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 c439b78423..671a70c2f8 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 21dad174c8..f3b4e40490 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 21dad174c8..f3b4e40490 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/PixelBufferBase.cs b/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroGraphics/Driver/Buffers/PixelBufferBase.cs index 123b0ed6f6..55e1aebe3c 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 @@ -59,7 +59,7 @@ public int BitDepth /// The buffer that holds the pixel data /// The packing structure in buffer-specific /// - public byte[] Buffer { get; protected set; } + public byte[] Buffer { get; protected set; } = default!; /// /// Did we create the buffer (true) or was it passed in (false) 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 631b62c736..2c45f0cd22 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 @@ -15,13 +15,13 @@ icon.png https://github.com/WildernessLabs/Meadow.Foundation Meadow,Meadow.Foundation,Display,Graphics - 0.9.54 + 1.7.0 true Lightweight integer accurate 2d graphics drawing system designed for embedded applications - + - + 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 f06177237f..e485033680 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,8 +29,8 @@ - - + + diff --git a/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroLayout/Driver/Charts/ChartExtensions.cs b/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroLayout/Driver/Charts/ChartExtensions.cs index 6e19e0fea6..96a89d4764 100644 --- a/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroLayout/Driver/Charts/ChartExtensions.cs +++ b/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroLayout/Driver/Charts/ChartExtensions.cs @@ -34,5 +34,4 @@ public static LineChartSeries ToLineChartSeries(this double[,] xyData) return series; } - -} +} \ No newline at end of file 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 fe2b8a0e88..361a507c4e 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 @@ -11,10 +11,12 @@ public class LineChart : ThemedControl /// The default color for axis lines /// public static Color DefaultAxisColor = Color.Gray; + /// /// The default color for axis labels /// public static Color DefaultAxisLabelColor = Color.White; + /// /// The default chart background color /// @@ -72,6 +74,8 @@ public class LineChart : ThemedControl private int ChartAreaLeft { get; set; } private int ChartAreaTop { get; set; } private int ChartAreaBottom { get; set; } + private int ParentOffsetX => (Parent?.Left ?? 0); + private int ParentOffsetY => (Parent?.Top ?? 0); /// /// Creates a DisplayLineChart instance @@ -158,8 +162,8 @@ private void DrawAxisLabels(MicroGraphics graphics) if (XAxisYIntercept != YMinimumValue) { graphics.DrawText( - x: Left + DefaultMargin, - y: XAxisScaledPosition - (font.Height / 2), // centered on tick + x: Left + DefaultMargin + ParentOffsetX, + y: XAxisScaledPosition - (font.Height / 2) + +ParentOffsetY, // centered on tick color: AxisLabelColor, text: XAxisYIntercept.ToString("0.0"), font: font); @@ -167,16 +171,16 @@ private void DrawAxisLabels(MicroGraphics graphics) // max label graphics.DrawText( - x: Left + DefaultMargin, - y: ChartAreaTop + font.Height, + x: Left + DefaultMargin + ParentOffsetX, + y: ChartAreaTop + font.Height + ParentOffsetY, color: AxisLabelColor, text: YMaximumValue.ToString("0.0"), font: font); // min label graphics.DrawText( - x: Left + DefaultMargin, - y: ChartAreaBottom - font.Height, + x: Left + DefaultMargin + ParentOffsetX, + y: ChartAreaBottom - font.Height + ParentOffsetY, color: AxisLabelColor, text: YMinimumValue.ToString("0.0"), font: font); @@ -203,8 +207,8 @@ private void DrawXAxis(MicroGraphics graphics, double minY, double maxY) // for now it's a fixed line at the bottom graphics.Stroke = DefaultAxisStroke; graphics.DrawLine( - ChartAreaLeft, - XAxisScaledPosition, + ChartAreaLeft + ParentOffsetX, + XAxisScaledPosition + ParentOffsetY, Right - DefaultMargin, XAxisScaledPosition, AxisColor); @@ -242,8 +246,8 @@ private void DrawYAxis(MicroGraphics graphics) // for now it's a fixed line at the left graphics.Stroke = DefaultAxisStroke; graphics.DrawLine( - ChartAreaLeft, - Top + DefaultMargin, + ChartAreaLeft + ParentOffsetX, + Top + DefaultMargin + ParentOffsetY, ChartAreaLeft, Bottom - DefaultMargin, AxisColor); @@ -261,8 +265,6 @@ private void DrawSeries(MicroGraphics graphics, LineChartSeries series) graphics.Stroke = series.LineStroke; - //graphics.DrawRectangle(ChartAreaLeft + DefaultAxisStroke * 2 + DefaultMargin, ChartAreaTop - DefaultAxisStroke, ChartAreaWidth, ChartAreaHeight, Color.Red, true); - foreach (var point in series.Points) { var scaledX = ChartAreaLeft + DefaultAxisStroke * 2 + DefaultMargin + (int)(point.X / xRange * ChartAreaWidth); @@ -277,8 +279,8 @@ private void DrawSeries(MicroGraphics graphics, LineChartSeries series) else { graphics.DrawLine( - (int)lastPoint.X, - (int)lastPoint.Y, + (int)lastPoint.X + ParentOffsetX, + (int)lastPoint.Y + ParentOffsetY, scaledX, scaledY, series.LineColor); @@ -290,7 +292,7 @@ private void DrawSeries(MicroGraphics graphics, LineChartSeries series) if (series.ShowPoints) { - graphics.DrawCircle(scaledX, scaledY, series.PointSize, series.PointColor, true); + graphics.DrawCircle(scaledX + ParentOffsetX, scaledY + ParentOffsetY, series.PointSize, series.PointColor, true); } } } diff --git a/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroLayout/Driver/ClickableControl.cs b/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroLayout/Driver/ClickableControl.cs index a0f1c34591..3143ddc3e8 100644 --- a/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroLayout/Driver/ClickableControl.cs +++ b/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroLayout/Driver/ClickableControl.cs @@ -22,7 +22,7 @@ public bool Pressed get => _pressed; set { - if (!Visible) return; + if (!IsVisible) return; if (_pressed == value) return; diff --git a/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroLayout/Driver/Controls/Box.cs b/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroLayout/Driver/Controls/Box.cs index 145acec3de..cd36d0686d 100644 --- a/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroLayout/Driver/Controls/Box.cs +++ b/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroLayout/Driver/Controls/Box.cs @@ -10,7 +10,7 @@ public class Box : ThemedControl /// /// Gets or sets a value indicating whether the display box is filled with the foreground color. /// - public bool Filled { get; set; } = true; + public bool IsFilled { get; set; } = true; /// /// Initializes a new instance of the class with the specified dimensions. @@ -53,7 +53,7 @@ protected override void OnDraw(MicroGraphics graphics) { if (ForeColor != Color.Transparent) { - graphics.DrawRectangle(Left, Top, Width, Height, ForeColor, Filled); + graphics.DrawRectangle(Left + (Parent?.Left ?? 0), Top + (Parent?.Top ?? 0), Width, Height, ForeColor, IsFilled); } } } diff --git a/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroLayout/Driver/Controls/Button.cs b/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroLayout/Driver/Controls/Button.cs index c394434241..dc9a4224f4 100644 --- a/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroLayout/Driver/Controls/Button.cs +++ b/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroLayout/Driver/Controls/Button.cs @@ -137,25 +137,31 @@ protected override void OnDraw(MicroGraphics graphics) { graphics.Stroke = ButtonDepth; + var parentOffsetX = Parent?.Left ?? 0; + var parentOffsetY = Parent?.Top ?? 0; + if (Pressed) { - graphics.DrawRectangle(Left, Top, Width, Height, PressedColor, true); + graphics.DrawRectangle(Left + parentOffsetX, Top + parentOffsetY, Width, Height, PressedColor, true); - graphics.DrawHorizontalLine(Left, Top, Width, ShadowColor); - graphics.DrawVerticalLine(Left, Top, Height, ShadowColor); + graphics.DrawHorizontalLine(Left + parentOffsetX, Top + parentOffsetY, Width, ShadowColor); + graphics.DrawVerticalLine(Left + parentOffsetX, Top + parentOffsetY, Height, ShadowColor); - graphics.DrawHorizontalLine(Left, Bottom, Width, HighlightColor); - graphics.DrawVerticalLine(Right, Top, Height, HighlightColor); + graphics.DrawHorizontalLine(Left + parentOffsetX, Bottom + parentOffsetY, Width, HighlightColor); + graphics.DrawVerticalLine(Right + parentOffsetX, Top + parentOffsetY, Height, HighlightColor); if (Image != null) // image always wins over text { - graphics.DrawImage(Left + ((this.Width - Image.Width) / 2) + ButtonDepth, Top + ((this.Height - Image.Height) / 2) + ButtonDepth, Image); + graphics.DrawImage( + Left + ((this.Width - Image.Width) / 2) + ButtonDepth + parentOffsetX, + Top + ((this.Height - Image.Height) / 2) + ButtonDepth + parentOffsetY, + Image); } else if (!string.IsNullOrEmpty(Text)) { graphics.DrawText( - Left + ButtonDepth + (this.Width / 2), - Top + ButtonDepth + (this.Height / 2), + Left + ButtonDepth + (this.Width / 2) + parentOffsetX, + Top + ButtonDepth + (this.Height / 2) + parentOffsetY, Text, TextColor, scaleFactor: ScaleFactor, @@ -166,26 +172,26 @@ protected override void OnDraw(MicroGraphics graphics) } else { - graphics.DrawRectangle(Left, Top, Width, Height, ForeColor, true); + graphics.DrawRectangle(Left + parentOffsetX, Top + parentOffsetY, Width, Height, ForeColor, true); - graphics.DrawHorizontalLine(Left, Top, Width, HighlightColor); - graphics.DrawVerticalLine(Left, Top, Height, HighlightColor); + graphics.DrawHorizontalLine(Left + parentOffsetX, Top + parentOffsetY, Width, HighlightColor); + graphics.DrawVerticalLine(Left + parentOffsetX, Top + parentOffsetY, Height, HighlightColor); - graphics.DrawHorizontalLine(Left, Bottom, Width, ShadowColor); - graphics.DrawVerticalLine(Right, Top, Height, ShadowColor); + graphics.DrawHorizontalLine(Left + parentOffsetX, Bottom + parentOffsetY, Width, ShadowColor); + graphics.DrawVerticalLine(Right + parentOffsetX, Top + parentOffsetY, Height, ShadowColor); if (Image != null) // image always wins over text { graphics.DrawImage( - Left + ((this.Width - Image.Width) / 2), - Top + ((this.Height - Image.Height) / 2), + Left + ((this.Width - Image.Width) / 2) + parentOffsetX, + Top + ((this.Height - Image.Height) / 2) + parentOffsetY, Image); } else if (!string.IsNullOrEmpty(Text)) { graphics.DrawText( - Left + (this.Width / 2), - Top + (this.Height / 2), + Left + (this.Width / 2) + parentOffsetX, + Top + (this.Height / 2) + parentOffsetY, Text, TextColor, scaleFactor: ScaleFactor, 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 fdf12a83c2..45404291ee 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 @@ -9,7 +9,7 @@ public abstract class Control : IControl private int _top; private int _width; private int _height; - private bool _visible = true; + private bool _isVisible = true; /// /// Gets or sets a value indicating whether the control needs to be redrawn. @@ -21,6 +21,9 @@ public abstract class Control : IControl /// public object? Context { get; set; } + /// + public IControl? Parent { get; set; } + /// /// Initializes a new instance of the class with the specified dimensions. /// @@ -67,10 +70,10 @@ public virtual void Invalidate() /// /// Gets or sets a value indicating whether the control is visible. /// - public virtual bool Visible + public virtual bool IsVisible { - get => _visible; - set => SetInvalidatingProperty(ref _visible, value); + get => _isVisible; + set => SetInvalidatingProperty(ref _isVisible, value); } /// @@ -127,7 +130,7 @@ public void Refresh(MicroGraphics graphics) { if (IsInvalid) { - if (Visible) + if (IsVisible) { OnDraw(graphics); } 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 8a5a44bc86..7ad5c19fd9 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 @@ -117,7 +117,7 @@ protected override void OnDraw(MicroGraphics graphics) { if (BackColor != Color.Transparent) { - graphics.DrawRectangle(Left, Top, Width, Height, BackColor, true); + graphics.DrawRectangle(Left + (Parent?.Left ?? 0), Top + (Parent?.Top ?? 0), Width, Height, BackColor, true); } int x, y; @@ -147,6 +147,9 @@ protected override void OnDraw(MicroGraphics graphics) break; } + x += Parent?.Left ?? 0; + y += Parent?.Top ?? 0; + graphics.DrawText( Left + x, Top + y, diff --git a/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroLayout/Driver/Controls/Picture.cs b/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroLayout/Driver/Controls/Picture.cs index 62c4a8f4e2..307fdba929 100644 --- a/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroLayout/Driver/Controls/Picture.cs +++ b/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroLayout/Driver/Controls/Picture.cs @@ -83,7 +83,13 @@ protected override void OnDraw(MicroGraphics graphics) { if (BackColor != Color.Transparent) { - graphics.DrawRectangle(Left, Top, Width, Height, BackColor, true); + graphics.DrawRectangle( + Left + (Parent?.Left ?? 0), + Top + (Parent?.Top ?? 0), + Width, + Height, + BackColor, + true); } int x, y; @@ -113,6 +119,9 @@ protected override void OnDraw(MicroGraphics graphics) y = Top; } + x += Parent?.Left ?? 0; + y += Parent?.Top ?? 0; + graphics.DrawImage(x, y, Image); } } diff --git a/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroLayout/Driver/Controls/ProgressBar.cs b/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroLayout/Driver/Controls/ProgressBar.cs new file mode 100644 index 0000000000..3a9621af13 --- /dev/null +++ b/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroLayout/Driver/Controls/ProgressBar.cs @@ -0,0 +1,142 @@ +using System; + +namespace Meadow.Foundation.Graphics.MicroLayout; + +/// +/// Represents a progress bar control in the user interface. +/// +public class ProgressBar : ThemedControl +{ + private Color _valueColor = Color.DarkBlue; + private Color _borderColor = Color.Transparent; + private Color _backColor = Color.DarkGray; + private int _value = 0; + private int _minimum = 0; + private int _maximum = 100; + + /// + /// Represents a rectangular, horizontal progress bar in the user interface. + /// + /// + public ProgressBar(int left, int top, int width, int height) + : base(left, top, width, height) + { + } + + /// + public override void ApplyTheme(DisplayTheme theme) + { + if (theme != null) + { + if (theme.ForegroundColor != null) this.ValueColor = theme.ForegroundColor.Value; + if (theme.BackgroundColor != null) this.BackColor = theme.BackgroundColor.Value; + if (theme.HighlightColor != null) this.BorderColor = theme.HighlightColor.Value; + } + } + + /// + /// Gets or set the Value for the ProgressBar + /// + public int Value + { + get => _value; + set + { + if (value > Maximum || value < Minimum) throw new ArgumentOutOfRangeException(); + SetInvalidatingProperty(ref _value, value); + } + } + + /// + /// Gets or set the minimum Value for the ProgressBar + /// + public int Minimum + { + get => _minimum; + set + { + if (value >= Maximum) throw new ArgumentOutOfRangeException(); + SetInvalidatingProperty(ref _minimum, value); + } + } + + /// + /// Gets or set the maximum Value for the ProgressBar + /// + public int Maximum + { + get => _maximum; + set + { + if (value <= Minimum) throw new ArgumentOutOfRangeException(); + SetInvalidatingProperty(ref _maximum, value); + } + } + + /// + /// Gets or sets the foreground (value) color to fill on the ProgressBar + /// + public Color ValueColor + { + get => _valueColor; + set => SetInvalidatingProperty(ref _valueColor, value); + } + + /// + /// Gets or sets the background (non-value) color to fill on the ProgressBar + /// + public Color BackColor + { + get => _backColor; + set => SetInvalidatingProperty(ref _backColor, value); + } + + /// + /// Gets or sets the border color to around the ProgressBar + /// + public Color BorderColor + { + get => _borderColor; + set => SetInvalidatingProperty(ref _borderColor, value); + } + + /// + protected override void OnDraw(MicroGraphics graphics) + { + var valueWidth = (int)((Value / (float)(Maximum - Minimum)) * Width); + var emptyWidth = Width - valueWidth; + + if (ValueColor != Color.Transparent) + { + graphics.DrawRectangle( + Left + (Parent?.Left ?? 0), + Top + (Parent?.Top ?? 0), + valueWidth, + Height, + ValueColor, + true); + } + if (BackColor != Color.Transparent) + { + Resolver.Log.Info($"Drawing back color of {BackColor}"); + + graphics.DrawRectangle( + Left + valueWidth + (Parent?.Left ?? 0), + Top + (Parent?.Top ?? 0), + emptyWidth, + Height, + BackColor, + true); + } + if (BorderColor != Color.Transparent) + { + graphics.DrawRectangle( + Left + (Parent?.Left ?? 0), + Top + (Parent?.Top ?? 0), + Width, + Height, + BorderColor, + false); + } + } +} 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 ef61065120..71248b6369 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 @@ -12,13 +12,17 @@ public sealed class ControlsCollection : IEnumerable private readonly List _controls = new(); private readonly object _syncRoot = new(); + private readonly IControl? _parent; + /// /// Initializes a new instance of the class. /// /// The that owns the controls collection. - internal ControlsCollection(DisplayScreen screen) + /// The parent control (if exists) + internal ControlsCollection(DisplayScreen screen, IControl? parent) { _screen = screen; + _parent = parent; } internal object SyncRoot => _syncRoot; @@ -66,7 +70,11 @@ public void Add(params IControl[] controls) lock (SyncRoot) { - _controls.AddRange(controls); + foreach (var control in controls) + { + control.Parent = _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 6a4a01074a..7890a4b511 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 @@ -47,7 +47,7 @@ public class DisplayScreen /// The display theme to use. public DisplayScreen(IGraphicsDisplay physicalDisplay, RotationType rotation = RotationType.Normal, ITouchScreen? touchScreen = null, DisplayTheme? theme = null) { - Controls = new ControlsCollection(this); + Controls = new ControlsCollection(this, null); Theme = theme; _display = physicalDisplay; @@ -148,9 +148,9 @@ public void EndUpdate() private void DrawLoop() { - if(Resolver.App != null) + if (Resolver.App != null) { - DrawLoopThreaded(); ; + DrawLoopThreaded(); } else { @@ -172,8 +172,10 @@ private void DrawLoopOnCaller() foreach (var control in Controls) { if (control != null) - // until micrographics supports invalidating regions, we have to invalidate everything when one control needs updating + { + // TODO: micrographics supports invalidating regions - we need to update to invalidate only regions here, too RefreshTree(control); + } } } _graphics.Show(); @@ -191,25 +193,25 @@ private void DrawLoopThreaded() { Resolver.App.InvokeOnMainThread((_) => { - if (!_updateInProgress && (IsInvalid || Controls.Any(c => c.IsInvalid))) + lock (Controls.SyncRoot) { - _graphics.Clear(BackgroundColor); - - lock (Controls.SyncRoot) + if (!_updateInProgress && (IsInvalid || Controls.Any(c => c.IsInvalid))) { + _graphics.Clear(BackgroundColor); + foreach (var control in Controls) { - if(control != null) - // until micrographics supports invalidating regions, we have to invalidate everything when one control needs updating + if (control != null) + { + // TODO: micrographics supports invalidating regions - we need to update to invalidate only regions here, too RefreshTree(control); + } } + _graphics.Show(); + IsInvalid = false; } - _graphics.Show(); - IsInvalid = false; } - } - - ); + }); Thread.Sleep(50); } 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 353ecfcabb..0718f071f6 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 @@ -13,7 +13,7 @@ icon.png https://github.com/WildernessLabs/Meadow.Foundation Meadow,Meadow.Foundation,Display,UI,MicroLayout - 0.1.0 + 1.7.0 true Lightweight UI Framework for embedded applications enable @@ -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 4366266a08..259db6c1d5 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 @@ -5,6 +5,11 @@ /// 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 + /// + IControl? Parent { get; set; } + /// /// Gets or sets the left coordinate of the display control. /// @@ -18,7 +23,7 @@ public interface IControl /// /// Gets or sets whether the control is visible. /// - bool Visible { get; set; } + bool IsVisible { get; set; } /// /// Gets or sets the width of the display control. 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 97d8b4e17d..14dec02065 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 @@ -30,9 +30,15 @@ public AbsoluteLayout(DisplayScreen screen, int left, int top, int width, int he /// protected override void OnDraw(MicroGraphics graphics) { - if (Visible && BackgroundColor != null) + if (IsVisible && BackgroundColor != null) { - graphics.DrawRectangle(Left, Top, Width, Height, BackgroundColor.Value, true); + graphics.DrawRectangle( + Left + (Parent?.Left ?? 0), + Top + (Parent?.Top ?? 0), + Width, + Height, + BackgroundColor.Value, + true); } } } diff --git a/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroLayout/Driver/Layouts/Layout.cs b/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroLayout/Driver/Layouts/Layout.cs index 918a84adff..c50a546cd5 100644 --- a/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroLayout/Driver/Layouts/Layout.cs +++ b/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroLayout/Driver/Layouts/Layout.cs @@ -7,6 +7,8 @@ namespace Meadow.Foundation.Graphics.MicroLayout; /// public abstract class Layout : ThemedControl { + private Color? _backColor; + /// /// Creates a DisplayLayout /// @@ -18,13 +20,17 @@ public abstract class Layout : ThemedControl protected Layout(DisplayScreen screen, int left, int top, int width, int height) : base(left, top, width, height) { - Controls = new ControlsCollection(screen); + Controls = new ControlsCollection(screen, this); } /// /// Gets or sets the background color of the Layout. /// - public Color? BackgroundColor { get; set; } + public Color? BackgroundColor + { + get => _backColor; + set => SetInvalidatingProperty(ref _backColor, value); + } /// public override bool IsInvalid => base.IsInvalid || Controls.Any(c => c.IsInvalid); @@ -42,16 +48,16 @@ public override void ApplyTheme(DisplayTheme theme) } /// - public override bool Visible + public override bool IsVisible { - get => base.Visible; + get => base.IsVisible; set { foreach (var control in Controls) { - control.Visible = value; + control.IsVisible = value; } - base.Visible = value; + base.IsVisible = value; } } 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 8fbb68954b..3be07fccad 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 b504520673..1002163cea 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 @@ -88,13 +88,13 @@ public override Task Run() _screen.Controls.Add(splashLayout, chartLayout); - chartLayout.Visible = false; + chartLayout.IsVisible = false; Task.Run(async () => { await Task.Delay(5000); - splashLayout.Visible = false; - chartLayout.Visible = true; + splashLayout.IsVisible = false; + chartLayout.IsVisible = true; }); Application.Run(display); 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/Ili9488Charts_Sample/Ili9488Charts_Sample.csproj index 10aedd88c2..4f722fbe67 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/Ili9488Charts_Sample/Ili9488Charts_Sample.csproj @@ -8,11 +8,11 @@ - - - - - + + + + + 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 f1285c7b03..04a7a643af 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/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 83f00cc429..0295aaab35 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 @@ -10,7 +10,7 @@ icon.png https://github.com/WildernessLabs/Meadow.Foundation Meadow.Foundation, Nmea, Gnss - 0.1.47 + 1.7.0 true GNSS NMEA parsing library @@ -22,8 +22,8 @@ 10.0 - + - + 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 95b2d112ed..f62abdd5b7 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,8 +13,8 @@ - - + + 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 c4319959c3..7d3f480de1 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 @@ -15,13 +15,13 @@ Meadow.Foundation.Audio.Mp3.Yx5300 https://github.com/WildernessLabs/Meadow.Foundation Meadow.Foundation, Audio, MP3, YX5300 - 0.1.21 + 1.7.0 true YX5300 serial MP3 player - + - + diff --git a/Source/Meadow.Foundation.Peripherals/Audio.Mp3.Yx5300/Driver/Yx5300.cs b/Source/Meadow.Foundation.Peripherals/Audio.Mp3.Yx5300/Driver/Yx5300.cs index fc56c8100a..1289961cc4 100644 --- a/Source/Meadow.Foundation.Peripherals/Audio.Mp3.Yx5300/Driver/Yx5300.cs +++ b/Source/Meadow.Foundation.Peripherals/Audio.Mp3.Yx5300/Driver/Yx5300.cs @@ -19,12 +19,16 @@ public partial class Yx5300 : IDisposable readonly bool createdPort = false; + private byte[] sendBuffer; + /// /// Create a YX5300 mp3 player object /// - /// + /// The serial port protected Yx5300(ISerialPort serialPort) { + sendBuffer = new byte[8]; + this.serialPort = serialPort; serialPort.Open(); @@ -233,8 +237,6 @@ private async Task> SendCommandAndReadResponse(Commands c private void SendCommand(Commands command, byte data1 = 0, byte data2 = 0) { - byte[] sendBuffer = new byte[8]; - Thread.Sleep(20); // Command Structure 0x7E 0xFF 0x06 CMD FBACK DAT1 DAT2 0xEF 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 e1fde545b9..e2e671b825 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,8 +9,8 @@ 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 c437e14662..cb17aacb50 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 @@ -15,13 +15,13 @@ Meadow.Foundation.Audio.Radio.Tea5767 https://github.com/WildernessLabs/Meadow.Foundation Meadow.Foundation, Audio, TEA5767 - 0.6.55 + 1.7.0 true TEA5767 I2C FM radio module - + - + 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 b7fc7b8a9b..88715e4c6a 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,10 +9,10 @@ App - + - + diff --git a/Source/Meadow.Foundation.Peripherals/Displays.AsciiConsole/Driver/AsciiConsoleDisplay.CharacterBuffer.cs b/Source/Meadow.Foundation.Peripherals/Displays.AsciiConsole/Driver/AsciiConsoleDisplay.CharacterBuffer.cs new file mode 100644 index 0000000000..60959be317 --- /dev/null +++ b/Source/Meadow.Foundation.Peripherals/Displays.AsciiConsole/Driver/AsciiConsoleDisplay.CharacterBuffer.cs @@ -0,0 +1,89 @@ +using Meadow.Foundation.Graphics; +using Meadow.Foundation.Graphics.Buffers; +using System; + +namespace Meadow.Foundation.Displays +{ + public partial class AsciiConsoleDisplay + { + internal class CharacterBuffer : IPixelBuffer + { + public int Width { get; } + public int Height { get; } + public ColorMode ColorMode => ColorMode.Format8bppGray; + public int BitDepth => 6; + + public int ByteCount => throw new NotImplementedException(); + + public byte[] Buffer => throw new NotImplementedException(); + + private char[,] _buffer; + + public CharacterBuffer(int width, int height) + { + Width = width; + Height = height; + + _buffer = new char[width, height]; + } + + public void Clear() + { + Fill(Color.Black); + } + + public void Fill(Color color) + { + for (var y = 0; y < Height; y++) + { + for (var x = 0; x < Width; x++) + { + SetPixel(x, y, color); + } + } + } + + public void Fill(int originX, int originY, int width, int height, Color color) + { + for (var y = originY; y < height + originY; y++) + { + for (var x = originX; x < width + originX; x++) + { + SetPixel(x, y, color); + } + } + } + + internal char GetPixelCharacter(int x, int y) + { + return _buffer[x, y]; + } + + public Color GetPixel(int x, int y) + { + throw new NotImplementedException(); + } + + public void InvertPixel(int x, int y) + { + throw new NotImplementedException(); + } + + public void SetPixel(int x, int y, Color color) + { + _buffer[x, y] = ColorToCharacter(color); + } + + public void WriteBuffer(int originX, int originY, IPixelBuffer buffer) + { + throw new NotImplementedException(); + } + + private char ColorToCharacter(Color color) + { + var index = (int)((color.Color8bppGray / 255d) * (_colors.Length - 1)); + return _colors[index]; + } + } + } +} \ No newline at end of file diff --git a/Source/Meadow.Foundation.Peripherals/Displays.AsciiConsole/Driver/AsciiConsoleDisplay.cs b/Source/Meadow.Foundation.Peripherals/Displays.AsciiConsole/Driver/AsciiConsoleDisplay.cs new file mode 100644 index 0000000000..cccda70867 --- /dev/null +++ b/Source/Meadow.Foundation.Peripherals/Displays.AsciiConsole/Driver/AsciiConsoleDisplay.cs @@ -0,0 +1,90 @@ +using Meadow.Foundation.Graphics; +using Meadow.Foundation.Graphics.Buffers; +using System; + +namespace Meadow.Foundation.Displays; + +public partial class AsciiConsoleDisplay : IGraphicsDisplay +{ + private readonly CharacterBuffer _buffer; + private const string _colors = " `.-':_,^=;><+!rc*/z?sLTv)J7(|Fi{C}fI31tlu[neoZ5Yxjya]2ESwqkP6h9d4VpOGbUAKXHm8RD#$Bg0MNWQ%&@"; // 92 "colors" + + public ColorMode ColorMode => PixelBuffer.ColorMode; + + public ColorMode SupportedColorModes => ColorMode.Format8bppGray; + + public int Width => PixelBuffer.Width; + public int Height => PixelBuffer.Height; + public IPixelBuffer PixelBuffer => _buffer; + + public AsciiConsoleDisplay(int width, int height) + { + Console.Clear(); + Console.SetCursorPosition(0, 0); + + _buffer = new CharacterBuffer(width, height); + PixelBuffer.Clear(); + } + + public void Clear(bool updateDisplay = false) + { + PixelBuffer.Clear(); + } + + public void DrawPixel(int x, int y, Color color) + { + PixelBuffer.SetPixel(x, y, color); + } + + public void DrawPixel(int x, int y, bool enabled) + { + PixelBuffer.SetPixel(x, y, enabled ? Color.White : Color.Black); + } + + public void Fill(Color fillColor, bool updateDisplay = false) + { + PixelBuffer.Fill(fillColor); + if (updateDisplay) + { + Show(); + } + } + + public void Fill(int x, int y, int width, int height, Color fillColor) + { + PixelBuffer.Fill(x, y, width, height, fillColor); + } + + public void InvertPixel(int x, int y) + { + PixelBuffer.InvertPixel(x, y); + } + + public void Show() + { + for (var y = 0; y < Height; y++) + { + for (var x = 0; x < Width; x++) + { + Console.SetCursorPosition(x, y); + Console.Write(_buffer.GetPixelCharacter(x, y)); + } + } + } + + public void Show(int left, int top, int right, int bottom) + { + for (; left < right; left++) + { + for (; top < bottom; top++) + { + Console.SetCursorPosition(left, top); + Console.Write(_buffer.GetPixelCharacter(left, top)); + } + } + } + + public void WriteBuffer(int x, int y, IPixelBuffer displayBuffer) + { + } +} \ No newline at end of file diff --git a/Source/Meadow.Foundation.Peripherals/Displays.AsciiConsole/Driver/Displays.AsciiConsole.csproj b/Source/Meadow.Foundation.Peripherals/Displays.AsciiConsole/Driver/Displays.AsciiConsole.csproj new file mode 100644 index 0000000000..038c0c3897 --- /dev/null +++ b/Source/Meadow.Foundation.Peripherals/Displays.AsciiConsole/Driver/Displays.AsciiConsole.csproj @@ -0,0 +1,27 @@ + + + Readme.md + enable + 10.0 + Apache-2.0 + true + icon.png + Wilderness Labs, Inc + netstandard2.1 + Library + AsciiConsole + Wilderness Labs, Inc + http://developer.wildernesslabs.co/Meadow/Meadow.Foundation/ + Meadow.Foundation.Displays.AsciiConsole + https://github.com/WildernessLabs/Meadow.Foundation + Meadow,Meadow.Foundation,Displays,Ascii,Console + 1.7.0 + true + Ascii console display + + + + + + + diff --git a/Source/Meadow.Foundation.Peripherals/Displays.AsciiConsole/Driver/Readme.md b/Source/Meadow.Foundation.Peripherals/Displays.AsciiConsole/Driver/Readme.md new file mode 100644 index 0000000000..92f22b5641 --- /dev/null +++ b/Source/Meadow.Foundation.Peripherals/Displays.AsciiConsole/Driver/Readme.md @@ -0,0 +1,22 @@ +# Meadow.Foundation.Displays.AsciiConsole + +**Ascii console display** + +The **AsciiConsole** library is designed for the [Wilderness Labs](www.wildernesslabs.co) Meadow .NET IoT platform and is part of [Meadow.Foundation](https://developer.wildernesslabs.co/Meadow/Meadow.Foundation/). + +The **Meadow.Foundation** peripherals library is an open-source repository of drivers and libraries that streamline and simplify adding hardware to your C# .NET Meadow IoT application. + +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/). + +## 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/). diff --git a/Source/Meadow.Foundation.Peripherals/Displays.AsciiConsole/Samples/AsciiConsoleDisplay_Sample/AsciiConsoleDisplay_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Displays.AsciiConsole/Samples/AsciiConsoleDisplay_Sample/AsciiConsoleDisplay_Sample.csproj new file mode 100644 index 0000000000..12ab7b8265 --- /dev/null +++ b/Source/Meadow.Foundation.Peripherals/Displays.AsciiConsole/Samples/AsciiConsoleDisplay_Sample/AsciiConsoleDisplay_Sample.csproj @@ -0,0 +1,16 @@ + + + + Exe + net7.0 + enable + enable + App + + + + + + + + diff --git a/Source/Meadow.Foundation.Peripherals/Displays.AsciiConsole/Samples/AsciiConsoleDisplay_Sample/Program.cs b/Source/Meadow.Foundation.Peripherals/Displays.AsciiConsole/Samples/AsciiConsoleDisplay_Sample/Program.cs new file mode 100644 index 0000000000..b989abfae4 --- /dev/null +++ b/Source/Meadow.Foundation.Peripherals/Displays.AsciiConsole/Samples/AsciiConsoleDisplay_Sample/Program.cs @@ -0,0 +1,103 @@ +using Meadow; +using Meadow.Foundation.Displays; +using Meadow.Foundation.Graphics; +using Meadow.Foundation.Graphics.MicroLayout; + +namespace AsciiConsoleDisplay_Sample; + +internal class Program +{ + private static void Main(string[] args) + { + DrawShapes(); + } + + private static async Task MovingBox() + { + var colors = typeof(Color) + .GetFields(System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public) + .Where(f => f.FieldType == typeof(Color)) + .Select(c => (Color)c.GetValue(null)!) + .ToArray(); + + var colorIndex = 0; + var display = new AsciiConsoleDisplay(20, 15); + var screen = new DisplayScreen(display); + var box = new Box(0, 0, 4, 3) + { + ForeColor = colors[colorIndex] + }; + screen.Controls.Add(box); + + var x = 0; + var y = 0; + var xdir = 1; + var ydir = 1; + + while (true) + { + screen.BeginUpdate(); + box.Top = y; + box.Left = x; + box.ForeColor = colors[colorIndex]; + screen.EndUpdate(); + + await Task.Delay(500); + + if ((x >= display.Width - 4) || (x < 0)) + { + xdir *= -1; + } + if ((y >= display.Height - 4) || (y < 0)) + { + ydir *= -1; + } + x += (1 * xdir); + y += (1 * ydir); + + colorIndex++; + if (colorIndex >= colors.Length) colorIndex = 0; + } + } + + private static void DrawShapes() + { + var display = new AsciiConsoleDisplay(80, 60); + + var graphics = new MicroGraphics(display) + { + IgnoreOutOfBoundsPixels = true, + }; + + graphics.Clear(); + + graphics.DrawTriangle(5, 5, 30, 30, 5, 30, Color.Red, false); + graphics.DrawRectangle(10, 12, 40, 20, Color.Yellow, false); + graphics.DrawCircle(20, 20, 20, Color.White, false); + + graphics.Show(); + } + + private static async Task CycleColors() + { + var display = new AsciiConsoleDisplay(40, 30); + + var colors = typeof(Color).GetFields(System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public).Where(c => c.FieldType == typeof(Color)); + foreach (var color in colors) + { + for (var x = 0; x < 16; x++) + { + for (var y = 0; y < 16; y++) + { + var c = (Color)color.GetValue(null)!; + + display.DrawPixel(x, y, c); + } + } + + display.Show(); + + await Task.Delay(100); + } + } +} 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 e254a60f58..f05ed5dbc8 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.Ch1115/Driver/Displays.Ch1115.csproj +++ b/Source/Meadow.Foundation.Peripherals/Displays.Ch1115/Driver/Displays.Ch1115.csproj @@ -15,13 +15,13 @@ Meadow.Foundation.Displays.Ch1115 https://github.com/WildernessLabs/Meadow.Foundation Meadow, Meadow.Foundation, Displays, LCD, Ch1115 - 0.1.0 + 1.7.0 true Ch1115 SPI monochrome OLED display - + - + 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 15da6d1968..3db6a98ba0 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,8 +9,8 @@ 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 429b3a4a6f..4196dec734 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.Gtk/Driver/Displays.Gtk.csproj +++ b/Source/Meadow.Foundation.Peripherals/Displays.Gtk/Driver/Displays.Gtk.csproj @@ -16,19 +16,19 @@ icon.png https://github.com/WildernessLabs/Meadow.Foundation Meadow.Foundation,Display,GTK - 0.94.0 + 1.7.0 true Gtk display driver for Meadow true - + - + diff --git a/Source/Meadow.Foundation.Peripherals/Displays.Gtk/Driver/Gtk.cs b/Source/Meadow.Foundation.Peripherals/Displays.Gtk/Driver/Gtk.cs index a131a3f222..d39e978a9c 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.Gtk/Driver/Gtk.cs +++ b/Source/Meadow.Foundation.Peripherals/Displays.Gtk/Driver/Gtk.cs @@ -211,7 +211,7 @@ public void Clear(bool updateDisplay = false) /// /// /// - public void Fill(Foundation.Color fillColor, bool updateDisplay = false) + public void Fill(Color fillColor, bool updateDisplay = false) { ShowComplete.WaitOne(); _pixelBuffer.Fill(fillColor); @@ -225,7 +225,7 @@ public void Fill(Foundation.Color fillColor, bool updateDisplay = false) /// /// /// - public void Fill(int x, int y, int width, int height, Foundation.Color fillColor) + public void Fill(int x, int y, int width, int height, Color fillColor) { ShowComplete.WaitOne(); _pixelBuffer.Fill(x, y, width, height, fillColor); @@ -237,7 +237,7 @@ public void Fill(int x, int y, int width, int height, Foundation.Color fillColor /// /// /// - public void DrawPixel(int x, int y, Foundation.Color color) + public void DrawPixel(int x, int y, Color color) { ShowComplete.WaitOne(); _pixelBuffer.SetPixel(x, y, color); @@ -252,7 +252,7 @@ public void DrawPixel(int x, int y, Foundation.Color color) public void DrawPixel(int x, int y, bool colored) { ShowComplete.WaitOne(); - DrawPixel(x, y, colored ? Foundation.Color.White : Foundation.Color.Black); + DrawPixel(x, y, colored ? Color.White : Color.Black); } /// 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 c0001fdcb6..c701fbb622 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 @@ -15,13 +15,13 @@ Meadow.Foundation.Displays.Lcd.CharacterDisplay https://github.com/WildernessLabs/Meadow.Foundation Meadow, Meadow.Foundation, Character Display - 0.8.45 + 1.7.0 true Digital and I2C LCD character displays - + - + 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 8434f97883..4521264427 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,8 +9,8 @@ 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 16d0748117..1fcded523c 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 @@ -15,13 +15,13 @@ Meadow.Foundation.Displays.Led.FourDigitSevenSegment https://github.com/WildernessLabs/Meadow.Foundation Meadow.Foundation, SevenSegment, Display - 0.1.46 + 1.7.0 true Digital Four digit seven segment displays - + - + 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 6b92dbb92f..321989e405 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,8 +9,8 @@ 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 83d792fd2e..574819cfb6 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 @@ -15,13 +15,13 @@ Meadow.Foundation.Displays.Led.FourteenSegment https://github.com/WildernessLabs/Meadow.Foundation Meadow.Foundation,FourteenSegment,Fourteen,14,Segment,Display,LED - 0.1.0 + 1.7.0 true Digital Fourteen (14) segment display - + - + 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 1efbf737ec..4535bdfcec 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,8 +9,8 @@ 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 9ae583e1a3..9eedcd013b 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 @@ -15,13 +15,13 @@ Meadow.Foundation.Displays.Led.SevenSegment https://github.com/WildernessLabs/Meadow.Foundation Meadow.Foundation,SevenSegment,Seven,7,Segment,Display,LED - 0.9.52 + 1.7.0 true Digital Seven (7) segment display - + - + 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 2d9b87f149..21a46cffe2 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,8 +9,8 @@ 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 2844f9954e..2d688e471e 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 @@ -15,13 +15,13 @@ Meadow.Foundation.Displays.Led.SixteenSegment https://github.com/WildernessLabs/Meadow.Foundation Meadow.Foundation,SixteenSegment,Sixteen,14,Segment,Display,LED - 0.1.0 + 1.7.0 true Digital Sixteen (16) segment display - + - + 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 2d8116d504..d9cd44cf0e 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,8 +9,8 @@ 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 cf5cbe4dde..a53307606f 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.Max7219/Driver/Displays.Max7219.csproj +++ b/Source/Meadow.Foundation.Peripherals/Displays.Max7219/Driver/Displays.Max7219.csproj @@ -15,13 +15,13 @@ Meadow.Foundation.Displays.Max7219 https://github.com/WildernessLabs/Meadow.Foundation Meadow, Meadow.Foundation, Displays, LCD, MAX7219 - 0.1.56 + 1.7.0 true MAX7219 SPI LED driver - + - + 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 6a9696ff28..2f6e488ed0 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,8 +9,8 @@ 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 6a9696ff28..2f6e488ed0 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,8 +9,8 @@ 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 6a9696ff28..2f6e488ed0 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,8 +9,8 @@ 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 8b8b8f8d91..b3720d3522 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.Pcd8544/Driver/Displays.Pcd8544.csproj +++ b/Source/Meadow.Foundation.Peripherals/Displays.Pcd8544/Driver/Displays.Pcd8544.csproj @@ -15,13 +15,13 @@ Meadow.Foundation.Displays.Pcd8544 https://github.com/WildernessLabs/Meadow.Foundation Meadow, Meadow.Foundation, Displays, PCD8544, Nokia, 5110 - 0.6.54 + 1.7.0 true PCD8544 SPI monochrome display (Nokia 5110) - + - + 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 05505daa1a..c0ab190530 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,8 +9,8 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Displays.Sh110x/Datasheet/SH1107-SINOWEALTH.pdf b/Source/Meadow.Foundation.Peripherals/Displays.Sh110x/Datasheet/SH1107-SINOWEALTH.pdf new file mode 100644 index 0000000000..89628da0da Binary files /dev/null and b/Source/Meadow.Foundation.Peripherals/Displays.Sh110x/Datasheet/SH1107-SINOWEALTH.pdf differ diff --git a/Source/Meadow.Foundation.Peripherals/Displays.Sh110x/Datasheet/SH1107.pdf b/Source/Meadow.Foundation.Peripherals/Displays.Sh110x/Datasheet/SH1107.pdf deleted file mode 100644 index 9c472f309c..0000000000 Binary files a/Source/Meadow.Foundation.Peripherals/Displays.Sh110x/Datasheet/SH1107.pdf and /dev/null differ 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 9f040d3017..fba4deb76b 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.Sh110x/Driver/Displays.Sh110x.csproj +++ b/Source/Meadow.Foundation.Peripherals/Displays.Sh110x/Driver/Displays.Sh110x.csproj @@ -15,13 +15,13 @@ Meadow.Foundation.Displays.Sh1106 https://github.com/WildernessLabs/Meadow.Foundation Meadow,Meadow.Foundation,Displays,LCD,Sh1106,SH1107,oled,monochrome - 0.1.0 + 1.7.0 true S1106 and SH1107 SPI and I2C monochrome OLED displays - + - + diff --git a/Source/Meadow.Foundation.Peripherals/Displays.Sh110x/Driver/Drivers/Sh1106.cs b/Source/Meadow.Foundation.Peripherals/Displays.Sh110x/Driver/Drivers/Sh1106.cs index 0a4d33f390..fa3618fc2b 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.Sh110x/Driver/Drivers/Sh1106.cs +++ b/Source/Meadow.Foundation.Peripherals/Displays.Sh110x/Driver/Drivers/Sh1106.cs @@ -4,7 +4,7 @@ namespace Meadow.Foundation.Displays { /// - /// Represents the Sh1106 family of displays + /// Represents the Sh1106 family of displays (up to 132 x 64) /// public class Sh1106 : Sh110x { @@ -15,8 +15,9 @@ public class Sh1106 : Sh110x /// I2C address /// Display width in pixels /// Display height in pixels - public Sh1106(II2cBus i2cBus, byte address, int width, int height) - : base(i2cBus, address, width, height) + /// The first visible column on the display (if display is cropped) + public Sh1106(II2cBus i2cBus, byte address, int width = 128, int height = 64, int firstColumn = 0) + : base(i2cBus, address, width, height, firstColumn) { } /// @@ -28,8 +29,10 @@ public Sh1106(II2cBus i2cBus, byte address, int width, int height) /// Reset pin /// Display width in pixels /// Display height in pixels - public Sh1106(ISpiBus spiBus, IPin chipSelectPin, IPin dcPin, IPin resetPin, int width = 128, int height = 64) - : base(spiBus, chipSelectPin, dcPin, resetPin, width, height) + /// The first visible column on the display (if display is cropped) + public Sh1106(ISpiBus spiBus, IPin chipSelectPin, IPin dcPin, IPin resetPin, + int width = 128, int height = 64, int firstColumn = 0) + : base(spiBus, chipSelectPin, dcPin, resetPin, width, height, firstColumn) { } /// @@ -41,12 +44,10 @@ public Sh1106(ISpiBus spiBus, IPin chipSelectPin, IPin dcPin, IPin resetPin, int /// Reset output port /// Display width in pixels /// Display height in pixels - public Sh1106(ISpiBus spiBus, - IDigitalOutputPort chipSelectPort, - IDigitalOutputPort dataCommandPort, - IDigitalOutputPort resetPort, - int width = 128, int height = 64) - : base(spiBus, chipSelectPort, dataCommandPort, resetPort, width, height) + /// The first visible column on the display (if display is cropped) + public Sh1106(ISpiBus spiBus, IDigitalOutputPort chipSelectPort, IDigitalOutputPort dataCommandPort, IDigitalOutputPort resetPort, + int width = 128, int height = 64, int firstColumn = 0) + : base(spiBus, chipSelectPort, dataCommandPort, resetPort, width, height, firstColumn) { } /// @@ -60,25 +61,25 @@ protected override void Initialize() SendCommand(DisplayCommand.SetDisplayClockDiv); SendCommand(0x80); - SendCommand(DisplayCommand.MultiplexModeSet); - SendCommand(DisplayCommand.MultiplexDataSet); + SendCommand(DisplayCommand.SetMultiplexRatio); + SendCommand(0x3F); SendCommand(DisplayCommand.SetDisplayOffset); - SendCommand((byte)0); + SendCommand((byte)0x00); SendCommand(DisplayCommand.DisplayStartLine); - SendCommand(DisplayCommand.SegInvNormal); - SendCommand(0xC0); + SendCommand(DisplayCommand.SetSegmentNormal); + SendCommand(DisplayCommand.ScanDirectionStandard); SendCommand(DisplayCommand.SetComPins); - SendCommand(0x12); + SendCommand(DisplayCommand.ComPinsAlternative); SendCommand(DisplayCommand.SetContrast); SendCommand(0x0F); - SendCommand(0x30); - SendCommand(DisplayCommand.DisplayOnResume); + SendCommand((byte)DisplayCommand.PumpVoltage + 0x02); + SendCommand(DisplayCommand.DisplayResume); SendCommand(DisplayCommand.SetDisplayClockDiv); SendCommand(0xF0); @@ -88,5 +89,14 @@ protected override void Initialize() Thread.Sleep(100); SendCommand(DisplayCommand.DisplayOn); } + + /// + public override void SetDisplayOffsets(byte startLine = 0, byte offset = 0) + { + SendCommand(DisplayCommand.DisplayStartLine + startLine); + SendCommand(DisplayCommand.SetDisplayOffset); + SendCommand(offset); + } + } } \ No newline at end of file diff --git a/Source/Meadow.Foundation.Peripherals/Displays.Sh110x/Driver/Drivers/Sh1107.cs b/Source/Meadow.Foundation.Peripherals/Displays.Sh110x/Driver/Drivers/Sh1107.cs index f81537e592..d8e3dc8863 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.Sh110x/Driver/Drivers/Sh1107.cs +++ b/Source/Meadow.Foundation.Peripherals/Displays.Sh110x/Driver/Drivers/Sh1107.cs @@ -4,7 +4,7 @@ namespace Meadow.Foundation.Displays { /// - /// Represents the Sh1107 family of displays + /// Represents the Sh1107 family of displays (up to 128x128) /// public class Sh1107 : Sh110x { @@ -15,8 +15,9 @@ public class Sh1107 : Sh110x /// I2C address /// Display width in pixels /// Display height in pixels - public Sh1107(II2cBus i2cBus, byte address, int width = 128, int height = 128) - : base(i2cBus, address, width, height) + /// The first visible column on the display (if display is cropped) + public Sh1107(II2cBus i2cBus, byte address, int width = 128, int height = 128, int firstColumn = 0) + : base(i2cBus, address, width, height, firstColumn) { } /// @@ -28,8 +29,10 @@ public Sh1107(II2cBus i2cBus, byte address, int width = 128, int height = 128) /// Reset pin /// Display width in pixels /// Display height in pixels - public Sh1107(ISpiBus spiBus, IPin chipSelectPin, IPin dcPin, IPin resetPin, int width = 128, int height = 128) - : base(spiBus, chipSelectPin, dcPin, resetPin, width, height) + /// The first visible column on the display (if display is cropped) + public Sh1107(ISpiBus spiBus, IPin chipSelectPin, IPin dcPin, IPin resetPin, + int width = 128, int height = 128, int firstColumn = 0) + : base(spiBus, chipSelectPin, dcPin, resetPin, width, height, firstColumn) { } /// @@ -41,12 +44,10 @@ public Sh1107(ISpiBus spiBus, IPin chipSelectPin, IPin dcPin, IPin resetPin, int /// Reset output port /// Display width in pixels /// Display height in pixels - public Sh1107(ISpiBus spiBus, - IDigitalOutputPort chipSelectPort, - IDigitalOutputPort dataCommandPort, - IDigitalOutputPort resetPort, - int width = 128, int height = 128) - : base(spiBus, chipSelectPort, dataCommandPort, resetPort, width, height) + /// The first visible column on the display (if display is cropped) + public Sh1107(ISpiBus spiBus, IDigitalOutputPort chipSelectPort, IDigitalOutputPort dataCommandPort, IDigitalOutputPort resetPort, + int width = 128, int height = 128, int firstColumn = 0) + : base(spiBus, chipSelectPort, dataCommandPort, resetPort, width, height, firstColumn) { } /// @@ -55,51 +56,50 @@ public Sh1107(ISpiBus spiBus, protected override void Initialize() { SendCommand(DisplayCommand.DisplayOff); - SendCommand(DisplayCommand.SetDisplayClockDiv); - SendCommand(0x51); + + SendCommand(DisplayCommand.ColumnAddressLow); + SendCommand(DisplayCommand.ColumnAddressHigh); + SendCommand(DisplayCommand.PageAddress); + + SendCommand(DisplayCommand.SetDisplayStartLine); + SendCommand((byte)0x00); + SendCommand(DisplayCommand.SetDisplayOffset); + SendCommand((byte)0x00); SendCommand(DisplayCommand.SetContrast); SendCommand(0x4F); - SendCommand(DisplayCommand.DCDC); - SendCommand(0x8A); - - SendCommand(DisplayCommand.SetSegmentRemap); - SendCommand(DisplayCommand.ComScanInc); + SendCommand(DisplayCommand.PageAddressMode); + SendCommand(DisplayCommand.SetSegmentNormal); + SendCommand(DisplayCommand.ScanDirectionStandard); - SendCommand(DisplayCommand.DisplayStartLine); - SendCommand((byte)0); + SendCommand(DisplayCommand.SetMultiplexRatio); + SendCommand(0x7F); - SendCommand(DisplayCommand.SegInvNormal); - SendCommand(0xC0); - - SendCommand(DisplayCommand.SetPrecharge); + SendCommand(DisplayCommand.SetDisplayClockDiv); + SendCommand(0x51); + SendCommand(DisplayCommand.SetChargePeriods); SendCommand(0x22); - - SendCommand(DisplayCommand.SetVComDetect); + SendCommand(DisplayCommand.SetVComDeselect); SendCommand(0x35); - SendCommand(DisplayCommand.DisplayOnResume); + SendCommand(DisplayCommand.SetDCDCStatus); + SendCommand(DisplayCommand.DCDCOff); + SendCommand(DisplayCommand.DisplayResume); SendCommand(DisplayCommand.DisplayVideoNormal); - - if (Width == 128 && Height == 128) - { - SendCommand(DisplayCommand.SetDisplayOffset); - SendCommand((byte)0x00); - SendCommand(DisplayCommand.MultiplexModeSet); - SendCommand(0x07F); - } - else - { - SendCommand(DisplayCommand.SetDisplayOffset); - SendCommand(0x60); - SendCommand(DisplayCommand.MultiplexModeSet); - SendCommand(DisplayCommand.MultiplexDataSet); - } - Thread.Sleep(100); SendCommand(DisplayCommand.DisplayOn); } + + /// + public override void SetDisplayOffsets(byte startLine = 0, byte offset = 0) + { + SendCommand(DisplayCommand.SetDisplayStartLine); + SendCommand(startLine); + SendCommand(DisplayCommand.SetDisplayOffset); + SendCommand(offset); + } + } -} \ No newline at end of file +} diff --git a/Source/Meadow.Foundation.Peripherals/Displays.Sh110x/Driver/Sh110x.Enums.cs b/Source/Meadow.Foundation.Peripherals/Displays.Sh110x/Driver/Sh110x.Enums.cs index 343c145196..20811daa8c 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.Sh110x/Driver/Sh110x.Enums.cs +++ b/Source/Meadow.Foundation.Peripherals/Displays.Sh110x/Driver/Sh110x.Enums.cs @@ -1,4 +1,6 @@ -namespace Meadow.Foundation.Displays +using System; + +namespace Meadow.Foundation.Displays { public partial class Sh110x { @@ -25,42 +27,208 @@ public enum ScrollDirection LeftAndVertical } + [Flags] internal enum DisplayCommand : byte { - DCDC = 0xAD, + /// + /// (SH1106 and SH1107) + /// Turns the Display off (Power Save Mode) + /// DisplayOff = 0xAE, + /// + /// (SH1106 and SH1107) + /// Turns the Display On + /// DisplayOn = 0xAF, - DisplayOnResume = 0xA4, - DisplayStartLine = 0x40, - SetPageAddress = 0xB0, - ColumnAddressHigh = 0x10, - ColumnAddressLow = 0x02, - + /// + /// (SH1106 and SH1107) + /// Restores normal operation after has turned all pixels on. + /// + DisplayResume = 0xA4, + /// + /// (SH1106 and SH1107) + /// Turns on all pixels on the display. Ignores . Restore normal operation wth + /// + DisplayAllPixelsOn = 0xA5, + /// + /// (SH1106 and SH1107) + /// Sets the display to "Normal" mode. A logical 1 in memory will turn on the OLED pixel. + /// DisplayVideoNormal = 0xA6, + /// + /// (SH1106 and SH1107) + /// Sets the display to "Reverse" mode. A logical 1 in memory will turn off the OLED pixel. + /// DisplayVideoReverse = 0xA7, - AllPixelsOn = 0xA5, + /// + /// (SH1106) + /// Modify this command by adding a value from 0x0 to 0x7 to select the page address to use. + /// (SH1107) + /// Modify this command by adding a value from 0x0 to 0xF to select the page address to use. + /// + PageAddress = 0xB0, + /// + /// (SH1106 only. For SH1107, see ) + /// Modify this command by adding a value from 0x00 to 0x3F to set the address of the initial display line. + /// The RAM display data at this line becomes the top line of OLED screen. + /// Changing the Start Line while displaying effectively scrolls the display or acts as a page change.. + /// + DisplayStartLine = 0x40, + /// + /// (SH1107 only. For SH1106, see ) + /// The next byte sent sets the address of the initial display line. + /// The RAM display data at this line becomes the top line of OLED screen. + /// Changing the line address while displaying effectively scrolls the display or acts as a page change. + /// Default value after reset is 0x00. + /// + SetDisplayStartLine = 0xDC, + /// + /// (SH1106 and SH1107) + /// Modify this command by adding a value from 0x0 to 0xF to set the lower 4 bits of the column address. + /// + ColumnAddressLow = 0x00, + /// + /// (SH1106) + /// Modify this command by adding a value from 0x0 to 0x8 to set the upper 4 bits of the column address. + /// (SH1107) + /// Modify this command by adding a value from 0x0 to 0x7 to set the upper 3 bits of the column address. + /// + ColumnAddressHigh = 0x10, + /// + /// (SH1107 only) + /// Sets the display memory to auto-increment to the next column of the current page after each byte of display data, wrapping around after 127. + /// If is applied, the direction of the auto-increment is reversed. + /// + PageAddressMode = 0x20, + /// + /// (SH1107 only) + /// Sets the display memory to auto-increment to the next page of the current column after each byte of display data, wrapping around after 127. + /// If is applied, the direction of the auto-increment is reversed. + /// + VerticalAddressMode = 0x21, + /// + /// (SH1106 and SH1107) + /// Sets the "Common" Scan direction to the default direction. + /// Opposite of + /// + ScanDirectionStandard = 0xC0, + /// + /// (SH1106 and SH1107) + /// Sets the "Common" Scan direction to the inverted direction, effectively flipping the display horizontally (column order). + /// Opposite of + /// + ScanDirectionInverted = 0xC8, + /// + /// (SH1106 and SH1107) + /// Sets the display to the default auto-increment direction and order of display data bits. + /// Opposite of + /// + SetSegmentNormal = 0xA0, + /// + /// (SH1106 and SH1107) + /// Sets the display to automatically reverse the auto-increment direction and order of display data bits, effectively flipping the display vertically (page order). + /// Opposite of + /// + SetSegmentInverted = 0xA1, + /// + /// (SH1106 and SH1107) + /// The next byte sent sets the contrast setting of the display. The chip has 256 contrast steps from 0x00 to 0xFF. + /// Default value after reset is 0x80. + /// SetContrast = 0x81, - SetDisplayClockDiv = 0xD5, + /// + /// (SH1106) + /// The next byte sent sets the column mapping of the first display line from 0x00 to 0x3F. + /// Default value after reset is 0x00. + /// (SH1107) + /// The next byte sent sets the column mapping of the first display line from 0x00 to 0x7F. + /// Default value after reset is 0x00. + /// SetDisplayOffset = 0xD3, - OutputFollowsRam = 0xA4, - MemoryMode = 0x20, - ColumnAddress = 0x21, - PageAddress = 0x22, - - MultiplexModeSet = 0xA8, - MultiplexDataSet = 0x3F, - - SetChargePump = 0x8D, - SetPrecharge = 0xD9, + /// + /// (SH1106 and SH1107) + /// A NOP (No Operation) + /// + NOP = 0xE3, + /// + /// (SH1106 and SH1107) + /// The next byte sent sets the frequency of the internal display clocks (DCLKs). + /// The lower 4 bits define as the divide ratio (Value from 1 to 16, represented using 0x_0 to 0x_F) used to divide the oscillator frequency. + /// The upper 4 bits adjust the base oscillator frequency by -25% (0x0_) to +50% (0xF_) in 5% steps. (0x5_ is 0%) + /// Default value after reset is 0x50 + /// + SetDisplayClockDiv = 0xD5, + /// + /// (SH1106 and SH1107) + /// The next byte sent sets the Pre-charge and Discharge period for the display in clocks. + /// The lower 4 bits are used for pre-charge. (Default 0x_2) + /// The upper 4 bits are used for discharge. (Default 0x2_) + /// Default value after reset is 0x22. + /// + SetChargePeriods = 0xD9, + /// + /// (SH1106 and SH1107) + /// This command is to control the DC-DC voltage converter status (and the switching frequency). + /// Issuing this command, followed by , followed by will turn on the converter. + /// The panel display must be off while issuing this command. + /// + SetDCDCStatus = 0xAD, + /// + /// (SH1107 only) + /// Value for command. (Also sets Charge pump switching frequency using bits 1-3) + /// + DCDCOffFrequencyAdjust = 0x80, + /// + /// (SH1107 only) + /// Value for command. (Also sets Charge pump switching frequency using bits 1-3) + /// + DCDCOnFrequencyAdjust = 0x81, + /// + /// (SH1106 and SH1107) + /// Value for command. + /// + DCDCOff = 0x8A, + /// + /// (SH1106 and SH1107) + /// Value for command. + /// + DCDCOn = 0x8B, + /// + /// (SH1106 only) + /// Modify this command by adding a value from 0x0 to 0x3 to set the charge pump voltage. + /// Default is 0x32. + /// + PumpVoltage = 0x30, + /// + /// (SH1106) + /// The next byte sent sets the multiplex ratio from 1 to 64 (Represented as 0x00 to 0x3F). + /// Default value after reset is 0x3F. + /// (SH1107) + /// The next byte sent sets the multiplex ratio from 1 to 128 (Represented as 0x00 to 0x7F). + /// Default value after reset is 0x7F. + /// + SetMultiplexRatio = 0xA8, + /// + /// (SH1106 and SH1107) + /// The next byte sent sets the output voltage for the currently de-selected Common pins. (See datasheet) + /// Default value after reset is 0x35. + /// + SetVComDeselect = 0xDB, + /// + /// (SH1106 only) + /// The next byte sets the common signals pad configuration (sequential or alternative) to match the OLED panel hardware layout. + /// Valid Values are (0x02) and (0x12). + /// Default value after reset is (0x12). + /// SetComPins = 0xDA, - SetVComDetect = 0xDB, - ComScanInc = 0xC0, - ComScanDec = 0xC8, - - SegInvOn = 0xA1, - SegInvNormal = 0xA0, - - SetSegmentRemap = 0xA1, + /// + /// (SH1106 only) Value for + /// + ComPinsSequential = 0x02, + /// + /// (SH1106 only) Value for + /// + ComPinsAlternative = 0x12, } /// diff --git a/Source/Meadow.Foundation.Peripherals/Displays.Sh110x/Driver/Sh110x.cs b/Source/Meadow.Foundation.Peripherals/Displays.Sh110x/Driver/Sh110x.cs index 45f8df6a68..cafd3e46d6 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.Sh110x/Driver/Sh110x.cs +++ b/Source/Meadow.Foundation.Peripherals/Displays.Sh110x/Driver/Sh110x.cs @@ -25,17 +25,17 @@ public abstract partial class Sh110x : IGraphicsDisplay, ISpiPeripheral, II2cPer /// /// The display width in pixels /// - public int Width { get; protected set; } = 128; + public int Width { get; protected set; } /// /// The display height in pixels /// - public int Height { get; protected set; } = 64; + public int Height { get; protected set; } /// /// The default SPI bus speed for the device /// - public Frequency DefaultSpiBusSpeed => new(4000, Frequency.UnitType.Kilohertz); + public Frequency DefaultSpiBusSpeed => new Frequency(4, Frequency.UnitType.Megahertz); /// /// The SPI bus speed for the device @@ -83,8 +83,8 @@ public SpiClockConfiguration.Mode SpiBusMode /// /// Did we create the port(s) used by the peripheral /// - readonly bool createdPorts = false; - + private readonly bool createdPorts = false; + /// /// I2C Communication bus used to communicate with the peripheral /// @@ -95,18 +95,21 @@ public SpiClockConfiguration.Mode SpiBusMode /// protected ISpiCommunications? spiComms; - readonly IDigitalOutputPort? dataCommandPort; - readonly IDigitalOutputPort? resetPort; - readonly IDigitalOutputPort? chipSelectPort; + private readonly IDigitalOutputPort? chipSelectPort; + private readonly IDigitalOutputPort? dataCommandPort; + private readonly IDigitalOutputPort? resetPort; - const int StartColumnOffset = 0; - readonly int PAGE_SIZE; + private readonly int pageWidth; + private readonly int totalPages; + private readonly byte startColumnOffset; + private byte startColumnOffsetLow => (byte)(startColumnOffset & 0x0F); + private byte startColumnOffsetHigh => (byte)((startColumnOffset & 0xF0) >> 4); - const bool Data = true; - const bool Command = false; + private const bool Data = true; + private const bool Command = false; - readonly Buffer1bpp imageBuffer; - readonly byte[] pageBuffer; + private readonly Buffer1bpp imageBuffer; + private readonly byte[] pageBuffer; /// /// Display command buffer @@ -120,19 +123,22 @@ public SpiClockConfiguration.Mode SpiBusMode /// I2C address /// Display width in pixels /// Display height in pixels - public Sh110x(II2cBus i2cBus, byte address, int width, int height) + /// The first visible column on the display (if display is cropped) + public Sh110x(II2cBus i2cBus, byte address, int width, int height, int firstColumn = 0) { + connectionType = ConnectionType.I2C; i2cComms = new I2cCommunications(i2cBus, address); Width = width; Height = height; - connectionType = ConnectionType.I2C; commandBuffer = new byte[2]; imageBuffer = new Buffer1bpp(Width, Height); - PAGE_SIZE = Width; - pageBuffer = new byte[PAGE_SIZE + 1]; + startColumnOffset = (byte)firstColumn; + pageWidth = Width; + totalPages = height >> 3; + pageBuffer = new byte[pageWidth + 1]; Initialize(); } @@ -146,9 +152,10 @@ public Sh110x(II2cBus i2cBus, byte address, int width, int height) /// Reset pin /// Display width in pixels /// Display height in pixels - public Sh110x(ISpiBus spiBus, IPin? chipSelectPin, IPin dcPin, IPin resetPin, int width, int height) : - this(spiBus, chipSelectPin?.CreateDigitalOutputPort() ?? null, dcPin.CreateDigitalOutputPort(), - resetPin.CreateDigitalOutputPort(), width, height) + /// The first visible column on the display (if display is cropped) + public Sh110x(ISpiBus spiBus, IPin? chipSelectPin, IPin dcPin, IPin resetPin, int width, int height, int firstColumn = 0) : + this(spiBus, chipSelectPin?.CreateDigitalOutputPort(), dcPin.CreateDigitalOutputPort(), + resetPin.CreateDigitalOutputPort(), width, height, firstColumn) { createdPorts = true; } @@ -162,37 +169,46 @@ public Sh110x(ISpiBus spiBus, IPin? chipSelectPin, IPin dcPin, IPin resetPin, in /// Reset output port /// Display width in pixels /// Display height in pixels - public Sh110x(ISpiBus spiBus, - IDigitalOutputPort? chipSelectPort, - IDigitalOutputPort dataCommandPort, - IDigitalOutputPort resetPort, - int width, int height) + /// The first visible column on the display (if display is cropped) + public Sh110x(ISpiBus spiBus, IDigitalOutputPort? chipSelectPort, IDigitalOutputPort dataCommandPort, IDigitalOutputPort resetPort, + int width, int height, int firstColumn = 0) { connectionType = ConnectionType.SPI; + this.chipSelectPort = chipSelectPort; this.dataCommandPort = dataCommandPort; this.resetPort = resetPort; - spiComms = new SpiCommunications(spiBus, this.chipSelectPort = chipSelectPort, DefaultSpiBusSpeed, DefaultSpiBusMode); + spiComms = new SpiCommunications(spiBus, chipSelectPort, DefaultSpiBusSpeed, DefaultSpiBusMode); Width = width; Height = height; imageBuffer = new Buffer1bpp(Width, Height); - pageBuffer = new byte[Width]; + startColumnOffset = (byte)firstColumn; + pageWidth = Width; + pageBuffer = new byte[pageWidth]; Initialize(); } /// - /// This varies between manufactures - /// If the display is misaligned, try 0 and 0x40 + /// This varies between manufacturers + /// If the display is misaligned horizontally, try offset values like 0x00, 0x20, 0x40, etc. + /// If the display is misaligned vertically, try offset values like 0x00, 0x20, 0x40, etc. /// - /// - public void SetDisplayOffset(byte offset) + /// Line number in display RAM to display at the top of the screen + /// Column number in display RAM to offset the screen + public abstract void SetDisplayOffsets(byte startLine = 0x00, byte offset = 0x00); + + /// + /// This varies between manufacturers + /// If the display is misaligned horizontally, try offset values like 0x00, 0x20, 0x40, etc. + /// + /// Column number in display RAM to offset the screen + public void SetDisplayOffset(byte offset = 0x00) { - SendCommand(DisplayCommand.SetDisplayOffset); - SendCommand(offset); + SendCommands(new [] {(byte)DisplayCommand.SetDisplayOffset, offset}); } /// @@ -200,14 +216,7 @@ public void SetDisplayOffset(byte offset) /// public void InvertDisplay(bool invert) { - if (invert) - { - SendCommand(DisplayCommand.DisplayVideoReverse); - } - else - { - SendCommand(DisplayCommand.DisplayVideoNormal); - } + SendCommand(invert ? DisplayCommand.DisplayVideoReverse : DisplayCommand.DisplayVideoNormal); } /// @@ -216,7 +225,7 @@ public void InvertDisplay(bool invert) public void PowerSaveMode() { SendCommand(DisplayCommand.DisplayOff); - SendCommand(DisplayCommand.AllPixelsOn); + SendCommand(DisplayCommand.DisplayAllPixelsOn); } /// @@ -243,7 +252,7 @@ protected void Reset() /// /// Set the display contrast /// - /// The contrast value (0-63) + /// The contrast value (0-255) public void SetContrast(byte contrast) { SendCommand(DisplayCommand.SetContrast); @@ -278,10 +287,17 @@ internal void SendCommand(DisplayCommand command) SendCommand((byte)command); } + internal void SendCommands(DisplayCommand[] commands) + { + var bytes = new byte[commands.Length]; + commands.CopyTo(bytes, 0); + SendCommands(bytes); + } + /// /// Send a sequence of commands to the display /// - /// List of commands to send + /// List of bytes to send internal void SendCommands(byte[] commands) { if (connectionType == ConnectionType.SPI) @@ -303,68 +319,67 @@ internal void SendCommands(byte[] commands) /// public void Show() { - if (connectionType == ConnectionType.SPI) + for (byte page = 0; page < totalPages; page++) { - int count = (Height + 7) / 8;//+7 to round up - for (int page = 0; page < count; page++) - { - { - SendCommand(DisplayCommand.ColumnAddressLow); - SendCommand(DisplayCommand.ColumnAddressHigh); - SendCommand((byte)((byte)DisplayCommand.SetPageAddress | page)); + SendCommand((byte)((byte)DisplayCommand.PageAddress + page)); + SendCommand((byte)((byte)DisplayCommand.ColumnAddressLow + startColumnOffsetLow)); + SendCommand((byte)((byte)DisplayCommand.ColumnAddressHigh + startColumnOffsetHigh)); - dataCommandPort!.State = Data; + if (connectionType == ConnectionType.SPI) + { + dataCommandPort!.State = Data; - Array.Copy(imageBuffer.Buffer, Width * page, pageBuffer, 0, PAGE_SIZE); - spiComms?.Write(pageBuffer); - } + Array.Copy(imageBuffer.Buffer, Width * page, pageBuffer, 0, pageWidth); + spiComms?.Write(pageBuffer); } - } - else //I2C - { - pageBuffer[0] = 0x40; - int count = (Height + 7) / 8;//+7 to round up - for (int page = 0; page < count; page++) + else // I2C { - SendCommand((byte)0); - SendCommand((byte)((byte)DisplayCommand.SetPageAddress | page)); - SendCommand(0x10 >> 4); - SendCommand((byte)(0x10 & 0xF)); + pageBuffer[0] = 0x40; - Array.Copy(imageBuffer.Buffer, Width * page, pageBuffer, 1, PAGE_SIZE); + Array.Copy(imageBuffer.Buffer, Width * page, pageBuffer, 1, pageWidth); i2cComms?.Write(pageBuffer); } } } /// - /// Update a region of the display from the offscreen buffer + /// Update a region of the display from the offscreen buffer. /// - /// Left bounds in pixels + /// Left bounds in pixels (Currently ignored) /// Top bounds in pixels - /// Right bounds in pixels + /// Right bounds in pixels (Currently ignored) /// Bottom bounds in pixels + /// This method currently increases the update area to cover the full area of all affected Width * 8 'pages' public void Show(int left, int top, int right, int bottom) { const int pageHeight = 8; - //must update in pages (area of 128x8 pixels) - //so iterate over all 8 pages and check if they're in range - for (int page = 0; page < 8; page++) + // currently only updates in pages (area of Width x 8 pixels) + // iterate over all pages and check if they're in range + for (byte page = 0; page < totalPages; page++) { if (top > pageHeight * page || bottom < (page + 1) * pageHeight) { continue; } - SendCommand((byte)((int)DisplayCommand.SetPageAddress | page)); - SendCommand((DisplayCommand.ColumnAddressLow) | (StartColumnOffset & 0x0F)); - SendCommand((int)DisplayCommand.ColumnAddressHigh | 0); + SendCommand((byte)(DisplayCommand.PageAddress + page)); + SendCommand((byte)((byte)DisplayCommand.ColumnAddressLow + startColumnOffsetLow)); + SendCommand((byte)((byte)DisplayCommand.ColumnAddressHigh + startColumnOffsetHigh)); + if (connectionType == ConnectionType.SPI) + { + dataCommandPort!.State = Data; - dataCommandPort!.State = Data; + Array.Copy(imageBuffer.Buffer, Width * page, pageBuffer, 0, pageWidth); + spiComms?.Write(pageBuffer); + } + else // I2C + { + pageBuffer[0] = 0x40; - Array.Copy(imageBuffer.Buffer, Width * page, pageBuffer, 0, PAGE_SIZE); - spiComms?.Write(pageBuffer); + Array.Copy(imageBuffer.Buffer, Width * page, pageBuffer, 1, pageWidth); + i2cComms?.Write(pageBuffer); + } } } @@ -508,7 +523,8 @@ public void WriteBuffer(int x, int y, IPixelBuffer displayBuffer) { imageBuffer.WriteBuffer(x, y, displayBuffer); } - + + #region IDisposible /// public void Dispose() { @@ -534,5 +550,6 @@ protected virtual void Dispose(bool disposing) IsDisposed = true; } } + #endregion } } \ No newline at end of file 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 858cf68f39..c710cd6dc7 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,8 +9,8 @@ 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 858cf68f39..c710cd6dc7 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,8 +9,8 @@ App - - + + 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 ebd4f2b5fa..eb3424fe28 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.Ssd130x/Driver/Displays.Ssd130x.csproj +++ b/Source/Meadow.Foundation.Peripherals/Displays.Ssd130x/Driver/Displays.Ssd130x.csproj @@ -15,13 +15,13 @@ Meadow.Foundation.Displays.Ssd130x https://github.com/WildernessLabs/Meadow.Foundation Meadow, Meadow.Foundation, Display, Graphics, OLED, SSD1306, SSD1309 - 0.12.53 + 1.7.0 true SSD1306 / SSD1309 SPI and I2C OLED monochrome displays - + - + diff --git a/Source/Meadow.Foundation.Peripherals/Displays.Ssd130x/Driver/Ssd130xBase.cs b/Source/Meadow.Foundation.Peripherals/Displays.Ssd130x/Driver/Ssd130xBase.cs index 0854ed3932..16665e98c8 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.Ssd130x/Driver/Ssd130xBase.cs +++ b/Source/Meadow.Foundation.Peripherals/Displays.Ssd130x/Driver/Ssd130xBase.cs @@ -127,7 +127,7 @@ public SpiClockConfiguration.Mode SpiBusMode /// /// Buffer holding the pixels in the display /// - protected Buffer1bpp imageBuffer; + protected Buffer1bpp imageBuffer = default!; /// /// Read buffer 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 05bb926b46..c3f830cc69 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,8 +9,8 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Displays.Ssd130x/Samples/Ssd1306_Sample/MeadowApp.cs b/Source/Meadow.Foundation.Peripherals/Displays.Ssd130x/Samples/Ssd1306_Sample/MeadowApp.cs index 6f4cb18ad5..d0241f55c5 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.Ssd130x/Samples/Ssd1306_Sample/MeadowApp.cs +++ b/Source/Meadow.Foundation.Peripherals/Displays.Ssd130x/Samples/Ssd1306_Sample/MeadowApp.cs @@ -54,7 +54,7 @@ public override Task Run() { graphics.Clear(); graphics.CurrentFont = new Font8x12(); - graphics.DrawText(0, 0, "Meadow F7", Meadow.Foundation.Color.White); + graphics.DrawText(0, 0, "Meadow F7", Color.White); graphics.DrawRectangle(5, 14, 30, 10, true); graphics.Show(); 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 05bb926b46..c3f830cc69 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,8 +9,8 @@ App - - + + 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 05bb926b46..c3f830cc69 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,8 +9,8 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Displays.Ssd130x/Samples/Ssd1309_Sample/MeadowApp.cs b/Source/Meadow.Foundation.Peripherals/Displays.Ssd130x/Samples/Ssd1309_Sample/MeadowApp.cs index 35c972f584..ebd86d1c90 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.Ssd130x/Samples/Ssd1309_Sample/MeadowApp.cs +++ b/Source/Meadow.Foundation.Peripherals/Displays.Ssd130x/Samples/Ssd1309_Sample/MeadowApp.cs @@ -58,7 +58,7 @@ public override Task Run() { graphics.Clear(); graphics.CurrentFont = new Font8x12(); - graphics.DrawText(0, 0, "Meadow F7", Meadow.Foundation.Color.White); + graphics.DrawText(0, 0, "Meadow F7", Color.White); graphics.DrawRectangle(5, 14, 30, 10, true); Resolver.Log.Info("Show..."); 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 05bb926b46..c3f830cc69 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,8 +9,8 @@ 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 e85a1f5383..bb465d2fb3 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.Ssd1327/Driver/Displays.Ssd1327.csproj +++ b/Source/Meadow.Foundation.Peripherals/Displays.Ssd1327/Driver/Displays.Ssd1327.csproj @@ -15,13 +15,13 @@ Meadow.Foundation.Displays.Ssd1327 https://github.com/WildernessLabs/Meadow.Foundation Meadow, Meadow.Foundation, Displays, OLED - 0.1.38 + 1.7.0 true SSD1327 SPI OLED 4bpp greyscale display - + - + diff --git a/Source/Meadow.Foundation.Peripherals/Displays.Ssd1327/Driver/Ssd1327.cs b/Source/Meadow.Foundation.Peripherals/Displays.Ssd1327/Driver/Ssd1327.cs index f413d0d1cd..1f8375a0ec 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.Ssd1327/Driver/Ssd1327.cs +++ b/Source/Meadow.Foundation.Peripherals/Displays.Ssd1327/Driver/Ssd1327.cs @@ -119,7 +119,7 @@ public Ssd1327(ISpiBus spiBus, this.dataCommandPort = dataCommandPort; this.resetPort = resetPort; - spiComms = new SpiCommunications(spiBus, chipSelectPort, DefaultSpiBusSpeed, DefaultSpiBusMode); + spiComms = new SpiCommunications(spiBus, this.chipSelectPort = chipSelectPort, DefaultSpiBusSpeed, DefaultSpiBusMode); Initialize(); } diff --git a/Source/Meadow.Foundation.Peripherals/Displays.Ssd1327/Samples/Ssd1327_Sample/MeadowApp.cs b/Source/Meadow.Foundation.Peripherals/Displays.Ssd1327/Samples/Ssd1327_Sample/MeadowApp.cs index c1f3da56ad..16d5f8d4f3 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.Ssd1327/Samples/Ssd1327_Sample/MeadowApp.cs +++ b/Source/Meadow.Foundation.Peripherals/Displays.Ssd1327/Samples/Ssd1327_Sample/MeadowApp.cs @@ -1,6 +1,5 @@ using Meadow; using Meadow.Devices; -using Meadow.Foundation; using Meadow.Foundation.Displays; using Meadow.Foundation.Graphics; using System; @@ -110,11 +109,11 @@ void ColorFontTest() graphics.Clear(); - graphics.DrawTriangle(120, 20, 200, 100, 120, 100, Meadow.Foundation.Color.Red, false); + graphics.DrawTriangle(120, 20, 200, 100, 120, 100, Color.Red, false); - graphics.DrawRectangle(140, 30, 40, 90, Meadow.Foundation.Color.Yellow, false); + graphics.DrawRectangle(140, 30, 40, 90, Color.Yellow, false); - graphics.DrawCircle(160, 80, 40, Meadow.Foundation.Color.Cyan, false); + graphics.DrawCircle(160, 80, 40, Color.Cyan, false); int indent = 5; int spacing = 14; @@ -122,25 +121,25 @@ void ColorFontTest() graphics.DrawText(indent, y, "Meadow + SSD1327!!"); - graphics.DrawText(indent, y += spacing, "Red", Meadow.Foundation.Color.Red); + graphics.DrawText(indent, y += spacing, "Red", Color.Red); - graphics.DrawText(indent, y += spacing, "Purple", Meadow.Foundation.Color.Purple); + graphics.DrawText(indent, y += spacing, "Purple", Color.Purple); - graphics.DrawText(indent, y += spacing, "BlueViolet", Meadow.Foundation.Color.BlueViolet); + graphics.DrawText(indent, y += spacing, "BlueViolet", Color.BlueViolet); - graphics.DrawText(indent, y += spacing, "Blue", Meadow.Foundation.Color.Blue); + graphics.DrawText(indent, y += spacing, "Blue", Color.Blue); - graphics.DrawText(indent, y += spacing, "Cyan", Meadow.Foundation.Color.Cyan); + graphics.DrawText(indent, y += spacing, "Cyan", Color.Cyan); - graphics.DrawText(indent, y += spacing, "LawnGreen", Meadow.Foundation.Color.LawnGreen); + graphics.DrawText(indent, y += spacing, "LawnGreen", Color.LawnGreen); - graphics.DrawText(indent, y += spacing, "GreenYellow", Meadow.Foundation.Color.GreenYellow); + graphics.DrawText(indent, y += spacing, "GreenYellow", Color.GreenYellow); - graphics.DrawText(indent, y += spacing, "Yellow", Meadow.Foundation.Color.Yellow); + graphics.DrawText(indent, y += spacing, "Yellow", Color.Yellow); - graphics.DrawText(indent, y += spacing, "Orange", Meadow.Foundation.Color.Orange); + graphics.DrawText(indent, y += spacing, "Orange", Color.Orange); - graphics.DrawText(indent, y += spacing, "Brown", Meadow.Foundation.Color.Brown); + graphics.DrawText(indent, y += spacing, "Brown", Color.Brown); graphics.Show(); 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 f296af7c56..6223aad7f2 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,8 +9,8 @@ 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 e84439bdbd..ca6675e57a 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.St7565/Driver/Displays.St7565.csproj +++ b/Source/Meadow.Foundation.Peripherals/Displays.St7565/Driver/Displays.St7565.csproj @@ -15,13 +15,13 @@ Meadow.Foundation.Displays.St7565 https://github.com/WildernessLabs/Meadow.Foundation Meadow, Meadow.Foundation, Displays, LCD, ST7565 - 0.1.55 + 1.7.0 true ST7565 SPI monochrome OLED display - + - + 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 8953339955..62b7f62a33 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,8 +9,8 @@ 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 b342effd00..702422fb60 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Driver/Displays.TftSpi.csproj +++ b/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Driver/Displays.TftSpi.csproj @@ -15,14 +15,14 @@ Meadow.Foundation.Displays.TftSpi https://github.com/WildernessLabs/Meadow.Foundation Meadow,Meadow.Foundation,Display,TFT,ILI9163,ILI9341,S6D02A1,SSD1331,SSD1351,ST7735,ST7789 - 0.7.58 + 1.7.0 true SPI Color TFT and OLED displays (GC9A01, HC8357B, HX8357D, ILI9163, ILI9341, ILI9481, ILI9488, RM68140, S6D02A1, SSD1331, SSD1351, ST7735, ST7789) - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Driver/Readme.md b/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Driver/Readme.md index 0b0773ae70..8d09a410e5 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Driver/Readme.md +++ b/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Driver/Readme.md @@ -44,8 +44,8 @@ public override Task Initialize() public override Task Run() { graphics.Clear(); - graphics.DrawCircle(120, 120, 100, Meadow.Foundation.Color.Cyan, false); - graphics.DrawRoundedRectangle(50, 50, 140, 140, 50, Meadow.Foundation.Color.BlueViolet, false); + graphics.DrawCircle(120, 120, 100, Color.Cyan, false); + graphics.DrawRoundedRectangle(50, 50, 140, 140, 50, Color.BlueViolet, false); graphics.DrawText(120, 120, "Meadow F7", alignmentH: HorizontalAlignment.Center, alignmentV: VerticalAlignment.Center); graphics.Show(); diff --git a/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Driver/TftSpiBase.cs b/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Driver/TftSpiBase.cs index 757d227c65..6211b68f91 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Driver/TftSpiBase.cs +++ b/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Driver/TftSpiBase.cs @@ -114,7 +114,7 @@ public SpiClockConfiguration.Mode SpiBusMode /// /// The off-screen image buffer /// - protected IPixelBuffer imageBuffer; + protected IPixelBuffer imageBuffer = default!; /// /// The read buffer 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 6c990acc2e..389daf36a2 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,8 +9,8 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/Gc9a01_Sample/MeadowApp.cs b/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/Gc9a01_Sample/MeadowApp.cs index 9fc43f0a69..b84681200c 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/Gc9a01_Sample/MeadowApp.cs +++ b/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/Gc9a01_Sample/MeadowApp.cs @@ -41,8 +41,8 @@ public override Task Initialize() public override Task Run() { graphics.Clear(); - graphics.DrawCircle(120, 120, 100, Meadow.Foundation.Color.Cyan, false); - graphics.DrawRoundedRectangle(50, 50, 140, 140, 50, Meadow.Foundation.Color.BlueViolet, false); + graphics.DrawCircle(120, 120, 100, Color.Cyan, false); + graphics.DrawRoundedRectangle(50, 50, 140, 140, 50, Color.BlueViolet, false); graphics.DrawText(120, 120, "Meadow F7", alignmentH: HorizontalAlignment.Center, alignmentV: VerticalAlignment.Center); graphics.Show(); 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 6c990acc2e..389daf36a2 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,8 +9,8 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/Hx8357b_Sample/MeadowApp.cs b/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/Hx8357b_Sample/MeadowApp.cs index 3d17ae9d19..d28aaa613d 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/Hx8357b_Sample/MeadowApp.cs +++ b/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/Hx8357b_Sample/MeadowApp.cs @@ -1,6 +1,5 @@ using Meadow; using Meadow.Devices; -using Meadow.Foundation; using Meadow.Foundation.Displays; using Meadow.Foundation.Graphics; using System; @@ -326,11 +325,11 @@ void ColorFontTest() graphics.Clear(); - graphics.DrawTriangle(120, 20, 200, 100, 120, 100, Meadow.Foundation.Color.Red, false); + graphics.DrawTriangle(120, 20, 200, 100, 120, 100, Color.Red, false); - graphics.DrawRectangle(140, 30, 40, 90, Meadow.Foundation.Color.Yellow, false); + graphics.DrawRectangle(140, 30, 40, 90, Color.Yellow, false); - graphics.DrawCircle(160, 80, 40, Meadow.Foundation.Color.Cyan, false); + graphics.DrawCircle(160, 80, 40, Color.Cyan, false); int indent = 5; int spacing = 14; @@ -338,25 +337,25 @@ void ColorFontTest() graphics.DrawText(indent, y, "Meadow F7 SPI ST7789!!"); - graphics.DrawText(indent, y += spacing, "Red", Meadow.Foundation.Color.Red); + graphics.DrawText(indent, y += spacing, "Red", Color.Red); - graphics.DrawText(indent, y += spacing, "Purple", Meadow.Foundation.Color.Purple); + graphics.DrawText(indent, y += spacing, "Purple", Color.Purple); - graphics.DrawText(indent, y += spacing, "BlueViolet", Meadow.Foundation.Color.BlueViolet); + graphics.DrawText(indent, y += spacing, "BlueViolet", Color.BlueViolet); - graphics.DrawText(indent, y += spacing, "Blue", Meadow.Foundation.Color.Blue); + graphics.DrawText(indent, y += spacing, "Blue", Color.Blue); - graphics.DrawText(indent, y += spacing, "Cyan", Meadow.Foundation.Color.Cyan); + graphics.DrawText(indent, y += spacing, "Cyan", Color.Cyan); - graphics.DrawText(indent, y += spacing, "LawnGreen", Meadow.Foundation.Color.LawnGreen); + graphics.DrawText(indent, y += spacing, "LawnGreen", Color.LawnGreen); - graphics.DrawText(indent, y += spacing, "GreenYellow", Meadow.Foundation.Color.GreenYellow); + graphics.DrawText(indent, y += spacing, "GreenYellow", Color.GreenYellow); - graphics.DrawText(indent, y += spacing, "Yellow", Meadow.Foundation.Color.Yellow); + graphics.DrawText(indent, y += spacing, "Yellow", Color.Yellow); - graphics.DrawText(indent, y += spacing, "Orange", Meadow.Foundation.Color.Orange); + graphics.DrawText(indent, y += spacing, "Orange", Color.Orange); - graphics.DrawText(indent, y += spacing, "Brown", Meadow.Foundation.Color.Brown); + graphics.DrawText(indent, y += spacing, "Brown", Color.Brown); graphics.Show(); 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 6c990acc2e..389daf36a2 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,8 +9,8 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/Hx8357d_Sample/MeadowApp.cs b/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/Hx8357d_Sample/MeadowApp.cs index 612b5a2363..6db7409dbd 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/Hx8357d_Sample/MeadowApp.cs +++ b/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/Hx8357d_Sample/MeadowApp.cs @@ -1,6 +1,5 @@ using Meadow; using Meadow.Devices; -using Meadow.Foundation; using Meadow.Foundation.Displays; using Meadow.Foundation.Graphics; using System; @@ -330,11 +329,11 @@ void ColorFontTest() graphics.Clear(); - graphics.DrawTriangle(120, 20, 200, 100, 120, 100, Meadow.Foundation.Color.Red, false); + graphics.DrawTriangle(120, 20, 200, 100, 120, 100, Color.Red, false); - graphics.DrawRectangle(140, 30, 40, 90, Meadow.Foundation.Color.Yellow, false); + graphics.DrawRectangle(140, 30, 40, 90, Color.Yellow, false); - graphics.DrawCircle(160, 80, 40, Meadow.Foundation.Color.Cyan, false); + graphics.DrawCircle(160, 80, 40, Color.Cyan, false); int indent = 5; int spacing = 14; @@ -342,25 +341,25 @@ void ColorFontTest() graphics.DrawText(indent, y, "Meadow F7 SPI ST7789!!"); - graphics.DrawText(indent, y += spacing, "Red", Meadow.Foundation.Color.Red); + graphics.DrawText(indent, y += spacing, "Red", Color.Red); - graphics.DrawText(indent, y += spacing, "Purple", Meadow.Foundation.Color.Purple); + graphics.DrawText(indent, y += spacing, "Purple", Color.Purple); - graphics.DrawText(indent, y += spacing, "BlueViolet", Meadow.Foundation.Color.BlueViolet); + graphics.DrawText(indent, y += spacing, "BlueViolet", Color.BlueViolet); - graphics.DrawText(indent, y += spacing, "Blue", Meadow.Foundation.Color.Blue); + graphics.DrawText(indent, y += spacing, "Blue", Color.Blue); - graphics.DrawText(indent, y += spacing, "Cyan", Meadow.Foundation.Color.Cyan); + graphics.DrawText(indent, y += spacing, "Cyan", Color.Cyan); - graphics.DrawText(indent, y += spacing, "LawnGreen", Meadow.Foundation.Color.LawnGreen); + graphics.DrawText(indent, y += spacing, "LawnGreen", Color.LawnGreen); - graphics.DrawText(indent, y += spacing, "GreenYellow", Meadow.Foundation.Color.GreenYellow); + graphics.DrawText(indent, y += spacing, "GreenYellow", Color.GreenYellow); - graphics.DrawText(indent, y += spacing, "Yellow", Meadow.Foundation.Color.Yellow); + graphics.DrawText(indent, y += spacing, "Yellow", Color.Yellow); - graphics.DrawText(indent, y += spacing, "Orange", Meadow.Foundation.Color.Orange); + graphics.DrawText(indent, y += spacing, "Orange", Color.Orange); - graphics.DrawText(indent, y += spacing, "Brown", Meadow.Foundation.Color.Brown); + graphics.DrawText(indent, y += spacing, "Brown", Color.Brown); graphics.Show(); 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 6c990acc2e..389daf36a2 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,8 +9,8 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/Ili9163_Sample/MeadowApp.cs b/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/Ili9163_Sample/MeadowApp.cs index e8e2ad9252..b6b01c298a 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/Ili9163_Sample/MeadowApp.cs +++ b/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/Ili9163_Sample/MeadowApp.cs @@ -43,9 +43,9 @@ public override Task Run() { graphics.Clear(); - graphics.DrawTriangle(10, 10, 50, 50, 10, 50, Meadow.Foundation.Color.Red); - graphics.DrawRectangle(20, 15, 40, 20, Meadow.Foundation.Color.Yellow, false); - graphics.DrawCircle(50, 50, 40, Meadow.Foundation.Color.Blue, false); + graphics.DrawTriangle(10, 10, 50, 50, 10, 50, Color.Red); + graphics.DrawRectangle(20, 15, 40, 20, Color.Yellow, false); + graphics.DrawCircle(50, 50, 40, Color.Blue, false); graphics.DrawText(5, 5, "Meadow F7"); graphics.Show(); 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 036ec6be8f..28a4ba69f4 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_Sample/Ili9341_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/Ili9341_Sample/Ili9341_Sample.csproj index 6c990acc2e..389daf36a2 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,8 +9,8 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/Ili9341_Sample/MeadowApp.cs b/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/Ili9341_Sample/MeadowApp.cs index 041e20ee90..103def9080 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/Ili9341_Sample/MeadowApp.cs +++ b/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/Ili9341_Sample/MeadowApp.cs @@ -1,6 +1,5 @@ using Meadow; using Meadow.Devices; -using Meadow.Foundation; using Meadow.Foundation.Displays; using Meadow.Foundation.Graphics; using System; @@ -44,10 +43,10 @@ public override Task Run() { graphics.Clear(); - graphics.DrawTriangle(10, 30, 50, 50, 10, 50, Meadow.Foundation.Color.Red); - graphics.DrawRectangle(20, 45, 40, 20, Meadow.Foundation.Color.Yellow, false); - graphics.DrawCircle(50, 50, 40, Meadow.Foundation.Color.Blue, false); - graphics.DrawText(5, 5, "Meadow F7", Meadow.Foundation.Color.White); + graphics.DrawTriangle(10, 30, 50, 50, 10, 50, Color.Red); + graphics.DrawRectangle(20, 45, 40, 20, Color.Yellow, false); + graphics.DrawCircle(50, 50, 40, Color.Blue, false); + graphics.DrawText(5, 5, "Meadow F7", Color.White); graphics.Show(); @@ -219,9 +218,9 @@ void TestDisplay() // Draw with Display Graphics Library graphics.CurrentFont = new Font8x8(); graphics.Clear(); - graphics.DrawTriangle(10, 10, 50, 50, 10, 50, Meadow.Foundation.Color.Red); - graphics.DrawRectangle(20, 15, 40, 20, Meadow.Foundation.Color.Yellow, false); - graphics.DrawCircle(50, 50, 40, Meadow.Foundation.Color.Blue, false); + graphics.DrawTriangle(10, 10, 50, 50, 10, 50, Color.Red); + graphics.DrawRectangle(20, 15, 40, 20, Color.Yellow, false); + graphics.DrawCircle(50, 50, 40, Color.Blue, false); graphics.DrawText(5, 5, "Meadow F7 SPI", Color.White); graphics.Show(); 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 6c990acc2e..389daf36a2 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,8 +9,8 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/Ili9481_Sample/MeadowApp.cs b/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/Ili9481_Sample/MeadowApp.cs index 7dc529438d..581de6d19b 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/Ili9481_Sample/MeadowApp.cs +++ b/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/Ili9481_Sample/MeadowApp.cs @@ -42,9 +42,9 @@ public override Task Run() { graphics.Clear(); - graphics.DrawTriangle(10, 10, 50, 50, 10, 50, Meadow.Foundation.Color.Red); - graphics.DrawRectangle(20, 15, 40, 20, Meadow.Foundation.Color.Yellow, false); - graphics.DrawCircle(50, 50, 40, Meadow.Foundation.Color.Blue, false); + graphics.DrawTriangle(10, 10, 50, 50, 10, 50, Color.Red); + graphics.DrawRectangle(20, 15, 40, 20, Color.Yellow, false); + graphics.DrawCircle(50, 50, 40, Color.Blue, false); graphics.DrawText(5, 5, "Meadow F7"); graphics.Show(); 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 6c990acc2e..389daf36a2 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,8 +9,8 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/Ili9486_Sample/MeadowApp.cs b/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/Ili9486_Sample/MeadowApp.cs index aa76b0625b..280ebb400c 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/Ili9486_Sample/MeadowApp.cs +++ b/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/Ili9486_Sample/MeadowApp.cs @@ -42,9 +42,9 @@ public override Task Run() { graphics.Clear(); - graphics.DrawTriangle(10, 10, 50, 50, 10, 50, Meadow.Foundation.Color.Red); - graphics.DrawRectangle(20, 15, 40, 20, Meadow.Foundation.Color.Yellow, false); - graphics.DrawCircle(50, 50, 40, Meadow.Foundation.Color.Blue, false); + graphics.DrawTriangle(10, 10, 50, 50, 10, 50, Color.Red); + graphics.DrawRectangle(20, 15, 40, 20, Color.Yellow, false); + graphics.DrawCircle(50, 50, 40, Color.Blue, false); graphics.DrawText(5, 5, "Meadow F7"); graphics.Show(); 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 6c990acc2e..389daf36a2 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,8 +9,8 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/Ili9488_Sample/MeadowApp.cs b/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/Ili9488_Sample/MeadowApp.cs index 2c65de9ea8..e390cf8206 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/Ili9488_Sample/MeadowApp.cs +++ b/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/Ili9488_Sample/MeadowApp.cs @@ -43,9 +43,9 @@ public override Task Run() graphics.Clear(); - graphics.DrawTriangle(10, 10, 50, 50, 10, 50, Meadow.Foundation.Color.Red); - graphics.DrawRectangle(20, 15, 40, 20, Meadow.Foundation.Color.Yellow, false); - graphics.DrawCircle(50, 50, 40, Meadow.Foundation.Color.Blue, false); + graphics.DrawTriangle(10, 10, 50, 50, 10, 50, Color.Red); + graphics.DrawRectangle(20, 15, 40, 20, Color.Yellow, false); + graphics.DrawCircle(50, 50, 40, Color.Blue, false); graphics.DrawText(5, 5, "Meadow F7"); graphics.Show(); diff --git a/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/Rm68140_Sample/MeadowApp.cs b/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/Rm68140_Sample/MeadowApp.cs index a95d1ecff2..2d87d5cb31 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/Rm68140_Sample/MeadowApp.cs +++ b/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/Rm68140_Sample/MeadowApp.cs @@ -42,9 +42,9 @@ public override Task Run() { graphics.Clear(); - graphics.DrawTriangle(10, 10, 50, 50, 10, 50, Meadow.Foundation.Color.Red); - graphics.DrawRectangle(20, 15, 40, 20, Meadow.Foundation.Color.Yellow, false); - graphics.DrawCircle(50, 50, 40, Meadow.Foundation.Color.Blue, false); + graphics.DrawTriangle(10, 10, 50, 50, 10, 50, Color.Red); + graphics.DrawRectangle(20, 15, 40, 20, Color.Yellow, false); + graphics.DrawCircle(50, 50, 40, Color.Blue, false); graphics.DrawText(5, 5, "Meadow F7"); graphics.Show(); 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 6c990acc2e..389daf36a2 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,8 +9,8 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/S6D02A1_Sample/MeadowApp.cs b/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/S6D02A1_Sample/MeadowApp.cs index ead06e0241..96ac3572c5 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/S6D02A1_Sample/MeadowApp.cs +++ b/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/S6D02A1_Sample/MeadowApp.cs @@ -42,9 +42,9 @@ public override Task Run() { graphics.Clear(); - graphics.DrawTriangle(10, 10, 50, 50, 10, 50, Meadow.Foundation.Color.Red); - graphics.DrawRectangle(20, 15, 40, 20, Meadow.Foundation.Color.Yellow, false); - graphics.DrawCircle(50, 50, 40, Meadow.Foundation.Color.Blue, false); + graphics.DrawTriangle(10, 10, 50, 50, 10, 50, Color.Red); + graphics.DrawRectangle(20, 15, 40, 20, Color.Yellow, false); + graphics.DrawCircle(50, 50, 40, Color.Blue, false); graphics.DrawText(5, 5, "Meadow F7"); graphics.Show(); 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 6c990acc2e..389daf36a2 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,8 +9,8 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/ST7789_Sample/MeadowApp.cs b/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/ST7789_Sample/MeadowApp.cs index 00ca56727c..7d211908d7 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/ST7789_Sample/MeadowApp.cs +++ b/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/ST7789_Sample/MeadowApp.cs @@ -495,11 +495,11 @@ void ColorFontTest() graphics.Clear(); - graphics.DrawTriangle(120, 20, 200, 100, 120, 100, Meadow.Foundation.Color.Red, false); + graphics.DrawTriangle(120, 20, 200, 100, 120, 100, Color.Red, false); - graphics.DrawRectangle(140, 30, 40, 90, Meadow.Foundation.Color.Yellow, false); + graphics.DrawRectangle(140, 30, 40, 90, Color.Yellow, false); - graphics.DrawCircle(160, 80, 40, Meadow.Foundation.Color.Cyan, false); + graphics.DrawCircle(160, 80, 40, Color.Cyan, false); int indent = 5; int spacing = 14; @@ -507,25 +507,25 @@ void ColorFontTest() graphics.DrawText(indent, y, "Meadow F7 SPI ST7789!!"); - graphics.DrawText(indent, y += spacing, "Red", Meadow.Foundation.Color.Red); + graphics.DrawText(indent, y += spacing, "Red", Color.Red); - graphics.DrawText(indent, y += spacing, "Purple", Meadow.Foundation.Color.Purple); + graphics.DrawText(indent, y += spacing, "Purple", Color.Purple); - graphics.DrawText(indent, y += spacing, "BlueViolet", Meadow.Foundation.Color.BlueViolet); + graphics.DrawText(indent, y += spacing, "BlueViolet", Color.BlueViolet); - graphics.DrawText(indent, y += spacing, "Blue", Meadow.Foundation.Color.Blue); + graphics.DrawText(indent, y += spacing, "Blue", Color.Blue); - graphics.DrawText(indent, y += spacing, "Cyan", Meadow.Foundation.Color.Cyan); + graphics.DrawText(indent, y += spacing, "Cyan", Color.Cyan); - graphics.DrawText(indent, y += spacing, "LawnGreen", Meadow.Foundation.Color.LawnGreen); + graphics.DrawText(indent, y += spacing, "LawnGreen", Color.LawnGreen); - graphics.DrawText(indent, y += spacing, "GreenYellow", Meadow.Foundation.Color.GreenYellow); + graphics.DrawText(indent, y += spacing, "GreenYellow", Color.GreenYellow); - graphics.DrawText(indent, y += spacing, "Yellow", Meadow.Foundation.Color.Yellow); + graphics.DrawText(indent, y += spacing, "Yellow", Color.Yellow); - graphics.DrawText(indent, y += spacing, "Orange", Meadow.Foundation.Color.Orange); + graphics.DrawText(indent, y += spacing, "Orange", Color.Orange); - graphics.DrawText(indent, y += spacing, "Brown", Meadow.Foundation.Color.Brown); + graphics.DrawText(indent, y += spacing, "Brown", Color.Brown); graphics.Show(); 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 6c990acc2e..389daf36a2 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,8 +9,8 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/Ssd1331_Sample/MeadowApp.cs b/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/Ssd1331_Sample/MeadowApp.cs index af1dd5a09a..16f2826c18 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/Ssd1331_Sample/MeadowApp.cs +++ b/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/Ssd1331_Sample/MeadowApp.cs @@ -39,8 +39,8 @@ public override Task Run() { graphics.Clear(); - graphics.DrawTriangle(10, 10, 50, 50, 10, 50, Meadow.Foundation.Color.Red); - graphics.DrawRectangle(20, 15, 40, 20, Meadow.Foundation.Color.Yellow, false); + graphics.DrawTriangle(10, 10, 50, 50, 10, 50, Color.Red); + graphics.DrawRectangle(20, 15, 40, 20, Color.Yellow, false); graphics.DrawText(5, 5, "Meadow F7"); graphics.Show(); 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 6c990acc2e..389daf36a2 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,8 +9,8 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/Ssd1351_Sample/MeadowApp.cs b/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/Ssd1351_Sample/MeadowApp.cs index c7c33854a6..2ff55446b4 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/Ssd1351_Sample/MeadowApp.cs +++ b/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/Ssd1351_Sample/MeadowApp.cs @@ -38,7 +38,7 @@ public override Task Run() { graphics.Clear(); - graphics.DrawCircle(80, 80, 40, Meadow.Foundation.Color.Cyan, false); + graphics.DrawCircle(80, 80, 40, Color.Cyan, false); int indent = 0; int spacing = 10; @@ -46,16 +46,16 @@ public override Task Run() graphics.DrawText(indent, y, "Meadow F7 (SSD1351)"); - graphics.DrawText(indent, y += spacing, "Red", Meadow.Foundation.Color.Red); - graphics.DrawText(indent, y += spacing, "Purple", Meadow.Foundation.Color.Purple); - graphics.DrawText(indent, y += spacing, "BlueViolet", Meadow.Foundation.Color.BlueViolet); - graphics.DrawText(indent, y += spacing, "Blue", Meadow.Foundation.Color.Blue); - graphics.DrawText(indent, y += spacing, "Cyan", Meadow.Foundation.Color.Cyan); - graphics.DrawText(indent, y += spacing, "LawnGreen", Meadow.Foundation.Color.LawnGreen); - graphics.DrawText(indent, y += spacing, "GreenYellow", Meadow.Foundation.Color.GreenYellow); - graphics.DrawText(indent, y += spacing, "Yellow", Meadow.Foundation.Color.Yellow); - graphics.DrawText(indent, y += spacing, "Orange", Meadow.Foundation.Color.Orange); - graphics.DrawText(indent, y += spacing, "Brown", Meadow.Foundation.Color.Brown); + graphics.DrawText(indent, y += spacing, "Red", Color.Red); + graphics.DrawText(indent, y += spacing, "Purple", Color.Purple); + graphics.DrawText(indent, y += spacing, "BlueViolet", Color.BlueViolet); + graphics.DrawText(indent, y += spacing, "Blue", Color.Blue); + graphics.DrawText(indent, y += spacing, "Cyan", Color.Cyan); + graphics.DrawText(indent, y += spacing, "LawnGreen", Color.LawnGreen); + graphics.DrawText(indent, y += spacing, "GreenYellow", Color.GreenYellow); + graphics.DrawText(indent, y += spacing, "Yellow", Color.Yellow); + graphics.DrawText(indent, y += spacing, "Orange", Color.Orange); + graphics.DrawText(indent, y += spacing, "Brown", Color.Brown); graphics.Show(); 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 6c990acc2e..389daf36a2 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,8 +9,8 @@ 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 6c990acc2e..389daf36a2 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,8 +9,8 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/St7796s_Sample/MeadowApp.cs b/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/St7796s_Sample/MeadowApp.cs index b3945a5cf6..6156f3b180 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/St7796s_Sample/MeadowApp.cs +++ b/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/St7796s_Sample/MeadowApp.cs @@ -39,8 +39,8 @@ public override Task Run() { graphics.Clear(); - graphics.DrawTriangle(10, 10, 50, 50, 10, 50, Meadow.Foundation.Color.Red); - graphics.DrawRectangle(20, 15, 40, 20, Meadow.Foundation.Color.Yellow, false); + graphics.DrawTriangle(10, 10, 50, 50, 10, 50, Color.Red); + graphics.DrawRectangle(20, 15, 40, 20, Color.Yellow, false); graphics.DrawText(5, 5, "Meadow F7"); graphics.Show(); 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 6c990acc2e..389daf36a2 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,8 +9,8 @@ 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 6425c388b9..672e1b85ce 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.Tm1637/Driver/Displays.Tm1637.csproj +++ b/Source/Meadow.Foundation.Peripherals/Displays.Tm1637/Driver/Displays.Tm1637.csproj @@ -15,13 +15,13 @@ Meadow.Foundation.Displays.Tm1637 https://github.com/WildernessLabs/Meadow.Foundation Meadow, Meadow.Foundation, Displays, LCD, TM1637 - 0.1.53 + 1.7.0 true TM1637 digital character display - + - + 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 d9611adb20..feef9f3048 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,8 +9,8 @@ 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 3805bc5eab..51fa990402 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.Uc1609c/Driver/Displays.Uc1609c.csproj +++ b/Source/Meadow.Foundation.Peripherals/Displays.Uc1609c/Driver/Displays.Uc1609c.csproj @@ -15,13 +15,13 @@ Meadow.Foundation.Displays.Uc1609c https://github.com/WildernessLabs/Meadow.Foundation Meadow,Meadow.Foundation,Displays,LCD,Uc1609c - 0.1.0 + 1.7.0 true Uc1609c SPI monochrome OLED display - + - + diff --git a/Source/Meadow.Foundation.Peripherals/Displays.Uc1609c/Driver/Uc1609c.cs b/Source/Meadow.Foundation.Peripherals/Displays.Uc1609c/Driver/Uc1609c.cs index 580aa3ed3e..283562cdc1 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.Uc1609c/Driver/Uc1609c.cs +++ b/Source/Meadow.Foundation.Peripherals/Displays.Uc1609c/Driver/Uc1609c.cs @@ -124,7 +124,7 @@ public Uc1609c(ISpiBus spiBus, this.dataCommandPort = dataCommandPort; this.resetPort = resetPort; - spiComms = new SpiCommunications(spiBus, chipSelectPort, DefaultSpiBusSpeed, DefaultSpiBusMode); + spiComms = new SpiCommunications(spiBus, this.chipSelectPort = chipSelectPort, DefaultSpiBusSpeed, DefaultSpiBusMode); imageBuffer = new Buffer1bpp(width, height); 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 5f1a22e75b..6a635be07c 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,8 +9,8 @@ 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 05f97b4a98..2ff85661f0 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.WinForms/Driver/Displays.WinForms.csproj +++ b/Source/Meadow.Foundation.Peripherals/Displays.WinForms/Driver/Displays.WinForms.csproj @@ -16,11 +16,12 @@ icon.png https://github.com/WildernessLabs/Meadow.Foundation Meadow.Foundation,Display,Windows,WinForms,Forms - 0.94.0 + 1.7.0 true Windows Forms display driver for Meadow + @@ -29,10 +30,9 @@ - - + diff --git a/Source/Meadow.Foundation.Peripherals/Displays.WinForms/Driver/WinForms.cs b/Source/Meadow.Foundation.Peripherals/Displays.WinForms/Driver/WinForms.cs index 26cf975cc3..7ef4a2020c 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.WinForms/Driver/WinForms.cs +++ b/Source/Meadow.Foundation.Peripherals/Displays.WinForms/Driver/WinForms.cs @@ -136,7 +136,7 @@ void IGraphicsDisplay.Clear(bool updateDisplay) /// /// /// - void IGraphicsDisplay.Fill(Foundation.Color fillColor, bool updateDisplay) + void IGraphicsDisplay.Fill(Color fillColor, bool updateDisplay) { lock (_buffer) { @@ -156,7 +156,7 @@ void IGraphicsDisplay.Fill(Foundation.Color fillColor, bool updateDisplay) /// /// /// - void IGraphicsDisplay.Fill(int x, int y, int width, int height, Foundation.Color fillColor) + void IGraphicsDisplay.Fill(int x, int y, int width, int height, Color fillColor) { lock (_buffer) { @@ -170,7 +170,7 @@ void IGraphicsDisplay.Fill(int x, int y, int width, int height, Foundation.Color /// /// /// - void IGraphicsDisplay.DrawPixel(int x, int y, Foundation.Color color) + void IGraphicsDisplay.DrawPixel(int x, int y, Color color) { lock (_buffer) { @@ -188,7 +188,7 @@ void IGraphicsDisplay.DrawPixel(int x, int y, bool enabled) { lock (_buffer) { - _buffer.SetPixel(x, y, enabled ? Foundation.Color.White : Foundation.Color.Black); + _buffer.SetPixel(x, y, enabled ? Color.White : Color.Black); } } diff --git a/Source/Meadow.Foundation.Peripherals/Displays.WinForms/Driver/WinFormsPixelBuffer.cs b/Source/Meadow.Foundation.Peripherals/Displays.WinForms/Driver/WinFormsPixelBuffer.cs index e3ff3bb302..9affa3076b 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.WinForms/Driver/WinFormsPixelBuffer.cs +++ b/Source/Meadow.Foundation.Peripherals/Displays.WinForms/Driver/WinFormsPixelBuffer.cs @@ -78,7 +78,7 @@ public void Clear() /// Fills the entire buffer with a specified color /// /// - public void Fill(Foundation.Color color) + public void Fill(Color color) { lock (_bmp) { @@ -97,7 +97,7 @@ public void Fill(Foundation.Color color) /// /// /// - public void Fill(int originX, int originY, int width, int height, Foundation.Color color) + public void Fill(int originX, int originY, int width, int height, Color color) { try { @@ -125,7 +125,7 @@ public Color GetPixel(int x, int y) lock (_bmp) { var p = _bmp.GetPixel(x, y); - return Foundation.Color.FromRgba(p.R, p.G, p.B, p.A); + return Color.FromRgba(p.R, p.G, p.B, p.A); } } 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 1a8ef8d8c7..229834ca1d 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.ePaper/Driver/Displays.ePaper.csproj +++ b/Source/Meadow.Foundation.Peripherals/Displays.ePaper/Driver/Displays.ePaper.csproj @@ -15,13 +15,13 @@ Meadow.Foundation.Displays.ePaper https://github.com/WildernessLabs/Meadow.Foundation Meadow.Foundation,Display,SPI,ePaper,eInk,IL0373,IL0376F,IL0398,IL3897,IL91874,ILI91874v3,SSD1608 - 0.1.54 + 1.7.0 true SPI eInk / ePaper display controllers (IL0373, IL0376F, IL0398, IL3897, IL91874, ILI91874v3, SSD1608) - + - + diff --git a/Source/Meadow.Foundation.Peripherals/Displays.ePaper/Driver/EPaperTriColorBase.cs b/Source/Meadow.Foundation.Peripherals/Displays.ePaper/Driver/EPaperTriColorBase.cs index baa60799fb..3e72612dc6 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.ePaper/Driver/EPaperTriColorBase.cs +++ b/Source/Meadow.Foundation.Peripherals/Displays.ePaper/Driver/EPaperTriColorBase.cs @@ -44,7 +44,7 @@ public abstract partial class EPaperTriColorBase : EPaperBase, IGraphicsDisplay /// The buffer the holds the black pixel data for the display /// - protected Buffer2bppEPaper imageBuffer; + protected Buffer2bppEPaper imageBuffer = default!; /// /// Width of display in pixels @@ -113,7 +113,7 @@ public EPaperTriColorBase(ISpiBus spiBus, int bufferWidth = width % 8 > 0 ? width + 8 - (width % 8) : width; CreateBuffer(bufferWidth, height); - imageBuffer?.Clear(); + imageBuffer.Clear(); Initialize(); } diff --git a/Source/Meadow.Foundation.Peripherals/Displays.ePaper/Driver/Readme.md b/Source/Meadow.Foundation.Peripherals/Displays.ePaper/Driver/Readme.md index c02332753e..146931c9d1 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.ePaper/Driver/Readme.md +++ b/Source/Meadow.Foundation.Peripherals/Displays.ePaper/Driver/Readme.md @@ -36,11 +36,11 @@ public override Task Initialize() public override Task Run() { //any color but black will show the ePaper alternate color - graphics.DrawRectangle(1, 1, 126, 32, Meadow.Foundation.Color.Black, false); + graphics.DrawRectangle(1, 1, 126, 32, Color.Black, false); graphics.CurrentFont = new Font12x16(); - graphics.DrawText(2, 2, "IL0373", Meadow.Foundation.Color.Black); - graphics.DrawText(2, 30, "Meadow F7", Meadow.Foundation.Color.Black); + graphics.DrawText(2, 2, "IL0373", Color.Black); + graphics.DrawText(2, 30, "Meadow F7", Color.Black); graphics.Show(); 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 d9e688fcb0..c00c79cea9 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,8 +9,8 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Displays.ePaper/Samples/IL0373_Sample/MeadowApp.cs b/Source/Meadow.Foundation.Peripherals/Displays.ePaper/Samples/IL0373_Sample/MeadowApp.cs index beaece84dd..a140309a68 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.ePaper/Samples/IL0373_Sample/MeadowApp.cs +++ b/Source/Meadow.Foundation.Peripherals/Displays.ePaper/Samples/IL0373_Sample/MeadowApp.cs @@ -33,11 +33,11 @@ public override Task Initialize() public override Task Run() { //any color but black will show the ePaper alternate color - graphics.DrawRectangle(1, 1, 126, 32, Meadow.Foundation.Color.Black, false); + graphics.DrawRectangle(1, 1, 126, 32, Color.Black, false); graphics.CurrentFont = new Font12x16(); - graphics.DrawText(2, 2, "IL0373", Meadow.Foundation.Color.Black); - graphics.DrawText(2, 30, "Meadow F7", Meadow.Foundation.Color.Black); + graphics.DrawText(2, 2, "IL0373", Color.Black); + graphics.DrawText(2, 30, "Meadow F7", Color.Black); graphics.Show(); 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 d9e688fcb0..c00c79cea9 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,8 +9,8 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Displays.ePaper/Samples/IL0376F_Sample/MeadowApp.cs b/Source/Meadow.Foundation.Peripherals/Displays.ePaper/Samples/IL0376F_Sample/MeadowApp.cs index 513122bd86..82b5ecd267 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.ePaper/Samples/IL0376F_Sample/MeadowApp.cs +++ b/Source/Meadow.Foundation.Peripherals/Displays.ePaper/Samples/IL0376F_Sample/MeadowApp.cs @@ -33,11 +33,11 @@ public override Task Initialize() public override Task Run() { //any color but black will show the ePaper alternate color - graphics.DrawRectangle(1, 1, 126, 32, Meadow.Foundation.Color.Red, false); + graphics.DrawRectangle(1, 1, 126, 32, Color.Red, false); graphics.CurrentFont = new Font8x12(); - graphics.DrawText(2, 2, "IL0376F", Meadow.Foundation.Color.Black); - graphics.DrawText(2, 20, "Meadow F7", Meadow.Foundation.Color.Black); + graphics.DrawText(2, 2, "IL0376F", Color.Black); + graphics.DrawText(2, 20, "Meadow F7", Color.Black); graphics.Show(); 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 d9e688fcb0..c00c79cea9 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,8 +9,8 @@ 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 d9e688fcb0..c00c79cea9 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,8 +9,8 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Displays.ePaper/Samples/IL3897_Sample/MeadowApp.cs b/Source/Meadow.Foundation.Peripherals/Displays.ePaper/Samples/IL3897_Sample/MeadowApp.cs index a5dfeae9ea..790d1b76b6 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.ePaper/Samples/IL3897_Sample/MeadowApp.cs +++ b/Source/Meadow.Foundation.Peripherals/Displays.ePaper/Samples/IL3897_Sample/MeadowApp.cs @@ -32,11 +32,11 @@ public override Task Initialize() public override Task Run() { - graphics.DrawRectangle(1, 1, 126, 32, Meadow.Foundation.Color.Red, false); + graphics.DrawRectangle(1, 1, 126, 32, Color.Red, false); graphics.CurrentFont = new Font8x12(); - graphics.DrawText(2, 2, "IL0373", Meadow.Foundation.Color.Black); - graphics.DrawText(2, 20, "Meadow F7", Meadow.Foundation.Color.Black); + graphics.DrawText(2, 2, "IL0373", Color.Black); + graphics.DrawText(2, 20, "Meadow F7", Color.Black); graphics.Show(); 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 d9e688fcb0..c00c79cea9 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,8 +9,8 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Displays.ePaper/Samples/IL91874V03_Sample/MeadowApp.cs b/Source/Meadow.Foundation.Peripherals/Displays.ePaper/Samples/IL91874V03_Sample/MeadowApp.cs index 5e37c8065c..4568f847c3 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.ePaper/Samples/IL91874V03_Sample/MeadowApp.cs +++ b/Source/Meadow.Foundation.Peripherals/Displays.ePaper/Samples/IL91874V03_Sample/MeadowApp.cs @@ -32,11 +32,11 @@ public override Task Initialize() public override Task Run() { - graphics.DrawRectangle(1, 1, 126, 32, Meadow.Foundation.Color.Red, false); + graphics.DrawRectangle(1, 1, 126, 32, Color.Red, false); graphics.CurrentFont = new Font8x12(); - graphics.DrawText(2, 2, "IL91874V03", Meadow.Foundation.Color.Black); - graphics.DrawText(2, 20, "Meadow F7", Meadow.Foundation.Color.Black); + graphics.DrawText(2, 2, "IL91874V03", Color.Black); + graphics.DrawText(2, 20, "Meadow F7", Color.Black); graphics.Show(); 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 d9e688fcb0..c00c79cea9 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,8 +9,8 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Displays.ePaper/Samples/SSD1608_Sample/MeadowApp.cs b/Source/Meadow.Foundation.Peripherals/Displays.ePaper/Samples/SSD1608_Sample/MeadowApp.cs index 6004823263..64bfdd45e6 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.ePaper/Samples/SSD1608_Sample/MeadowApp.cs +++ b/Source/Meadow.Foundation.Peripherals/Displays.ePaper/Samples/SSD1608_Sample/MeadowApp.cs @@ -31,11 +31,11 @@ public override Task Initialize() public override Task Run() { - graphics.DrawRectangle(1, 1, 126, 32, Meadow.Foundation.Color.Black); + graphics.DrawRectangle(1, 1, 126, 32, Color.Black); graphics.CurrentFont = new Font8x12(); - graphics.DrawText(2, 2, "SSD1608", Meadow.Foundation.Color.Black); - graphics.DrawText(2, 20, "Meadow F7", Meadow.Foundation.Color.Black); + graphics.DrawText(2, 2, "SSD1608", Color.Black); + graphics.DrawText(2, 20, "Meadow F7", Color.Black); graphics.Show(); 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 d9e688fcb0..c00c79cea9 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,8 +9,8 @@ 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 d9e688fcb0..c00c79cea9 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,8 +9,8 @@ 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 d9e688fcb0..c00c79cea9 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,8 +9,8 @@ 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 d9e688fcb0..c00c79cea9 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,8 +9,8 @@ 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 dbb146881c..4cfc3a31c7 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.ePaperWaveShare/Driver/Displays.ePaperWaveShare.csproj +++ b/Source/Meadow.Foundation.Peripherals/Displays.ePaperWaveShare/Driver/Displays.ePaperWaveShare.csproj @@ -15,13 +15,13 @@ Meadow.Foundation.Displays.ePaperWaveShare https://github.com/WildernessLabs/Meadow.Foundation Meadow.Foundation,Display,SPI,ePaper,eInk,WaveShare - 0.1.0 + 1.7.0 true WaveShare SPI eInk / ePaper display controllers - + - + 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 78bf2bbead..8da1308efd 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,8 +9,8 @@ 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 78bf2bbead..8da1308efd 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,8 +9,8 @@ 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 78bf2bbead..8da1308efd 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,8 +9,8 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/ICs.ADC.Ads1x15/Driver/Ads1x15Base.cs b/Source/Meadow.Foundation.Peripherals/ICs.ADC.Ads1x15/Driver/Ads1x15Base.cs index 7aa9531623..187301dd18 100644 --- a/Source/Meadow.Foundation.Peripherals/ICs.ADC.Ads1x15/Driver/Ads1x15Base.cs +++ b/Source/Meadow.Foundation.Peripherals/ICs.ADC.Ads1x15/Driver/Ads1x15Base.cs @@ -48,7 +48,7 @@ protected Ads1x15Base(II2cBus i2cBus, MeasureMode measureMode, ChannelSetting channelSetting) { - i2cComms = new I2cCommunications(i2cBus, (byte)address, 3, 3); + i2cComms = new I2cCommunications(i2cBus, (byte)address, 3); SetConfigRegister(0x8583); // this is the default reset - force it in case it's not been reset config = GetConfigRegister(); 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 3e1da77a09..47cda41c93 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 @@ -15,13 +15,13 @@ icon.png https://github.com/WildernessLabs/Meadow.Foundation Meadow.Foundation,ADC,analog,digital,converter,TI,ADS1015,ADS1115 - 0.1.7 + 1.7.0 true TI ADS1x15 I2C analog to digital converters (ADS1015 / ADS1115) - + - + 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 c5b2509d72..56caf8d493 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,8 +6,8 @@ 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 c5b2509d72..56caf8d493 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,8 +6,8 @@ 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 ae1bf3acf1..c294d40ada 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 @@ -14,14 +14,14 @@ Meadow.Foundation.ICs.ADCs.Mcp3xxx https://github.com/WildernessLabs/Meadow.Foundation Meadow.Foundation,Meadow,ADC,analog,digital,Mcp3001,Mcp3002,Mcp3004,Mcp3008,Mcp3201,Mcp3202,Mcp3204,Mcp3208 - 0.1.0 + 1.7.0 true Mcp3xxx SPI analog-to-digital converter (MCP3001, MCP3002, MCP3004, MCP3008, MCP3201, MCP3202, MCP3204, MCP3208) 10.0 - + - + 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 0fc53fa4cd..9a61795c74 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,8 +9,8 @@ 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 0fc53fa4cd..9a61795c74 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,8 +9,8 @@ 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 0fc53fa4cd..9a61795c74 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,8 +9,8 @@ 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 0fc53fa4cd..9a61795c74 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,8 +9,8 @@ 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 0fc53fa4cd..9a61795c74 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,8 +9,8 @@ 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 0fc53fa4cd..9a61795c74 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,8 +9,8 @@ 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 0fc53fa4cd..9a61795c74 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,8 +9,8 @@ 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 0fc53fa4cd..9a61795c74 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,8 +9,8 @@ App - - + + 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 04b291b3aa..5c16f23db1 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 @@ -13,15 +13,15 @@ icon.png https://github.com/WildernessLabs/Meadow.Foundation Meadow.Foundation,DAC,analog,digital,converter,Microchip,MCP4921,MCP4922 - 0.1.7 + 1.7.0 true Microchip MCP4921 and MCP4922 SPI digital to analog converters - enable + enable 10.0 - + - + 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 b7810a1875..eba64a9564 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 @@ -15,13 +15,13 @@ Meadow.Foundation.ICs.DigiPots.Ds3502 https://github.com/WildernessLabs/Meadow.Foundation Meadow.Foundation, DigiPots, Ds3502 - 0.1.5 + 1.7.0 true Ds3502 I2C digital potentiometer - + - + 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 a5f18346ef..99ab9c31dc 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,8 +9,8 @@ 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 b5f6ee21cd..969d75d443 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 @@ -15,13 +15,13 @@ Meadow.Foundation.ICs.DigiPots.Mcp4xxx https://github.com/WildernessLabs/Meadow.Foundation Meadow.Foundation, DigiPots, Mcp4101, Mcp4102, Mcp41xx, Mcp42xx, Mcp41x1, Mcp41x2, Mcp42x1, Mcp42x2 - 0.1.5 + 1.7.0 true Mcp4xxx SPI digital rheostats and potentiometers - + - + 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 f227a0b527..9098616b0f 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,8 +10,8 @@ 10 - - + + 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 762287d8cd..4d8ad226f5 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 @@ -16,13 +16,13 @@ icon.png https://github.com/WildernessLabs/Meadow.Foundation Meadow.Foundation, EEPROM, At24Cxx - 0.1.45 + 1.7.0 true At24Cxx I2C EEPROMs (AT24C32 / AT24C64 / AT24C128 / AT24C256) - + - + 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 a401f071fa..f452f0cf70 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,8 +9,8 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/ICs.FanControllers.Emc2101/Driver/Emc2101.cs b/Source/Meadow.Foundation.Peripherals/ICs.FanControllers.Emc2101/Driver/Emc2101.cs index b2dacfded0..9cda6c29b1 100644 --- a/Source/Meadow.Foundation.Peripherals/ICs.FanControllers.Emc2101/Driver/Emc2101.cs +++ b/Source/Meadow.Foundation.Peripherals/ICs.FanControllers.Emc2101/Driver/Emc2101.cs @@ -195,7 +195,6 @@ protected override void RaiseEventsAndNotify(IChangeResult<(Temperature? Interna { FanSpeedUpdated?.Invoke(this, new ChangeResult(fanSpeed, changeResult.Old?.FanSpeed)); } - base.RaiseEventsAndNotify(changeResult); } 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 b60002891d..842fcc2bef 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 @@ -15,13 +15,13 @@ Meadow.Foundation.ICs.FanControllers.Emc2101 https://github.com/WildernessLabs/Meadow.Foundation Meadow.Foundation,fan,controller,emc2101,temperature,sensor - 0.1.0 + 1.7.0 true Emc2101 I2C fan controller and temperature monitor - - + + 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 9b1d05ba22..e31f98840e 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,8 +9,8 @@ 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 d53c6f1437..24c54be009 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 @@ -14,14 +14,14 @@ Meadow.Foundation.ICs.IOExpanders.AnalogMux https://github.com/WildernessLabs/Meadow.Foundation Meadow.Foundation, IOExpanders, Analog, Input, Multiplexer, 74HC4051, 74HC4067, HP4067 - 0.1.0 + 1.7.0 true Library for various analog multiplexers - enable + enable - + - + 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 e12373d3cd..d522b14ae6 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,8 +9,8 @@ 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 e563137b6b..af67ca4a6e 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 @@ -15,13 +15,13 @@ Meadow.Foundation.ICs.IOExpanders.As1115 https://github.com/WildernessLabs/Meadow.Foundation Meadow.Foundation, IOExpanders, As1115, led, driver, keyscan - 0.1.0 + 1.7.0 true AS1115 I2C IO expander, led driver, character display controller and keyscan - + - + 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 aaf9ec299f..6430708e25 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,8 +9,8 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Cp2112/Data Sheets/an495-cp2112-interface-specification.pdf b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Cp2112/Data Sheets/an495-cp2112-interface-specification.pdf new file mode 100644 index 0000000000..207374f298 Binary files /dev/null and b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Cp2112/Data Sheets/an495-cp2112-interface-specification.pdf differ diff --git a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Cp2112/Data Sheets/an496-hid-usb-to-smbus-api-specification.pdf b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Cp2112/Data Sheets/an496-hid-usb-to-smbus-api-specification.pdf new file mode 100644 index 0000000000..d214c8d3ed Binary files /dev/null and b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Cp2112/Data Sheets/an496-hid-usb-to-smbus-api-specification.pdf differ diff --git a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Cp2112/Driver/Cp2112.PinDefinitions.cs b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Cp2112/Driver/Cp2112.PinDefinitions.cs new file mode 100644 index 0000000000..7e010a2e2d --- /dev/null +++ b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Cp2112/Driver/Cp2112.PinDefinitions.cs @@ -0,0 +1,139 @@ +using Meadow.Hardware; +using System.Collections; +using System.Collections.Generic; + +namespace Meadow.Foundation.ICs.IOExpanders; + +public partial class Cp2112 +{ + /// + /// Provides definitions for the pins of the Cp2112 device. + /// + public class PinDefinitions : IPinDefinitions + { + /// + public IEnumerator GetEnumerator() => AllPins.GetEnumerator(); + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); + + /// + /// Collection of pins + /// + public IList AllPins { get; } = new List(); + + /// + public IPinController? Controller { get; set; } + + /// + /// Create a new PinDefinitions object + /// + internal PinDefinitions(Cp2112 controller) + { + Controller = controller; + InitAllPins(); + } + + /// + /// Gets the pin representing IO0 on the Cp2112 device. + /// + public IPin IO0 => new Pin( + Controller, + "IO0", + (byte)(1 << 0), + new List { + new DigitalChannelInfo("IO0", interruptCapable: false, pullUpCapable: false, pullDownCapable: false) + }); + + /// + /// Gets the pin representing IO1 on the Cp2112 device. + /// + public IPin IO1 => new Pin( + Controller, + "IO1", + (byte)(1 << 1), + new List { + new DigitalChannelInfo("IO1", interruptCapable: false, pullUpCapable: false, pullDownCapable: false) + }); + + /// + /// Gets the pin representing IO2 on the Cp2112 device. + /// + public IPin IO2 => new Pin( + Controller, + "IO2", + (byte)(1 << 2), + new List { + new DigitalChannelInfo("IO2", interruptCapable: false, pullUpCapable: false, pullDownCapable: false) + }); + + /// + /// Gets the pin representing IO3 on the Cp2112 device. + /// + public IPin IO3 => new Pin( + Controller, + "IO3", + (byte)(1 << 3), + new List { + new DigitalChannelInfo("IO3", interruptCapable: false, pullUpCapable: false, pullDownCapable: false) + }); + + /// + /// Gets the pin representing IO4 on the Cp2112 device. + /// + public IPin IO4 => new Pin( + Controller, + "IO4", + (byte)(1 << 4), + new List { + new DigitalChannelInfo("IO4", interruptCapable: false, pullUpCapable: false, pullDownCapable: false) + }); + + /// + /// Gets the pin representing IO5 on the Cp2112 device. + /// + public IPin IO5 => new Pin( + Controller, + "IO5", + (byte)(1 << 5), + new List { + new DigitalChannelInfo("IO5", interruptCapable: false, pullUpCapable: false, pullDownCapable: false) + }); + + /// + /// Gets the pin representing IO6 on the Cp2112 device. + /// + public IPin IO6 => new Pin( + Controller, + "IO6", + (byte)(1 << 6), + new List { + new DigitalChannelInfo("IO6", interruptCapable: false, pullUpCapable: false, pullDownCapable: false) + }); + + /// + /// Gets the pin representing IO7 on the Cp2112 device. + /// + public IPin IO7 => new Pin( + Controller, + "IO7", + (byte)(1 << 7), + new List { + new DigitalChannelInfo("IO7", interruptCapable: false, pullUpCapable: false, pullDownCapable: false) + }); + + /// + /// Initialized all pins of the CP2112 + /// + protected void InitAllPins() + { + // add all our pins to the collection + AllPins.Add(IO0); + AllPins.Add(IO1); + AllPins.Add(IO2); + AllPins.Add(IO3); + AllPins.Add(IO4); + AllPins.Add(IO5); + AllPins.Add(IO6); + AllPins.Add(IO7); + } + } +} \ No newline at end of file diff --git a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Cp2112/Driver/Cp2112.cs b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Cp2112/Driver/Cp2112.cs new file mode 100644 index 0000000000..41fa0cdd42 --- /dev/null +++ b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Cp2112/Driver/Cp2112.cs @@ -0,0 +1,174 @@ +using Meadow.Hardware; +using System; +using System.Linq; +using static Meadow.Foundation.ICs.IOExpanders.Native; + +namespace Meadow.Foundation.ICs.IOExpanders; + +/// +/// Represents a CP2112 USB IO Expander +/// +public partial class Cp2112 : + IDisposable, + IDigitalInputOutputController, + IDigitalOutputController, + II2cController +{ + private bool _isDisposed; + + private IntPtr _handle; + private int _deviceNumber; + private ushort _vid; + private ushort _pid; + private byte _direction; + private byte _mode; + private byte _function; + private byte _clockDivisor; + + internal Cp2112(int deviceNumber, ushort vid, ushort pid) + { + _deviceNumber = deviceNumber; + _vid = vid; + _pid = pid; + + Pins = new PinDefinitions(this); + } + + /// + /// The pins + /// + public PinDefinitions Pins { get; } + + private bool IsOpen() + { + if (_handle == IntPtr.Zero) return false; ; + + int isOpen = 0; + CheckStatus(Functions.HidSmbus_IsOpened(_handle, ref isOpen)); + + return isOpen != 0; + } + + private void Open() + { + if (IsOpen()) return; + + CheckStatus(Functions.HidSmbus_Open(ref _handle, _deviceNumber, _vid, _pid)); + CheckStatus(Functions.HidSmbus_GetGpioConfig(_handle, ref _direction, ref _mode, ref _function, ref _clockDivisor)); + } + + private void Close() + { + if (!IsOpen()) return; + + CheckStatus(Native.Functions.HidSmbus_Close(_handle)); + _handle = IntPtr.Zero; + } + + /// + public II2cBus CreateI2cBus(int busNumber = 0) + { + return CreateI2cBus(busNumber, I2cBusSpeed.Standard); + } + + /// + public II2cBus CreateI2cBus(IPin[] pins, I2cBusSpeed busSpeed) + { + return CreateI2cBus(0, busSpeed); + } + + /// + public II2cBus CreateI2cBus(IPin clock, IPin data, I2cBusSpeed busSpeed) + { + return CreateI2cBus(0, busSpeed); + } + + /// + public II2cBus CreateI2cBus(int busNumber, I2cBusSpeed busSpeed) + { + // TODO: only allow this once + // TODO: convert frequency + // TODO: lock out access to GPIO0,1,5 and 7 + + //HID_SMBUS_STATUS HidSmbus_SetSmbusConfig(HID_SMBUS_DEVICE device,DWORD bitRate, BYTE address, BOOL autoReadRespond, WORD writeTimeout,WORD readTimeout, BOOL sclLowTimeout, WORD transferRetries) + // Functions.HidSmbus_SetSmbusConfig(_handle, 100000, 0x02, 0, 100, 100, 0, 2); + //HID_SMBUS_STATUS HidSmbus_SetGpioConfig(HID_SMBUS_DEVICE device,BYTE direction, BYTE mode, BYTE special, BYTE clkDiv) + // Functions.HidSmbus_SetGpioConfig(_handle, 0x20, 0x20, 0x13, 0xFF); //GPIO5 output/push-pull/GPIO0,1,7 special function/clkDiv=48MHz/(2x255) + //HID_SMBUS_STATUS HidSmbus_WriteLatch(HID_SMBUS_DEVICE device,BYTE latchValue, BYTE latchMask) + // Functions.HidSmbus_WriteLatch(_handle, 0, 0x20); //"Low" active for GPIO5 + + Open(); + + return new Cp2112I2cBus(this, busSpeed); + } + + internal void I2CWrite(byte peripheralAddress, Span writeBuffer) + { + CheckStatus(Functions.HidSmbus_WriteRequest(_handle, peripheralAddress, writeBuffer.ToArray(), (byte)writeBuffer.Length)); + } + + internal void SetState(byte pinMask) + { + CheckStatus(Functions.HidSmbus_WriteLatch(_handle, pinMask, pinMask)); + } + + internal void ClearState(byte pinMask) + { + CheckStatus(Functions.HidSmbus_WriteLatch(_handle, (byte)~pinMask, pinMask)); + } + + /// + public IDigitalInputPort CreateDigitalInputPort(IPin pin, ResistorMode resistorMode) + { + throw new NotImplementedException(); + } + + /// + public IDigitalOutputPort CreateDigitalOutputPort(IPin pin, bool initialState = false, OutputType initialOutputType = OutputType.PushPull) + { + // TODO: check if pin is in use already + Open(); + + var d = _direction; + d |= (byte)pin.Key; + + var mode = _mode; + if (initialOutputType == OutputType.PushPull) + { + mode |= (byte)pin.Key; + } + + CheckStatus(Functions.HidSmbus_SetGpioConfig(_handle, d, mode, _function, _clockDivisor)); + _direction = d; + _mode = mode; + // _stateMask |= (byte)pin.Key; + + return new Cp2112DigitalOutputPort(pin, (pin.SupportedChannels.First(c => c is DigitalChannelInfo) as IDigitalChannelInfo)!, initialState, initialOutputType, this); + } + + /// + protected virtual void Dispose(bool disposing) + { + if (!_isDisposed) + { + Close(); + + _isDisposed = true; + } + } + + /// + /// Finalizes native resources for the CP2112 + /// + ~Cp2112() + { + Dispose(false); + } + + /// + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } +} \ No newline at end of file diff --git a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Cp2112/Driver/Cp2112Collection.cs b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Cp2112/Driver/Cp2112Collection.cs new file mode 100644 index 0000000000..f7f3c00ae1 --- /dev/null +++ b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Cp2112/Driver/Cp2112Collection.cs @@ -0,0 +1,79 @@ +using System.Collections; +using System.Collections.Generic; + +#nullable enable + +namespace Meadow.Foundation.ICs.IOExpanders; + +/// +/// Represents a collection of Cp2112 devices and provides functionality for device enumeration. +/// +public class Cp2112Collection : IEnumerable +{ + private static Cp2112Collection? _instance; + + private List _list = new List(); + + /// + /// Gets the number of Cp2112 devices connected to the host machine. + /// + public int Count => _list.Count; + + /// + /// Gets the Cp2112 device at the specified index in the collection. + /// + /// The index of the Cp2112 device to retrieve. + public Cp2112 this[int index] => _list[index]; + + private Cp2112Collection() + { + } + + /// + /// Refreshes the collection by detecting and updating Cp2112 devices. + /// + public void Refresh() + { + _list.Clear(); + + uint deviceCount = 0; + + var vid = Native.UsbParameters.SG_VID; + var pid = Native.UsbParameters.CP2112_PID; + + Native.CheckStatus(Native.Functions.HidSmbus_GetNumDevices(ref deviceCount, vid, pid)); + + for (var i = 0; i < deviceCount; i++) + { + _list.Add(new Cp2112(i, vid, pid)); + } + + } + + /// + public IEnumerator GetEnumerator() + { + return _list.GetEnumerator(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + + /// + /// Gets the singleton instance of Cp2112Collection, initializing it if necessary. + /// + public static Cp2112Collection Devices + { + get + { + if (_instance == null) + { + _instance = new Cp2112Collection(); + _instance.Refresh(); + } + return _instance; + } + } +} \ No newline at end of file diff --git a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Cp2112/Driver/Cp2112DigitalInputPort.cs b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Cp2112/Driver/Cp2112DigitalInputPort.cs new file mode 100644 index 0000000000..d1c072d8f2 --- /dev/null +++ b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Cp2112/Driver/Cp2112DigitalInputPort.cs @@ -0,0 +1,47 @@ +using Meadow.Hardware; +using System; + +namespace Meadow.Foundation.ICs.IOExpanders +{ + /// + /// Represents a digital input port implementation for the CP2112 bus. + /// + public sealed class Cp2112DigitalInputPort : DigitalInputPortBase + { + private readonly Cp2112 _device; + + /// + /// Instantiates a . + /// + /// The pin connected to the input port. + /// The digital channel info associated with the pin. + /// The CP2112 device instance. + internal Cp2112DigitalInputPort(IPin pin, IDigitalChannelInfo info, Cp2112 device) + : base(pin, info) + { + _device = device; + } + + /// + /// Gets the current state of the input port. + /// + /// The current state of the input port. + public override bool State + { + get + { + throw new NotImplementedException(); + } + } + + /// + /// Gets or sets the resistor mode of the input port. + /// + /// The CP2112 does not support internal resistors. + public override ResistorMode Resistor + { + get => ResistorMode.Disabled; + set => throw new NotSupportedException("The CP2112 does not support internal resistors"); + } + } +} \ No newline at end of file diff --git a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Cp2112/Driver/Cp2112DigitalOutputPort.cs b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Cp2112/Driver/Cp2112DigitalOutputPort.cs new file mode 100644 index 0000000000..e853208589 --- /dev/null +++ b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Cp2112/Driver/Cp2112DigitalOutputPort.cs @@ -0,0 +1,54 @@ +using Meadow.Hardware; +using System; + +namespace Meadow.Foundation.ICs.IOExpanders +{ + /// + /// Digital output port for CP2112 devices. + /// + public sealed class Cp2112DigitalOutputPort : DigitalOutputPortBase + { + private readonly Cp2112 _device; + private readonly bool _state; + + /// + /// Initializes a new instance of the class. + /// + /// The pin to use. + /// The digital channel info. + /// The initial state of the output port. + /// The initial output type. + /// The CP2112 device. + internal Cp2112DigitalOutputPort(IPin pin, IDigitalChannelInfo info, bool initialState, OutputType initialOutputType, Cp2112 device) + : base(pin, info, initialState, initialOutputType) + { + _device = device; + State = initialState; + } + + /// + /// Gets or sets the state of the digital output port. + /// + /// + /// The state of the digital output port. + /// + public override bool State + { + get => _state; + set + { + if (value) + { + Console.WriteLine("ON"); + _device.SetState((byte)this.Pin.Key); + + } + else + { + Console.WriteLine("OFF"); + _device.ClearState((byte)this.Pin.Key); + } + } + } + } +} \ No newline at end of file diff --git a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Cp2112/Driver/Cp2112I2cBus.cs b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Cp2112/Driver/Cp2112I2cBus.cs new file mode 100644 index 0000000000..192158611b --- /dev/null +++ b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Cp2112/Driver/Cp2112I2cBus.cs @@ -0,0 +1,64 @@ +using Meadow.Hardware; +using System; + +namespace Meadow.Foundation.ICs.IOExpanders; + +/// +/// Represents an I2C bus implementation using the Cp2112 device. +/// +public sealed class Cp2112I2cBus : II2cBus, IDisposable +{ + private bool _isDisposed; + private Cp2112 _device; + + internal Cp2112I2cBus(Cp2112 device, I2cBusSpeed busSpeed) + { + BusSpeed = busSpeed; + _device = device; + } + + /// + public I2cBusSpeed BusSpeed { get; set; } + + private void Dispose(bool _) + { + if (!_isDisposed) + { + _isDisposed = true; + } + } + + /// + /// Finalizer for the Cp2112I2cBus class, used to release unmanaged resources. + /// + ~Cp2112I2cBus() + { + Dispose(false); + } + + /// + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } + + /// + public void Exchange(byte peripheralAddress, Span writeBuffer, Span readBuffer) + { + Write(peripheralAddress, writeBuffer); + Read(peripheralAddress, readBuffer); + } + + /// + public void Read(byte peripheralAddress, Span readBuffer) + { + throw new NotImplementedException(); + } + + /// + public void Write(byte peripheralAddress, Span writeBuffer) + { + _device.I2CWrite(peripheralAddress, writeBuffer); + } +} \ No newline at end of file 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 new file mode 100644 index 0000000000..6580f6ac88 --- /dev/null +++ b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Cp2112/Driver/ICs.IOExpanders.Cp2112.csproj @@ -0,0 +1,28 @@ + + + Readme.md + enable + 10.0 + Apache-2.0 + true + icon.png + Wilderness Labs, Inc + netstandard2.1 + Library + Cp2112 + Wilderness Labs, Inc + http://developer.wildernesslabs.co/Meadow/Meadow.Foundation/ + Meadow.Foundation.ICs.IOExpanders.Cp2112 + https://github.com/WildernessLabs/Meadow.Foundation + Meadow.Foundation,IOExpanders,expander,IO,CP2112 + 1.7.0 + true + false + CP2112 USB IOExpander for GPIO, I2C, SPI on Windows + + + + + + + diff --git a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Cp2112/Driver/Native.Functions.cs b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Cp2112/Driver/Native.Functions.cs new file mode 100644 index 0000000000..fa6cf15a93 --- /dev/null +++ b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Cp2112/Driver/Native.Functions.cs @@ -0,0 +1,57 @@ +using System; +using System.Runtime.InteropServices; + +namespace Meadow.Foundation.ICs.IOExpanders +{ + internal static partial class Native + { + + public class Functions + { + private const string HIDtoSMB = "SLABHIDtoSMBus"; + + [DllImport(HIDtoSMB)] + public static extern HID_SMBUS_STATUS HidSmbus_GetNumDevices(ref uint numDevices, ushort vid, ushort pid); + + [DllImport(HIDtoSMB)] + public static extern HID_SMBUS_STATUS HidSmbus_Open(ref IntPtr device, int deviceNum, ushort vid, ushort pid); + + [DllImport(HIDtoSMB)] + public static extern HID_SMBUS_STATUS HidSmbus_Close(IntPtr device); + + [DllImport(HIDtoSMB)] + public static extern HID_SMBUS_STATUS HidSmbus_IsOpened(IntPtr device, ref int opened); + + [DllImport(HIDtoSMB)] + public static extern HID_SMBUS_STATUS HidSmbus_GetGpioConfig(IntPtr device, ref byte direction, ref byte mode, ref byte function, ref byte clockDivisor); + + [DllImport(HIDtoSMB)] + public static extern HID_SMBUS_STATUS HidSmbus_SetGpioConfig(IntPtr device, byte direction, byte mode, byte function, byte clockDivisor); + + [DllImport(HIDtoSMB)] + public static extern HID_SMBUS_STATUS HidSmbus_ReadLatch(IntPtr device, out byte value); + + [DllImport(HIDtoSMB)] + public static extern HID_SMBUS_STATUS HidSmbus_WriteLatch(IntPtr device, byte value, byte mask); + + [DllImport(HIDtoSMB)] + public static extern HID_SMBUS_STATUS HidSmbus_ReadRequest(IntPtr device, byte slaveAddress, byte numBytesToRead); + + [DllImport(HIDtoSMB)] + public static extern HID_SMBUS_STATUS HidSmbus_GetReadResponse(IntPtr device, byte statusS0, byte[] buffer, byte bufferSize, out byte bytesRead); + + [DllImport(HIDtoSMB)] + public static extern HID_SMBUS_STATUS HidSmbus_AddressReadRequest(IntPtr device, byte slaveAddress, short numBytesToRead, byte targetAddressSize, byte[] targetAddress); + + [DllImport(HIDtoSMB)] + public static extern HID_SMBUS_STATUS HidSmbus_GetSmbusConfig(IntPtr device, out uint bitRate, out byte address, out int autoReadRespond, out short writeTimeout, out short readTimeout, out int sclLowtimeout, out short transferRetries); + + [DllImport(HIDtoSMB)] + public static extern HID_SMBUS_STATUS HidSmbus_SetSmbusConfig(IntPtr device, uint bitRate, byte address, int autoReadRespond, short writeTimeout, short readTimeout, int sclLowTimeout, short transferRetries); + + // HID_SMBUS_STATUS HidSmbus_WriteRequest (HID_SMBUS_DEVICE device, BYTE slaveAddress, BYTE* buffer, BYTE numBytesToWrite) + [DllImport(HIDtoSMB)] + public static extern HID_SMBUS_STATUS HidSmbus_WriteRequest(IntPtr device, byte slaveAddress, byte[] buffer, byte numBytes); + } + } +} \ No newline at end of file diff --git a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Cp2112/Driver/Native.cs b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Cp2112/Driver/Native.cs new file mode 100644 index 0000000000..3c2700661e --- /dev/null +++ b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Cp2112/Driver/Native.cs @@ -0,0 +1,60 @@ +using System; + +namespace Meadow.Foundation.ICs.IOExpanders +{ + internal static partial class Native + { + public static bool CheckStatus(Native.HID_SMBUS_STATUS status) + { + if (status == Native.HID_SMBUS_STATUS.HID_SMBUS_SUCCESS) + { + return true; + } + + throw new Exception($"Native error: {status}"); + } + + public enum HID_SMBUS_STATUS + { + HID_SMBUS_SUCCESS = 0x00, + HID_SMBUS_DEVICE_NOT_FOUND = 0x01, + HID_SMBUS_INVALID_HANDLE = 0x02, + HID_SMBUS_INVALID_DEVICE_OBJECT = 0x03, + HID_SMBUS_INVALID_PARAMETER = 0x04, + HID_SMBUS_INVALID_REQUEST_LENGTH = 0x05, + HID_SMBUS_READ_ERROR = 0x10, + HID_SMBUS_WRITE_ERROR = 0x11, + HID_SMBUS_READ_TIMED_OUT = 0x12, + HID_SMBUS_WRITE_TIMED_OUT = 0x13, + HID_SMBUS_DEVICE_IO_FAILED = 0x14, + HID_SMBUS_DEVICE_ACCESS_ERROR = 0x15, + HID_SMBUS_DEVICE_NOT_SUPPORTED = 0x16, + HID_SMBUS_UNKNOWN_ERROR = 0xFF, + } + + public static class UsbParameters + { + public const ushort SG_VID = 0x10C4; + public const ushort CP2112_PID = 0xEA90; + } + + public const byte HID_SMBUS_S0_IDLE = 0x00; + public const byte HID_SMBUS_S0_BUSY = 0x01; + public const byte HID_SMBUS_S0_COMPLETE = 0x02; + public const byte HID_SMBUS_S0_ERROR = 0x03; + + // HID_SMBUS_TRANSFER_S0 = HID_SMBUS_S0_BUSY + public const byte HID_SMBUS_S1_BUSY_ADDRESS_ACKED = 0x00; + public const byte HID_SMBUS_S1_BUSY_ADDRESS_NACKED = 0x01; + public const byte HID_SMBUS_S1_BUSY_READING = 0x02; + public const byte HID_SMBUS_S1_BUSY_WRITING = 0x03; + + // HID_SMBUS_TRANSFER_S0 = HID_SMBUS_S0_ERROR + public const byte HID_SMBUS_S1_ERROR_TIMEOUT_NACK = 0x00; + public const byte HID_SMBUS_S1_ERROR_TIMEOUT_BUS_NOT_FREE = 0x01; + public const byte HID_SMBUS_S1_ERROR_ARB_LOST = 0x02; + public const byte HID_SMBUS_S1_ERROR_READ_INCOMPLETE = 0x03; + public const byte HID_SMBUS_S1_ERROR_WRITE_INCOMPLETE = 0x04; + public const byte HID_SMBUS_S1_ERROR_SUCCESS_AFTER_RETRY = 0x05; + } +} \ No newline at end of file diff --git a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Cp2112/Driver/Readme.md b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Cp2112/Driver/Readme.md new file mode 100644 index 0000000000..8b40307977 --- /dev/null +++ b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Cp2112/Driver/Readme.md @@ -0,0 +1,22 @@ +# Meadow.Foundation.ICs.IOExpanders.Cp2112 + +**CP2112 USB IOExpander for GPIO, I2C, SPI on Windows** + +The **Cp2112** library is designed for the [Wilderness Labs](www.wildernesslabs.co) Meadow .NET IoT platform and is part of [Meadow.Foundation](https://developer.wildernesslabs.co/Meadow/Meadow.Foundation/). + +The **Meadow.Foundation** peripherals library is an open-source repository of drivers and libraries that streamline and simplify adding hardware to your C# .NET Meadow IoT application. + +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/). + +## 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/). 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 new file mode 100644 index 0000000000..b48fe6042a --- /dev/null +++ b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Cp2112/Samples/Cp2112_Windows_Sample/Cp2112_Windows_Sample.csproj @@ -0,0 +1,23 @@ + + + + Exe + net7.0 + enable + enable + + + + + Always + + + Always + + + + + + + + diff --git a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Cp2112/Samples/Cp2112_Windows_Sample/Program.cs b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Cp2112/Samples/Cp2112_Windows_Sample/Program.cs new file mode 100644 index 0000000000..a44900a707 --- /dev/null +++ b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Cp2112/Samples/Cp2112_Windows_Sample/Program.cs @@ -0,0 +1,28 @@ +// See https://aka.ms/new-console-template for more information +using Meadow.Foundation.ICs.IOExpanders; +using Meadow.Hardware; + +Console.WriteLine("HELLO FROM THE WILDERNESS CP2112 DRIVER!"); + +if (Cp2112Collection.Devices.Count == 0) +{ + Console.WriteLine("No CP2112 devices detected!"); + Console.ReadKey(); + return; +} + +var cp = Cp2112Collection.Devices[0]; + +var output = cp.Pins.IO6.CreateDigitalOutputPort(); + +while (true) +{ + output.State = true; + Thread.Sleep(1000); + output.State = false; + Thread.Sleep(1000); +} + +Console.ReadKey(); + + diff --git a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ft232h/Data Sheets/AN_108_Command_Processor_for_MPSSE_and_MCU_Host_Bus_Emulation_Modes.pdf b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ft232h/Data Sheets/AN_108_Command_Processor_for_MPSSE_and_MCU_Host_Bus_Emulation_Modes.pdf new file mode 100644 index 0000000000..ef93742266 Binary files /dev/null and b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ft232h/Data Sheets/AN_108_Command_Processor_for_MPSSE_and_MCU_Host_Bus_Emulation_Modes.pdf differ diff --git a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ft232h/Data Sheets/D2XX_Programmers_Guide.pdf b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ft232h/Data Sheets/D2XX_Programmers_Guide.pdf new file mode 100644 index 0000000000..69920646fb Binary files /dev/null and b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ft232h/Data Sheets/D2XX_Programmers_Guide.pdf differ diff --git a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ft232h/Data Sheets/ftd2xx.h b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ft232h/Data Sheets/ftd2xx.h new file mode 100644 index 0000000000..895f2267f5 --- /dev/null +++ b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ft232h/Data Sheets/ftd2xx.h @@ -0,0 +1,1446 @@ +/*++ + +Copyright © 2001-2011 Future Technology Devices International Limited + +THIS SOFTWARE IS PROVIDED BY FUTURE TECHNOLOGY DEVICES INTERNATIONAL LIMITED "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL +FUTURE TECHNOLOGY DEVICES INTERNATIONAL LIMITED BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT +OF SUBSTITUTE GOODS OR SERVICES LOSS OF USE, DATA, OR PROFITS OR BUSINESS INTERRUPTION) +HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR +TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, +EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +FTDI DRIVERS MAY BE USED ONLY IN CONJUNCTION WITH PRODUCTS BASED ON FTDI PARTS. + +FTDI DRIVERS MAY BE DISTRIBUTED IN ANY FORM AS LONG AS LICENSE INFORMATION IS NOT MODIFIED. + +IF A CUSTOM VENDOR ID AND/OR PRODUCT ID OR DESCRIPTION STRING ARE USED, IT IS THE +RESPONSIBILITY OF THE PRODUCT MANUFACTURER TO MAINTAIN ANY CHANGES AND SUBSEQUENT WHQL +RE-CERTIFICATION AS A RESULT OF MAKING THESE CHANGES. + + +Module Name: + +ftd2xx.h + +Abstract: + +Native USB device driver for FTDI FT232x, FT245x, FT2232x and FT4232x devices +FTD2XX library definitions + +Environment: + +kernel & user mode + + +--*/ + + +#ifndef FTD2XX_H +#define FTD2XX_H + +#ifdef _WIN32 +// Compiling on Windows +#include + +// The following ifdef block is the standard way of creating macros +// which make exporting from a DLL simpler. All files within this DLL +// are compiled with the FTD2XX_EXPORTS symbol defined on the command line. +// This symbol should not be defined on any project that uses this DLL. +// This way any other project whose source files include this file see +// FTD2XX_API functions as being imported from a DLL, whereas this DLL +// sees symbols defined with this macro as being exported. + +#ifdef FTD2XX_EXPORTS +#define FTD2XX_API __declspec(dllexport) +#elif defined(FTD2XX_STATIC) +// Avoid decorations when linking statically to D2XX. +#define FTD2XX_API +// Static D2XX depends on these Windows libs: +#pragma comment(lib, "setupapi.lib") +#pragma comment(lib, "advapi32.lib") +#pragma comment(lib, "user32.lib") +#else +#define FTD2XX_API __declspec(dllimport) +#endif + +#else // _WIN32 +// Compiling on non-Windows platform. +#include "WinTypes.h" +// No decorations needed. +#define FTD2XX_API + +#endif // _WIN32 + +typedef PVOID FT_HANDLE; +typedef ULONG FT_STATUS; + +// +// Device status +// +enum { + FT_OK, + FT_INVALID_HANDLE, + FT_DEVICE_NOT_FOUND, + FT_DEVICE_NOT_OPENED, + FT_IO_ERROR, + FT_INSUFFICIENT_RESOURCES, + FT_INVALID_PARAMETER, + FT_INVALID_BAUD_RATE, + + FT_DEVICE_NOT_OPENED_FOR_ERASE, + FT_DEVICE_NOT_OPENED_FOR_WRITE, + FT_FAILED_TO_WRITE_DEVICE, + FT_EEPROM_READ_FAILED, + FT_EEPROM_WRITE_FAILED, + FT_EEPROM_ERASE_FAILED, + FT_EEPROM_NOT_PRESENT, + FT_EEPROM_NOT_PROGRAMMED, + FT_INVALID_ARGS, + FT_NOT_SUPPORTED, + FT_OTHER_ERROR, + FT_DEVICE_LIST_NOT_READY, +}; + + +#define FT_SUCCESS(status) ((status) == FT_OK) + +// +// FT_OpenEx Flags +// + +#define FT_OPEN_BY_SERIAL_NUMBER 1 +#define FT_OPEN_BY_DESCRIPTION 2 +#define FT_OPEN_BY_LOCATION 4 + +#define FT_OPEN_MASK (FT_OPEN_BY_SERIAL_NUMBER | \ + FT_OPEN_BY_DESCRIPTION | \ + FT_OPEN_BY_LOCATION) + +// +// FT_ListDevices Flags (used in conjunction with FT_OpenEx Flags +// + +#define FT_LIST_NUMBER_ONLY 0x80000000 +#define FT_LIST_BY_INDEX 0x40000000 +#define FT_LIST_ALL 0x20000000 + +#define FT_LIST_MASK (FT_LIST_NUMBER_ONLY|FT_LIST_BY_INDEX|FT_LIST_ALL) + +// +// Baud Rates +// + +#define FT_BAUD_300 300 +#define FT_BAUD_600 600 +#define FT_BAUD_1200 1200 +#define FT_BAUD_2400 2400 +#define FT_BAUD_4800 4800 +#define FT_BAUD_9600 9600 +#define FT_BAUD_14400 14400 +#define FT_BAUD_19200 19200 +#define FT_BAUD_38400 38400 +#define FT_BAUD_57600 57600 +#define FT_BAUD_115200 115200 +#define FT_BAUD_230400 230400 +#define FT_BAUD_460800 460800 +#define FT_BAUD_921600 921600 + +// +// Word Lengths +// + +#define FT_BITS_8 (UCHAR) 8 +#define FT_BITS_7 (UCHAR) 7 + +// +// Stop Bits +// + +#define FT_STOP_BITS_1 (UCHAR) 0 +#define FT_STOP_BITS_2 (UCHAR) 2 + +// +// Parity +// + +#define FT_PARITY_NONE (UCHAR) 0 +#define FT_PARITY_ODD (UCHAR) 1 +#define FT_PARITY_EVEN (UCHAR) 2 +#define FT_PARITY_MARK (UCHAR) 3 +#define FT_PARITY_SPACE (UCHAR) 4 + +// +// Flow Control +// + +#define FT_FLOW_NONE 0x0000 +#define FT_FLOW_RTS_CTS 0x0100 +#define FT_FLOW_DTR_DSR 0x0200 +#define FT_FLOW_XON_XOFF 0x0400 + +// +// Purge rx and tx buffers +// +#define FT_PURGE_RX 1 +#define FT_PURGE_TX 2 + +// +// Events +// + +typedef void (*PFT_EVENT_HANDLER)(DWORD,DWORD); + +#define FT_EVENT_RXCHAR 1 +#define FT_EVENT_MODEM_STATUS 2 +#define FT_EVENT_LINE_STATUS 4 + +// +// Timeouts +// + +#define FT_DEFAULT_RX_TIMEOUT 300 +#define FT_DEFAULT_TX_TIMEOUT 300 + +// +// Device types +// + +typedef ULONG FT_DEVICE; + +enum { + FT_DEVICE_BM, + FT_DEVICE_AM, + FT_DEVICE_100AX, + FT_DEVICE_UNKNOWN, + FT_DEVICE_2232C, + FT_DEVICE_232R, + FT_DEVICE_2232H, + FT_DEVICE_4232H, + FT_DEVICE_232H, + FT_DEVICE_X_SERIES, + FT_DEVICE_4222H_0, + FT_DEVICE_4222H_1_2, + FT_DEVICE_4222H_3, + FT_DEVICE_4222_PROG, + FT_DEVICE_900, + FT_DEVICE_930, + FT_DEVICE_UMFTPD3A, +}; + +// +// Bit Modes +// + +#define FT_BITMODE_RESET 0x00 +#define FT_BITMODE_ASYNC_BITBANG 0x01 +#define FT_BITMODE_MPSSE 0x02 +#define FT_BITMODE_SYNC_BITBANG 0x04 +#define FT_BITMODE_MCU_HOST 0x08 +#define FT_BITMODE_FAST_SERIAL 0x10 +#define FT_BITMODE_CBUS_BITBANG 0x20 +#define FT_BITMODE_SYNC_FIFO 0x40 + +// +// FT232R CBUS Options EEPROM values +// + +#define FT_232R_CBUS_TXDEN 0x00 // Tx Data Enable +#define FT_232R_CBUS_PWRON 0x01 // Power On +#define FT_232R_CBUS_RXLED 0x02 // Rx LED +#define FT_232R_CBUS_TXLED 0x03 // Tx LED +#define FT_232R_CBUS_TXRXLED 0x04 // Tx and Rx LED +#define FT_232R_CBUS_SLEEP 0x05 // Sleep +#define FT_232R_CBUS_CLK48 0x06 // 48MHz clock +#define FT_232R_CBUS_CLK24 0x07 // 24MHz clock +#define FT_232R_CBUS_CLK12 0x08 // 12MHz clock +#define FT_232R_CBUS_CLK6 0x09 // 6MHz clock +#define FT_232R_CBUS_IOMODE 0x0A // IO Mode for CBUS bit-bang +#define FT_232R_CBUS_BITBANG_WR 0x0B // Bit-bang write strobe +#define FT_232R_CBUS_BITBANG_RD 0x0C // Bit-bang read strobe + +// +// FT232H CBUS Options EEPROM values +// + +#define FT_232H_CBUS_TRISTATE 0x00 // Tristate +#define FT_232H_CBUS_TXLED 0x01 // Tx LED +#define FT_232H_CBUS_RXLED 0x02 // Rx LED +#define FT_232H_CBUS_TXRXLED 0x03 // Tx and Rx LED +#define FT_232H_CBUS_PWREN 0x04 // Power Enable +#define FT_232H_CBUS_SLEEP 0x05 // Sleep +#define FT_232H_CBUS_DRIVE_0 0x06 // Drive pin to logic 0 +#define FT_232H_CBUS_DRIVE_1 0x07 // Drive pin to logic 1 +#define FT_232H_CBUS_IOMODE 0x08 // IO Mode for CBUS bit-bang +#define FT_232H_CBUS_TXDEN 0x09 // Tx Data Enable +#define FT_232H_CBUS_CLK30 0x0A // 30MHz clock +#define FT_232H_CBUS_CLK15 0x0B // 15MHz clock +#define FT_232H_CBUS_CLK7_5 0x0C // 7.5MHz clock + +// +// FT X Series CBUS Options EEPROM values +// + +#define FT_X_SERIES_CBUS_TRISTATE 0x00 // Tristate +#define FT_X_SERIES_CBUS_TXLED 0x01 // Tx LED +#define FT_X_SERIES_CBUS_RXLED 0x02 // Rx LED +#define FT_X_SERIES_CBUS_TXRXLED 0x03 // Tx and Rx LED +#define FT_X_SERIES_CBUS_PWREN 0x04 // Power Enable +#define FT_X_SERIES_CBUS_SLEEP 0x05 // Sleep +#define FT_X_SERIES_CBUS_DRIVE_0 0x06 // Drive pin to logic 0 +#define FT_X_SERIES_CBUS_DRIVE_1 0x07 // Drive pin to logic 1 +#define FT_X_SERIES_CBUS_IOMODE 0x08 // IO Mode for CBUS bit-bang +#define FT_X_SERIES_CBUS_TXDEN 0x09 // Tx Data Enable +#define FT_X_SERIES_CBUS_CLK24 0x0A // 24MHz clock +#define FT_X_SERIES_CBUS_CLK12 0x0B // 12MHz clock +#define FT_X_SERIES_CBUS_CLK6 0x0C // 6MHz clock +#define FT_X_SERIES_CBUS_BCD_CHARGER 0x0D // Battery charger detected +#define FT_X_SERIES_CBUS_BCD_CHARGER_N 0x0E // Battery charger detected inverted +#define FT_X_SERIES_CBUS_I2C_TXE 0x0F // I2C Tx empty +#define FT_X_SERIES_CBUS_I2C_RXF 0x10 // I2C Rx full +#define FT_X_SERIES_CBUS_VBUS_SENSE 0x11 // Detect VBUS +#define FT_X_SERIES_CBUS_BITBANG_WR 0x12 // Bit-bang write strobe +#define FT_X_SERIES_CBUS_BITBANG_RD 0x13 // Bit-bang read strobe +#define FT_X_SERIES_CBUS_TIMESTAMP 0x14 // Toggle output when a USB SOF token is received +#define FT_X_SERIES_CBUS_KEEP_AWAKE 0x15 // + + +// Driver types +#define FT_DRIVER_TYPE_D2XX 0 +#define FT_DRIVER_TYPE_VCP 1 + + + +#ifdef __cplusplus +extern "C" { +#endif + + +#ifdef FTD2XX_STATIC + FTD2XX_API + FT_STATUS WINAPI FT_Initialise( + void + ); + + FTD2XX_API + void WINAPI FT_Finalise( + void + ); +#endif // FTD2XX_STATIC + + FTD2XX_API + FT_STATUS WINAPI FT_Open( + int deviceNumber, + FT_HANDLE *pHandle + ); + + FTD2XX_API + FT_STATUS WINAPI FT_OpenEx( + PVOID pArg1, + DWORD Flags, + FT_HANDLE *pHandle + ); + + FTD2XX_API + FT_STATUS WINAPI FT_ListDevices( + PVOID pArg1, + PVOID pArg2, + DWORD Flags + ); + + FTD2XX_API + FT_STATUS WINAPI FT_Close( + FT_HANDLE ftHandle + ); + + FTD2XX_API + FT_STATUS WINAPI FT_Read( + FT_HANDLE ftHandle, + LPVOID lpBuffer, + DWORD dwBytesToRead, + LPDWORD lpBytesReturned + ); + + FTD2XX_API + FT_STATUS WINAPI FT_Write( + FT_HANDLE ftHandle, + LPVOID lpBuffer, + DWORD dwBytesToWrite, + LPDWORD lpBytesWritten + ); + + FTD2XX_API + FT_STATUS WINAPI FT_IoCtl( + FT_HANDLE ftHandle, + DWORD dwIoControlCode, + LPVOID lpInBuf, + DWORD nInBufSize, + LPVOID lpOutBuf, + DWORD nOutBufSize, + LPDWORD lpBytesReturned, + LPOVERLAPPED lpOverlapped + ); + + FTD2XX_API + FT_STATUS WINAPI FT_SetBaudRate( + FT_HANDLE ftHandle, + ULONG BaudRate + ); + + FTD2XX_API + FT_STATUS WINAPI FT_SetDivisor( + FT_HANDLE ftHandle, + USHORT Divisor + ); + + FTD2XX_API + FT_STATUS WINAPI FT_SetDataCharacteristics( + FT_HANDLE ftHandle, + UCHAR WordLength, + UCHAR StopBits, + UCHAR Parity + ); + + FTD2XX_API + FT_STATUS WINAPI FT_SetFlowControl( + FT_HANDLE ftHandle, + USHORT FlowControl, + UCHAR XonChar, + UCHAR XoffChar + ); + + FTD2XX_API + FT_STATUS WINAPI FT_ResetDevice( + FT_HANDLE ftHandle + ); + + FTD2XX_API + FT_STATUS WINAPI FT_SetDtr( + FT_HANDLE ftHandle + ); + + FTD2XX_API + FT_STATUS WINAPI FT_ClrDtr( + FT_HANDLE ftHandle + ); + + FTD2XX_API + FT_STATUS WINAPI FT_SetRts( + FT_HANDLE ftHandle + ); + + FTD2XX_API + FT_STATUS WINAPI FT_ClrRts( + FT_HANDLE ftHandle + ); + + FTD2XX_API + FT_STATUS WINAPI FT_GetModemStatus( + FT_HANDLE ftHandle, + ULONG *pModemStatus + ); + + FTD2XX_API + FT_STATUS WINAPI FT_SetChars( + FT_HANDLE ftHandle, + UCHAR EventChar, + UCHAR EventCharEnabled, + UCHAR ErrorChar, + UCHAR ErrorCharEnabled + ); + + FTD2XX_API + FT_STATUS WINAPI FT_Purge( + FT_HANDLE ftHandle, + ULONG Mask + ); + + FTD2XX_API + FT_STATUS WINAPI FT_SetTimeouts( + FT_HANDLE ftHandle, + ULONG ReadTimeout, + ULONG WriteTimeout + ); + + FTD2XX_API + FT_STATUS WINAPI FT_GetQueueStatus( + FT_HANDLE ftHandle, + DWORD *dwRxBytes + ); + + FTD2XX_API + FT_STATUS WINAPI FT_SetEventNotification( + FT_HANDLE ftHandle, + DWORD Mask, + PVOID Param + ); + + FTD2XX_API + FT_STATUS WINAPI FT_GetStatus( + FT_HANDLE ftHandle, + DWORD *dwRxBytes, + DWORD *dwTxBytes, + DWORD *dwEventDWord + ); + + FTD2XX_API + FT_STATUS WINAPI FT_SetBreakOn( + FT_HANDLE ftHandle + ); + + FTD2XX_API + FT_STATUS WINAPI FT_SetBreakOff( + FT_HANDLE ftHandle + ); + + FTD2XX_API + FT_STATUS WINAPI FT_SetWaitMask( + FT_HANDLE ftHandle, + DWORD Mask + ); + + FTD2XX_API + FT_STATUS WINAPI FT_WaitOnMask( + FT_HANDLE ftHandle, + DWORD *Mask + ); + + FTD2XX_API + FT_STATUS WINAPI FT_GetEventStatus( + FT_HANDLE ftHandle, + DWORD *dwEventDWord + ); + + FTD2XX_API + FT_STATUS WINAPI FT_ReadEE( + FT_HANDLE ftHandle, + DWORD dwWordOffset, + LPWORD lpwValue + ); + + FTD2XX_API + FT_STATUS WINAPI FT_WriteEE( + FT_HANDLE ftHandle, + DWORD dwWordOffset, + WORD wValue + ); + + FTD2XX_API + FT_STATUS WINAPI FT_EraseEE( + FT_HANDLE ftHandle + ); + + // + // structure to hold program data for FT_EE_Program, FT_EE_ProgramEx, FT_EE_Read + // and FT_EE_ReadEx functions + // + typedef struct ft_program_data { + + DWORD Signature1; // Header - must be 0x00000000 + DWORD Signature2; // Header - must be 0xffffffff + DWORD Version; // Header - FT_PROGRAM_DATA version + // 0 = original + // 1 = FT2232 extensions + // 2 = FT232R extensions + // 3 = FT2232H extensions + // 4 = FT4232H extensions + // 5 = FT232H extensions + + WORD VendorId; // 0x0403 + WORD ProductId; // 0x6001 + char *Manufacturer; // "FTDI" + char *ManufacturerId; // "FT" + char *Description; // "USB HS Serial Converter" + char *SerialNumber; // "FT000001" if fixed, or NULL + WORD MaxPower; // 0 < MaxPower <= 500 + WORD PnP; // 0 = disabled, 1 = enabled + WORD SelfPowered; // 0 = bus powered, 1 = self powered + WORD RemoteWakeup; // 0 = not capable, 1 = capable + // + // Rev4 (FT232B) extensions + // + UCHAR Rev4; // non-zero if Rev4 chip, zero otherwise + UCHAR IsoIn; // non-zero if in endpoint is isochronous + UCHAR IsoOut; // non-zero if out endpoint is isochronous + UCHAR PullDownEnable; // non-zero if pull down enabled + UCHAR SerNumEnable; // non-zero if serial number to be used + UCHAR USBVersionEnable; // non-zero if chip uses USBVersion + WORD USBVersion; // BCD (0x0200 => USB2) + // + // Rev 5 (FT2232) extensions + // + UCHAR Rev5; // non-zero if Rev5 chip, zero otherwise + UCHAR IsoInA; // non-zero if in endpoint is isochronous + UCHAR IsoInB; // non-zero if in endpoint is isochronous + UCHAR IsoOutA; // non-zero if out endpoint is isochronous + UCHAR IsoOutB; // non-zero if out endpoint is isochronous + UCHAR PullDownEnable5; // non-zero if pull down enabled + UCHAR SerNumEnable5; // non-zero if serial number to be used + UCHAR USBVersionEnable5; // non-zero if chip uses USBVersion + WORD USBVersion5; // BCD (0x0200 => USB2) + UCHAR AIsHighCurrent; // non-zero if interface is high current + UCHAR BIsHighCurrent; // non-zero if interface is high current + UCHAR IFAIsFifo; // non-zero if interface is 245 FIFO + UCHAR IFAIsFifoTar; // non-zero if interface is 245 FIFO CPU target + UCHAR IFAIsFastSer; // non-zero if interface is Fast serial + UCHAR AIsVCP; // non-zero if interface is to use VCP drivers + UCHAR IFBIsFifo; // non-zero if interface is 245 FIFO + UCHAR IFBIsFifoTar; // non-zero if interface is 245 FIFO CPU target + UCHAR IFBIsFastSer; // non-zero if interface is Fast serial + UCHAR BIsVCP; // non-zero if interface is to use VCP drivers + // + // Rev 6 (FT232R) extensions + // + UCHAR UseExtOsc; // Use External Oscillator + UCHAR HighDriveIOs; // High Drive I/Os + UCHAR EndpointSize; // Endpoint size + UCHAR PullDownEnableR; // non-zero if pull down enabled + UCHAR SerNumEnableR; // non-zero if serial number to be used + UCHAR InvertTXD; // non-zero if invert TXD + UCHAR InvertRXD; // non-zero if invert RXD + UCHAR InvertRTS; // non-zero if invert RTS + UCHAR InvertCTS; // non-zero if invert CTS + UCHAR InvertDTR; // non-zero if invert DTR + UCHAR InvertDSR; // non-zero if invert DSR + UCHAR InvertDCD; // non-zero if invert DCD + UCHAR InvertRI; // non-zero if invert RI + UCHAR Cbus0; // Cbus Mux control + UCHAR Cbus1; // Cbus Mux control + UCHAR Cbus2; // Cbus Mux control + UCHAR Cbus3; // Cbus Mux control + UCHAR Cbus4; // Cbus Mux control + UCHAR RIsD2XX; // non-zero if using D2XX driver + // + // Rev 7 (FT2232H) Extensions + // + UCHAR PullDownEnable7; // non-zero if pull down enabled + UCHAR SerNumEnable7; // non-zero if serial number to be used + UCHAR ALSlowSlew; // non-zero if AL pins have slow slew + UCHAR ALSchmittInput; // non-zero if AL pins are Schmitt input + UCHAR ALDriveCurrent; // valid values are 4mA, 8mA, 12mA, 16mA + UCHAR AHSlowSlew; // non-zero if AH pins have slow slew + UCHAR AHSchmittInput; // non-zero if AH pins are Schmitt input + UCHAR AHDriveCurrent; // valid values are 4mA, 8mA, 12mA, 16mA + UCHAR BLSlowSlew; // non-zero if BL pins have slow slew + UCHAR BLSchmittInput; // non-zero if BL pins are Schmitt input + UCHAR BLDriveCurrent; // valid values are 4mA, 8mA, 12mA, 16mA + UCHAR BHSlowSlew; // non-zero if BH pins have slow slew + UCHAR BHSchmittInput; // non-zero if BH pins are Schmitt input + UCHAR BHDriveCurrent; // valid values are 4mA, 8mA, 12mA, 16mA + UCHAR IFAIsFifo7; // non-zero if interface is 245 FIFO + UCHAR IFAIsFifoTar7; // non-zero if interface is 245 FIFO CPU target + UCHAR IFAIsFastSer7; // non-zero if interface is Fast serial + UCHAR AIsVCP7; // non-zero if interface is to use VCP drivers + UCHAR IFBIsFifo7; // non-zero if interface is 245 FIFO + UCHAR IFBIsFifoTar7; // non-zero if interface is 245 FIFO CPU target + UCHAR IFBIsFastSer7; // non-zero if interface is Fast serial + UCHAR BIsVCP7; // non-zero if interface is to use VCP drivers + UCHAR PowerSaveEnable; // non-zero if using BCBUS7 to save power for self-powered designs + // + // Rev 8 (FT4232H) Extensions + // + UCHAR PullDownEnable8; // non-zero if pull down enabled + UCHAR SerNumEnable8; // non-zero if serial number to be used + UCHAR ASlowSlew; // non-zero if A pins have slow slew + UCHAR ASchmittInput; // non-zero if A pins are Schmitt input + UCHAR ADriveCurrent; // valid values are 4mA, 8mA, 12mA, 16mA + UCHAR BSlowSlew; // non-zero if B pins have slow slew + UCHAR BSchmittInput; // non-zero if B pins are Schmitt input + UCHAR BDriveCurrent; // valid values are 4mA, 8mA, 12mA, 16mA + UCHAR CSlowSlew; // non-zero if C pins have slow slew + UCHAR CSchmittInput; // non-zero if C pins are Schmitt input + UCHAR CDriveCurrent; // valid values are 4mA, 8mA, 12mA, 16mA + UCHAR DSlowSlew; // non-zero if D pins have slow slew + UCHAR DSchmittInput; // non-zero if D pins are Schmitt input + UCHAR DDriveCurrent; // valid values are 4mA, 8mA, 12mA, 16mA + UCHAR ARIIsTXDEN; // non-zero if port A uses RI as RS485 TXDEN + UCHAR BRIIsTXDEN; // non-zero if port B uses RI as RS485 TXDEN + UCHAR CRIIsTXDEN; // non-zero if port C uses RI as RS485 TXDEN + UCHAR DRIIsTXDEN; // non-zero if port D uses RI as RS485 TXDEN + UCHAR AIsVCP8; // non-zero if interface is to use VCP drivers + UCHAR BIsVCP8; // non-zero if interface is to use VCP drivers + UCHAR CIsVCP8; // non-zero if interface is to use VCP drivers + UCHAR DIsVCP8; // non-zero if interface is to use VCP drivers + // + // Rev 9 (FT232H) Extensions + // + UCHAR PullDownEnableH; // non-zero if pull down enabled + UCHAR SerNumEnableH; // non-zero if serial number to be used + UCHAR ACSlowSlewH; // non-zero if AC pins have slow slew + UCHAR ACSchmittInputH; // non-zero if AC pins are Schmitt input + UCHAR ACDriveCurrentH; // valid values are 4mA, 8mA, 12mA, 16mA + UCHAR ADSlowSlewH; // non-zero if AD pins have slow slew + UCHAR ADSchmittInputH; // non-zero if AD pins are Schmitt input + UCHAR ADDriveCurrentH; // valid values are 4mA, 8mA, 12mA, 16mA + UCHAR Cbus0H; // Cbus Mux control + UCHAR Cbus1H; // Cbus Mux control + UCHAR Cbus2H; // Cbus Mux control + UCHAR Cbus3H; // Cbus Mux control + UCHAR Cbus4H; // Cbus Mux control + UCHAR Cbus5H; // Cbus Mux control + UCHAR Cbus6H; // Cbus Mux control + UCHAR Cbus7H; // Cbus Mux control + UCHAR Cbus8H; // Cbus Mux control + UCHAR Cbus9H; // Cbus Mux control + UCHAR IsFifoH; // non-zero if interface is 245 FIFO + UCHAR IsFifoTarH; // non-zero if interface is 245 FIFO CPU target + UCHAR IsFastSerH; // non-zero if interface is Fast serial + UCHAR IsFT1248H; // non-zero if interface is FT1248 + UCHAR FT1248CpolH; // FT1248 clock polarity - clock idle high (1) or clock idle low (0) + UCHAR FT1248LsbH; // FT1248 data is LSB (1) or MSB (0) + UCHAR FT1248FlowControlH; // FT1248 flow control enable + UCHAR IsVCPH; // non-zero if interface is to use VCP drivers + UCHAR PowerSaveEnableH; // non-zero if using ACBUS7 to save power for self-powered designs + + } FT_PROGRAM_DATA, *PFT_PROGRAM_DATA; + + FTD2XX_API + FT_STATUS WINAPI FT_EE_Program( + FT_HANDLE ftHandle, + PFT_PROGRAM_DATA pData + ); + + FTD2XX_API + FT_STATUS WINAPI FT_EE_ProgramEx( + FT_HANDLE ftHandle, + PFT_PROGRAM_DATA pData, + char *Manufacturer, + char *ManufacturerId, + char *Description, + char *SerialNumber + ); + + FTD2XX_API + FT_STATUS WINAPI FT_EE_Read( + FT_HANDLE ftHandle, + PFT_PROGRAM_DATA pData + ); + + FTD2XX_API + FT_STATUS WINAPI FT_EE_ReadEx( + FT_HANDLE ftHandle, + PFT_PROGRAM_DATA pData, + char *Manufacturer, + char *ManufacturerId, + char *Description, + char *SerialNumber + ); + + FTD2XX_API + FT_STATUS WINAPI FT_EE_UASize( + FT_HANDLE ftHandle, + LPDWORD lpdwSize + ); + + FTD2XX_API + FT_STATUS WINAPI FT_EE_UAWrite( + FT_HANDLE ftHandle, + PUCHAR pucData, + DWORD dwDataLen + ); + + FTD2XX_API + FT_STATUS WINAPI FT_EE_UARead( + FT_HANDLE ftHandle, + PUCHAR pucData, + DWORD dwDataLen, + LPDWORD lpdwBytesRead + ); + + + typedef struct ft_eeprom_header { + FT_DEVICE deviceType; // FTxxxx device type to be programmed + // Device descriptor options + WORD VendorId; // 0x0403 + WORD ProductId; // 0x6001 + UCHAR SerNumEnable; // non-zero if serial number to be used + // Config descriptor options + WORD MaxPower; // 0 < MaxPower <= 500 + UCHAR SelfPowered; // 0 = bus powered, 1 = self powered + UCHAR RemoteWakeup; // 0 = not capable, 1 = capable + // Hardware options + UCHAR PullDownEnable; // non-zero if pull down in suspend enabled + } FT_EEPROM_HEADER, *PFT_EEPROM_HEADER; + + + // FT232B EEPROM structure for use with FT_EEPROM_Read and FT_EEPROM_Program + typedef struct ft_eeprom_232b { + // Common header + FT_EEPROM_HEADER common; // common elements for all device EEPROMs + } FT_EEPROM_232B, *PFT_EEPROM_232B; + + + // FT2232 EEPROM structure for use with FT_EEPROM_Read and FT_EEPROM_Program + typedef struct ft_eeprom_2232 { + // Common header + FT_EEPROM_HEADER common; // common elements for all device EEPROMs + // Drive options + UCHAR AIsHighCurrent; // non-zero if interface is high current + UCHAR BIsHighCurrent; // non-zero if interface is high current + // Hardware options + UCHAR AIsFifo; // non-zero if interface is 245 FIFO + UCHAR AIsFifoTar; // non-zero if interface is 245 FIFO CPU target + UCHAR AIsFastSer; // non-zero if interface is Fast serial + UCHAR BIsFifo; // non-zero if interface is 245 FIFO + UCHAR BIsFifoTar; // non-zero if interface is 245 FIFO CPU target + UCHAR BIsFastSer; // non-zero if interface is Fast serial + // Driver option + UCHAR ADriverType; // + UCHAR BDriverType; // + } FT_EEPROM_2232, *PFT_EEPROM_2232; + + + // FT232R EEPROM structure for use with FT_EEPROM_Read and FT_EEPROM_Program + typedef struct ft_eeprom_232r { + // Common header + FT_EEPROM_HEADER common; // common elements for all device EEPROMs + // Drive options + UCHAR IsHighCurrent; // non-zero if interface is high current + // Hardware options + UCHAR UseExtOsc; // Use External Oscillator + UCHAR InvertTXD; // non-zero if invert TXD + UCHAR InvertRXD; // non-zero if invert RXD + UCHAR InvertRTS; // non-zero if invert RTS + UCHAR InvertCTS; // non-zero if invert CTS + UCHAR InvertDTR; // non-zero if invert DTR + UCHAR InvertDSR; // non-zero if invert DSR + UCHAR InvertDCD; // non-zero if invert DCD + UCHAR InvertRI; // non-zero if invert RI + UCHAR Cbus0; // Cbus Mux control + UCHAR Cbus1; // Cbus Mux control + UCHAR Cbus2; // Cbus Mux control + UCHAR Cbus3; // Cbus Mux control + UCHAR Cbus4; // Cbus Mux control + // Driver option + UCHAR DriverType; // + } FT_EEPROM_232R, *PFT_EEPROM_232R; + + + // FT2232H EEPROM structure for use with FT_EEPROM_Read and FT_EEPROM_Program + typedef struct ft_eeprom_2232h { + // Common header + FT_EEPROM_HEADER common; // common elements for all device EEPROMs + // Drive options + UCHAR ALSlowSlew; // non-zero if AL pins have slow slew + UCHAR ALSchmittInput; // non-zero if AL pins are Schmitt input + UCHAR ALDriveCurrent; // valid values are 4mA, 8mA, 12mA, 16mA + UCHAR AHSlowSlew; // non-zero if AH pins have slow slew + UCHAR AHSchmittInput; // non-zero if AH pins are Schmitt input + UCHAR AHDriveCurrent; // valid values are 4mA, 8mA, 12mA, 16mA + UCHAR BLSlowSlew; // non-zero if BL pins have slow slew + UCHAR BLSchmittInput; // non-zero if BL pins are Schmitt input + UCHAR BLDriveCurrent; // valid values are 4mA, 8mA, 12mA, 16mA + UCHAR BHSlowSlew; // non-zero if BH pins have slow slew + UCHAR BHSchmittInput; // non-zero if BH pins are Schmitt input + UCHAR BHDriveCurrent; // valid values are 4mA, 8mA, 12mA, 16mA + // Hardware options + UCHAR AIsFifo; // non-zero if interface is 245 FIFO + UCHAR AIsFifoTar; // non-zero if interface is 245 FIFO CPU target + UCHAR AIsFastSer; // non-zero if interface is Fast serial + UCHAR BIsFifo; // non-zero if interface is 245 FIFO + UCHAR BIsFifoTar; // non-zero if interface is 245 FIFO CPU target + UCHAR BIsFastSer; // non-zero if interface is Fast serial + UCHAR PowerSaveEnable; // non-zero if using BCBUS7 to save power for self-powered designs + // Driver option + UCHAR ADriverType; // + UCHAR BDriverType; // + } FT_EEPROM_2232H, *PFT_EEPROM_2232H; + + + // FT4232H EEPROM structure for use with FT_EEPROM_Read and FT_EEPROM_Program + typedef struct ft_eeprom_4232h { + // Common header + FT_EEPROM_HEADER common; // common elements for all device EEPROMs + // Drive options + UCHAR ASlowSlew; // non-zero if A pins have slow slew + UCHAR ASchmittInput; // non-zero if A pins are Schmitt input + UCHAR ADriveCurrent; // valid values are 4mA, 8mA, 12mA, 16mA + UCHAR BSlowSlew; // non-zero if B pins have slow slew + UCHAR BSchmittInput; // non-zero if B pins are Schmitt input + UCHAR BDriveCurrent; // valid values are 4mA, 8mA, 12mA, 16mA + UCHAR CSlowSlew; // non-zero if C pins have slow slew + UCHAR CSchmittInput; // non-zero if C pins are Schmitt input + UCHAR CDriveCurrent; // valid values are 4mA, 8mA, 12mA, 16mA + UCHAR DSlowSlew; // non-zero if D pins have slow slew + UCHAR DSchmittInput; // non-zero if D pins are Schmitt input + UCHAR DDriveCurrent; // valid values are 4mA, 8mA, 12mA, 16mA + // Hardware options + UCHAR ARIIsTXDEN; // non-zero if port A uses RI as RS485 TXDEN + UCHAR BRIIsTXDEN; // non-zero if port B uses RI as RS485 TXDEN + UCHAR CRIIsTXDEN; // non-zero if port C uses RI as RS485 TXDEN + UCHAR DRIIsTXDEN; // non-zero if port D uses RI as RS485 TXDEN + // Driver option + UCHAR ADriverType; // + UCHAR BDriverType; // + UCHAR CDriverType; // + UCHAR DDriverType; // + } FT_EEPROM_4232H, *PFT_EEPROM_4232H; + + + // FT232H EEPROM structure for use with FT_EEPROM_Read and FT_EEPROM_Program + typedef struct ft_eeprom_232h { + // Common header + FT_EEPROM_HEADER common; // common elements for all device EEPROMs + // Drive options + UCHAR ACSlowSlew; // non-zero if AC bus pins have slow slew + UCHAR ACSchmittInput; // non-zero if AC bus pins are Schmitt input + UCHAR ACDriveCurrent; // valid values are 4mA, 8mA, 12mA, 16mA + UCHAR ADSlowSlew; // non-zero if AD bus pins have slow slew + UCHAR ADSchmittInput; // non-zero if AD bus pins are Schmitt input + UCHAR ADDriveCurrent; // valid values are 4mA, 8mA, 12mA, 16mA + // CBUS options + UCHAR Cbus0; // Cbus Mux control + UCHAR Cbus1; // Cbus Mux control + UCHAR Cbus2; // Cbus Mux control + UCHAR Cbus3; // Cbus Mux control + UCHAR Cbus4; // Cbus Mux control + UCHAR Cbus5; // Cbus Mux control + UCHAR Cbus6; // Cbus Mux control + UCHAR Cbus7; // Cbus Mux control + UCHAR Cbus8; // Cbus Mux control + UCHAR Cbus9; // Cbus Mux control + // FT1248 options + UCHAR FT1248Cpol; // FT1248 clock polarity - clock idle high (1) or clock idle low (0) + UCHAR FT1248Lsb; // FT1248 data is LSB (1) or MSB (0) + UCHAR FT1248FlowControl; // FT1248 flow control enable + // Hardware options + UCHAR IsFifo; // non-zero if interface is 245 FIFO + UCHAR IsFifoTar; // non-zero if interface is 245 FIFO CPU target + UCHAR IsFastSer; // non-zero if interface is Fast serial + UCHAR IsFT1248 ; // non-zero if interface is FT1248 + UCHAR PowerSaveEnable; // + // Driver option + UCHAR DriverType; // + } FT_EEPROM_232H, *PFT_EEPROM_232H; + + + // FT X Series EEPROM structure for use with FT_EEPROM_Read and FT_EEPROM_Program + typedef struct ft_eeprom_x_series { + // Common header + FT_EEPROM_HEADER common; // common elements for all device EEPROMs + // Drive options + UCHAR ACSlowSlew; // non-zero if AC bus pins have slow slew + UCHAR ACSchmittInput; // non-zero if AC bus pins are Schmitt input + UCHAR ACDriveCurrent; // valid values are 4mA, 8mA, 12mA, 16mA + UCHAR ADSlowSlew; // non-zero if AD bus pins have slow slew + UCHAR ADSchmittInput; // non-zero if AD bus pins are Schmitt input + UCHAR ADDriveCurrent; // valid values are 4mA, 8mA, 12mA, 16mA + // CBUS options + UCHAR Cbus0; // Cbus Mux control + UCHAR Cbus1; // Cbus Mux control + UCHAR Cbus2; // Cbus Mux control + UCHAR Cbus3; // Cbus Mux control + UCHAR Cbus4; // Cbus Mux control + UCHAR Cbus5; // Cbus Mux control + UCHAR Cbus6; // Cbus Mux control + // UART signal options + UCHAR InvertTXD; // non-zero if invert TXD + UCHAR InvertRXD; // non-zero if invert RXD + UCHAR InvertRTS; // non-zero if invert RTS + UCHAR InvertCTS; // non-zero if invert CTS + UCHAR InvertDTR; // non-zero if invert DTR + UCHAR InvertDSR; // non-zero if invert DSR + UCHAR InvertDCD; // non-zero if invert DCD + UCHAR InvertRI; // non-zero if invert RI + // Battery Charge Detect options + UCHAR BCDEnable; // Enable Battery Charger Detection + UCHAR BCDForceCbusPWREN; // asserts the power enable signal on CBUS when charging port detected + UCHAR BCDDisableSleep; // forces the device never to go into sleep mode + // I2C options + WORD I2CSlaveAddress; // I2C slave device address + DWORD I2CDeviceId; // I2C device ID + UCHAR I2CDisableSchmitt; // Disable I2C Schmitt trigger + // FT1248 options + UCHAR FT1248Cpol; // FT1248 clock polarity - clock idle high (1) or clock idle low (0) + UCHAR FT1248Lsb; // FT1248 data is LSB (1) or MSB (0) + UCHAR FT1248FlowControl; // FT1248 flow control enable + // Hardware options + UCHAR RS485EchoSuppress; // + UCHAR PowerSaveEnable; // + // Driver option + UCHAR DriverType; // + } FT_EEPROM_X_SERIES, *PFT_EEPROM_X_SERIES; + + + FTD2XX_API + FT_STATUS WINAPI FT_EEPROM_Read( + FT_HANDLE ftHandle, + void *eepromData, + DWORD eepromDataSize, + char *Manufacturer, + char *ManufacturerId, + char *Description, + char *SerialNumber + ); + + + FTD2XX_API + FT_STATUS WINAPI FT_EEPROM_Program( + FT_HANDLE ftHandle, + void *eepromData, + DWORD eepromDataSize, + char *Manufacturer, + char *ManufacturerId, + char *Description, + char *SerialNumber + ); + + + FTD2XX_API + FT_STATUS WINAPI FT_SetLatencyTimer( + FT_HANDLE ftHandle, + UCHAR ucLatency + ); + + FTD2XX_API + FT_STATUS WINAPI FT_GetLatencyTimer( + FT_HANDLE ftHandle, + PUCHAR pucLatency + ); + + FTD2XX_API + FT_STATUS WINAPI FT_SetBitMode( + FT_HANDLE ftHandle, + UCHAR ucMask, + UCHAR ucEnable + ); + + FTD2XX_API + FT_STATUS WINAPI FT_GetBitMode( + FT_HANDLE ftHandle, + PUCHAR pucMode + ); + + FTD2XX_API + FT_STATUS WINAPI FT_SetUSBParameters( + FT_HANDLE ftHandle, + ULONG ulInTransferSize, + ULONG ulOutTransferSize + ); + + FTD2XX_API + FT_STATUS WINAPI FT_SetDeadmanTimeout( + FT_HANDLE ftHandle, + ULONG ulDeadmanTimeout + ); + +#ifndef _WIN32 + // Extra functions for non-Windows platforms to compensate + // for lack of .INF file to specify Vendor and Product IDs. + + FTD2XX_API + FT_STATUS FT_SetVIDPID( + DWORD dwVID, + DWORD dwPID + ); + + FTD2XX_API + FT_STATUS FT_GetVIDPID( + DWORD * pdwVID, + DWORD * pdwPID + ); + + FTD2XX_API + FT_STATUS WINAPI FT_GetDeviceLocId( + FT_HANDLE ftHandle, + LPDWORD lpdwLocId + ); +#endif // _WIN32 + + FTD2XX_API + FT_STATUS WINAPI FT_GetDeviceInfo( + FT_HANDLE ftHandle, + FT_DEVICE *lpftDevice, + LPDWORD lpdwID, + PCHAR SerialNumber, + PCHAR Description, + LPVOID Dummy + ); + + FTD2XX_API + FT_STATUS WINAPI FT_StopInTask( + FT_HANDLE ftHandle + ); + + FTD2XX_API + FT_STATUS WINAPI FT_RestartInTask( + FT_HANDLE ftHandle + ); + + FTD2XX_API + FT_STATUS WINAPI FT_SetResetPipeRetryCount( + FT_HANDLE ftHandle, + DWORD dwCount + ); + + FTD2XX_API + FT_STATUS WINAPI FT_ResetPort( + FT_HANDLE ftHandle + ); + + FTD2XX_API + FT_STATUS WINAPI FT_CyclePort( + FT_HANDLE ftHandle + ); + + + // + // Win32-type functions + // + + FTD2XX_API + FT_HANDLE WINAPI FT_W32_CreateFile( + LPCTSTR lpszName, + DWORD dwAccess, + DWORD dwShareMode, + LPSECURITY_ATTRIBUTES lpSecurityAttributes, + DWORD dwCreate, + DWORD dwAttrsAndFlags, + HANDLE hTemplate + ); + + FTD2XX_API + BOOL WINAPI FT_W32_CloseHandle( + FT_HANDLE ftHandle + ); + + FTD2XX_API + BOOL WINAPI FT_W32_ReadFile( + FT_HANDLE ftHandle, + LPVOID lpBuffer, + DWORD nBufferSize, + LPDWORD lpBytesReturned, + LPOVERLAPPED lpOverlapped + ); + + FTD2XX_API + BOOL WINAPI FT_W32_WriteFile( + FT_HANDLE ftHandle, + LPVOID lpBuffer, + DWORD nBufferSize, + LPDWORD lpBytesWritten, + LPOVERLAPPED lpOverlapped + ); + + FTD2XX_API + DWORD WINAPI FT_W32_GetLastError( + FT_HANDLE ftHandle + ); + + FTD2XX_API + BOOL WINAPI FT_W32_GetOverlappedResult( + FT_HANDLE ftHandle, + LPOVERLAPPED lpOverlapped, + LPDWORD lpdwBytesTransferred, + BOOL bWait + ); + + FTD2XX_API + BOOL WINAPI FT_W32_CancelIo( + FT_HANDLE ftHandle + ); + + + // + // Win32 COMM API type functions + // + typedef struct _FTCOMSTAT { + DWORD fCtsHold : 1; + DWORD fDsrHold : 1; + DWORD fRlsdHold : 1; + DWORD fXoffHold : 1; + DWORD fXoffSent : 1; + DWORD fEof : 1; + DWORD fTxim : 1; + DWORD fReserved : 25; + DWORD cbInQue; + DWORD cbOutQue; + } FTCOMSTAT, *LPFTCOMSTAT; + + typedef struct _FTDCB { + DWORD DCBlength; /* sizeof(FTDCB) */ + DWORD BaudRate; /* Baudrate at which running */ + DWORD fBinary: 1; /* Binary Mode (skip EOF check) */ + DWORD fParity: 1; /* Enable parity checking */ + DWORD fOutxCtsFlow:1; /* CTS handshaking on output */ + DWORD fOutxDsrFlow:1; /* DSR handshaking on output */ + DWORD fDtrControl:2; /* DTR Flow control */ + DWORD fDsrSensitivity:1; /* DSR Sensitivity */ + DWORD fTXContinueOnXoff: 1; /* Continue TX when Xoff sent */ + DWORD fOutX: 1; /* Enable output X-ON/X-OFF */ + DWORD fInX: 1; /* Enable input X-ON/X-OFF */ + DWORD fErrorChar: 1; /* Enable Err Replacement */ + DWORD fNull: 1; /* Enable Null stripping */ + DWORD fRtsControl:2; /* Rts Flow control */ + DWORD fAbortOnError:1; /* Abort all reads and writes on Error */ + DWORD fDummy2:17; /* Reserved */ + WORD wReserved; /* Not currently used */ + WORD XonLim; /* Transmit X-ON threshold */ + WORD XoffLim; /* Transmit X-OFF threshold */ + BYTE ByteSize; /* Number of bits/byte, 4-8 */ + BYTE Parity; /* 0-4=None,Odd,Even,Mark,Space */ + BYTE StopBits; /* FT_STOP_BITS_1 or FT_STOP_BITS_2 */ + char XonChar; /* Tx and Rx X-ON character */ + char XoffChar; /* Tx and Rx X-OFF character */ + char ErrorChar; /* Error replacement char */ + char EofChar; /* End of Input character */ + char EvtChar; /* Received Event character */ + WORD wReserved1; /* Fill for now. */ + } FTDCB, *LPFTDCB; + + typedef struct _FTTIMEOUTS { + DWORD ReadIntervalTimeout; /* Maximum time between read chars. */ + DWORD ReadTotalTimeoutMultiplier; /* Multiplier of characters. */ + DWORD ReadTotalTimeoutConstant; /* Constant in milliseconds. */ + DWORD WriteTotalTimeoutMultiplier; /* Multiplier of characters. */ + DWORD WriteTotalTimeoutConstant; /* Constant in milliseconds. */ + } FTTIMEOUTS,*LPFTTIMEOUTS; + + + FTD2XX_API + BOOL WINAPI FT_W32_ClearCommBreak( + FT_HANDLE ftHandle + ); + + FTD2XX_API + BOOL WINAPI FT_W32_ClearCommError( + FT_HANDLE ftHandle, + LPDWORD lpdwErrors, + LPFTCOMSTAT lpftComstat + ); + + FTD2XX_API + BOOL WINAPI FT_W32_EscapeCommFunction( + FT_HANDLE ftHandle, + DWORD dwFunc + ); + + FTD2XX_API + BOOL WINAPI FT_W32_GetCommModemStatus( + FT_HANDLE ftHandle, + LPDWORD lpdwModemStatus + ); + + FTD2XX_API + BOOL WINAPI FT_W32_GetCommState( + FT_HANDLE ftHandle, + LPFTDCB lpftDcb + ); + + FTD2XX_API + BOOL WINAPI FT_W32_GetCommTimeouts( + FT_HANDLE ftHandle, + FTTIMEOUTS *pTimeouts + ); + + FTD2XX_API + BOOL WINAPI FT_W32_PurgeComm( + FT_HANDLE ftHandle, + DWORD dwMask + ); + + FTD2XX_API + BOOL WINAPI FT_W32_SetCommBreak( + FT_HANDLE ftHandle + ); + + FTD2XX_API + BOOL WINAPI FT_W32_SetCommMask( + FT_HANDLE ftHandle, + ULONG ulEventMask + ); + + FTD2XX_API + BOOL WINAPI FT_W32_GetCommMask( + FT_HANDLE ftHandle, + LPDWORD lpdwEventMask + ); + + FTD2XX_API + BOOL WINAPI FT_W32_SetCommState( + FT_HANDLE ftHandle, + LPFTDCB lpftDcb + ); + + FTD2XX_API + BOOL WINAPI FT_W32_SetCommTimeouts( + FT_HANDLE ftHandle, + FTTIMEOUTS *pTimeouts + ); + + FTD2XX_API + BOOL WINAPI FT_W32_SetupComm( + FT_HANDLE ftHandle, + DWORD dwReadBufferSize, + DWORD dwWriteBufferSize + ); + + FTD2XX_API + BOOL WINAPI FT_W32_WaitCommEvent( + FT_HANDLE ftHandle, + PULONG pulEvent, + LPOVERLAPPED lpOverlapped + ); + + + // + // Device information + // + + typedef struct _ft_device_list_info_node { + ULONG Flags; + ULONG Type; + ULONG ID; + DWORD LocId; + char SerialNumber[16]; + char Description[64]; + FT_HANDLE ftHandle; + } FT_DEVICE_LIST_INFO_NODE; + + // Device information flags + enum { + FT_FLAGS_OPENED = 1, + FT_FLAGS_HISPEED = 2 + }; + + + FTD2XX_API + FT_STATUS WINAPI FT_CreateDeviceInfoList( + LPDWORD lpdwNumDevs + ); + + FTD2XX_API + FT_STATUS WINAPI FT_GetDeviceInfoList( + FT_DEVICE_LIST_INFO_NODE *pDest, + LPDWORD lpdwNumDevs + ); + + FTD2XX_API + FT_STATUS WINAPI FT_GetDeviceInfoDetail( + DWORD dwIndex, + LPDWORD lpdwFlags, + LPDWORD lpdwType, + LPDWORD lpdwID, + LPDWORD lpdwLocId, + LPVOID lpSerialNumber, + LPVOID lpDescription, + FT_HANDLE *pftHandle + ); + + + // + // Version information + // + + FTD2XX_API + FT_STATUS WINAPI FT_GetDriverVersion( + FT_HANDLE ftHandle, + LPDWORD lpdwVersion + ); + + FTD2XX_API + FT_STATUS WINAPI FT_GetLibraryVersion( + LPDWORD lpdwVersion + ); + + + FTD2XX_API + FT_STATUS WINAPI FT_Rescan( + void + ); + + FTD2XX_API + FT_STATUS WINAPI FT_Reload( + WORD wVid, + WORD wPid + ); + + FTD2XX_API + FT_STATUS WINAPI FT_GetComPortNumber( + FT_HANDLE ftHandle, + LPLONG lpdwComPortNumber + ); + + + // + // FT232H additional EEPROM functions + // + + FTD2XX_API + FT_STATUS WINAPI FT_EE_ReadConfig( + FT_HANDLE ftHandle, + UCHAR ucAddress, + PUCHAR pucValue + ); + + FTD2XX_API + FT_STATUS WINAPI FT_EE_WriteConfig( + FT_HANDLE ftHandle, + UCHAR ucAddress, + UCHAR ucValue + ); + + FTD2XX_API + FT_STATUS WINAPI FT_EE_ReadECC( + FT_HANDLE ftHandle, + UCHAR ucOption, + LPWORD lpwValue + ); + + FTD2XX_API + FT_STATUS WINAPI FT_GetQueueStatusEx( + FT_HANDLE ftHandle, + DWORD *dwRxBytes + ); + + FTD2XX_API + FT_STATUS WINAPI FT_ComPortIdle( + FT_HANDLE ftHandle + ); + + FTD2XX_API + FT_STATUS WINAPI FT_ComPortCancelIdle( + FT_HANDLE ftHandle + ); + + FTD2XX_API + FT_STATUS WINAPI FT_VendorCmdGet( + FT_HANDLE ftHandle, + UCHAR Request, + UCHAR *Buf, + USHORT Len + ); + + FTD2XX_API + FT_STATUS WINAPI FT_VendorCmdSet( + FT_HANDLE ftHandle, + UCHAR Request, + UCHAR *Buf, + USHORT Len + ); + + FTD2XX_API + FT_STATUS WINAPI FT_VendorCmdGetEx( + FT_HANDLE ftHandle, + USHORT wValue, + UCHAR *Buf, + USHORT Len + ); + + FTD2XX_API + FT_STATUS WINAPI FT_VendorCmdSetEx( + FT_HANDLE ftHandle, + USHORT wValue, + UCHAR *Buf, + USHORT Len + ); + +#ifdef __cplusplus +} +#endif + + +#endif /* FTD2XX_H */ + diff --git a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ft232h/Driver/AssemblyInfo.cs b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ft232h/Driver/AssemblyInfo.cs new file mode 100644 index 0000000000..00e534e733 --- /dev/null +++ b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ft232h/Driver/AssemblyInfo.cs @@ -0,0 +1,4 @@ + +using System.Runtime.CompilerServices; + +[assembly: InternalsVisibleTo("FT232.Unit.Tests")] \ No newline at end of file diff --git a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ft232h/Driver/Exceptions.cs b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ft232h/Driver/Exceptions.cs new file mode 100644 index 0000000000..b991346e09 --- /dev/null +++ b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ft232h/Driver/Exceptions.cs @@ -0,0 +1,33 @@ +using System; + +namespace Meadow.Foundation.ICs.IOExpanders; + +/// +/// Represents an exception thrown when no FT232 device is found during a connection check. +/// +public class DeviceNotFoundException : Exception +{ + /// + /// Initializes a new instance of the class + /// with a default error message instructing to check the connection. + /// + internal DeviceNotFoundException() + : base("No FT232 device found. Check your connection") + { + } +} + +/// +/// Represents an exception thrown when the Ftd2xx driver is not installed for device operation in Ftd2xx mode. +/// +public class DriverNotInstalledException : Exception +{ + /// + /// Initializes a new instance of the class + /// with a default error message indicating that the Ftd2xx driver must be installed. + /// + internal DriverNotInstalledException() + : base("The Ftd2xx driver must be installed to use the device in Ftd2xx mode.") + { + } +} diff --git a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ft232h/Driver/Ft232DigitalOutputPort.cs b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ft232h/Driver/Ft232DigitalOutputPort.cs index 6c20155878..0ef7b5ec56 100644 --- a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ft232h/Driver/Ft232DigitalOutputPort.cs +++ b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ft232h/Driver/Ft232DigitalOutputPort.cs @@ -6,20 +6,20 @@ namespace Meadow.Foundation.ICs.IOExpanders /// /// Digital output port for FT232 devices. /// - public sealed class Ft232DigitalOutputPort : DigitalOutputPortBase + public sealed class MpsseDigitalOutputPort : DigitalOutputPortBase { private readonly IFt232Bus _bus; private bool _state; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The pin to use. /// The digital channel info. /// The initial state of the output port. /// The initial output type. /// The FT232 bus. - internal Ft232DigitalOutputPort(IPin pin, IDigitalChannelInfo info, bool initialState, OutputType initialOutputType, IFt232Bus bus) + internal MpsseDigitalOutputPort(IPin pin, IDigitalChannelInfo info, bool initialState, OutputType initialOutputType, IFt232Bus bus) : base(pin, info, initialState, initialOutputType) { if (initialOutputType != OutputType.PushPull) @@ -50,10 +50,10 @@ public override bool State } else { - s &= (byte)~((byte)Pin.Key); + s &= (byte)~(byte)Pin.Key; } - var result = Native.Functions.FT_WriteGPIO(_bus.Handle, _bus.GpioDirectionMask, s); + var result = Native.Mpsse.FT_WriteGPIO(_bus.Handle, _bus.GpioDirectionMask, s); Native.CheckStatus(result); _bus.GpioState = s; diff --git a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ft232h/Driver/Ft232I2cBus.cs b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ft232h/Driver/Ft232I2cBus.cs deleted file mode 100644 index 5cd0a02b6b..0000000000 --- a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ft232h/Driver/Ft232I2cBus.cs +++ /dev/null @@ -1,165 +0,0 @@ -using Meadow.Hardware; -using System; -using System.Diagnostics; -using System.Runtime.InteropServices; -using static Meadow.Foundation.ICs.IOExpanders.Native; - -namespace Meadow.Foundation.ICs.IOExpanders -{ - /// - /// Represents an I2C bus using the FT232H USB to I2C bridge. - /// - public sealed class Ft232I2cBus : IFt232Bus, II2cBus, IDisposable - { - private const byte DefaultLatencyTimer = 10; - private const I2CChannelOptions DefaultChannelOptions = I2CChannelOptions.None; - - private bool _isDisposed; - - /// - /// Gets the handle for the FT232H I2C bus. - /// - public IntPtr Handle { get; private set; } - - /// - /// Gets or sets the GPIO direction mask for the FT232H I2C bus. - /// - public byte GpioDirectionMask { get; set; } - - /// - /// Gets or sets the GPIO state for the FT232H I2C bus. - /// - public byte GpioState { get; set; } - - internal bool IsOpen { get; private set; } = false; - internal int ChannelNumber { get; } - private FT_DEVICE_LIST_INFO_NODE InfoNode { get; } - - /// - /// Initializes a new instance of the class. - /// - internal Ft232I2cBus(int channelNumber, FT_DEVICE_LIST_INFO_NODE info) - { - ChannelNumber = channelNumber; - InfoNode = info; - } - - /// - /// Gets or sets the bus speed for the FT232H I2C bus. - /// - public I2cBusSpeed BusSpeed { get; set; } - - private void Dispose(bool disposing) - { - if (!_isDisposed) - { - CloseChannel(); - - _isDisposed = true; - } - } - - /// - /// Finalizes an instance of the class. - /// - ~Ft232I2cBus() - { - // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method - Dispose(false); - } - - /// - /// Releases the unmanaged resources used by the object. - /// - public void Dispose() - { - // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method - Dispose(true); - GC.SuppressFinalize(this); - } - - internal void Open(I2CClockRate clockRate = I2CClockRate.Standard) - { - if (CheckStatus(Functions.I2C_OpenChannel(ChannelNumber, out IntPtr handle))) - { - Handle = handle; - - var config = new I2CChannelConfig - { - ClockRate = clockRate, - LatencyTimer = DefaultLatencyTimer, - Options = DefaultChannelOptions - }; - - CheckStatus(Functions.I2C_InitChannel(Handle, ref config)); - - IsOpen = true; - } - } - - private void CloseChannel() - { - if (Handle != IntPtr.Zero) - { - CheckStatus(Functions.I2C_CloseChannel(Handle)); - Handle = IntPtr.Zero; - } - } - - /// - /// Exchanges data with a peripheral on the I2C bus. - /// - /// The address of the peripheral device. - /// The data to write to the peripheral. - /// The data to read from the peripheral. - public void Exchange(byte peripheralAddress, Span writeBuffer, Span readBuffer) - { - Write(peripheralAddress, writeBuffer); - Read(peripheralAddress, readBuffer); - } - - /// - /// Reads data from a peripheral on the I2C bus. - /// - /// The address of the peripheral device. - /// The buffer to store the read data. - public void Read(byte peripheralAddress, Span readBuffer) - { - var status = Functions.I2C_DeviceRead( - Handle, - peripheralAddress, - readBuffer.Length, - MemoryMarshal.GetReference(readBuffer), - out int transferred, - I2CTransferOptions.FAST_TRANSFER | I2CTransferOptions.FAST_TRANSFER_BYTES - //I2CTransferOptions.START_BIT | I2CTransferOptions.STOP_BIT | I2CTransferOptions.NACK_LAST_BYTE - //I2CTransferOptions.START_BIT | I2CTransferOptions.STOP_BIT | I2CTransferOptions.FAST_TRANSFER | I2CTransferOptions.NACK_LAST_BYTE - ); - - Debug.WriteLine($"transferred: {transferred}"); - CheckStatus(status); - } - - /// - /// Writes data to a peripheral on the I2C bus. - /// - /// The address of the peripheral device. - /// The data to write to the peripheral. - public void Write(byte peripheralAddress, Span writeBuffer) - { - var status = Functions.I2C_DeviceWrite( - Handle, - peripheralAddress, - writeBuffer.Length, - MemoryMarshal.GetReference(writeBuffer), - out int transferred, - I2CTransferOptions.FAST_TRANSFER | I2CTransferOptions.FAST_TRANSFER_BYTES - //I2CTransferOptions.START_BIT | I2CTransferOptions.BREAK_ON_NACK - //I2CTransferOptions.START_BIT | I2CTransferOptions.STOP_BIT | I2CTransferOptions.NACK_LAST_BYTE - ); - - Debug.WriteLine($"transferred: {transferred}"); - // CheckStatus(status); - } - } -} diff --git a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ft232h/Driver/Ft232SpiBus.cs b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ft232h/Driver/Ft232SpiBus.cs index a5acd246f8..0dfeab01b4 100644 --- a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ft232h/Driver/Ft232SpiBus.cs +++ b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ft232h/Driver/Ft232SpiBus.cs @@ -5,288 +5,273 @@ using static Meadow.Foundation.ICs.IOExpanders.Ft232h; using static Meadow.Foundation.ICs.IOExpanders.Native; -namespace Meadow.Foundation.ICs.IOExpanders +namespace Meadow.Foundation.ICs.IOExpanders; + +/// +/// Represents an SPI bus implementation using the FT232 device. +/// +public sealed class Ft232SpiBus : IFt232Bus, ISpiBus, IDisposable { /// - /// Represents an SPI bus using the FT232H USB to SPI bridge. + /// The default SPI clock rate for the FT232H /// - public sealed class Ft232SpiBus : IFt232Bus, ISpiBus, IDisposable - { - /// - /// The default clock rate for the FT232 SPI bus. - /// - public const uint DefaultClockRate = 25000000; + public const uint DefaultClockRate = 25000000; + private const byte DefaultLatencyTimer = 10; // from the FTDI sample - private const byte DefaultLatencyTimer = 10; // from the FTDI sample + private bool _isDisposed; - private bool _isDisposed; + private SpiClockConfiguration _config = default!; + private SpiChannelConfig _channelConfig; - private SpiClockConfiguration _config; - private SpiChannelConfig _channelConfig; + /// + public IntPtr Handle { get; private set; } + /// + public byte GpioDirectionMask { get; set; } + /// + public byte GpioState { get; set; } + internal bool IsOpen { get; private set; } = false; + internal int ChannelNumber { get; } + private FT_DEVICE_LIST_INFO_NODE InfoNode { get; } - /// - /// Gets the handle for the FT232H SPI bus. - /// - public IntPtr Handle { get; private set; } + /// + public Frequency[] SupportedSpeeds => new Frequency[] { new Frequency(30d, Frequency.UnitType.Megahertz) }; - /// - /// Gets or sets the GPIO direction mask for the FT232H SPI bus. - /// - public byte GpioDirectionMask { get; set; } + internal Ft232SpiBus(int channelNumber, FT_DEVICE_LIST_INFO_NODE info) + { + ChannelNumber = channelNumber; + InfoNode = info; + } - /// - /// Gets or sets the GPIO state for the FT232H SPI bus. - /// - public byte GpioState { get; set; } + private void Dispose(bool disposing) + { + if (!_isDisposed) + { + CloseChannel(); - internal bool IsOpen { get; private set; } = false; - internal int ChannelNumber { get; } - private FT_DEVICE_LIST_INFO_NODE InfoNode { get; } + _isDisposed = true; + } + } - /// - /// Gets the supported SPI bus speeds for the FT232H SPI bus. - /// - public Frequency[] SupportedSpeeds => new Frequency[] { new Frequency(30d, Frequency.UnitType.Megahertz) }; + /// + /// Finalizer for the Ft232SpiBus class, used to release unmanaged resources. + /// + ~Ft232SpiBus() + { + // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method + Dispose(false); + } - internal Ft232SpiBus(int channelNumber, FT_DEVICE_LIST_INFO_NODE info) + /// + public SpiClockConfiguration Configuration + { + get { return _config; } + set { - ChannelNumber = channelNumber; - InfoNode = info; + _channelConfig = CreateChannelConfig(value); + _config = value; + this.Configuration.Changed += OnConfigurationChanged; } + } - private void Dispose(bool disposing) - { - if (!_isDisposed) - { - CloseChannel(); - - _isDisposed = true; - } - } + private void OnConfigurationChanged(object sender, EventArgs e) + { + var changed = false; - /// - /// Finalizes an instance of the class. - /// - ~Ft232SpiBus() + if (Configuration.Speed.Hertz != _channelConfig.ClockRate) { - // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method - Dispose(false); + _channelConfig.ClockRate = (uint)Configuration.Speed.Hertz; + changed = true; } - /// - /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. - /// - public void Dispose() + switch (Configuration.SpiMode) { - // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method - Dispose(true); - GC.SuppressFinalize(this); + case SpiClockConfiguration.Mode.Mode0: + if ((_channelConfig.Options & SpiConfigOptions.MODE3) != SpiConfigOptions.MODE0) + { + _channelConfig.Options |= SpiConfigOptions.MODE0; + changed = true; + } + break; + case SpiClockConfiguration.Mode.Mode1: + if ((_channelConfig.Options & SpiConfigOptions.MODE3) != SpiConfigOptions.MODE1) + { + _channelConfig.Options = (_channelConfig.Options & ~SpiConfigOptions.MODE3) | SpiConfigOptions.MODE1; + changed = true; + } + break; + case SpiClockConfiguration.Mode.Mode2: + if ((_channelConfig.Options & SpiConfigOptions.MODE3) != SpiConfigOptions.MODE2) + { + _channelConfig.Options = (_channelConfig.Options & ~SpiConfigOptions.MODE3) | SpiConfigOptions.MODE2; + changed = true; + } + break; + case SpiClockConfiguration.Mode.Mode3: + if ((_channelConfig.Options & SpiConfigOptions.MODE3) != SpiConfigOptions.MODE3) + { + _channelConfig.Options = (_channelConfig.Options & ~SpiConfigOptions.MODE3) | SpiConfigOptions.MODE3; + changed = true; + } + break; } - internal void Open(SpiClockConfiguration config) + if (changed) { - Configuration = config; + CheckStatus(Mpsse.SPI_InitChannel(Handle, ref _channelConfig)); + } + } - if (CheckStatus(Functions.SPI_OpenChannel(ChannelNumber, out IntPtr handle))) - { - Handle = handle; + /// + public void Dispose() + { + // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method + Dispose(true); + GC.SuppressFinalize(this); + } - CheckStatus(Functions.SPI_InitChannel(Handle, ref _channelConfig)); - } - } + internal void Open(SpiClockConfiguration config) + { + Configuration = config; - private void CloseChannel() + if (CheckStatus(Mpsse.SPI_OpenChannel(ChannelNumber, out IntPtr handle))) { - if (Handle != IntPtr.Zero) - { - CheckStatus(Functions.SPI_CloseChannel(Handle)); - Handle = IntPtr.Zero; - } + Handle = handle; + + CheckStatus(Mpsse.SPI_InitChannel(Handle, ref _channelConfig)); } + } - private SpiChannelConfig CreateChannelConfig(SpiClockConfiguration config) + private void CloseChannel() + { + if (Handle != IntPtr.Zero) { - // For now, we support CS on D3 and that's it - Ft232h.SpiConfigOptions opts = SpiConfigOptions.CS_ACTIVELOW | SpiConfigOptions.CS_DBUS3; - - switch (config.SpiMode) - { - case SpiClockConfiguration.Mode.Mode0: - opts = SpiConfigOptions.MODE0; - break; - case SpiClockConfiguration.Mode.Mode1: - opts = SpiConfigOptions.MODE1; - break; - case SpiClockConfiguration.Mode.Mode2: - opts = SpiConfigOptions.MODE2; - break; - case SpiClockConfiguration.Mode.Mode3: - opts = SpiConfigOptions.MODE3; - break; - } - - return new SpiChannelConfig - { - ClockRate = (uint)config.Speed.Hertz, - LatencyTimer = DefaultLatencyTimer, - Options = opts - }; + CheckStatus(Mpsse.SPI_CloseChannel(Handle)); + Handle = IntPtr.Zero; } + } - private SPITransferOptions CreateTransferOptions(ChipSelectMode mode) + private SpiChannelConfig CreateChannelConfig(SpiClockConfiguration config) + { + // for now we support CS on D3 and that's it + Ft232h.SpiConfigOptions opts = SpiConfigOptions.CS_ACTIVELOW | SpiConfigOptions.CS_DBUS3; + + switch (config.SpiMode) { - SPITransferOptions opts = SPITransferOptions.SIZE_IN_BYTES; - - switch (mode) - { - case ChipSelectMode.ActiveLow: - opts |= SPITransferOptions.CHIPSELECT_DISABLE; - break; - case ChipSelectMode.ActiveHigh: - opts |= SPITransferOptions.CHIPSELECT_ENABLE; - break; - } - - return opts; + case SpiClockConfiguration.Mode.Mode0: + opts = SpiConfigOptions.MODE0; + break; + case SpiClockConfiguration.Mode.Mode1: + opts = SpiConfigOptions.MODE1; + break; + case SpiClockConfiguration.Mode.Mode2: + opts = SpiConfigOptions.MODE2; + break; + case SpiClockConfiguration.Mode.Mode3: + opts = SpiConfigOptions.MODE3; + break; } - /// - /// Reads data from a device on the SPI bus. - /// - /// The digital output port representing the chip select line. - /// The buffer to store the read data. - /// The chip select mode (active low or active high). - public void Read(IDigitalOutputPort chipSelect, Span readBuffer, ChipSelectMode csMode = ChipSelectMode.ActiveLow) + return new SpiChannelConfig { - var options = CreateTransferOptions(csMode); + ClockRate = (uint)config.Speed.Hertz, + LatencyTimer = DefaultLatencyTimer, + Options = opts + }; + } - chipSelect.State = csMode == ChipSelectMode.ActiveLow ? false : true; + private SPITransferOptions CreateTransferOptions(ChipSelectMode mode) + { + SPITransferOptions opts = SPITransferOptions.SIZE_IN_BYTES; - var status = Functions.SPI_Read( - Handle, - MemoryMarshal.GetReference(readBuffer), - readBuffer.Length, - out _, - options - ); + switch (mode) + { + case ChipSelectMode.ActiveLow: + opts |= SPITransferOptions.CHIPSELECT_DISABLE; + break; + case ChipSelectMode.ActiveHigh: + opts |= SPITransferOptions.CHIPSELECT_ENABLE; + break; + } - chipSelect.State = csMode == ChipSelectMode.ActiveLow ? true : false; + return opts; + } - CheckStatus(status); - } + /// + public void Read(IDigitalOutputPort? chipSelect, Span readBuffer, ChipSelectMode csMode = ChipSelectMode.ActiveLow) + { + var options = CreateTransferOptions(csMode); - /// - /// Writes data to a device on the SPI bus. - /// - /// The digital output port representing the chip select line. - /// The data to write to the device. - /// The chip select mode (active low or active high). - public void Write(IDigitalOutputPort chipSelect, Span writeBuffer, ChipSelectMode csMode = ChipSelectMode.ActiveLow) + if (chipSelect != null) { - var options = CreateTransferOptions(csMode); - chipSelect.State = csMode == ChipSelectMode.ActiveLow ? false : true; + } - var status = Functions.SPI_Write( - Handle, - MemoryMarshal.GetReference(writeBuffer), - writeBuffer.Length, - out _, - options + var status = Mpsse.SPI_Read( + Handle, + MemoryMarshal.GetReference(readBuffer), + readBuffer.Length, + out _, + options ); + if (chipSelect != null) + { chipSelect.State = csMode == ChipSelectMode.ActiveLow ? true : false; - - CheckStatus(status); } - /// - /// Exchanges data with a device on the SPI bus. - /// - /// The digital output port representing the chip select line. - /// The data to write to the device. - /// The buffer to store the read data. - /// The chip select mode (active low or active high). - public void Exchange(IDigitalOutputPort chipSelect, Span writeBuffer, Span readBuffer, ChipSelectMode csMode = ChipSelectMode.ActiveLow) - { - var options = CreateTransferOptions(csMode); + CheckStatus(status); + } + /// + public void Write(IDigitalOutputPort? chipSelect, Span writeBuffer, ChipSelectMode csMode = ChipSelectMode.ActiveLow) + { + var options = CreateTransferOptions(csMode); + + if (chipSelect != null) + { chipSelect.State = csMode == ChipSelectMode.ActiveLow ? false : true; + } - var status = Functions.SPI_ReadWrite( - Handle, - MemoryMarshal.GetReference(readBuffer), - MemoryMarshal.GetReference(writeBuffer), - writeBuffer.Length, - out _, - options + var status = Mpsse.SPI_Write( + Handle, + MemoryMarshal.GetReference(writeBuffer), + writeBuffer.Length, + out _, + options ); + if (chipSelect != null) + { chipSelect.State = csMode == ChipSelectMode.ActiveLow ? true : false; - - CheckStatus(status); } - /// - /// Gets or sets the SPI bus configuration. - /// - public SpiClockConfiguration Configuration + CheckStatus(status); + } + + /// + public void Exchange(IDigitalOutputPort? chipSelect, Span writeBuffer, Span readBuffer, ChipSelectMode csMode = ChipSelectMode.ActiveLow) + { + var options = CreateTransferOptions(csMode); + + if (chipSelect != null) { - get { return _config; } - set - { - _channelConfig = CreateChannelConfig(value); - _config = value; - this.Configuration.Changed += OnConfigurationChanged; - } + chipSelect.State = csMode == ChipSelectMode.ActiveLow ? false : true; } - private void OnConfigurationChanged(object sender, EventArgs e) + var status = Mpsse.SPI_ReadWrite( + Handle, + MemoryMarshal.GetReference(readBuffer), + MemoryMarshal.GetReference(writeBuffer), + writeBuffer.Length, + out _, + options + ); + + if (chipSelect != null) { - var changed = false; - - if (Configuration.Speed.Hertz != _channelConfig.ClockRate) - { - _channelConfig.ClockRate = (uint)Configuration.Speed.Hertz; - changed = true; - } - - switch (Configuration.SpiMode) - { - case SpiClockConfiguration.Mode.Mode0: - if ((_channelConfig.Options & SpiConfigOptions.MODE3) != SpiConfigOptions.MODE0) - { - _channelConfig.Options |= SpiConfigOptions.MODE0; - changed = true; - } - break; - case SpiClockConfiguration.Mode.Mode1: - if ((_channelConfig.Options & SpiConfigOptions.MODE3) != SpiConfigOptions.MODE1) - { - _channelConfig.Options = (_channelConfig.Options & ~SpiConfigOptions.MODE3) | SpiConfigOptions.MODE1; - changed = true; - } - break; - case SpiClockConfiguration.Mode.Mode2: - if ((_channelConfig.Options & SpiConfigOptions.MODE3) != SpiConfigOptions.MODE2) - { - _channelConfig.Options = (_channelConfig.Options & ~SpiConfigOptions.MODE3) | SpiConfigOptions.MODE2; - changed = true; - } - break; - case SpiClockConfiguration.Mode.Mode3: - if ((_channelConfig.Options & SpiConfigOptions.MODE3) != SpiConfigOptions.MODE3) - { - _channelConfig.Options = (_channelConfig.Options & ~SpiConfigOptions.MODE3) | SpiConfigOptions.MODE3; - changed = true; - } - break; - } - - if (changed) - { - CheckStatus(Functions.SPI_InitChannel(Handle, ref _channelConfig)); - } + chipSelect.State = csMode == ChipSelectMode.ActiveLow ? true : false; } + + CheckStatus(status); } -} +} \ No newline at end of file diff --git a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ft232h/Driver/Ft232h.PinDefinitions.cs b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ft232h/Driver/Ft232h.PinDefinitions.cs index 2773ee9e05..7839cec451 100644 --- a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ft232h/Driver/Ft232h.PinDefinitions.cs +++ b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ft232h/Driver/Ft232h.PinDefinitions.cs @@ -31,12 +31,15 @@ public class PinDefinitions : IPinDefinitions /// public IPinController? Controller { get; set; } + private bool UseMpsseKeys { get; } + /// /// Creates a new PinDefinitions object. /// /// The Ft232h controller associated with the pins. internal PinDefinitions(Ft232h controller) { + UseMpsseKeys = controller.UsingMpsse; Controller = controller; InitAllPins(); } @@ -114,12 +117,54 @@ internal PinDefinitions(Ft232h controller) public IPin D3 => new Pin( Controller, "D3", - (byte)0x12, + (byte)0x13, new List { new SpiChannelInfo("SPI_CS0", SpiLineType.ChipSelect) }); - // TODO: D4-D7 can be used as CS, and (probably??) GPIO. The docs are not terribly clear on this. Maybe just outputs and direct write the CS? + /// + /// Pin D4 definition. + /// + public IPin D4 => new Pin( + Controller, + "D4", + UseMpsseKeys ? (byte)0x14 : (ushort)(1 << 4), + new List { + new DigitalChannelInfo("D4", interruptCapable: false, pullUpCapable: false, pullDownCapable: false) + }); + + /// + /// Pin D5 definition. + /// + public IPin D5 => new Pin( + Controller, + "D5", + UseMpsseKeys ? (byte)0x15 : (ushort)(1 << 5), + new List { + new DigitalChannelInfo("D5", interruptCapable: false, pullUpCapable: false, pullDownCapable: false) + }); + + /// + /// Pin D6 definition. + /// + public IPin D6 => new Pin( + Controller, + "D6", + UseMpsseKeys ? (byte)0x16 : (ushort)(1 << 6), + new List { + new DigitalChannelInfo("D6", interruptCapable: false, pullUpCapable: false, pullDownCapable: false) + }); + + /// + /// Pin D7 definition. + /// + public IPin D7 => new Pin( + Controller, + "D7", + UseMpsseKeys ? (byte)0x17 : (ushort)(1 << 7), + new List { + new DigitalChannelInfo("D7", interruptCapable: false, pullUpCapable: false, pullDownCapable: false) + }); /// /// Pin SPI_COPI_D1 definition. @@ -138,7 +183,7 @@ internal PinDefinitions(Ft232h controller) public IPin C0 => new Pin( Controller, "C0", - (byte)(1 << 0), + UseMpsseKeys ? (byte)(1 << 0) : (ushort)(1 << 8), new List { new DigitalChannelInfo("C0", interruptCapable: false, pullUpCapable: false, pullDownCapable: false) }); @@ -149,7 +194,7 @@ internal PinDefinitions(Ft232h controller) public IPin C1 => new Pin( Controller, "C1", - (byte)(1 << 1), + UseMpsseKeys ? (byte)(1 << 1) : (ushort)(1 << 9), new List { new DigitalChannelInfo("C1", interruptCapable: false, pullUpCapable: false, pullDownCapable: false) }); @@ -160,7 +205,7 @@ internal PinDefinitions(Ft232h controller) public IPin C2 => new Pin( Controller, "C2", - (byte)(1 << 2), + UseMpsseKeys ? (byte)(1 << 2) : (ushort)(1 << 10), new List { new DigitalChannelInfo("C2", interruptCapable: false, pullUpCapable: false, pullDownCapable: false) }); @@ -171,7 +216,7 @@ internal PinDefinitions(Ft232h controller) public IPin C3 => new Pin( Controller, "C3", - (byte)(1 << 3), + UseMpsseKeys ? (byte)(1 << 3) : (ushort)(1 << 11), new List { new DigitalChannelInfo("C3", interruptCapable: false, pullUpCapable: false, pullDownCapable: false) }); @@ -182,7 +227,7 @@ internal PinDefinitions(Ft232h controller) public IPin C4 => new Pin( Controller, "C4", - (byte)(1 << 4), + UseMpsseKeys ? (byte)(1 << 4) : (ushort)(1 << 12), new List { new DigitalChannelInfo("C4", interruptCapable: false, pullUpCapable: false, pullDownCapable: false) }); @@ -193,7 +238,7 @@ internal PinDefinitions(Ft232h controller) public IPin C5 => new Pin( Controller, "C5", - (byte)(1 << 5), + UseMpsseKeys ? (byte)(1 << 5) : (ushort)(1 << 13), new List { new DigitalChannelInfo("C5", interruptCapable: false, pullUpCapable: false, pullDownCapable: false) }); @@ -204,7 +249,7 @@ internal PinDefinitions(Ft232h controller) public IPin C6 => new Pin( Controller, "C6", - (byte)(1 << 6), + UseMpsseKeys ? (byte)(1 << 6) : (ushort)(1 << 14), new List { new DigitalChannelInfo("C6", interruptCapable: false, pullUpCapable: false, pullDownCapable: false) }); @@ -215,7 +260,7 @@ internal PinDefinitions(Ft232h controller) public IPin C7 => new Pin( Controller, "C7", - (byte)(1 << 7), + UseMpsseKeys ? (byte)(1 << 7) : (ushort)(1 << 15), new List { new DigitalChannelInfo("C7", interruptCapable: false, pullUpCapable: false, pullDownCapable: false) }); diff --git a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ft232h/Driver/Ft232h.cs b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ft232h/Driver/Ft232h.cs index 3b1ee09a07..b80a3f53f2 100644 --- a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ft232h/Driver/Ft232h.cs +++ b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ft232h/Driver/Ft232h.cs @@ -1,330 +1,159 @@ using Meadow.Hardware; using Meadow.Units; using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading; -namespace Meadow.Foundation.ICs.IOExpanders +namespace Meadow.Foundation.ICs.IOExpanders; + +/// +/// Represents a DS3502 digital potentiometer +/// +public partial class Ft232h : + IDisposable, + IDigitalInputOutputController, + IDigitalOutputController, + ISpiController, + II2cController { - /// - /// Represents an FT232H IO expander - /// - public partial class Ft232h : - IDisposable, - IDigitalInputOutputController, - IDigitalOutputController, - ISpiController, - II2cController - { - private bool _isDisposed; - private static int _instanceCount = 0; - private Dictionary _i2cBuses = new Dictionary(); - private Dictionary _spiBuses = new Dictionary(); - private IFt232Bus? _activeBus = null; - - static Ft232h() - { - if (Interlocked.Increment(ref _instanceCount) == 1) - { - // only do this one time (no matter how many instances are created instances) - Native.Functions.Init_libMPSSE(); - } - } - - /// - /// Initializes a new instance of the class. - /// - public Ft232h() - { - Pins = new PinDefinitions(this); - EnumerateBuses(); - } - - /// - /// The pins - /// - public PinDefinitions Pins { get; } - - private void EnumerateBuses() - { - _i2cBuses = GetI2CBuses(); - _spiBuses = GetSpiBuses(); - } - - private Dictionary GetI2CBuses() - { - Dictionary result = new Dictionary(); - - if (Native.CheckStatus(Native.Functions.I2C_GetNumChannels(out int channels))) - { - if (channels > 0) - { - for (var c = 0; c < channels; c++) - { - if (Native.CheckStatus(Native.Functions.I2C_GetChannelInfo(c, out Native.FT_DEVICE_LIST_INFO_NODE info))) - { - result.Add(c, new Ft232I2cBus(c, info)); - } - } - } - } - - return result; - } - - private Dictionary GetSpiBuses() - { - Dictionary result = new Dictionary(); - - if (Native.CheckStatus(Native.Functions.SPI_GetNumChannels(out int channels))) - { - if (channels > 0) - { - for (var c = 0; c < channels; c++) - { - if (Native.CheckStatus(Native.Functions.SPI_GetChannelInfo(c, out Native.FT_DEVICE_LIST_INFO_NODE info))) - { - result.Add(c, new Ft232SpiBus(c, info)); - } - } - } - } - - return result; - } - - /// - /// Creates an I2C bus with the specified bus number and clock rate. - /// - /// The bus number. - /// The I2C bus. - public II2cBus CreateI2cBus(int busNumber = 0) - { - return CreateI2cBus(busNumber, I2CClockRate.Standard); - } + private bool _isDisposed; + private IFtdiImpl _impl; - /// - /// Creates an I2C bus with the specified bus number and clock rate. - /// - /// The bus number. - /// The I2C bus speed. - /// The I2C bus. - public II2cBus CreateI2cBus(int busNumber, I2cBusSpeed busSpeed) - { - // TODO: convert frequency - return CreateI2cBus(busNumber, I2CClockRate.Standard); - } - - /// - /// Creates an I2C bus with the specified pins and bus speed. - /// - /// The I2C clock and data pins. - /// The I2C bus speed. - /// The I2C bus. - public II2cBus CreateI2cBus(IPin[] pins, I2cBusSpeed busSpeed) - { - // TODO: map the pins to the bus number - // TODO: convert frequency - return CreateI2cBus(0, I2CClockRate.Standard); - } - - /// - /// Creates an I2C bus with the specified clock and data pins and bus speed. - /// - /// The clock pin. - /// The data pin. - /// The I2C bus speed. - /// The I2C bus. - public II2cBus CreateI2cBus(IPin clock, IPin data, I2cBusSpeed busSpeed) - { - // TODO: map the pins to the bus number - // TODO: convert frequency - return CreateI2cBus(0, I2CClockRate.Standard); - } - - private II2cBus CreateI2cBus(int busNumber, I2CClockRate clock) - { - if (_activeBus != null) - { - throw new InvalidOperationException("The FT232 allows only one bus to be active at a time."); - } - - if (_i2cBuses.Count == 0) - { - throw new InvalidOperationException("No I2C Busses found! Is the FT232 properly connected?"); - } - - if (!_i2cBuses.ContainsKey(busNumber)) throw new ArgumentOutOfRangeException(nameof(busNumber)); - - var bus = _i2cBuses[busNumber]; - if (!bus.IsOpen) - { - bus.Open(clock); - } + internal bool UsingMpsse { get; } - _activeBus = bus; - - return bus; - } - - /// - /// Creates an SPI bus with the default configuration. - /// - /// The SPI bus. - public ISpiBus CreateSpiBus() - { - return CreateSpiBus(0, DefaultClockConfiguration); - } - - /// - /// Creates an SPI bus with the specified clock, MOSI, MISO pins, and configuration. - /// - /// The clock pin. - /// The MOSI (Master Out Slave In) pin. - /// The MISO (Master In Slave Out) pin. - /// The SPI configuration. - /// The SPI bus. - public ISpiBus CreateSpiBus(IPin clock, IPin mosi, IPin miso, SpiClockConfiguration config) - { - if (!clock.Supports(c => c.LineTypes.HasFlag(SpiLineType.Clock))) - { - throw new ArgumentException("Invalid Clock line"); - } + /// + /// The pins + /// + public PinDefinitions Pins { get; } - // TODO: map the pins to the bus number - return CreateSpiBus(0, config); - } + /// + /// Initializes a new instance of the class. + /// + /// Specifies whether to use Multi-Protocol Synchronous Serial Engine (MPSSE) mode (default is false). + public Ft232h(bool useMPSSE = false) + { + UsingMpsse = useMPSSE; - /// - /// Creates an SPI bus with the specified clock, MOSI, MISO pins, and configuration. - /// - /// The clock pin. - /// The MOSI (Master Out Slave In) pin. - /// The MISO (Master In Slave Out) pin. - /// The SPI frequency. - /// The SPI bus. - public ISpiBus CreateSpiBus(IPin clock, IPin mosi, IPin miso, Frequency speed) - { - // TODO: map the pins to the bus number - var config = new SpiClockConfiguration(speed); - return CreateSpiBus(0, config); - } + _impl = UsingMpsse ? new MpsseImpl() : new Ftd2xxImpl(); + _impl.Initialize(); - /// - /// The default SPI clock configuration - /// - public static SpiClockConfiguration DefaultClockConfiguration - { - get => new SpiClockConfiguration( - new Frequency(Ft232SpiBus.DefaultClockRate, Frequency.UnitType.Hertz)); - } + Pins = new PinDefinitions(this); + } - private ISpiBus CreateSpiBus(int busNumber, SpiClockConfiguration config) - { - if (_activeBus != null) - { - throw new InvalidOperationException("The FT232 allows only one bus to be active at a time."); - } + /// + public II2cBus CreateI2cBus(int busNumber = 0) + { + return CreateI2cBus(busNumber, I2CClockRate.Standard); + } - if (_spiBuses.Count == 0) - { - throw new InvalidOperationException("No SPI Busses found! Is the FT232 properly connected?"); - } + /// + public II2cBus CreateI2cBus(int busNumber, I2cBusSpeed busSpeed) + { + // TODO: convert frequency + return CreateI2cBus(busNumber, I2CClockRate.Standard); + } - if (!_spiBuses.ContainsKey(busNumber)) throw new ArgumentOutOfRangeException(nameof(busNumber)); + /// + public II2cBus CreateI2cBus(IPin[] pins, I2cBusSpeed busSpeed) + { + // TODO: map the pins to the bus number + // TODO: convert frequency + return CreateI2cBus(0, I2CClockRate.Standard); + } - var bus = _spiBuses[busNumber]; - if (!bus.IsOpen) - { - bus.Open(config); - } + /// + public II2cBus CreateI2cBus(IPin clock, IPin data, I2cBusSpeed busSpeed) + { + // TODO: map the pins to the bus number + // TODO: convert frequency + return CreateI2cBus(0, I2CClockRate.Standard); + } - _activeBus = bus; + private II2cBus CreateI2cBus(int busNumber, I2CClockRate clock) + { + return _impl.CreateI2cBus(busNumber, clock); + } - return bus; - } + /// + public ISpiBus CreateSpiBus() + { + return CreateSpiBus(0, DefaultClockConfiguration); + } - public IDigitalInputPort CreateDigitalInputPort(IPin pin) + /// + public ISpiBus CreateSpiBus(IPin clock, IPin mosi, IPin miso, SpiClockConfiguration config) + { + if (!clock.Supports(c => c.LineTypes.HasFlag(SpiLineType.Clock))) { - return CreateDigitalInputPort(pin, ResistorMode.Disabled); + throw new ArgumentException("Invalid Clock line"); } - private bool _spiBusAutoCreated = false; - - /// - public IDigitalInputPort CreateDigitalInputPort(IPin pin, ResistorMode resistorMode) - { - // MPSSE requires a bus, it can be either I2C or SPI, but that bus must be created before you can use GPIO - // if no bus is yet open, we'll default to a SPI bus. - // If this is created before an I2C comms bus, we need to let the caller know to create the comms bus first - - if (_activeBus == null) - { - var bus = CreateSpiBus(0, DefaultClockConfiguration); - _spiBusAutoCreated = true; - _activeBus = bus as IFt232Bus; - } - - // TODO: do we need to set the direction make (see outputs) or are they defaulted to input? + // TODO: map the pins to the bus number + return CreateSpiBus(0, config); + } - var info = pin.SupportedChannels?.FirstOrDefault(c => c is IDigitalChannelInfo) as IDigitalChannelInfo; - return new Ft232DigitalInputPort(pin, info!, _activeBus!); - } + /// + public ISpiBus CreateSpiBus(IPin clock, IPin mosi, IPin miso, Frequency speed) + { + // TODO: map the pins to the bus number + var config = new SpiClockConfiguration(speed); + return CreateSpiBus(0, config); + } - /// - public IDigitalOutputPort CreateDigitalOutputPort(IPin pin, bool initialState = false, OutputType initialOutputType = OutputType.PushPull) - { - // MPSSE requires a bus, it can be either I2C or SPI, but that bus must be created before you can use GPIO - // if no bus is yet open, we'll default to a SPI bus. - // If this is created before an I2C comms bus, we need to let the caller know to create the comms bus first + /// + public ISpiBus CreateSpiBus(int busNumber, SpiClockConfiguration config) + { + return _impl.CreateSpiBus(busNumber, config); + } - if (_activeBus == null) - { - var bus = CreateSpiBus(0, DefaultClockConfiguration); - _spiBusAutoCreated = true; - _activeBus = bus as IFt232Bus; - } + /// + public static SpiClockConfiguration DefaultClockConfiguration + { + get => new SpiClockConfiguration( + new Frequency(Ft232SpiBus.DefaultClockRate, Frequency.UnitType.Hertz)); + } - // update the global mask to make this an output - _activeBus!.GpioDirectionMask |= (byte)pin.Key; + /// + public IDigitalInputPort CreateDigitalInputPort(IPin pin) + { + return CreateDigitalInputPort(pin, ResistorMode.Disabled); + } - // update the direction - Native.Functions.FT_WriteGPIO(_activeBus.Handle, _activeBus.GpioDirectionMask, 0); + /// + public IDigitalInputPort CreateDigitalInputPort(IPin pin, ResistorMode resistorMode) + { + // TODO: need to select the proper channel based on pin + return _impl.CreateDigitalInputPort(0, pin, resistorMode); + } - var info = pin.SupportedChannels?.FirstOrDefault(c => c is IDigitalChannelInfo) as IDigitalChannelInfo; - return new Ft232DigitalOutputPort(pin, info!, initialState, initialOutputType, _activeBus); - } + /// + public IDigitalOutputPort CreateDigitalOutputPort(IPin pin, bool initialState = false, OutputType initialOutputType = OutputType.PushPull) + { + // TODO: need to select the proper channel based on pin + return _impl.CreateDigitalOutputPort(0, pin, initialState, initialOutputType); + } - /// - protected virtual void Dispose(bool disposing) + /// + protected virtual void Dispose(bool disposing) + { + if (!_isDisposed) { - if (!_isDisposed) - { - foreach (var bus in _i2cBuses) - { - bus.Value?.Dispose(); - } + _impl.Dispose(); - if (Interlocked.Decrement(ref _instanceCount) == 0) - { - // last instance was disposed, clean house - Native.Functions.Cleanup_libMPSSE(); - } - - _isDisposed = true; - } + _isDisposed = true; } + } - ~Ft232h() - { - Dispose(false); - } + /// + /// Finalizer for the Ft232h class, used to release unmanaged resources. + /// + ~Ft232h() + { + Dispose(false); + } - public void Dispose() - { - Dispose(true); - GC.SuppressFinalize(this); - } + /// + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); } } \ No newline at end of file diff --git a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ft232h/Driver/Ft232h.ft23xx.cs b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ft232h/Driver/Ft232h.ft23xx.cs new file mode 100644 index 0000000000..88c3d1595e --- /dev/null +++ b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ft232h/Driver/Ft232h.ft23xx.cs @@ -0,0 +1,69 @@ +using Meadow.Hardware; + +namespace Meadow.Foundation.ICs.IOExpanders; + +internal class Ftd2xxImpl : IFtdiImpl +{ + private FtdiDeviceCollection _devices = default!; + + public void Initialize() + { + _devices = new FtdiDeviceCollection(); + _devices.Refresh(); + } + + public II2cBus CreateI2cBus(int channel, I2CClockRate clock) + { + if (_devices.Count == 0) + { + throw new DeviceNotFoundException(); + } + + _devices[channel].Open(); + + return new Ft23xxI2cBus(_devices[channel]); + } + + public ISpiBus CreateSpiBus(int channel, SpiClockConfiguration config) + { + if (_devices.Count == 0) + { + throw new DeviceNotFoundException(); + } + + _devices[channel].Open(); + + return new Ft23xxSpiBus(_devices[channel], config); + } + + public IDigitalInputPort CreateDigitalInputPort(int channel, IPin pin, ResistorMode resistorMode) + { + if (_devices.Count == 0) + { + throw new DeviceNotFoundException(); + } + + return new Ft23xxDigitalInputPort(_devices[channel], pin, resistorMode, + new DigitalChannelInfo(pin.Name, true, true, false, false, false, false)); + } + + public IDigitalOutputPort CreateDigitalOutputPort(int channel, IPin pin, bool initialState = false, OutputType initialOutputType = OutputType.PushPull) + { + if (_devices.Count == 0) + { + throw new DeviceNotFoundException(); + } + + return new Ft23xxDigitalOutputPort(_devices[channel], pin, + new DigitalChannelInfo(pin.Name, true, true, false, false, false, false), + initialState, initialOutputType); + } + + public void Dispose() + { + foreach (var d in _devices) + { + d.Close(); + } + } +} diff --git a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ft232h/Driver/Ft232h.mpsse.cs b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ft232h/Driver/Ft232h.mpsse.cs new file mode 100644 index 0000000000..a69cf63072 --- /dev/null +++ b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ft232h/Driver/Ft232h.mpsse.cs @@ -0,0 +1,197 @@ +using Meadow.Hardware; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading; + +namespace Meadow.Foundation.ICs.IOExpanders; + +internal class MpsseImpl : IFtdiImpl +{ + private static int _instanceCount = 0; + private bool _isDisposed = false; + private Dictionary _i2cBuses = new Dictionary(); + private Dictionary _spiBuses = new Dictionary(); + private bool _spiBusAutoCreated = false; + + private IFt232Bus? _activeBus = null; + + public void Initialize() + { + if (Interlocked.Increment(ref _instanceCount) == 1) + { + // only do this one time (no matter how many instances are created instances) + Native.Mpsse.Init_libMPSSE(); + } + + EnumerateBuses(); + } + + private void EnumerateBuses() + { + _i2cBuses = GetI2CBuses(); + _spiBuses = GetSpiBuses(); + } + + private Dictionary GetI2CBuses() + { + Dictionary result = new Dictionary(); + + if (Native.CheckStatus(Native.Mpsse.I2C_GetNumChannels(out int channels))) + { + if (channels > 0) + { + for (var c = 0; c < channels; c++) + { + if (Native.CheckStatus(Native.Mpsse.I2C_GetChannelInfo(c, out Native.FT_DEVICE_LIST_INFO_NODE info))) + { + result.Add(c, new MpsseI2cBus(c, info)); + } + } + } + } + + return result; + } + + private Dictionary GetSpiBuses() + { + Dictionary result = new Dictionary(); + + if (Native.CheckStatus(Native.Mpsse.SPI_GetNumChannels(out int channels))) + { + if (channels > 0) + { + for (var c = 0; c < channels; c++) + { + if (Native.CheckStatus(Native.Mpsse.SPI_GetChannelInfo(c, out Native.FT_DEVICE_LIST_INFO_NODE info))) + { + result.Add(c, new Ft232SpiBus(c, info)); + } + } + } + } + + return result; + } + + public II2cBus CreateI2cBus(int busNumber, I2CClockRate clock) + { + // dev note: this fails on WIndows in all my testing + // it's a bug in the MPSSE DLL delivered by FTDI + // even using their C example, compiling it myself, it fails + + if (_activeBus != null) + { + throw new InvalidOperationException("The FT232 allows only one bus to be active at a time."); + } + + if (_i2cBuses.Count == 0) + { + throw new InvalidOperationException("No I2C Busses found! Is the FT232 properly connected?"); + } + + if (!_i2cBuses.ContainsKey(busNumber)) throw new ArgumentOutOfRangeException(nameof(busNumber)); + + var bus = _i2cBuses[busNumber]; + if (!bus.IsOpen) + { + bus.Open(clock); + } + + _activeBus = bus; + + return bus; + } + + public ISpiBus CreateSpiBus(int busNumber, SpiClockConfiguration config) + { + if (_activeBus != null) + { + throw new InvalidOperationException("The FT232 allows only one bus to be active at a time."); + } + + if (_spiBuses.Count == 0) + { + throw new InvalidOperationException("No SPI Busses found! Is the FT232 properly connected?"); + } + + if (!_spiBuses.ContainsKey(busNumber)) throw new ArgumentOutOfRangeException(nameof(busNumber)); + + var bus = _spiBuses[busNumber]; + if (!bus.IsOpen) + { + bus.Open(config); + } + + _activeBus = bus; + + return bus; + } + + public IDigitalInputPort CreateDigitalInputPort(int channel, IPin pin, ResistorMode resistorMode) + { + // MPSSE requires a bus, it can be either I2C or SPI, but that bus must be created before you can use GPIO + // if no bus is yet open, we'll default to a SPI bus. + // If this is created before an I2C comms bus, we need to let the caller know to create the comms bus first + + if (_activeBus == null) + { + var bus = CreateSpiBus(channel, Ft232h.DefaultClockConfiguration); + _spiBusAutoCreated = true; + _activeBus = bus as IFt232Bus; + } + + // TODO: do we need to set the direction make (see outpuuts) or are they defaulted to input? + + var info = pin.SupportedChannels?.FirstOrDefault(c => c is IDigitalChannelInfo) as IDigitalChannelInfo; + return new MpsseDigitalInputPort(pin, info!, _activeBus!); + } + + public IDigitalOutputPort CreateDigitalOutputPort(int channel, IPin pin, bool initialState = false, OutputType initialOutputType = OutputType.PushPull) + { + // MPSSE requires a bus, it can be either I2C or SPI, but that bus must be created before you can use GPIO + // if no bus is yet open, we'll default to a SPI bus. + // If this is created before an I2C comms bus, we need to let the caller know to create the comms bus first + + if (_activeBus == null) + { + var bus = CreateSpiBus(channel, Ft232h.DefaultClockConfiguration); + _spiBusAutoCreated = true; + _activeBus = bus as IFt232Bus; + } + + // update the global mask to make this an output + _activeBus!.GpioDirectionMask |= (byte)pin.Key; + + // update the direction + Native.Mpsse.FT_WriteGPIO(_activeBus.Handle, _activeBus.GpioDirectionMask, 0); + + var info = pin.SupportedChannels?.FirstOrDefault(c => c is IDigitalChannelInfo) as IDigitalChannelInfo; + return new MpsseDigitalOutputPort(pin, info!, initialState, initialOutputType, _activeBus); + } + + public void Dispose() + { + if (!_isDisposed) + { + foreach (var bus in _spiBuses) + { + bus.Value?.Dispose(); + } + + if (Interlocked.Decrement(ref _instanceCount) == 0) + { + if (_spiBusAutoCreated) + { + // TODO: + } + + // last instance was disposed, clean house + Native.Mpsse.Cleanup_libMPSSE(); + } + + _isDisposed = true; + } + } +} diff --git a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ft232h/Driver/Ft23xxDigitalInputPort.cs b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ft232h/Driver/Ft23xxDigitalInputPort.cs new file mode 100644 index 0000000000..4226f634de --- /dev/null +++ b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ft232h/Driver/Ft23xxDigitalInputPort.cs @@ -0,0 +1,50 @@ +using Meadow.Hardware; +using System; + +namespace Meadow.Foundation.ICs.IOExpanders; + +/// +/// Represents a digital input port implementation for the FT23xx device. +/// +public sealed class Ft23xxDigitalInputPort : DigitalInputPortBase +{ + private FtdiDevice _device; + private ResistorMode _resistor; + + internal Ft23xxDigitalInputPort(FtdiDevice device, IPin pin, ResistorMode resistorMode, IDigitalChannelInfo channel) + : base(pin, channel) + { + Resistor = resistorMode; + _device = device; + } + + /// + public override bool State + { + get + { + // reads all 8 pis at once + var state = _device.GetGpioState(true); + // the pin key is the mask + return (state & (byte)Pin.Key) != 0; + } + } + + /// + public override ResistorMode Resistor + { + get => _resistor; + set + { + switch (value) + { + case ResistorMode.InternalPullUp: + case ResistorMode.InternalPullDown: + throw new NotSupportedException("Internal resistors are not supported"); + default: + _resistor = value; + break; + } + } + } +} diff --git a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ft232h/Driver/Ft23xxDigitalOutputPort.cs b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ft232h/Driver/Ft23xxDigitalOutputPort.cs new file mode 100644 index 0000000000..4f3982d9e2 --- /dev/null +++ b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ft232h/Driver/Ft23xxDigitalOutputPort.cs @@ -0,0 +1,59 @@ +using Meadow.Hardware; +using System; + +namespace Meadow.Foundation.ICs.IOExpanders; + +/// +/// Represents a digital output port implementation for the FT23xx device. +/// +public sealed class Ft23xxDigitalOutputPort : DigitalOutputPortBase +{ + private FtdiDevice _device; + private bool _state; + private bool _isHighByte; + private byte _key; + + internal Ft23xxDigitalOutputPort(FtdiDevice device, IPin pin, IDigitalChannelInfo channel, bool initialState, OutputType initialOutputType) + : base(pin, channel, initialState, initialOutputType) + { + _device = device; + + // TODO: make sure the pin isn't already in use + var key = Convert.ToUInt16(Pin.Key); + if (key > 255) + { + _isHighByte = true; + _key = (byte)(key >> 8); + } + else + { + _isHighByte = false; + _key = (byte)(key & 0xff); + } + + _device.GpioDirectionMask |= _key; + } + + /// + public override bool State + { + get => _state; + set + { + byte s = _device.GpioState; + + if (value) + { + s |= _key; + } + else + { + s &= (byte)~_key; + } + + _device.SetGpioState(!_isHighByte, _device.GpioDirectionMask, s); + _device.GpioState = s; + _state = value; + } + } +} diff --git a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ft232h/Driver/Ft23xxI2cBus.cs b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ft232h/Driver/Ft23xxI2cBus.cs new file mode 100644 index 0000000000..54b7964b06 --- /dev/null +++ b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ft232h/Driver/Ft23xxI2cBus.cs @@ -0,0 +1,94 @@ +using Meadow.Hardware; +using System; +using System.IO; + +namespace Meadow.Foundation.ICs.IOExpanders; + +/// +/// Represents an I2C bus implementation using the FT23xx device. +/// +public sealed class Ft23xxI2cBus : II2cBus, IDisposable +{ + private FtdiDevice _device; + + /// + /// Gets the handle to the FT23xx device used by the I2C bus. + /// + public IntPtr Handle => _device.Handle; + + /// + public I2cBusSpeed BusSpeed { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } + + internal Ft23xxI2cBus(FtdiDevice device) + { + if (device.Handle == IntPtr.Zero) + { + device.Open(); + } + + _device = device; + + _device.InitializeI2C(); + } + + /// + public void Dispose() + { + _device.Close(); + } + + /// + public void Exchange(byte peripheralAddress, Span writeBuffer, Span readBuffer) + { + Write(peripheralAddress, writeBuffer); + Read(peripheralAddress, readBuffer); + } + + /// + public void Read(byte peripheralAddress, Span readBuffer) + { + _device.I2cStart(); + var ack = _device.I2cSendDeviceAddrAndCheckACK(peripheralAddress, true); + if (!ack) + { + _device.I2cStop(); + throw new IOException($"Error reading device while setting up address"); + } + + for (int i = 0; i < readBuffer.Length - 1; i++) + { + readBuffer[i] = _device.I2CReadByte(true); + } + + if (readBuffer.Length > 0) + { + readBuffer[readBuffer.Length - 1] = _device.I2CReadByte(false); + } + + _device.I2cStop(); + } + + /// + public void Write(byte peripheralAddress, Span writeBuffer) + { + _device.I2cStart(); + var ack = _device.I2cSendDeviceAddrAndCheckACK(peripheralAddress, false); + if (!ack) + { + _device.I2cStop(); + throw new IOException($"Error writing device while setting up address"); + } + + for (int i = 0; i < writeBuffer.Length; i++) + { + ack = _device.I2cSendByteAndCheckACK(writeBuffer[i]); + if (!ack) + { + _device.I2cStop(); + throw new IOException($"Error writing device on byte {i}"); + } + } + + _device.I2cStop(); + } +} diff --git a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ft232h/Driver/Ft23xxSpiBus.cs b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ft232h/Driver/Ft23xxSpiBus.cs new file mode 100644 index 0000000000..66923ba9c9 --- /dev/null +++ b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ft232h/Driver/Ft23xxSpiBus.cs @@ -0,0 +1,67 @@ +using Meadow.Hardware; +using Meadow.Units; +using System; + +namespace Meadow.Foundation.ICs.IOExpanders; + +/// +/// Represents an SPI bus implementation using the FT23xx device. +/// +public sealed class Ft23xxSpiBus : IFt232Bus, ISpiBus, IDisposable +{ + private FtdiDevice _device; + + /// + /// Gets the handle to the FT23xx device used by the SPI bus. + /// + public IntPtr Handle => _device.Handle; + + /// + public byte GpioDirectionMask { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } + + /// + public byte GpioState { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } + + /// + public Frequency[] SupportedSpeeds => throw new NotImplementedException(); + + /// + public SpiClockConfiguration Configuration { get; } + + internal Ft23xxSpiBus(FtdiDevice device, SpiClockConfiguration config) + { + Configuration = config; + + if (device.Handle == IntPtr.Zero) + { + device.Open(); + } + + _device = device; + + _device.InitializeSpi(Configuration); + } + + /// + public void Dispose() + { + } + + /// + public void Exchange(IDigitalOutputPort? chipSelect, Span writeBuffer, Span readBuffer, ChipSelectMode csMode) + { + _device.SpiExchange(chipSelect, writeBuffer, readBuffer, csMode); + } + + /// + public void Read(IDigitalOutputPort? chipSelect, Span readBuffer, ChipSelectMode csMode) + { + _device.SpiRead(chipSelect, readBuffer, csMode); + } + + /// + public void Write(IDigitalOutputPort? chipSelect, Span writeBuffer, ChipSelectMode csMode) + { + _device.SpiWrite(chipSelect, writeBuffer, csMode); + } +} diff --git a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ft232h/Driver/FtdiDevice.Gpio.cs b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ft232h/Driver/FtdiDevice.Gpio.cs new file mode 100644 index 0000000000..4aeb29edee --- /dev/null +++ b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ft232h/Driver/FtdiDevice.Gpio.cs @@ -0,0 +1,93 @@ +using Meadow.Hardware; +using System; +using System.Threading; +using static Meadow.Foundation.ICs.IOExpanders.Native.Ftd2xx; + +namespace Meadow.Foundation.ICs.IOExpanders; + +internal partial class FtdiDevice +{ + private bool? _useMpseeForGpio = null; + + public byte GpioDirectionMask { get; set; } + public byte GpioState { get; set; } + + public I2cBusSpeed BusSpeed { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } + + internal void InitializeGpio() + { + // for now we don't support GPIO channels C and D on the FT4232H + + if (Handle == IntPtr.Zero) Open(); + + _useMpseeForGpio = true; + + if (_useMpseeForGpio ?? true) + { + // Reset + Native.CheckStatus( + FT_SetBitMode(Handle, 0x00, Native.FT_BITMODE.FT_BITMODE_RESET)); + + // Enable MPSSE mode + Native.CheckStatus( + FT_SetBitMode(Handle, 0x00, Native.FT_BITMODE.FT_BITMODE_MPSSE)); + + Thread.Sleep(50); + + ClearInputBuffer(); + InitializeMpsse(); + } + else + { + Native.CheckStatus( + FT_SetBitMode(Handle, 0x00, Native.FT_BITMODE.FT_BITMODE_RESET)); + + // Enable asynchronous bit bang mode, thise does allow to have different pin modes, put all pins as input + Native.CheckStatus( + FT_SetBitMode(Handle, 0x00, Native.FT_BITMODE.FT_BITMODE_ASYNC_BITBANG)); + + ClearInputBuffer(); + } + } + + internal byte GetGpioState(bool lowByte) + { + if (!_useMpseeForGpio.HasValue) + { + InitializeGpio(); + } + + if (_useMpseeForGpio ?? false) + { + 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]; + } + + throw new NotImplementedException(); + } + + internal void SetGpioState(bool lowByte, byte direction, byte state) + { + if (!_useMpseeForGpio.HasValue) + { + InitializeGpio(); + } + + if (_useMpseeForGpio ?? false) + { + Span outBuffer = stackalloc byte[3]; + outBuffer[0] = (byte)(lowByte ? Native.FT_OPCODE.SetDataBitsLowByte : Native.FT_OPCODE.SetDataBitsHighByte); + outBuffer[1] = state; //data + outBuffer[2] = direction; //direction 1 == output, 0 == input + Write(outBuffer); + return; + } + + throw new NotImplementedException(); + } +} diff --git a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ft232h/Driver/FtdiDevice.I2c.cs b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ft232h/Driver/FtdiDevice.I2c.cs new file mode 100644 index 0000000000..296ebb9eba --- /dev/null +++ b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ft232h/Driver/FtdiDevice.I2c.cs @@ -0,0 +1,398 @@ +using System; +using static Meadow.Foundation.ICs.IOExpanders.Native; +using static Meadow.Foundation.ICs.IOExpanders.Native.Ftd2xx; + +namespace Meadow.Foundation.ICs.IOExpanders; + +internal partial class FtdiDevice +{ + private byte GpioLowData = 0; + private byte GpioLowDir = 0; + // private byte GpioHighData = 0; + // private byte GpioHighDir = 0; + private uint _i2cFreqKbps = 400; + + private const byte NumberCycles = 6; + private const byte MaskGpio = 0xF8; + + internal static class PinDirection + { + public const byte SDAinSCLin = 0x00; + public const byte SDAinSCLout = 0x01; + public const byte SDAoutSCLin = 0x02; + public const byte SDAoutSCLout = 0x03; + } + + internal static class PinData + { + public const byte SDAloSCLhi = 0x01; + public const byte SDAhiSCLhi = 0x03; + public const byte SDAloSCLlo = 0x00; + public const byte SDAhiSCLlo = 0x02; + } + + public uint I2cBusFrequencyKbps + { + get => _i2cFreqKbps; + set + { + _i2cFreqKbps |= value; + InitializeI2CClocks(); + } + } + + public void InitializeI2C() + { + // TODO: make sure we're not already set up for SPI + + CheckStatus( + FT_SetTimeouts(Handle, DefaultTimeoutMs, DefaultTimeoutMs)); + CheckStatus( + FT_SetLatencyTimer(Handle, DefaultLatencyTimer)); + CheckStatus( + FT_SetFlowControl(Handle, FT_FLOWCONTROL.FT_FLOW_RTS_CTS, 0x00, 0x00)); + CheckStatus( + FT_SetBitMode(Handle, 0x00, FT_BITMODE.FT_BITMODE_RESET)); + CheckStatus( + FT_SetBitMode(Handle, 0x00, FT_BITMODE.FT_BITMODE_MPSSE)); + + ClearInputBuffer(); + InitializeI2CClocks(); + InitializeMpsse(); + } + + private void InitializeI2CClocks() + { + // Now setup the clock and other elements + Span toSend = stackalloc byte[13]; + int idx = 0; + // Disable clock divide by 5 for 60Mhz master clock + toSend[idx++] = (byte)FT_OPCODE.DisableClockDivideBy5; + // Turn off adaptive clocking + toSend[idx++] = (byte)FT_OPCODE.TurnOffAdaptiveClocking; + // Enable 3 phase data clock, used by I2C to allow data on both clock edges + toSend[idx++] = (byte)FT_OPCODE.Enable3PhaseDataClocking; + // The SK clock frequency can be worked out by below algorithm with divide by 5 set as off + // TCK period = 60MHz / (( 1 + [ (0xValueH * 256) OR 0xValueL] ) * 2) + // Command to set clock divisor + toSend[idx++] = (byte)FT_OPCODE.SetClockDivisor; + uint clockDivisor = (60000 / (I2cBusFrequencyKbps * 2)) - 1; + toSend[idx++] = (byte)(clockDivisor & 0x00FF); + toSend[idx++] = (byte)((clockDivisor >> 8) & 0x00FF); + // loopback off + toSend[idx++] = (byte)FT_OPCODE.DisconnectTDItoTDOforLoopback; + // Enable the FT232H's drive-zero mode with the following enable mask + toSend[idx++] = (byte)FT_OPCODE.SetIOOnlyDriveOn0AndTristateOn1; + // Low byte (ADx) enables - bits 0, 1 and 2 + toSend[idx++] = 0x07; + // High byte (ACx) enables - all off + toSend[idx++] = 0x00; + // Command to set directions of lower 8 pins and force value on bits set as output + toSend[idx++] = (byte)FT_OPCODE.SetDataBitsLowByte; + if (DeviceType == FtDeviceType.Ft232H) + { + // SDA and SCL both output high(open drain) + GpioLowData = (byte)(PinData.SDAhiSCLhi | (GpioLowData & MaskGpio)); + GpioLowDir = (byte)(PinDirection.SDAoutSCLout | (GpioLowDir & MaskGpio)); + } + else + { + // SDA and SCL set low but as input to mimic open drain + GpioLowData = (byte)(PinData.SDAloSCLlo | (GpioLowData & MaskGpio)); + GpioLowDir = (byte)(PinDirection.SDAinSCLin | (GpioLowDir & MaskGpio)); + } + + toSend[idx++] = GpioLowData; + toSend[idx++] = GpioLowDir; + Write(toSend); + } + + internal void I2cStart() + { + int count; + int idx = 0; + // SDA high, SCL high + // The behavior is a bit different for FT232H and FT2232H/FT4232H + if (DeviceType == FtDeviceType.Ft232H) + { + GpioLowData = (byte)(PinData.SDAhiSCLhi | (GpioLowData & MaskGpio)); + GpioLowDir = (byte)(PinDirection.SDAoutSCLout | (GpioLowDir & MaskGpio)); + } + else + { + GpioLowData = (byte)(PinData.SDAloSCLlo | (GpioLowData & MaskGpio)); + GpioLowDir = (byte)(PinDirection.SDAinSCLin | (GpioLowDir & MaskGpio)); + } + + Span toSend = stackalloc byte[(NumberCycles * 3 * 3) + 3]; + for (count = 0; count < NumberCycles; count++) + { + toSend[idx++] = (byte)FT_OPCODE.SetDataBitsLowByte; + toSend[idx++] = GpioLowData; + toSend[idx++] = GpioLowDir; + } + + // SDA lo, SCL high + // The behavior is a bit different for FT232H and FT2232H/FT4232H + if (DeviceType == FtDeviceType.Ft232H) + { + GpioLowData = (byte)(PinData.SDAloSCLhi | (GpioLowData & MaskGpio)); + } + else + { + GpioLowDir = (byte)(PinDirection.SDAoutSCLin | (GpioLowDir & MaskGpio)); + } + + for (count = 0; count < NumberCycles; count++) + { + toSend[idx++] = (byte)FT_OPCODE.SetDataBitsLowByte; + toSend[idx++] = GpioLowData; + toSend[idx++] = GpioLowDir; + } + + // SDA lo, SCL lo + // The behavior is a bit different for FT232H and FT2232H/FT4232H + if (DeviceType == FtDeviceType.Ft232H) + { + GpioLowData = (byte)(PinData.SDAloSCLlo | (GpioLowData & MaskGpio)); + } + else + { + GpioLowDir = (byte)(PinDirection.SDAoutSCLout | (GpioLowDir & MaskGpio)); + } + + for (count = 0; count < NumberCycles; count++) + { + toSend[idx++] = (byte)FT_OPCODE.SetDataBitsLowByte; + toSend[idx++] = GpioLowData; + toSend[idx++] = GpioLowDir; + } + + // Release SDA + // The behavior is a bit different for FT232H and FT2232H/FT4232H + if (DeviceType == FtDeviceType.Ft232H) + { + GpioLowData = (byte)(PinData.SDAhiSCLlo | (GpioLowData & MaskGpio)); + } + else + { + GpioLowDir = (byte)(PinDirection.SDAinSCLout | (GpioLowDir & MaskGpio)); + } + + toSend[idx++] = (byte)FT_OPCODE.SetDataBitsLowByte; + toSend[idx++] = GpioLowData; + toSend[idx++] = GpioLowDir; + + Write(toSend); + } + + internal void I2cStop() + { + int count; + int idx = 0; + // SDA low, SCL low + GpioLowData = (byte)(PinData.SDAloSCLlo | (GpioLowData & MaskGpio)); + GpioLowDir = (byte)(PinDirection.SDAoutSCLout | (GpioLowDir & MaskGpio)); + + Span toSend = stackalloc byte[NumberCycles * 3 * 3]; + for (count = 0; count < NumberCycles; count++) + { + toSend[idx++] = (byte)FT_OPCODE.SetDataBitsLowByte; + toSend[idx++] = GpioLowData; + toSend[idx++] = GpioLowDir; + } + + // SDA low, SCL high + // The behavior is a bit different for FT232H and FT2232H/FT4232H + if (DeviceType == FtDeviceType.Ft232H) + { + GpioLowData = (byte)(PinData.SDAloSCLhi | (GpioLowData & MaskGpio)); + GpioLowDir = (byte)(PinDirection.SDAoutSCLout | (GpioLowDir & MaskGpio)); + } + else + { + GpioLowData = (byte)(PinData.SDAloSCLlo | (GpioLowData & MaskGpio)); + GpioLowDir = (byte)(PinDirection.SDAoutSCLin | (GpioLowDir & MaskGpio)); + } + + for (count = 0; count < NumberCycles; count++) + { + toSend[idx++] = (byte)FT_OPCODE.SetDataBitsLowByte; + toSend[idx++] = GpioLowData; + toSend[idx++] = GpioLowDir; + } + + // SDA high, SCL high + // The behavior is a bit different for FT232H and FT2232H/FT4232H + if (DeviceType == FtDeviceType.Ft232H) + { + GpioLowData = (byte)(PinData.SDAhiSCLhi | (GpioLowData & MaskGpio)); + GpioLowDir = (byte)(PinDirection.SDAoutSCLout | (GpioLowDir & MaskGpio)); + } + else + { + GpioLowData = (byte)(PinData.SDAloSCLlo | (GpioLowData & MaskGpio)); + GpioLowDir = (byte)(PinDirection.SDAinSCLin | (GpioLowDir & MaskGpio)); + } + + for (count = 0; count < NumberCycles; count++) + { + toSend[idx++] = (byte)FT_OPCODE.SetDataBitsLowByte; + toSend[idx++] = GpioLowData; + toSend[idx++] = GpioLowDir; + } + + Write(toSend); + } + + internal void I2cLineIdle() + { + int idx = 0; + // SDA low, SCL low + // The behavior is a bit different for FT232H and FT2232H/FT4232H + if (DeviceType == FtDeviceType.Ft232H) + { + GpioLowData = (byte)(PinData.SDAhiSCLhi | (GpioLowData & MaskGpio)); + GpioLowDir = (byte)(PinDirection.SDAoutSCLout | (GpioLowDir & MaskGpio)); + } + else + { + GpioLowData = (byte)(PinData.SDAloSCLlo | (GpioLowData & MaskGpio)); + GpioLowDir = (byte)(PinDirection.SDAinSCLin | (GpioLowDir & MaskGpio)); + } + + Span toSend = stackalloc byte[3]; + toSend[idx++] = (byte)FT_OPCODE.SetDataBitsLowByte; + toSend[idx++] = GpioLowData; + toSend[idx++] = GpioLowDir; + Write(toSend); + } + + internal bool I2cSendByteAndCheckACK(byte data) + { + int idx = 0; + Span toSend = stackalloc byte[DeviceType == FtDeviceType.Ft232H ? 10 : 13]; + Span toRead = stackalloc byte[1]; + // The behavior is a bit different for FT232H and FT2232H/FT4232H + if (DeviceType == FtDeviceType.Ft232H) + { + // Just clock with one byte (0 = 1 byte) + toSend[idx++] = (byte)FT_OPCODE.ClockDataBytesOutOnMinusVeClockMSBFirst; + toSend[idx++] = 0; + toSend[idx++] = 0; + toSend[idx++] = data; + // Put line back to idle (data released, clock pulled low) + GpioLowData = (byte)(PinData.SDAhiSCLlo | (GpioLowData & MaskGpio)); + GpioLowDir = (byte)(PinDirection.SDAoutSCLout | (GpioLowDir & MaskGpio)); + toSend[idx++] = (byte)FT_OPCODE.SetDataBitsLowByte; + toSend[idx++] = GpioLowData; + toSend[idx++] = GpioLowDir; + // Clock in (0 = 1 byte) + toSend[idx++] = (byte)FT_OPCODE.ClockDataBitsInOnPlusVeClockMSBFirst; + toSend[idx++] = 0; + } + else + { + // Set directions and clock data + GpioLowData = (byte)(PinData.SDAloSCLlo | (GpioLowData & MaskGpio)); + GpioLowDir = (byte)(PinDirection.SDAoutSCLout | (GpioLowDir & MaskGpio)); + toSend[idx++] = (byte)FT_OPCODE.SetDataBitsLowByte; + toSend[idx++] = GpioLowData; + toSend[idx++] = GpioLowDir; + // Just clock with one byte (0 = 1 byte) + toSend[idx++] = (byte)FT_OPCODE.ClockDataBytesOutOnMinusVeClockMSBFirst; + toSend[idx++] = 0; + toSend[idx++] = 0; + toSend[idx++] = data; + // Put line back to idle (data released, clock pulled low) + // Set directions and clock data + GpioLowData = (byte)(PinData.SDAloSCLlo | (GpioLowData & MaskGpio)); + GpioLowDir = (byte)(PinDirection.SDAinSCLout | (GpioLowDir & MaskGpio)); + toSend[idx++] = (byte)FT_OPCODE.SetDataBitsLowByte; + toSend[idx++] = GpioLowData; + toSend[idx++] = GpioLowDir; + // Clock in (0 = 1 byte) + toSend[idx++] = (byte)FT_OPCODE.ClockDataBitsInOnPlusVeClockMSBFirst; + toSend[idx++] = 0; + } + + // And ask it right away + toSend[idx++] = (byte)FT_OPCODE.SendImmediate; + Write(toSend); + ReadInto(toRead); + // Bit 0 equivalent to acknowledge, otherwise nack + return (toRead[0] & 0x01) == 0; + } + + internal bool I2cSendDeviceAddrAndCheckACK(byte Address, bool Read) + { + // Set address for read or write + Address <<= 1; + if (Read == true) + { + Address |= 0x01; + } + + return I2cSendByteAndCheckACK(Address); + } + + internal byte I2CReadByte(bool ack) + { + int idx = 0; + Span toSend = stackalloc byte[DeviceType == FtDeviceType.Ft232H ? 10 : 16]; + Span toRead = stackalloc byte[1]; + // The behavior is a bit different for FT232H and FT2232H/FT4232H + if (DeviceType == FtDeviceType.Ft232H) + { + // Read one byte + toSend[idx++] = (byte)FT_OPCODE.ClockDataBytesInOnPlusVeClockMSBFirst; + toSend[idx++] = 0; + toSend[idx++] = 0; + // Send out either ack either nak + toSend[idx++] = (byte)FT_OPCODE.ClockDataBitsOutOnMinusVeClockMSBFirst; + toSend[idx++] = 0; + toSend[idx++] = (byte)(ack ? 0x00 : 0xFF); + // I2C lines back to idle state + toSend[idx++] = (byte)FT_OPCODE.SetDataBitsLowByte; + GpioLowData = (byte)(PinData.SDAhiSCLlo | (GpioLowData & MaskGpio)); + GpioLowDir = (byte)(PinDirection.SDAoutSCLout | (GpioLowDir & MaskGpio)); + toSend[idx++] = GpioLowData; + toSend[idx++] = GpioLowDir; + } + else + { + // Make sure no open gain + GpioLowData = (byte)(PinData.SDAloSCLlo | (GpioLowData & MaskGpio)); + GpioLowDir = (byte)(PinDirection.SDAinSCLout | (GpioLowDir & MaskGpio)); + toSend[idx++] = (byte)FT_OPCODE.SetDataBitsLowByte; + toSend[idx++] = GpioLowData; + toSend[idx++] = GpioLowDir; + // Read one byte + toSend[idx++] = (byte)FT_OPCODE.ClockDataBytesInOnPlusVeClockMSBFirst; + toSend[idx++] = 0; + toSend[idx++] = 0; + // Change direction + GpioLowData = (byte)(PinData.SDAloSCLlo | (GpioLowData & MaskGpio)); + GpioLowDir = (byte)(PinDirection.SDAoutSCLout | (GpioLowDir & MaskGpio)); + toSend[idx++] = (byte)FT_OPCODE.SetDataBitsLowByte; + toSend[idx++] = GpioLowData; + toSend[idx++] = GpioLowDir; + // Send out either ack either nak + toSend[idx++] = (byte)FT_OPCODE.ClockDataBitsOutOnMinusVeClockMSBFirst; + toSend[idx++] = 0; + toSend[idx++] = (byte)(ack ? 0x00 : 0xFF); + // I2C lines back to idle state + toSend[idx++] = (byte)FT_OPCODE.SetDataBitsLowByte; + GpioLowData = (byte)(PinData.SDAhiSCLlo | (GpioLowData & MaskGpio)); + GpioLowDir = (byte)(PinDirection.SDAinSCLout | (GpioLowDir & MaskGpio)); + toSend[idx++] = GpioLowData; + toSend[idx++] = GpioLowDir; + } + + // And ask it right away + toSend[idx++] = (byte)FT_OPCODE.SendImmediate; + Write(toSend); + ReadInto(toRead); + return toRead[0]; + } +} diff --git a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ft232h/Driver/FtdiDevice.Spi.cs b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ft232h/Driver/FtdiDevice.Spi.cs new file mode 100644 index 0000000000..147811933c --- /dev/null +++ b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ft232h/Driver/FtdiDevice.Spi.cs @@ -0,0 +1,210 @@ +using Meadow.Hardware; +using System; +using System.Threading; +using static Meadow.Foundation.ICs.IOExpanders.Native; +using static Meadow.Foundation.ICs.IOExpanders.Native.Ftd2xx; + +namespace Meadow.Foundation.ICs.IOExpanders; + +internal partial class FtdiDevice +{ + private SpiClockConfiguration? _spiConfig; + + internal void InitializeSpi(SpiClockConfiguration config) + { + if (_spiConfig != null) return; + + // TODO: make sure we're not already initialized for I2C + + _spiConfig = config; + + if (Handle == IntPtr.Zero) Open(); + + CheckStatus( + FT_SetLatencyTimer(Handle, 1)); + CheckStatus( + FT_SetUSBParameters(Handle, 65535, 65535)); + CheckStatus( + FT_SetChars(Handle, 0, 0, 0, 0)); + CheckStatus( + FT_SetTimeouts(Handle, 3000, 3000)); + CheckStatus( + FT_SetLatencyTimer(Handle, 1)); + // Reset + CheckStatus( + FT_SetBitMode(Handle, 0x00, FT_BITMODE.FT_BITMODE_RESET)); + // Enable MPSSE mode + CheckStatus( + FT_SetBitMode(Handle, 0x00, FT_BITMODE.FT_BITMODE_MPSSE)); + + // 50 ms according to thr doc for all USB to complete + Thread.Sleep(50); + ClearInputBuffer(); + InitializeMpsse(); + + int idx = 0; + Span toSend = stackalloc byte[10]; + toSend[idx++] = (byte)FT_OPCODE.DisableClockDivideBy5; + toSend[idx++] = (byte)FT_OPCODE.TurnOffAdaptiveClocking; + toSend[idx++] = (byte)FT_OPCODE.Disable3PhaseDataClocking; + toSend[idx++] = (byte)FT_OPCODE.SetDataBitsLowByte; + // Pin clock output, MISO output, MOSI input + GpioLowDir = (byte)((GpioLowDir & MaskGpio) | 0x03); + // clock, MOSI and MISO to 0 + GpioLowData = (byte)(GpioLowData & MaskGpio); + toSend[idx++] = GpioLowDir; + toSend[idx++] = GpioLowData; + // The SK clock frequency can be worked out by below algorithm with divide by 5 set as off + // TCK period = 60MHz / (( 1 + [ (0xValueH * 256) OR 0xValueL] ) * 2) + // Command to set clock divisor + toSend[idx++] = (byte)FT_OPCODE.SetClockDivisor; + uint clockDivisor = (uint)((60000 / (_spiConfig.Speed.Hertz / 1000 * 2)) - 1); + toSend[idx++] = (byte)(clockDivisor & 0xFF); + toSend[idx++] = (byte)(clockDivisor >> 8); + // loopback off + toSend[idx++] = (byte)FT_OPCODE.DisconnectTDItoTDOforLoopback; + Write(toSend); + // Delay as in the documentation + Thread.Sleep(30); + } + + internal void SpiWrite(IDigitalOutputPort? chipSelect, ReadOnlySpan writeBuffer, ChipSelectMode csMode) + { + if (_spiConfig == null) + { + throw new Exception("SPI not configured"); + } + + if (writeBuffer.Length > 65535) + { + throw new ArgumentException("Buffer too large, maximum size if 65535"); + } + + byte clock; + switch (_spiConfig.SpiMode) + { + default: + case SpiClockConfiguration.Mode.Mode3: + case SpiClockConfiguration.Mode.Mode0: + clock = (byte)FT_OPCODE.ClockDataBytesOutOnMinusVeClockMSBFirst; + break; + case SpiClockConfiguration.Mode.Mode2: + case SpiClockConfiguration.Mode.Mode1: + clock = (byte)FT_OPCODE.ClockDataBytesOutOnPlusVeClockMSBFirst; + break; + } + + if (chipSelect != null) + { + // assert + chipSelect.State = csMode == ChipSelectMode.ActiveHigh ? true : false; + } + + int idx = 0; + Span toSend = stackalloc byte[3 + writeBuffer.Length]; + toSend[idx++] = clock; + toSend[idx++] = (byte)((writeBuffer.Length - 1) & 0xFF); + toSend[idx++] = (byte)((writeBuffer.Length - 1) >> 8); + writeBuffer.CopyTo(toSend.Slice(3)); + Write(toSend); + if (chipSelect != null) + { + // deassert + chipSelect.State = csMode == ChipSelectMode.ActiveHigh ? false : true; + } + } + + internal void SpiRead(IDigitalOutputPort? chipSelect, Span readBuffer, ChipSelectMode csMode) + { + if (_spiConfig == null) + { + throw new Exception("SPI not configured"); + } + + if (readBuffer.Length > 65535) + { + throw new ArgumentException("Buffer too large, maximum size if 65535"); + } + + byte clock; + switch (_spiConfig.SpiMode) + { + default: + case SpiClockConfiguration.Mode.Mode3: + case SpiClockConfiguration.Mode.Mode0: + clock = (byte)FT_OPCODE.ClockDataBytesInOnPlusVeClockMSBFirst; + break; + case SpiClockConfiguration.Mode.Mode2: + case SpiClockConfiguration.Mode.Mode1: + clock = (byte)FT_OPCODE.ClockDataBytesInOnMinusVeClockMSBFirst; + break; + } + + if (chipSelect != null) + { + // assert + chipSelect.State = csMode == ChipSelectMode.ActiveHigh ? true : false; + } + + int idx = 0; + Span toSend = stackalloc byte[3]; + toSend[idx++] = clock; + toSend[idx++] = (byte)((readBuffer.Length - 1) & 0xFF); + toSend[idx++] = (byte)((readBuffer.Length - 1) >> 8); + Write(toSend); + ReadInto(readBuffer); + + if (chipSelect != null) + { + // deassert + chipSelect.State = csMode == ChipSelectMode.ActiveHigh ? false : true; + } + } + + internal void SpiExchange(IDigitalOutputPort? chipSelect, ReadOnlySpan writeBuffer, Span readBuffer, ChipSelectMode csMode) + { + if (_spiConfig == null) + { + throw new Exception("SPI not configured"); + } + + if ((readBuffer.Length > 65535) || (writeBuffer.Length > 65535)) + { + throw new ArgumentException("Buffer too large, maximum size if 65535"); + } + + byte clock; + switch (_spiConfig.SpiMode) + { + default: + case SpiClockConfiguration.Mode.Mode3: + case SpiClockConfiguration.Mode.Mode0: + clock = (byte)FT_OPCODE.ClockDataBytesOutOnMinusBytesInOnPlusVeClockMSBFirst; + break; + case SpiClockConfiguration.Mode.Mode2: + case SpiClockConfiguration.Mode.Mode1: + clock = (byte)FT_OPCODE.ClockDataBytesOutOnPlusBytesInOnMinusVeClockMSBFirst; + break; + } + + if (chipSelect != null) + { + // assert + chipSelect.State = csMode == ChipSelectMode.ActiveHigh ? true : false; + } + + int idx = 0; + Span toSend = stackalloc byte[3 + writeBuffer.Length]; + toSend[idx++] = clock; + toSend[idx++] = (byte)((writeBuffer.Length - 1) & 0xFF); + toSend[idx++] = (byte)((writeBuffer.Length - 1) >> 8); + writeBuffer.CopyTo(toSend.Slice(3)); + Write(toSend); + ReadInto(readBuffer); + if (chipSelect != null) + { + // deassert + chipSelect.State = csMode == ChipSelectMode.ActiveHigh ? false : true; + } + } +} diff --git a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ft232h/Driver/FtdiDevice.cs b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ft232h/Driver/FtdiDevice.cs new file mode 100644 index 0000000000..99dfcffacd --- /dev/null +++ b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ft232h/Driver/FtdiDevice.cs @@ -0,0 +1,138 @@ +using System; +using System.IO; +using System.Runtime.InteropServices; +using static Meadow.Foundation.ICs.IOExpanders.Native; +using static Meadow.Foundation.ICs.IOExpanders.Native.Ftd2xx; + +namespace Meadow.Foundation.ICs.IOExpanders; + +internal partial class FtdiDevice +{ + private const int DefaultTimeoutMs = 5000; + private const int DefaultLatencyTimer = 16; + + internal uint Index { get; } + internal uint Flags { get; } + internal FtDeviceType DeviceType { get; } + internal uint ID { get; } + internal uint LocID { get; } + internal string SerialNumber { get; } + internal string Description { get; } + internal IntPtr Handle { get; private set; } + + internal FtdiDevice( + uint index, + uint flags, + FtDeviceType deviceType, + uint id, + uint locid, + string serialNumber, + string description, + IntPtr handle + ) + { + Index = index; + Flags = flags; + DeviceType = deviceType; + ID = id; + LocID = locid; + SerialNumber = serialNumber; + Description = description; + Handle = handle; + } + + public void Open() + { + if (Handle == IntPtr.Zero) + { + Native.CheckStatus( + FT_OpenEx(LocID, Native.FT_OPEN_TYPE.FT_OPEN_BY_LOCATION, out IntPtr handle) + ); + Handle = handle; + } + } + + private void InitializeMpsse() + { + Span writeBuffer = stackalloc byte[1]; + writeBuffer[0] = 0xAA; + Write(writeBuffer); + Span readBuffer = stackalloc byte[2]; + ReadInto(readBuffer); + if (!((readBuffer[0] == 0xFA) && (readBuffer[1] == 0xAA))) + { + throw new IOException($"Failed to setup device {Description} in MPSSE mode using magic 0xAA sync"); + } + + // Second with 0xAB + writeBuffer[0] = 0xAB; + Write(writeBuffer); + ReadInto(readBuffer); + if (!((readBuffer[0] == 0xFA) && (readBuffer[1] == 0xAB))) + { + throw new IOException($"Failed to setup device {Description}, status in MPSSE mode using magic 0xAB sync"); + } + } + + public int ReadInto(Span buffer) + { + var totalRead = 0; + uint read = 0; + + while (totalRead < buffer.Length) + { + var available = GetAvailableBytes(); + if (available > 0) + { + CheckStatus( + FT_Read(Handle, in buffer[totalRead], available, ref read)); + + totalRead += (int)read; + } + } + + return totalRead; + } + + public void Write(ReadOnlySpan data) + { + uint written = 0; + + CheckStatus( + FT_Write(Handle, in MemoryMarshal.GetReference(data), (ushort)data.Length, ref written)); + } + + private void ClearInputBuffer() + { + var available = GetAvailableBytes(); + + if (available > 0) + { + var toRead = new byte[available]; + uint bytesRead = 0; + CheckStatus( + FT_Read(Handle, in toRead[0], available, ref bytesRead)); + } + } + + private uint GetAvailableBytes() + { + uint availableBytes = 0; + + CheckStatus( + FT_GetQueueStatus(Handle, ref availableBytes)); + + return availableBytes; + } + + public void Close() + { + if (Handle != IntPtr.Zero) + { + CheckStatus( + FT_Close(Handle)); + + Handle = IntPtr.Zero; + } + } +} diff --git a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ft232h/Driver/FtdiDeviceCollection.cs b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ft232h/Driver/FtdiDeviceCollection.cs new file mode 100644 index 0000000000..0ea1c4c4f3 --- /dev/null +++ b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ft232h/Driver/FtdiDeviceCollection.cs @@ -0,0 +1,80 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Runtime.InteropServices; +using System.Text; +using static Meadow.Foundation.ICs.IOExpanders.Native.Ftd2xx; + +namespace Meadow.Foundation.ICs.IOExpanders; + +internal class FtdiDeviceCollection : IEnumerable +{ + private List _devices = new(); + + public int Count => _devices.Count; + + public FtdiDevice this[int index] + { + get => _devices[index]; + } + + public void Refresh() + { + _devices.Clear(); + + uint count; + + try + { + Native.CheckStatus(FT_CreateDeviceInfoList(out count)); + } + catch (DllNotFoundException) + { + throw new DriverNotInstalledException(); + } + + ReadOnlySpan serialNumberBuffer = stackalloc byte[16]; + ReadOnlySpan descriptionBuffer = stackalloc byte[64]; + + for (uint index = 0; index < count; index++) + { + Native.CheckStatus(FT_GetDeviceInfoDetail( + index, + out uint flags, + out FtDeviceType deviceType, + out uint id, + out uint locid, + in MemoryMarshal.GetReference(serialNumberBuffer), + in MemoryMarshal.GetReference(descriptionBuffer), + out IntPtr handle)); + + switch (deviceType) + { + case FtDeviceType.Ft232H: + case FtDeviceType.Ft2232: + case FtDeviceType.Ft2232H: + case FtDeviceType.Ft4232H: + // valid, add to list + break; + default: + continue; + } + + // no idea why the buffer isn't all zeros after the null terminator - thanks FTDI! + var serialNumber = Encoding.ASCII.GetString(serialNumberBuffer.ToArray(), 0, serialNumberBuffer.IndexOf((byte)0)); + var description = Encoding.ASCII.GetString(descriptionBuffer.ToArray(), 0, descriptionBuffer.IndexOf((byte)0)); + + _devices.Add(new FtdiDevice(index, flags, deviceType, id, locid, serialNumber, description, handle)); + } + } + + public IEnumerator GetEnumerator() + { + return _devices.GetEnumerator(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } +} diff --git a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ft232h/Driver/ICs.IOExpanders.Ft232h.csproj b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ft232h/Driver/ICs.IOExpanders.Ft232h.csproj index 99c106b31c..b25097c2d2 100644 --- a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ft232h/Driver/ICs.IOExpanders.Ft232h.csproj +++ b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ft232h/Driver/ICs.IOExpanders.Ft232h.csproj @@ -15,13 +15,13 @@ Meadow.Foundation.ICs.IOExpanders.Ft232h https://github.com/WildernessLabs/Meadow.Foundation Meadow.Foundation,IOExpanders,expander,IO,Ft232h - 0.1.0 + 1.7.0 true Ft232h USB IOExpander for GPIO, I2C, SPI on Windows - - + + diff --git a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ft232h/Driver/IFt232Bus.cs b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ft232h/Driver/IFt232Bus.cs index d91ee18fd5..bade933078 100644 --- a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ft232h/Driver/IFt232Bus.cs +++ b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ft232h/Driver/IFt232Bus.cs @@ -1,11 +1,24 @@ using System; -namespace Meadow.Foundation.ICs.IOExpanders +namespace Meadow.Foundation.ICs.IOExpanders; + +/// +/// Represents an interface for interacting with an FT232 bus. +/// +internal interface IFt232Bus { - internal interface IFt232Bus - { - public IntPtr Handle { get; } - public byte GpioDirectionMask { get; set; } - public byte GpioState { get; set; } - } -} \ No newline at end of file + /// + /// Gets the handle to the FT232 device. + /// + IntPtr Handle { get; } + + /// + /// Gets or sets the GPIO direction mask for the FT232 device. + /// + byte GpioDirectionMask { get; set; } + + /// + /// Gets or sets the state of the GPIO pins on the FT232 device. + /// + byte GpioState { get; set; } +} diff --git a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ft232h/Driver/IFtdiImpl.cs b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ft232h/Driver/IFtdiImpl.cs new file mode 100644 index 0000000000..0ce8faca27 --- /dev/null +++ b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ft232h/Driver/IFtdiImpl.cs @@ -0,0 +1,13 @@ +using Meadow.Hardware; +using System; + +namespace Meadow.Foundation.ICs.IOExpanders; + +internal interface IFtdiImpl : IDisposable +{ + void Initialize(); + II2cBus CreateI2cBus(int busNumber, I2CClockRate clock); + ISpiBus CreateSpiBus(int busNumber, SpiClockConfiguration config); + IDigitalInputPort CreateDigitalInputPort(int channel, IPin pin, ResistorMode resistorMode); + IDigitalOutputPort CreateDigitalOutputPort(int channel, IPin pin, bool initialState = false, OutputType initialOutputType = OutputType.PushPull); +} diff --git a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ft232h/Driver/Ft232DigitalInputPort.cs b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ft232h/Driver/MpsseDigitalInputPort.cs similarity index 89% rename from Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ft232h/Driver/Ft232DigitalInputPort.cs rename to Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ft232h/Driver/MpsseDigitalInputPort.cs index 0b86f372e1..312af6ae0b 100644 --- a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ft232h/Driver/Ft232DigitalInputPort.cs +++ b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ft232h/Driver/MpsseDigitalInputPort.cs @@ -6,17 +6,17 @@ namespace Meadow.Foundation.ICs.IOExpanders /// /// Represents a digital input port implementation for the FT232 bus. /// - public sealed class Ft232DigitalInputPort : DigitalInterruptPortBase + public sealed class MpsseDigitalInputPort : DigitalInterruptPortBase { private readonly IFt232Bus _bus; /// - /// Instantiates a . + /// Instantiates a . /// /// The pin connected to the input port. /// The digital channel info associated with the pin. /// The FT232 bus instance. - internal Ft232DigitalInputPort(IPin pin, IDigitalChannelInfo info, IFt232Bus bus) + internal MpsseDigitalInputPort(IPin pin, IDigitalChannelInfo info, IFt232Bus bus) : base(pin, info) { _bus = bus; @@ -31,7 +31,7 @@ public override bool State get { // reads all 8 pis at once - Native.Functions.FT_ReadGPIO(_bus.Handle, out byte state); + Native.Mpsse.FT_ReadGPIO(_bus.Handle, out byte state); // the pin key is the mask return (state & (byte)Pin.Key) != 0; } diff --git a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ft232h/Driver/MpsseI2cBus.cs b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ft232h/Driver/MpsseI2cBus.cs new file mode 100644 index 0000000000..1e7b13911c --- /dev/null +++ b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ft232h/Driver/MpsseI2cBus.cs @@ -0,0 +1,137 @@ +using Meadow.Hardware; +using System; +using System.Diagnostics; +using System.Runtime.InteropServices; +using static Meadow.Foundation.ICs.IOExpanders.Native; + +namespace Meadow.Foundation.ICs.IOExpanders; + +/// +/// Represents an I2C bus implementation using the MPSSE mode of the FT232 device. +/// +public sealed class MpsseI2cBus : IFt232Bus, II2cBus, IDisposable +{ + private const byte DefaultLatencyTimer = 10; + private const I2CChannelOptions DefaultChannelOptions = I2CChannelOptions.None; + + private bool _isDisposed; + + /// + public IntPtr Handle { get; private set; } + + /// + public byte GpioDirectionMask { get; set; } + + /// + public byte GpioState { get; set; } + internal bool IsOpen { get; private set; } = false; + internal int ChannelNumber { get; } + private FT_DEVICE_LIST_INFO_NODE InfoNode { get; } + + internal MpsseI2cBus(int channelNumber, FT_DEVICE_LIST_INFO_NODE info) + { + ChannelNumber = channelNumber; + InfoNode = info; + } + + /// + public I2cBusSpeed BusSpeed { get; set; } + + private void Dispose(bool disposing) + { + if (!_isDisposed) + { + CloseChannel(); + + _isDisposed = true; + } + } + + /// + /// Finalizer for the MpsseI2cBus class, used to release unmanaged resources. + /// + ~MpsseI2cBus() + { + // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method + Dispose(false); + } + + /// + public void Dispose() + { + // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method + Dispose(true); + GC.SuppressFinalize(this); + } + + internal void Open(I2CClockRate clockRate = I2CClockRate.Standard) + { + if (CheckStatus(Mpsse.I2C_OpenChannel(ChannelNumber, out IntPtr handle))) + { + Handle = handle; + + var config = new I2CChannelConfig + { + ClockRate = clockRate, + LatencyTimer = DefaultLatencyTimer, + Options = DefaultChannelOptions + }; + + CheckStatus(Mpsse.I2C_InitChannel(Handle, ref config)); + + IsOpen = true; + } + } + + private void CloseChannel() + { + if (Handle != IntPtr.Zero) + { + CheckStatus(Mpsse.I2C_CloseChannel(Handle)); + Handle = IntPtr.Zero; + } + } + + /// + public void Exchange(byte peripheralAddress, Span writeBuffer, Span readBuffer) + { + Write(peripheralAddress, writeBuffer); + Read(peripheralAddress, readBuffer); + } + + /// + public void Read(byte peripheralAddress, Span readBuffer) + { + var status = Mpsse.I2C_DeviceRead( + Handle, + peripheralAddress, + readBuffer.Length, + MemoryMarshal.GetReference(readBuffer), + out int transferred, + I2CTransferOptions.FAST_TRANSFER | I2CTransferOptions.FAST_TRANSFER_BYTES + //I2CTransferOptions.START_BIT | I2CTransferOptions.STOP_BIT | I2CTransferOptions.NACK_LAST_BYTE + // I2CTransferOptions.START_BIT | I2CTransferOptions.STOP_BIT | I2CTransferOptions.FAST_TRANSFER | I2CTransferOptions.NACK_LAST_BYTE + ); + + Debug.WriteLine($"transferred: {transferred}"); + CheckStatus(status); + } + + /// + public void Write(byte peripheralAddress, Span writeBuffer) + { + var status = Mpsse.I2C_DeviceWrite( + Handle, + peripheralAddress, + writeBuffer.Length, + MemoryMarshal.GetReference(writeBuffer), + out int transferred, + I2CTransferOptions.FAST_TRANSFER | I2CTransferOptions.FAST_TRANSFER_BYTES + //I2CTransferOptions.START_BIT | I2CTransferOptions.BREAK_ON_NACK + //I2CTransferOptions.START_BIT | I2CTransferOptions.STOP_BIT | I2CTransferOptions.NACK_LAST_BYTE + ); + + Debug.WriteLine($"transferred: {transferred}"); + // CheckStatus(status); + } +} \ No newline at end of file diff --git a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ft232h/Driver/Native.Ftd2xx.cs b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ft232h/Driver/Native.Ftd2xx.cs new file mode 100644 index 0000000000..39d8391e8c --- /dev/null +++ b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ft232h/Driver/Native.Ftd2xx.cs @@ -0,0 +1,72 @@ +using System; +using System.Runtime.InteropServices; + +namespace Meadow.Foundation.ICs.IOExpanders; + +internal static partial class Native +{ + public class Ftd2xx + { + public enum FtDeviceType + { + Ft232BOrFt245B = 0, + Ft8U232AmOrFTtU245Am, + Ft8U100Ax, + UnknownDevice, + Ft2232, + Ft232ROrFt245R, + Ft2232H, + Ft4232H, + Ft232H, + FtXSeries, + Ft4222HMode0or2With2Interfaces, + Ft4222HMode1or2With4Interfaces, + Ft4222HMode3With1Interface, + Ft4222OtpProgrammerBoard, + } + + private const string FTDI_LIB = "ftd2xx"; + + [DllImport(FTDI_LIB, CallingConvention = CallingConvention.Cdecl, SetLastError = true)] + public static extern FT_STATUS FT_CreateDeviceInfoList(out uint numdevs); + + [DllImport(FTDI_LIB, CallingConvention = CallingConvention.Cdecl, SetLastError = true)] + public static extern FT_STATUS FT_GetDeviceInfoDetail(uint index, out uint flags, out FtDeviceType chiptype, out uint id, out uint locid, in byte serialnumber, in byte description, out IntPtr ftHandle); + + [DllImport(FTDI_LIB, CallingConvention = CallingConvention.Cdecl, SetLastError = true)] + public static extern FT_STATUS FT_OpenEx(uint pvArg1, FT_OPEN_TYPE dwFlags, out IntPtr ftHandle); + + [DllImport(FTDI_LIB, CallingConvention = CallingConvention.Cdecl, SetLastError = true)] + public static extern FT_STATUS FT_Close(IntPtr ftHandle); + + [DllImport(FTDI_LIB, CallingConvention = CallingConvention.Cdecl, SetLastError = true)] + public static extern FT_STATUS FT_SetTimeouts(IntPtr ftHandle, uint dwReadTimeout, uint dwWriteTimeout); + + [DllImport(FTDI_LIB, CallingConvention = CallingConvention.Cdecl, SetLastError = true)] + public static extern FT_STATUS FT_SetLatencyTimer(IntPtr ftHandle, byte ucLatency); + + [DllImport(FTDI_LIB, CallingConvention = CallingConvention.Cdecl, SetLastError = true)] + public static extern FT_STATUS FT_SetFlowControl(IntPtr ftHandle, FT_FLOWCONTROL usFlowControl, byte uXon, byte uXoff); + + [DllImport(FTDI_LIB, CallingConvention = CallingConvention.Cdecl, SetLastError = true)] + public static extern FT_STATUS FT_SetBitMode(IntPtr ftHandle, byte ucMask, FT_BITMODE ucMode); + + [DllImport(FTDI_LIB, CallingConvention = CallingConvention.Cdecl, SetLastError = true)] + public static extern FT_STATUS FT_GetBitMode(IntPtr ftHandle, ref byte ucMode); + + [DllImport(FTDI_LIB, CallingConvention = CallingConvention.Cdecl, SetLastError = true)] + public static extern FT_STATUS FT_GetQueueStatus(IntPtr ftHandle, ref uint lpdwAmountInRxQueue); + + [DllImport(FTDI_LIB, CallingConvention = CallingConvention.Cdecl, SetLastError = true)] + public static extern FT_STATUS FT_Read(IntPtr ftHandle, in byte lpBuffer, uint dwBytesToRead, ref uint lpdwBytesReturned); + + [DllImport(FTDI_LIB, CallingConvention = CallingConvention.Cdecl, SetLastError = true)] + public static extern FT_STATUS FT_Write(IntPtr ftHandle, in byte lpBuffer, uint dwBytesToWrite, ref uint lpdwBytesWritten); + + [DllImport(FTDI_LIB, CallingConvention = CallingConvention.Cdecl, SetLastError = true)] + public static extern FT_STATUS FT_SetChars(IntPtr ftHandle, byte uEventCh, byte uEventChEn, byte uErrorCh, byte uErrorChEn); + + [DllImport(FTDI_LIB, CallingConvention = CallingConvention.Cdecl, SetLastError = true)] + public static extern FT_STATUS FT_SetUSBParameters(IntPtr ftHandle, uint dwInTransferSize, uint dwOutTransferSize); + } +} \ No newline at end of file diff --git a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ft232h/Driver/Native.Functions.cs b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ft232h/Driver/Native.Mpsse.cs similarity index 99% rename from Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ft232h/Driver/Native.Functions.cs rename to Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ft232h/Driver/Native.Mpsse.cs index 0c0d75659d..01f0c95108 100644 --- a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ft232h/Driver/Native.Functions.cs +++ b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ft232h/Driver/Native.Mpsse.cs @@ -6,8 +6,7 @@ namespace Meadow.Foundation.ICs.IOExpanders { internal static partial class Native { - - public class Functions + public static class Mpsse { private const string MPSSE_LIB = "libmpsse"; diff --git a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ft232h/Driver/Native.cs b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ft232h/Driver/Native.cs index b2514a077f..b928a2ebe6 100644 --- a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ft232h/Driver/Native.cs +++ b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ft232h/Driver/Native.cs @@ -15,6 +15,13 @@ public static bool CheckStatus(Native.FT_STATUS status) throw new Exception($"Native error: {status}"); } + public enum FT_OPEN_TYPE + { + FT_OPEN_BY_SERIAL_NUMBER = 1, + FT_OPEN_BY_DESCRIPTION = 2, + FT_OPEN_BY_LOCATION = 4 + } + public enum FT_DEVICE_TYPE { FT_DEVICE_BM, @@ -57,6 +64,90 @@ public enum FT_FLAGS FT_FLAGS_HISPEED = 2 } + [Flags] + public enum FT_FLOWCONTROL : ushort + { + FT_FLOW_NONE = 0x0000, + FT_FLOW_RTS_CTS = 0x0100, + FT_FLOW_DTR_DSR = 0x0200, + FT_FLOW_XON_XOFF = 0x0400, + } + + [Flags] + public enum FT_BITMODE + { + FT_BITMODE_RESET = 0x00, + FT_BITMODE_ASYNC_BITBANG = 0x01, + FT_BITMODE_MPSSE = 0x02, + FT_BITMODE_SYNC_BITBANG = 0x04, + FT_BITMODE_MCU_HOST = 0x08, + FT_BITMODE_FAST_SERIAL = 0x10, + FT_BITMODE_CBUS_BITBANG = 0x20, + FT_BITMODE_SYNC_FIFO = 0x40, + + } + internal enum FT_OPCODE + { + ClockDataBytesOutOnPlusVeClockMSBFirst = 0x10, + ClockDataBytesOutOnMinusVeClockMSBFirst = 0x11, + ClockDataBitsOutOnPlusVeClockMSBFirst = 0x12, + ClockDataBitsOutOnMinusVeClockMSBFirst = 0x13, + ClockDataBytesInOnPlusVeClockMSBFirst = 0x20, + ClockDataBytesInOnMinusVeClockMSBFirst = 0x24, + ClockDataBitsInOnPlusVeClockMSBFirst = 0x22, + ClockDataBitsInOnMinusVeClockMSBFirst = 0x26, + ClockDataBytesOutOnMinusBytesInOnPlusVeClockMSBFirst = 0x31, + ClockDataBytesOutOnPlusBytesInOnMinusVeClockMSBFirst = 0x34, + ClockDataBitsOutOnMinusBitsInOnPlusVeClockMSBFirst = 0x33, + ClockDataBitsOutOnPlusBitsInOnMinusVeClockMSBFirst = 0x36, + ClockDataBytesOutOnPlusVeClockLSBFirst = 0x18, + ClockDataBytesOutOnMinusVeClockLSBFirst = 0x19, + ClockDataBitsOutOnPlusVeClockLSBFirst = 0x1A, + ClockDataBitsOutOnMinusVeClockLSBFirst = 0x1B, + ClockDataBytesInOnPlusVeClockLSBFirst = 0x28, + ClockDataBytesInOnMinusVeClockLSBFirst = 0x2C, + ClockDataBitsInOnPlusVeClockLSBFirst = 0x2A, + ClockDataBitsInOnMinusVeClockSBFirst = 0x2E, + ClockDataBytesOutOnMinusBytesInOnPlusVeClockLSBFirst = 0x39, + ClockDataBytesOutOnPlusBytesInOnMinusVeClockLSBFirst = 0x3C, + ClockDataBitsOutOnMinusBitsInOnPlusVeClockLSBFirst = 0x3B, + ClockDataBitsOutOnPlusBitsInOnMinusVeClockLSBFirst = 0x3E, + ClockDataBytesOutOnPlusVeClockTMSPinLSBFirst = 0x4A, + ClockDataBytesOutOnMinusVeClockTMSPinSBFirst = 0x4B, + ClockDataBytesOutOnPlusDataInOnPlusVeClockTMSPinSBFirst = 0x6A, + ClockDataBytesOutOnMinusDataInOnPlusVeClockTMSPinSBFirst = 0x6B, + ClockDataBytesOutOnPlusDataInOnMinusVeClockTMSPinSBFirst = 0x6E, + ClockDataBytesOutOnMinusDataInOnMinusVeClockTMSPinSBFirst = 0x6F, + SetDataBitsLowByte = 0x80, + SetDataBitsHighByte = 0x82, + ReadDataBitsLowByte = 0x81, + ReadDataBitsHighByte = 0x83, + ConnectTDItoTDOforLoopback = 0x84, + DisconnectTDItoTDOforLoopback = 0x85, + SetTCKSKDivisor = 0x86, + SetClockDivisor = 0x86, + CPUModeReadShortAddress = 0x90, + CPUModeReadExtendedAddress = 0x91, + CPUModeWriteShortAddress = 0x92, + CPUModeWriteExtendedAddress = 0x93, + SendImmediate = 0x87, + WaitOnIOHigh = 0x88, + WaitOnIOLow = 0x89, + DisableClockDivideBy5 = 0x8A, + EnableClockDivideBy5 = 0x8B, + Enable3PhaseDataClocking = 0x8C, + Disable3PhaseDataClocking = 0x8D, + ClockForNBitsWithNoDataTransfer = 0x8E, + ClockForNx8BitsWithNoDataTransfer = 0x8F, + ClockContinuouslyAndWaitOnIOHigh = 0x94, + ClockContinuouslyAndWaitOnIOLow = 0x95, + TurnOnAdaptiveClocking = 0x96, + TurnOffAdaptiveClocking = 0x97, + ClockForNx8BitsWithNoDataTransferOrUntilGPIOL1IsHigh = 0x9C, + ClockForNx8BitsWithNoDataTransferOrUntilGPIOL1IsLow = 0x9D, + SetIOOnlyDriveOn0AndTristateOn1 = 0x9E, + } + public enum FT_STATUS { FT_OK, diff --git a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ft232h/Samples/Ft232h_Windows_Sample/Ft232h_Windows_Sample.csproj b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ft232h/Samples/Ft232h_Windows_Sample/Ft232h_Windows_Sample.csproj index c6330111cf..4d9ba1d580 100644 --- a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ft232h/Samples/Ft232h_Windows_Sample/Ft232h_Windows_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ft232h/Samples/Ft232h_Windows_Sample/Ft232h_Windows_Sample.csproj @@ -14,7 +14,10 @@ - + + + + diff --git a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ft232h/Samples/Ft232h_Windows_Sample/Program.cs b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ft232h/Samples/Ft232h_Windows_Sample/Program.cs index e3b8a036a9..14eaaffede 100644 --- a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ft232h/Samples/Ft232h_Windows_Sample/Program.cs +++ b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ft232h/Samples/Ft232h_Windows_Sample/Program.cs @@ -1,29 +1,79 @@ // See https://aka.ms/new-console-template for more information using Meadow; +using Meadow.Foundation.Displays; using Meadow.Foundation.ICs.IOExpanders; +using Meadow.Foundation.Sensors.Atmospheric; +using Meadow.Hardware; +using System.Diagnostics; -Resolver.Log.Info("HELLO FROM THE WILDERNESS FT232H DRIVER!"); +Console.WriteLine("HELLO FROM THE WILDERNESS FT232H DRIVER!"); var ft232 = new Ft232h(); -/* -var i2cChannels = ft232.GetI2CChannels(); -Resolver.Log.Info($"{i2cChannels.Length} I2C CHANNELS"); -foreach (var c in i2cChannels) +//await TestBME280(ft232); +await TestIli9341(ft232); +//await TestGpio(ft232); + +async Task TestBME280(Ft232h expander) { - Resolver.Log.Info($"Serial #: {c.SerialNumber}"); - Resolver.Log.Info($"Description #: {c.Description}"); + var bme = new Bme280(expander.CreateI2cBus()); + + while (true) + { + var reading = await bme.Read(); + Debug.WriteLine($"Temp: {reading.Temperature.Value.Fahrenheit}F Humidity: {reading.Humidity.Value.Percent}%"); + await Task.Delay(1000); + } } -var spiChannels = ft232.GetSpiChannels(); -Resolver.Log.Info($"{spiChannels.Length} SPI CHANNELS"); -foreach (var c in spiChannels) +async Task TestGpio(Ft232h expander) { - Resolver.Log.Info($"Serial #: {c.SerialNumber}"); - Resolver.Log.Info($"Description #: {c.Description}"); -} -*/ + var outputs = new List + { + expander.CreateDigitalOutputPort(expander.Pins.C0), + expander.CreateDigitalOutputPort(expander.Pins.C1), + expander.CreateDigitalOutputPort(expander.Pins.C2), + expander.CreateDigitalOutputPort(expander.Pins.C3), + expander.CreateDigitalOutputPort(expander.Pins.C4), + expander.CreateDigitalOutputPort(expander.Pins.C5), + expander.CreateDigitalOutputPort(expander.Pins.C6), + expander.CreateDigitalOutputPort(expander.Pins.D7), +}; + + var s = false; -Console.ReadKey(); + while (true) + { + for (var i = 0; i < outputs.Count; i++) + { + var setTo = (i % 2 == 0) ? s : !s; + outputs[i].State = setTo; + } + + await Task.Delay(1000); + s = !s; + } +} + +async Task TestIli9341(Ft232h expander) +{ + var ili = new Ili9341( + expander.CreateSpiBus(), + expander.CreateDigitalOutputPort(expander.Pins.C0), + expander.CreateDigitalOutputPort(expander.Pins.C2), + expander.CreateDigitalOutputPort(expander.Pins.C1), + 480, + 320 + ); + while (true) + { + ili.Fill(Color.Red); + await Task.Delay(1000); + ili.Fill(Color.Green); + await Task.Delay(1000); + ili.Fill(Color.Blue); + await Task.Delay(1000); + } +} \ No newline at end of file diff --git a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ft232h/Tests/FT232.Unit.Tests/FT232.Unit.Tests.csproj b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ft232h/Tests/FT232.Unit.Tests/FT232.Unit.Tests.csproj new file mode 100644 index 0000000000..fda06f7398 --- /dev/null +++ b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ft232h/Tests/FT232.Unit.Tests/FT232.Unit.Tests.csproj @@ -0,0 +1,31 @@ + + + + Readme.md + net7.0 + enable + enable + + false + true + + + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + + + + + diff --git a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ft232h/Tests/FT232.Unit.Tests/UnitTest1.cs b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ft232h/Tests/FT232.Unit.Tests/UnitTest1.cs new file mode 100644 index 0000000000..acf2f26d54 --- /dev/null +++ b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ft232h/Tests/FT232.Unit.Tests/UnitTest1.cs @@ -0,0 +1,65 @@ +using Meadow.Foundation.ICs.IOExpanders; + +namespace FT232.Unit.Tests; + +public class Ftd2xxTests +{ + [Fact] + public void GetDeviceList() + { + // assumes an FT232 is connected + var devices = new FtdiDeviceCollection(); + devices.Refresh(); + Assert.True(devices.Count > 0); + } + + [Fact] + public void OpenI2CBus() + { + // assumes an FT232 is connected + var ftdi = new Ft232h(false); + var bus = ftdi.CreateI2cBus(); + Assert.NotNull(bus); + } + + [Fact] + public void OpenSPIBus() + { + // assumes an FT232 is connected + var ftdi = new Ft232h(false); + var bus = ftdi.CreateSpiBus(); + Assert.NotNull(bus); + } + + [Fact] + public void NoDeviceForSpiCheck() + { + // assumes no FT232 is connected + var ftdi = new Ft232h(false); + Assert.Throws(() => + { + var bus = ftdi.CreateSpiBus(); + }); + } + + [Fact] + public void NoDeviceForI2CCheck() + { + // assumes no FT232 is connected + var ftdi = new Ft232h(false); + Assert.Throws(() => + { + var bus = ftdi.CreateI2cBus(); + }); + } + + [Fact] + public void NoDriverCheck() + { + // assumes no FT232 driver is installed (rename C:\Windows\System32\ftd2xx.dll) + Assert.Throws(() => + { + var ftdi = new Ft232h(false); + }); + } +} \ No newline at end of file diff --git a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ft232h/Tests/FT232.Unit.Tests/Usings.cs b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ft232h/Tests/FT232.Unit.Tests/Usings.cs new file mode 100644 index 0000000000..8c927eb747 --- /dev/null +++ b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ft232h/Tests/FT232.Unit.Tests/Usings.cs @@ -0,0 +1 @@ +global using Xunit; \ No newline at end of file diff --git a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ht16k33/Driver/Ht16k33.cs b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ht16k33/Driver/Ht16k33.cs index 4527c4c926..28d458f9dd 100644 --- a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ht16k33/Driver/Ht16k33.cs +++ b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Ht16k33/Driver/Ht16k33.cs @@ -35,7 +35,7 @@ public partial class Ht16k33 : II2cPeripheral /// I2C bus instance public Ht16k33(II2cBus i2cBus, byte address = (byte)Addresses.Default) { - i2cComms = new I2cCommunications(i2cBus, address, 8, 17); + i2cComms = new I2cCommunications(i2cBus, address, 17); Initialize(); } 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 e4ac711d2e..5fe7f25a8f 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 @@ -15,13 +15,13 @@ Meadow.Foundation.ICs.IOExpanders.Ht16k33 https://github.com/WildernessLabs/Meadow.Foundation Meadow.Foundation, IOExpanders, HT16K33 - 0.6.55 + 1.7.0 true HT16K33 I2C IO expander, led driver, and character display controller - + - + 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 45151de832..62be12eee4 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,8 +9,8 @@ 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 45151de832..62be12eee4 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,8 +9,8 @@ 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 58b00ca74a..53a22ab39e 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 @@ -15,13 +15,13 @@ Meadow.Foundation.ICs.IOExpanders.Is31fl3731 https://github.com/WildernessLabs/Meadow.Foundation Meadow.Foundation, IS31FL3731, LED driver - 0.1.49 + 1.7.0 true IS31FL3731 I2C matrix led driver - + - + 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 19000869dd..8ff0187002 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,8 +9,8 @@ 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 f09f890a5d..c4c4e9738d 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 @@ -14,14 +14,14 @@ Meadow.Foundation.ICs.IOExpanders.Mcp23xxx https://github.com/WildernessLabs/Meadow.Foundation Meadow.Foundation,Meadow,Expanders,IOExpanders,MCP23008,MCP23009,MCP23017,MCP23018,MCP23S08,MCP23S09,MCP23S17,MCP23S18 - 0.1.0 + 1.7.0 true Mcp23xxx I2C and SPI digital output expanders enable - + - + 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 3beeb48e21..0e346278f1 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,8 +9,8 @@ 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 3beeb48e21..0e346278f1 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,8 +9,8 @@ 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 3beeb48e21..0e346278f1 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,8 +9,8 @@ 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 3beeb48e21..0e346278f1 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,8 +9,8 @@ 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 3beeb48e21..0e346278f1 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,8 +9,8 @@ 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 3beeb48e21..0e346278f1 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,8 +9,8 @@ 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 3beeb48e21..0e346278f1 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,8 +9,8 @@ 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 3beeb48e21..0e346278f1 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,8 +9,8 @@ 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 7fd12a97bd..a2789e5950 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,8 +9,8 @@ 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 7fd12a97bd..a2789e5950 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,8 +9,8 @@ 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 5b8f1a2372..ab292eba47 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 @@ -14,14 +14,14 @@ Meadow.Foundation.ICs.IOExpanders.Pca9671 https://github.com/WildernessLabs/Meadow.Foundation Meadow.Foundation,Meadow,Expanders,IOExpanders,Pca9671 - 0.1.0 + 1.7.0 true PCA9671 I2C digital input/output expander enable - + - + diff --git a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Pca9671/Driver/Pca9671.cs b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Pca9671/Driver/Pca9671.cs index ead69700c3..5cc61fe568 100644 --- a/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Pca9671/Driver/Pca9671.cs +++ b/Source/Meadow.Foundation.Peripherals/ICs.IOExpanders.Pca9671/Driver/Pca9671.cs @@ -51,7 +51,7 @@ public Pca9671(II2cBus i2cBus, byte peripheralAddress, IPin? resetPin = default) /// The i2cBus address of the peripheral /// The optional pin connected to the peripheral's reset public Pca9671(II2cBus i2cBus, byte peripheralAddress, IDigitalOutputPort? resetPort = default) - : base(i2cBus, peripheralAddress, 8, 8) + : base(i2cBus, peripheralAddress, 8) { this.resetPort = resetPort; Pins = new PinDefinitions(this); 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 5fb654b9a9..a0aeeceb73 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,8 +9,8 @@ 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 0fb783f0c2..e7813e58b7 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 @@ -15,13 +15,13 @@ Meadow.Foundation.ICs.IOExpanders.Pca9685 https://github.com/WildernessLabs/Meadow.Foundation Meadow.Foundation, PCA9685 - 0.1.49 + 1.7.0 true PCA9685 I2C PWM expander - + - + 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 0491f4d0ec..4de2093686 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,8 +10,8 @@ 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 a68900cc91..9078de0799 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 @@ -14,14 +14,14 @@ Meadow.Foundation.ICs.IOExpanders.Pcx857x https://github.com/WildernessLabs/Meadow.Foundation Meadow.Foundation,Meadow,Expanders,IOExpanders,Pcx857x - 0.1.0 + 1.7.0 true Pcx857x I2C digital input/output expander (Pca8574, Pca8575, Pcf8574, Pcf855) enable - + - + 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 8aeed22fc6..1886f6acc3 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,8 +9,8 @@ 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 8aeed22fc6..1886f6acc3 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,8 +9,8 @@ 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 8aeed22fc6..1886f6acc3 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,8 +9,8 @@ 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 8aeed22fc6..1886f6acc3 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,8 +9,8 @@ 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 912a374b4e..7fca2cd874 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 @@ -13,15 +13,15 @@ Meadow.Foundation.ICs.IOExpanders.Sc16is7x2 https://github.com/WildernessLabs/Meadow.Foundation Meadow.Foundation,Sc16is7x2,Sc16is752,Sc16is762,I2C,UART,expander - 0.1.0 + 1.7.0 enable 10.0 true SC16IS7x2 SPI I2C family of UART expanders (SC16IS752, SC16IS762) - + - + 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 6db9b2bddd..ff60c7acbb 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,8 +10,8 @@ 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 6db9b2bddd..ff60c7acbb 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,8 +10,8 @@ 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 dbfa19f270..6ffffaf43d 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 @@ -14,16 +14,16 @@ Meadow.Foundation.ICs.IOExpanders.SerialWombat https://github.com/WildernessLabs/Meadow.Foundation Meadow.Foundation,IOExpanders,SerialWombat,serial,Multiplexer,wombat,18ab,gpio,pwm,servo - 0.1.0 + 1.7.0 true SerialWombat I2C IO expander for GPIO, PWM, servos, etc. - enable + enable - + - - - + + + 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 846e4649e8..9934933bae 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,8 +17,8 @@ - - + + 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 098496d20f..a189227b2c 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,8 +9,8 @@ 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 098496d20f..a189227b2c 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,8 +9,8 @@ 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 098496d20f..a189227b2c 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,8 +9,8 @@ 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 846e4649e8..9934933bae 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,8 +17,8 @@ - - + + 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 f660bf4ed4..fad1628a61 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 @@ -15,13 +15,13 @@ Meadow.Foundation.ICs.IOExpanders.Tca9548a https://github.com/WildernessLabs/Meadow.Foundation Meadow.Foundation, TCA9548A, i2c, io, expander - 0.1.17 + 1.7.0 true TCA9548A I2C IO expander - + - + 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 b0e43cc221..be4a3799f2 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,9 +10,9 @@ 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 2b7dc61671..91d4c13706 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 @@ -15,13 +15,13 @@ Meadow.Foundation.ICs.IOExpanders.x74595 https://github.com/WildernessLabs/Meadow.Foundation Meadow.Foundation, IOExpanders, x74595 - 0.1.52 + 1.7.0 true x74595 SPI shift register digital output expander - + - + 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 3c9d11b5b8..96378979e6 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,8 +9,8 @@ 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 75f2312f83..0979a32cc6 100644 --- a/Source/Meadow.Foundation.Peripherals/Leds.Apa102/Driver/Leds.Apa102.csproj +++ b/Source/Meadow.Foundation.Peripherals/Leds.Apa102/Driver/Leds.Apa102.csproj @@ -15,13 +15,13 @@ Meadow.Foundation.Leds.Apa102 https://github.com/WildernessLabs/Meadow.Foundation Meadow.Foundation, Apa102 - 0.1.49 + 1.7.0 true Apa102 SPI RGB LED driver - + - + diff --git a/Source/Meadow.Foundation.Peripherals/Leds.Apa102/Driver/SparkFunQwiicLEDStick.cs b/Source/Meadow.Foundation.Peripherals/Leds.Apa102/Driver/SparkFunQwiicLEDStick.cs index e3306414ef..2954fc587d 100644 --- a/Source/Meadow.Foundation.Peripherals/Leds.Apa102/Driver/SparkFunQwiicLEDStick.cs +++ b/Source/Meadow.Foundation.Peripherals/Leds.Apa102/Driver/SparkFunQwiicLEDStick.cs @@ -25,7 +25,7 @@ public partial class SparkFunQwiicLEDStick : I2cCommunications, IApa102 /// The I2C address public SparkFunQwiicLEDStick(II2cBus i2cbus, byte address = (byte)Addresses.Default) - : base(i2cbus, address, 1, 16) + : base(i2cbus, address, 16) { Initialize(); } 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 6d0ef895a8..05b272d3c5 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,9 +9,9 @@ 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 056313bb8f..5aed6b82fb 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,8 +9,8 @@ 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 63badf2aa5..fe6e80461e 100644 --- a/Source/Meadow.Foundation.Peripherals/Leds.Pca9633/Driver/Leds.Pca9633.csproj +++ b/Source/Meadow.Foundation.Peripherals/Leds.Pca9633/Driver/Leds.Pca9633.csproj @@ -15,13 +15,13 @@ Meadow.Foundation.Leds.Pca9633 https://github.com/WildernessLabs/Meadow.Foundation Meadow.Foundation, Pca9633 - 0.1.7 + 1.7.0 true Pca9633 I2C RGB LED driver - + - + 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 2badf6395a..ebc89adcb9 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,8 +9,8 @@ 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 8b45669ffe..c87002e24b 100644 --- a/Source/Meadow.Foundation.Peripherals/Leds.Ws2812/Driver/Leds.Ws2812.csproj +++ b/Source/Meadow.Foundation.Peripherals/Leds.Ws2812/Driver/Leds.Ws2812.csproj @@ -15,15 +15,15 @@ Meadow.Foundation.Leds.Ws2812 https://github.com/WildernessLabs/Meadow.Foundation Meadow.Foundation,WS2812,neopixel - 0.1.0 + 1.7.0 true WS2812 SPI RGB LED driver - + - + 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 946e45f193..6d6a1dd96b 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,8 +9,8 @@ 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 5c7f930f5c..8f4b02c464 100644 --- a/Source/Meadow.Foundation.Peripherals/Motors.ElectronicSpeedController/Driver/Motors.ElectronicSpeedController.csproj +++ b/Source/Meadow.Foundation.Peripherals/Motors.ElectronicSpeedController/Driver/Motors.ElectronicSpeedController.csproj @@ -15,13 +15,13 @@ Meadow.Foundation.Motors.ElectronicSpeedController https://github.com/WildernessLabs/Meadow.Foundation Meadow.Foundation, Motors, Electronic, Speed, Controller, PWM - 0.1.18 + 1.7.0 true PWM Electronic speed controller - + - + 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 55e6bfdf11..8bd88808cb 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,8 +9,8 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Motors.GpioStepper/Driver/GpioStepper.cs b/Source/Meadow.Foundation.Peripherals/Motors.GpioStepper/Driver/GpioStepper.cs index f10810eb38..488325fe89 100644 --- a/Source/Meadow.Foundation.Peripherals/Motors.GpioStepper/Driver/GpioStepper.cs +++ b/Source/Meadow.Foundation.Peripherals/Motors.GpioStepper/Driver/GpioStepper.cs @@ -73,8 +73,6 @@ public Task GoTo(Angle position, AngularVelocity velocity, CancellationToken can return Task.CompletedTask; } - Resolver.Log.Info($"Currently at: {Position.Degrees} moving to: {position.Degrees}"); - // determine shortest path to destination double totalDistance; if (position.Degrees < Position.Degrees) @@ -104,8 +102,6 @@ public Task GoTo(Angle position, AngularVelocity velocity, CancellationToken can } } - Resolver.Log.Info($"Distance to move: {totalDistance} degrees"); - return Rotate(new Angle(totalDistance, Angle.UnitType.Degrees), shortestDirection, velocity, cancellationToken); } @@ -127,8 +123,6 @@ public Task GoTo(Angle position, RotationDirection direction, AngularVelocity ve // convert velocity into frequency based on drive parameters var freq = GetFrequencyForVelocity(velocity); - Resolver.Log.Info($"Currently at: {start} moving to: {dest}"); - double totalDistance; if (dest < start) @@ -148,8 +142,6 @@ public Task GoTo(Angle position, RotationDirection direction, AngularVelocity ve }; } - Resolver.Log.Info($"Distance to move: {totalDistance} degrees"); - return Rotate((int)(totalDistance * _stepsPerDegree), direction, freq, cancellationToken); } @@ -160,8 +152,6 @@ public Task Rotate(Angle amountToRotate, RotationDirection direction, AngularVel var freq = GetFrequencyForVelocity(velocity); var steps = (int)(amountToRotate.Degrees * _stepsPerDegree); - Resolver.Log.Info($"Rotating {steps} at {freq.Hertz}"); - return Rotate(steps, direction, freq, cancellationToken); } 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 462eefc82c..865f714ab6 100644 --- a/Source/Meadow.Foundation.Peripherals/Motors.GpioStepper/Driver/Motors.GpioStepper.csproj +++ b/Source/Meadow.Foundation.Peripherals/Motors.GpioStepper/Driver/Motors.GpioStepper.csproj @@ -1,5 +1,6 @@ + Readme.md enable 10.0 Apache-2.0 @@ -14,12 +15,13 @@ Meadow.Foundation.Motors.Stepper.GpioStepper https://github.com/WildernessLabs/Meadow.Foundation Meadow,Meadow.Foundation,Motor,Stepper,controller,gpio - 0.1.0 + 1.7.0 true Digital input stepper motor controller + - + diff --git a/Source/Meadow.Foundation.Peripherals/Motors.GpioStepper/Driver/Readme.md b/Source/Meadow.Foundation.Peripherals/Motors.GpioStepper/Driver/Readme.md index 3031bbbe57..56e639c815 100644 --- a/Source/Meadow.Foundation.Peripherals/Motors.GpioStepper/Driver/Readme.md +++ b/Source/Meadow.Foundation.Peripherals/Motors.GpioStepper/Driver/Readme.md @@ -13,7 +13,7 @@ To view all Wilderness Labs open-source projects, including samples, visit [gith ## Usage ```csharp -private IPositionalMotor stepper; +private IStepperMotor stepper; private bool UseStepDirConfiguration { get; set; } = true; 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 0555477946..4ad65f0a5b 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,8 +9,8 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Motors.GpioStepper/Samples/GpioStepper_Sample/MeadowApp.cs b/Source/Meadow.Foundation.Peripherals/Motors.GpioStepper/Samples/GpioStepper_Sample/MeadowApp.cs index b4834e7051..d1baf2191a 100644 --- a/Source/Meadow.Foundation.Peripherals/Motors.GpioStepper/Samples/GpioStepper_Sample/MeadowApp.cs +++ b/Source/Meadow.Foundation.Peripherals/Motors.GpioStepper/Samples/GpioStepper_Sample/MeadowApp.cs @@ -13,7 +13,7 @@ namespace MeadowApp public class MeadowApp : App { // - private IPositionalMotor stepper; + private IStepperMotor stepper; private bool UseStepDirConfiguration { get; set; } = true; 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 06c66477a8..4b377610d0 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 @@ -15,13 +15,13 @@ Meadow.Foundation.Motors.Stepper.A4988 https://github.com/WildernessLabs/Meadow.Foundation Meadow, Meadow.Foundation, Motor, Stepper, A4988 - 0.1.49 + 1.7.0 true A4988 digital input stepper motor controller - + - + 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 7c09663a4a..672f352325 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,8 +9,8 @@ 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 4c0dd86bc3..a3c5657cfa 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 @@ -15,13 +15,13 @@ Meadow.Foundation.Motors.Stepper.Uln2003 https://github.com/WildernessLabs/Meadow.Foundation Meadow, Meadow.Foundation, Motor, Stepper - 0.1.53 + 1.7.0 true ULN2003 digital input stepper motor controller - + - + 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 5014ac2359..5d579773e2 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,8 +9,8 @@ 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 c614178f7a..0877111519 100644 --- a/Source/Meadow.Foundation.Peripherals/Motors.Tb67h420ftg/Driver/Motors.Tb67h420ftg.csproj +++ b/Source/Meadow.Foundation.Peripherals/Motors.Tb67h420ftg/Driver/Motors.Tb67h420ftg.csproj @@ -11,7 +11,7 @@ Meadow.Foundation.Motors.Tb67h420ftg https://github.com/WildernessLabs/Meadow.Foundation Meadow,Meadow.Foundation,Motor,HBridge,Tb67h420ftg - 0.1.22 + 1.7.0 true Tb67h420ftg digital input motor controller @@ -22,8 +22,8 @@ 10.0 - + - + 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 70f0fb83a0..eb9acbe53b 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,9 +9,9 @@ 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 7d0e1f91f4..48e474082b 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,8 +9,8 @@ App - - + + 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 22f8a8e9b2..1275e79e95 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 @@ Meadow.Foundation.RTCs.Ds1307 https://github.com/WildernessLabs/Meadow.Foundation Meadow, Meadow.Foundation, RTC - 0.7.55 + 1.7.0 true DS1307 I2C real time clock - + - + 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 acc982ca7f..7d3a3b51cc 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,8 +9,8 @@ App - - + + 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 f30972af73..77d1056ee1 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 @@ Meadow.Foundation.RTCs.Ds323x https://github.com/WildernessLabs/Meadow.Foundation Meadow.Foundation, RTC, Ds323x - 0.1.52 + 1.7.0 true Ds323x I2C real time clock (DS3231) - + - + diff --git a/Source/Meadow.Foundation.Peripherals/RTCs.Ds323x/Samples/Ds323x_Sample/Ds323x_Sample.csproj b/Source/Meadow.Foundation.Peripherals/RTCs.Ds323x/Samples/Ds323x_Sample/Ds323x_Sample.csproj index d6b167fcb4..1fbd4f5355 100644 --- a/Source/Meadow.Foundation.Peripherals/RTCs.Ds323x/Samples/Ds323x_Sample/Ds323x_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/RTCs.Ds323x/Samples/Ds323x_Sample/Ds323x_Sample.csproj @@ -9,8 +9,8 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.AdafruitMPRLS/Driver/AdafruitMPRLS.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.AdafruitMPRLS/Driver/AdafruitMPRLS.cs index c95461a259..e988fa9cda 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.AdafruitMPRLS/Driver/AdafruitMPRLS.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.AdafruitMPRLS/Driver/AdafruitMPRLS.cs @@ -21,7 +21,7 @@ public partial class AdafruitMPRLS : /// public byte DefaultI2cAddress => (byte)Addresses.Default; - private event EventHandler> _pressureHandlers; + private event EventHandler> _pressureHandlers = default!; event EventHandler> ISamplingSensor.Updated { @@ -69,7 +69,7 @@ event EventHandler> ISamplingSensor.Updated /// /// I2Cbus connected to the sensor public AdafruitMPRLS(II2cBus i2cbus) - : base(i2cbus, (byte)Addresses.Default) + : base(i2cbus, (byte)Addresses.Default, 5, 0) { } /// 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 b7a5d5161b..e7d9c955b4 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 @@ -15,13 +15,13 @@ Meadow.Foundation.Sensors.Atmospheric.AdafruitMPRLS https://github.com/WildernessLabs/Meadow.Foundation Meadow.Foundation, pressure, Adafruit, MPRLS - 0.1.29 + 1.7.0 true Adafruit MPRLS I2C barometric pressure sensor with metal port connector - + - + 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 595064fa32..5343e3670e 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,8 +9,8 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Bh1900Nux/Driver/Bh1900Nux.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Bh1900Nux/Driver/Bh1900Nux.cs index 10102ac648..2cccf76caf 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Bh1900Nux/Driver/Bh1900Nux.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Bh1900Nux/Driver/Bh1900Nux.cs @@ -10,11 +10,6 @@ namespace Meadow.Foundation.Sensors.Atmospheric /// public partial class Bh1900Nux : ByteCommsSensorBase, ITemperatureSensor, II2cPeripheral { - /// - /// Raised when the temperature value changes - /// - public event EventHandler> TemperatureUpdated = default!; - /// /// The current temperature /// @@ -223,16 +218,5 @@ private Units.Temperature RegisterToTemp(Memory data) return Task.FromResult(RegisterToTemp(ReadBuffer)); } - - /// - /// Raise events for subscribers and notify of value changes - /// - /// The updated sensor data - protected override void RaiseEventsAndNotify(IChangeResult changeResult) - { - TemperatureUpdated?.Invoke(this, changeResult); - - base.RaiseEventsAndNotify(changeResult); - } } } \ 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 9f49d55af1..c938114c83 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 @@ -11,7 +11,7 @@ Meadow.Foundation.Sensors.Atmospheric.Bh1900Nux https://github.com/WildernessLabs/Meadow.Foundation Meadow.Foundation, Atmospheric, BH1900NUX - 0.1.0 + 1.7.0 true Rohm BH1900NUX I2C temperature sensor enable @@ -22,10 +22,10 @@ 10.0 - + - + 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 452c75246d..5b72c173c7 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,8 +12,8 @@ 8.0 - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Bme280/Driver/Bme280.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Bme280/Driver/Bme280.cs index 23d950cc73..f5ce9cc992 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Bme280/Driver/Bme280.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Bme280/Driver/Bme280.cs @@ -21,9 +21,9 @@ public partial class Bme280 : PollingSensorBase<(Units.Temperature? Temperature, RelativeHumidity? Humidity, Pressure? Pressure)>, ITemperatureSensor, IHumiditySensor, IBarometricPressureSensor, ISpiPeripheral, II2cPeripheral, IDisposable { - private event EventHandler> _temperatureHandlers; - private event EventHandler> _humidityHandlers; - private event EventHandler> _pressureHandlers; + private event EventHandler> _temperatureHandlers = default!; + private event EventHandler> _humidityHandlers = default!; + private event EventHandler> _pressureHandlers = default!; event EventHandler> ISamplingSensor.Updated { diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Bme280/Driver/Sensors.Atmospheric.Bme280.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Bme280/Driver/Sensors.Atmospheric.Bme280.csproj index 68549ba2fe..cbba0889d2 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Bme280/Driver/Sensors.Atmospheric.Bme280.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Bme280/Driver/Sensors.Atmospheric.Bme280.csproj @@ -11,7 +11,7 @@ Meadow.Foundation.Sensors.Atmospheric.Bme280 https://github.com/WildernessLabs/Meadow.Foundation Meadow.Foundation, Atmospheric, BME280 - 0.5.57 + 1.7.0 true Bosch BME280 SPI and I2C absolute barometric pressure sensor enable @@ -22,10 +22,10 @@ 10.0 - + - + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Bme280/Samples/Bme280_Sample/Bme280_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Bme280/Samples/Bme280_Sample/Bme280_Sample.csproj index 98687d92c6..13538af27b 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Bme280/Samples/Bme280_Sample/Bme280_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Bme280/Samples/Bme280_Sample/Bme280_Sample.csproj @@ -12,8 +12,8 @@ 8.0 - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Bme68x/Driver/Bme68x.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Bme68x/Driver/Bme68x.cs index c60245ea81..23aa3500c0 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Bme68x/Driver/Bme68x.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Bme68x/Driver/Bme68x.cs @@ -1,6 +1,7 @@ using Meadow.Hardware; using Meadow.Peripherals.Sensors; using Meadow.Peripherals.Sensors.Atmospheric; +using Meadow.Peripherals.Sensors.Environmental; using Meadow.Units; using Meadow.Utilities; using System; @@ -22,21 +23,12 @@ public abstract partial class Bme68x : RelativeHumidity? Humidity, Pressure? Pressure, Resistance? GasResistance)>, - ITemperatureSensor, IHumiditySensor, IBarometricPressureSensor, ISpiPeripheral, II2cPeripheral, IDisposable + ITemperatureSensor, IHumiditySensor, IBarometricPressureSensor, IGasResistanceSensor, ISpiPeripheral, II2cPeripheral, IDisposable { - private event EventHandler> _temperatureHandlers; - private event EventHandler> _humidityHandlers; - private event EventHandler> _pressureHandlers; - - /// - /// Raised when the pressure value changes - /// - public event EventHandler> PressureUpdated = default!; - - /// - /// Raised when the gas resistance value changes - /// - public event EventHandler> GasResistanceUpdated = default!; + private event EventHandler> _temperatureHandlers = default!; + private event EventHandler> _humidityHandlers = default!; + private event EventHandler> _pressureHandlers = default!; + private event EventHandler> _gasResistanceHandlers = default!; /// /// The temperature oversampling mode @@ -297,6 +289,12 @@ event EventHandler> ISamplingSensor.Updated remove => _pressureHandlers -= value; } + event EventHandler> ISamplingSensor.Updated + { + add => _gasResistanceHandlers += value; + remove => _gasResistanceHandlers -= value; + } + /// /// Initialize the sensor /// @@ -431,11 +429,11 @@ protected override void RaiseEventsAndNotify(IChangeResult<(Units.Temperature? T } if (changeResult.New.Pressure is { } pressure) { - PressureUpdated?.Invoke(this, new ChangeResult(pressure, changeResult.Old?.Pressure)); + _pressureHandlers?.Invoke(this, new ChangeResult(pressure, changeResult.Old?.Pressure)); } if (changeResult.New.GasResistance is { } gasResistance) { - GasResistanceUpdated?.Invoke(this, new ChangeResult(gasResistance, changeResult.Old?.GasResistance)); + _gasResistanceHandlers?.Invoke(this, new ChangeResult(gasResistance, changeResult.Old?.GasResistance)); } base.RaiseEventsAndNotify(changeResult); } @@ -674,5 +672,8 @@ async Task ISensor.Read() async Task ISensor.Read() => (await Read()).Pressure!.Value; + + async Task ISensor.Read() + => (await Read()).GasResistance!.Value; } } diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Bme68x/Driver/Bme68xSpiCommunications.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Bme68x/Driver/Bme68xSpiCommunications.cs index e82dc1b9d9..f26905fd6f 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Bme68x/Driver/Bme68xSpiCommunications.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Bme68x/Driver/Bme68xSpiCommunications.cs @@ -30,9 +30,8 @@ internal enum SpiRegisterPage : byte SpiRegisterPage currentPage = SpiRegisterPage.Page1; internal Bme68xSpiCommunications(ISpiBus spiBus, IDigitalOutputPort? chipSelect, Frequency busSpeed, SpiClockConfiguration.Mode busMode) - : base(spiBus, chipSelect, busSpeed, busMode, 32, 32) - { - } + : base(spiBus, chipSelect, busSpeed, busMode, 32) + { } public override byte ReadRegister(byte address) { 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 aabff99029..4a2619423e 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 @@ -10,7 +10,7 @@ Meadow.Foundation.Sensors.Atmospheric.Bme68x https://github.com/WildernessLabs/Meadow.Foundation Meadow.Foundation,Atmospheric,BME680,BME688,temperature,pressure,humidity,gas,VOC - 0.1.7 + 1.7.0 true Bosch BME68x SPI / I2C humidity, barometric pressure, ambient temperature and gas (VOC) sensor enable @@ -22,8 +22,8 @@ 10.0 - + - + 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 f26e12d364..65cfb775d7 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,8 +13,8 @@ 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 f26e12d364..65cfb775d7 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,8 +13,8 @@ 8.0 - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Bmp085/Driver/Bmp085.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Bmp085/Driver/Bmp085.cs index a749901d16..77d218ef5a 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Bmp085/Driver/Bmp085.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Bmp085/Driver/Bmp085.cs @@ -15,8 +15,8 @@ public partial class Bmp085 : ByteCommsSensorBase<(Units.Temperature? Temperature, Pressure? Pressure)>, ITemperatureSensor, IBarometricPressureSensor, II2cPeripheral { - private event EventHandler> _temperatureHandlers; - private event EventHandler> _pressureHandlers; + private event EventHandler> _temperatureHandlers = default!; + private event EventHandler> _pressureHandlers = default!; event EventHandler> ISamplingSensor.Updated { @@ -73,7 +73,7 @@ event EventHandler> ISamplingSensor.Updated /// The device mode public Bmp085(II2cBus i2cBus, byte address = (byte)Addresses.Default, DeviceMode deviceMode = DeviceMode.Standard) - : base(i2cBus, address) + : base(i2cBus, address, 2, 2) { oversamplingSetting = (byte)deviceMode; 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 c4998bc42f..21a24cb621 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 @@ -11,7 +11,7 @@ Meadow.Foundation.Sensors.Atmospheric.Bmp085 https://github.com/WildernessLabs/Meadow.Foundation Meadow.Foundation, Atmospheric, BMP085, Bosche - 0.1.53 + 1.7.0 true Bosch BMP085 I2C barometric pressure sensor enable @@ -22,8 +22,8 @@ 10.0 - + - + 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 22728df94d..b53afa6616 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,8 +11,8 @@ 10.0 - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Bmp180/Driver/Bmp180.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Bmp180/Driver/Bmp180.cs index 804d16017a..caa7525482 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Bmp180/Driver/Bmp180.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Bmp180/Driver/Bmp180.cs @@ -15,8 +15,8 @@ public partial class Bmp180 : ByteCommsSensorBase<(Units.Temperature? Temperature, Pressure? Pressure)>, ITemperatureSensor, IBarometricPressureSensor, II2cPeripheral { - private event EventHandler> _temperatureHandlers; - private event EventHandler> _pressureHandlers; + private event EventHandler> _temperatureHandlers = default!; + private event EventHandler> _pressureHandlers = default!; event EventHandler> ISamplingSensor.Updated { @@ -76,7 +76,7 @@ event EventHandler> ISamplingSensor.Updated /// The device mode public Bmp180(II2cBus i2cBus, byte address = (byte)Addresses.Default, DeviceMode deviceMode = DeviceMode.Standard) - : base(i2cBus, address) + : base(i2cBus, address, 2, 2) { oversamplingSetting = (byte)deviceMode; 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 e80a2c6601..19c74d2fc3 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 @@ -13,15 +13,15 @@ Meadow.Foundation.Sensors.Atmospheric.Bmp180 https://github.com/WildernessLabs/Meadow.Foundation Meadow.Foundation, Atmospheric, BMP180 - 0.1.52 + 1.7.0 true BMP180 I2C barometric pressure, temperature, and altitude sensor enable 10.0 - + - + 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 5236ddabc2..c9848e5319 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,8 +10,8 @@ 10.0 - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Ccs811/Driver/Ccs811.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Ccs811/Driver/Ccs811.cs index d524f90f18..a5df45b2d6 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Ccs811/Driver/Ccs811.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Ccs811/Driver/Ccs811.cs @@ -12,16 +12,14 @@ namespace Meadow.Foundation.Sensors.Atmospheric; /// Provide access to the CCS811 C02 and VOC Air Quality Sensor /// public partial class Ccs811 : - ByteCommsSensorBase<(Concentration? Co2, Concentration? Voc)>, + PollingSensorBase<(Concentration? Co2, Concentration? Voc)>, ICo2Sensor, IVocSensor, II2cPeripheral { - private const int ReadBufferSize = 10; - private const int WriteBufferSize = 8; + private II2cCommunications i2cComms; - // internal thread lock private byte[] _readingBuffer = new byte[8]; - private event EventHandler> _co2Handlers; + private event EventHandler> _co2Handlers = default!; event EventHandler> ISamplingSensor.Updated { @@ -64,8 +62,9 @@ public Ccs811(II2cBus i2cBus, Addresses address = Addresses.Default) /// The I2C bus /// The I2C address public Ccs811(II2cBus i2cBus, byte address) - : base(i2cBus, address, ReadBufferSize, WriteBufferSize) { + i2cComms = new I2cCommunications(i2cBus, address); + switch (address) { case 0x5a: @@ -89,31 +88,31 @@ protected void Initialize() Thread.Sleep(100); - var id = BusComms?.ReadRegister((byte)Register.HW_ID); + var id = i2cComms?.ReadRegister((byte)Register.HW_ID); if (id != 0x81) { throw new Exception("Hardware is not identifying as a CCS811"); } - BusComms?.Write((byte)BootloaderCommand.APP_START); + i2cComms?.Write((byte)BootloaderCommand.APP_START); SetMeasurementMode(MeasurementMode.ConstantPower1s); - var mode = BusComms?.ReadRegister((byte)Register.MEAS_MODE); + _ = i2cComms?.ReadRegister((byte)Register.MEAS_MODE); } private void ShowDebugInfo() { - var ver = BusComms?.ReadRegister((byte)Register.HW_VERSION); + var ver = i2cComms?.ReadRegister((byte)Register.HW_VERSION); Resolver.Log.Info($"hardware version A = 0x{ver:x2}"); - var fwb = BusComms?.ReadRegister((byte)Register.FW_BOOT_VERSION); + var fwb = i2cComms?.ReadRegister((byte)Register.FW_BOOT_VERSION); Resolver.Log.Info($"FWB version = 0x{fwb:x4}"); - var fwa = BusComms?.ReadRegister((byte)Register.FW_APP_VERSION); + var fwa = i2cComms?.ReadRegister((byte)Register.FW_APP_VERSION); Resolver.Log.Info($"FWA version = 0x{fwa:x4}"); // read status - var status = BusComms?.ReadRegister((byte)Register.STATUS); + var status = i2cComms?.ReadRegister((byte)Register.STATUS); Resolver.Log.Info($"status = 0x{status:x2}"); } @@ -123,7 +122,7 @@ private void ShowDebugInfo() /// The baseline value public ushort GetBaseline() { - return BusComms?.ReadRegister((byte)Register.BASELINE) ?? 0; + return i2cComms?.ReadRegister((byte)Register.BASELINE) ?? 0; } /// @@ -132,7 +131,7 @@ public ushort GetBaseline() /// The new baseline public void SetBaseline(ushort value) { - BusComms?.WriteRegister((byte)Register.BASELINE, (byte)value); + i2cComms?.WriteRegister((byte)Register.BASELINE, (byte)value); } /// @@ -141,7 +140,7 @@ public void SetBaseline(ushort value) /// The measurement mode public MeasurementMode GetMeasurementMode() { - return (MeasurementMode)(BusComms?.ReadRegister((byte)Register.MEAS_MODE) ?? 0); + return (MeasurementMode)(i2cComms?.ReadRegister((byte)Register.MEAS_MODE) ?? 0); } /// @@ -151,12 +150,12 @@ public MeasurementMode GetMeasurementMode() public void SetMeasurementMode(MeasurementMode mode) { var m = (byte)mode; - BusComms?.WriteRegister((byte)Register.MEAS_MODE, m); + i2cComms?.WriteRegister((byte)Register.MEAS_MODE, m); } private void Reset() { - BusComms?.Write(new byte[] { (byte)Register.SW_RESET, 0x11, 0xE5, 0x72, 0x8A }); + i2cComms?.Write(new byte[] { (byte)Register.SW_RESET, 0x11, 0xE5, 0x72, 0x8A }); } /// @@ -166,7 +165,7 @@ private void Reset() protected override Task<(Concentration? Co2, Concentration? Voc)> ReadSensor() { // data is really in just the first 4, but this gets us status and raw data as well - BusComms?.ReadRegister((byte)Register.ALG_RESULT_DATA, _readingBuffer); + i2cComms?.ReadRegister((byte)Register.ALG_RESULT_DATA, _readingBuffer); (Concentration? co2, Concentration? voc) state; state.co2 = new Concentration(_readingBuffer[0] << 8 | _readingBuffer[1], Concentration.UnitType.PartsPerMillion); @@ -189,7 +188,6 @@ protected override void RaiseEventsAndNotify(IChangeResult<(Concentration? Co2, { VocUpdated?.Invoke(this, new ChangeResult(voc, changeResult.Old?.Voc)); } - base.RaiseEventsAndNotify(changeResult); } 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 72f170a41e..1b7dd79165 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 @@ -9,7 +9,7 @@ Meadow.Foundation.Sensors.Atmospheric.Ccs811 https://github.com/WildernessLabs/Meadow.Foundation Meadow.Foundation,VOC,Air,quality,Ccs811 - 0.1.17 + 1.7.0 true Ccs811 I2C VOC Air Quality Sensor enable @@ -22,8 +22,8 @@ 10.0 - + - + 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 ab6907b626..6432454c66 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,8 +9,8 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Dhtxx/Driver/DhtBase.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Dhtxx/Driver/DhtBase.cs index a3bda20a98..1b76710283 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Dhtxx/Driver/DhtBase.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Dhtxx/Driver/DhtBase.cs @@ -15,8 +15,8 @@ public abstract partial class DhtBase : ByteCommsSensorBase<(Units.Temperature? Temperature, RelativeHumidity? Humidity)>, ITemperatureSensor, IHumiditySensor { - private event EventHandler> _temperatureHandlers; - private event EventHandler> _humidityHandlers; + private event EventHandler> _temperatureHandlers = default!; + private event EventHandler> _humidityHandlers = default!; event EventHandler> ISamplingSensor.Updated { 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 9e5b42dc8b..784c351aa4 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 @@ -13,7 +13,7 @@ Meadow.Foundation.Sensors.Atmospheric.Dhtxx https://github.com/WildernessLabs/Meadow.Foundation Meadow.Foundation,Atmospheric,DHT10,DHT12,Dhtxx - 0.1.52 + 1.7.0 true DHTxx I2C temperature and humidity sensors (DHT10, DHT12) enable @@ -22,8 +22,8 @@ 10.0 - + - + 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 edb67f5b88..c789d41969 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,8 +13,8 @@ 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 edb67f5b88..c789d41969 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,8 +13,8 @@ 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 2e48309423..00f1ee36f8 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Hc2/Driver/Hc2.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Hc2/Driver/Hc2.cs @@ -13,8 +13,8 @@ public partial class HC2 : PollingSensorBase<(RelativeHumidity? Humidity, Units.Temperature? Temperature)>, ITemperatureSensor, IHumiditySensor { - private event EventHandler> _temperatureHandlers; - private event EventHandler> _humidityHandlers; + private event EventHandler> _temperatureHandlers = default!; + private event EventHandler> _humidityHandlers = default!; event EventHandler> ISamplingSensor.Updated { 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 e4c111d1b9..1c76a21d7a 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 @@ -11,7 +11,7 @@ Meadow.Foundation.Sensors.Atmospheric.Hc2 https://github.com/WildernessLabs/Meadow.Foundation Meadow.Foundation,Atmospheric,HC2,Temperature,Humidity - 0.1.0 + 1.7.0 true HC2 Analog and Serial humidity and temperature probe enable @@ -22,8 +22,8 @@ 10.0 - + - + 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 afeff2156d..7ced6007c7 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,8 +12,8 @@ 10.0 - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Hih6130/Driver/Hih6130.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Hih6130/Driver/Hih6130.cs index d3d46e97bf..a37339ff88 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Hih6130/Driver/Hih6130.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Hih6130/Driver/Hih6130.cs @@ -14,8 +14,8 @@ public partial class Hih6130 : ByteCommsSensorBase<(Units.Temperature? Temperature, RelativeHumidity? Humidity)>, ITemperatureSensor, IHumiditySensor, II2cPeripheral { - private event EventHandler> _temperatureHandlers; - private event EventHandler> _humidityHandlers; + private event EventHandler> _temperatureHandlers = default!; + private event EventHandler> _humidityHandlers = default!; event EventHandler> ISamplingSensor.Updated { 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 0ffe13f135..b93a3c4dbd 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 @@ -13,15 +13,15 @@ Meadow.Foundation.Sensors.Atmospheric.Hih6130 https://github.com/WildernessLabs/Meadow.Foundation Meadow.Foundation, Atmospheric, HIH6130 - 0.1.53 + 1.7.0 true HIH6130 I2C temperature and humidity sensor enable 10.0 - + - + 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 54f514cdc7..8ca910fb5b 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,8 +11,8 @@ 10.0 - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Htu2xd/Driver/Drivers/Htu21d.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Htu2xd/Driver/Drivers/Htu21d.cs index df61f72e6c..175fa0f4ef 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Htu2xd/Driver/Drivers/Htu21d.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Htu2xd/Driver/Drivers/Htu21d.cs @@ -23,9 +23,8 @@ public partial class Htu21d : Htux1dBase /// /// Sensor address (default to 0x40) /// I2CBus (default to 100 KHz) - /// Update interval, defaults to 1 sec if null - public Htu21d(II2cBus i2cBus, byte address = (byte)Addresses.Default, TimeSpan? updateInterval = null) - : base(i2cBus, address, updateInterval) + public Htu21d(II2cBus i2cBus, byte address = (byte)Addresses.Default) + : base(i2cBus, address) { Initialize(); } diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Htu2xd/Driver/Drivers/Htu31d.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Htu2xd/Driver/Drivers/Htu31d.cs index c8cd0cdd4c..7d85fc1b69 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Htu2xd/Driver/Drivers/Htu31d.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Htu2xd/Driver/Drivers/Htu31d.cs @@ -18,9 +18,8 @@ public partial class Htu31d : Htux1dBase /// /// Sensor address (default to 0x40). /// I2CBus (default to 100 KHz). - /// Update interval, defaults to 1 sec if null - public Htu31d(II2cBus i2cBus, byte address = (byte)Addresses.Default, TimeSpan? updateInterval = null) - : base(i2cBus, address, updateInterval) + public Htu31d(II2cBus i2cBus, byte address = (byte)Addresses.Default) + : base(i2cBus, address) { SerialNumber = GetSerial(); } diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Htu2xd/Driver/Htux1dBase.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Htu2xd/Driver/Htux1dBase.cs index 9124ac179c..3591fb87df 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Htu2xd/Driver/Htux1dBase.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Htu2xd/Driver/Htux1dBase.cs @@ -29,8 +29,8 @@ public abstract class Htux1dBase : ByteCommsSensorBase<(Units.Temperature? Temperature, RelativeHumidity? Humidity)>, ITemperatureSensor, IHumiditySensor, II2cPeripheral { - private event EventHandler> _temperatureHandlers; - private event EventHandler> _humidityHandlers; + private event EventHandler> _temperatureHandlers = default!; + private event EventHandler> _humidityHandlers = default!; event EventHandler> ISamplingSensor.Updated { @@ -74,11 +74,9 @@ event EventHandler> ISamplingSensor /// /// - /// - public Htux1dBase(II2cBus i2cBus, byte address = (byte)Addresses.Default, TimeSpan? updateInterval = null) - : base(i2cBus, address, (int)(updateInterval == null ? 1000 : updateInterval.Value.TotalMilliseconds)) - { - } + public Htux1dBase(II2cBus i2cBus, byte address = (byte)Addresses.Default) + : base(i2cBus, address) + { } /// /// Inheritance-safe way to raise events and notify observers 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 77c2d3f65c..31810476cb 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 @@ -11,7 +11,7 @@ Meadow.Foundation.Sensors.Atmospheric.Htux1d https://github.com/WildernessLabs/Meadow.Foundation Meadow.Foundation, Atmospheric, Humidity, Temperature, Htu21d, Htu31d - 0.1.5 + 1.7.0 true HTU21D(F) and HTU31D I2C temperature and humidity sensors enable @@ -22,8 +22,8 @@ 10.0 - + - + 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 ac5ef03e42..647aa52559 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,8 +13,8 @@ 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 ac5ef03e42..647aa52559 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,8 +13,8 @@ 9.0 - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Mpl3115a2/Driver/Mpl3115a2.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Mpl3115a2/Driver/Mpl3115a2.cs index 6939ccd319..cda51bffcc 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Mpl3115a2/Driver/Mpl3115a2.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Mpl3115a2/Driver/Mpl3115a2.cs @@ -14,8 +14,8 @@ public partial class Mpl3115a2 : ByteCommsSensorBase<(Units.Temperature? Temperature, Pressure? Pressure)>, ITemperatureSensor, IBarometricPressureSensor, II2cPeripheral { - private event EventHandler> _temperatureHandlers; - private event EventHandler> _pressureHandlers; + private event EventHandler> _temperatureHandlers = default!; + private event EventHandler> _pressureHandlers = default!; event EventHandler> ISamplingSensor.Updated { @@ -125,7 +125,6 @@ public Mpl3115a2(II2cBus i2cBus, byte address = (byte)Addresses.Default) /// protected override void RaiseEventsAndNotify(IChangeResult<(Units.Temperature? Temperature, Pressure? Pressure)> changeResult) { - //Updated?.Invoke(this, changeResult); if (changeResult.New.Temperature is { } temp) { _temperatureHandlers?.Invoke(this, new ChangeResult(temp, changeResult.Old?.Temperature)); 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 9a227eebed..6e6d22e40c 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 @@ -13,16 +13,16 @@ Meadow.Foundation.Sensors.Atmospheric.Mpl3115a2 https://github.com/WildernessLabs/Meadow.Foundation Meadow.Foundation,Meadow,Atmospheric,Temperature,Humidity,Mpl3115a2 - 0.1.49 + 1.7.0 true MPL3115A2 I2C barometric pressure, temperature, and altitude sensor enable Meadow.Foundation.Sensors.Atmospheric - 10.0 + 10.0 - + - + 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 62f3ef8cb0..5f11732550 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,8 +11,8 @@ 10.0 - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Ms5611/Driver/Ms5611.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Ms5611/Driver/Ms5611.cs index b8c4a2c628..b5221182fd 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Ms5611/Driver/Ms5611.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Ms5611/Driver/Ms5611.cs @@ -12,11 +12,11 @@ namespace Meadow.Foundation.Sensors.Atmospheric; /// Represents an Ms5611 pressure and temperature sensor /// public partial class Ms5611 : - ByteCommsSensorBase<(Units.Temperature? Temperature, Pressure? Pressure)>, + PollingSensorBase<(Units.Temperature? Temperature, Pressure? Pressure)>, ITemperatureSensor, IBarometricPressureSensor, II2cPeripheral { - private event EventHandler> _temperatureHandlers; - private event EventHandler> _pressureHandlers; + private event EventHandler> _temperatureHandlers = default!; + private event EventHandler> _pressureHandlers = default!; event EventHandler> ISamplingSensor.Updated { 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 2cdcbaa717..5410df5d6b 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 @@ -15,13 +15,13 @@ Meadow.Foundation.Sensors.Atmospheric.Ms5611 https://github.com/WildernessLabs/Meadow.Foundation Meadow.Foundation, Atmospheric, Ms5611 - 0.1.52 + 1.7.0 true MS5611 I2C altimeter and barometric pressure sensor - + - + 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 31e748cbd9..198ab83969 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/Sensors.Atmospheric.Sgp40.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Sgp40/Driver/Sensors.Atmospheric.Sgp40.csproj index 537acc074d..6f667ebc13 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 @@ -11,7 +11,7 @@ Meadow.Foundation.Sensors.Atmospheric.Sgp40 https://github.com/WildernessLabs/Meadow.Foundation Meadow.Foundation, Atmospheric, SGP40, Sensiron - 0.1.0 + 1.7.0 true SGP40 I2C VOC sensor driver enable @@ -22,8 +22,8 @@ 10.0 - + - + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Sgp40/Driver/Sgp40.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Sgp40/Driver/Sgp40.cs index 835fab3dd1..42a3ada1a5 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Sgp40/Driver/Sgp40.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Sgp40/Driver/Sgp40.cs @@ -11,10 +11,6 @@ namespace Meadow.Foundation.Sensors.Atmospheric /// public partial class Sgp40 : ByteCommsSensorBase, II2cPeripheral { - /// - /// - public event EventHandler> VocIndexUpdated = default!; - /// /// The VOC Index, from the last reading /// @@ -98,17 +94,6 @@ protected override Task ReadSensor() return Task.FromResult(data[0] << 8 | data[1]); } - /// - /// Inheritance-safe way to raise events and notify observers. - /// - /// - protected override void RaiseEventsAndNotify(IChangeResult changeResult) - { - VocIndexUpdated?.Invoke(this, new ChangeResult(VocIndex, changeResult.Old)); - - base.RaiseEventsAndNotify(changeResult); - } - /// /// This command turns the hotplate off and stops the measurement. Subsequently, the sensor enters idle mode. /// 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 20576593ba..1d1c5b24fd 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,8 +11,8 @@ 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 c0a373814c..64d4317eea 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 @@ -11,7 +11,7 @@ Meadow.Foundation.Sensors.Atmospheric.Sht31d https://github.com/WildernessLabs/Meadow.Foundation Meadow.Foundation, Meadow, Atmospheric, Temperature, Humidity, SHT31D - 0.1.54 + 1.7.0 true SHT31-D I2C temperature and humidity sensor enable @@ -22,8 +22,8 @@ 10.0 - + - + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Sht31D/Driver/Sht31d.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Sht31D/Driver/Sht31d.cs index 09dc31b6a8..5a2e044574 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Sht31D/Driver/Sht31d.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Sht31D/Driver/Sht31d.cs @@ -14,8 +14,8 @@ public partial class Sht31d : ByteCommsSensorBase<(Units.Temperature? Temperature, RelativeHumidity? Humidity)>, ITemperatureSensor, IHumiditySensor, II2cPeripheral { - private event EventHandler> _temperatureHandlers; - private event EventHandler> _humidityHandlers; + private event EventHandler> _temperatureHandlers = default!; + private event EventHandler> _humidityHandlers = default!; event EventHandler> ISamplingSensor.Updated { 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 9df0eb73b0..96f78af2d6 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,8 +10,8 @@ 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 22d2fcf8b8..d58ced9dd4 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 @@ -11,7 +11,7 @@ Meadow.Foundation.Sensors.Atmospheric.Sht4x https://github.com/WildernessLabs/Meadow.Foundation Meadow.Foundation Meadow,Atmospheric,Temperature,Humidity,SHT40,SHT41,SHT45 - 0.1.5 + 1.7.0 true SHT40, SHT41, SHT45 etc. I2C temperature and humidity sensor enable @@ -22,8 +22,8 @@ 10.0 - + - + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Sht4x/Driver/Sht4x.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Sht4x/Driver/Sht4x.cs index 75ed0a16a1..42dbacfc0f 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Sht4x/Driver/Sht4x.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Sht4x/Driver/Sht4x.cs @@ -15,8 +15,8 @@ public partial class Sht4x : ByteCommsSensorBase<(Units.Temperature? Temperature, RelativeHumidity? Humidity)>, ITemperatureSensor, IHumiditySensor, II2cPeripheral { - private event EventHandler> _temperatureHandlers; - private event EventHandler> _humidityHandlers; + private event EventHandler> _temperatureHandlers = default!; + private event EventHandler> _humidityHandlers = default!; event EventHandler> ISamplingSensor.Updated { 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 24dbf2ed5f..21e2effd0a 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,8 +12,8 @@ 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 99c54f698d..bff203aea6 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 @@ -13,15 +13,15 @@ Meadow.Foundation.Sensors.Atmospheric.Si70xx https://github.com/WildernessLabs/Meadow.Foundation Meadow.Foundation, Atmospheric, Si70xx, Si7013, Si7020, Si7021 - 0.1.54 + 1.7.0 true Si70xx I2C humidity and temperature sensors enable - 10.0 + 10.0 - + - + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Si70xx/Driver/Si70xx.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Si70xx/Driver/Si70xx.cs index cdc6687b54..607fd2f213 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Si70xx/Driver/Si70xx.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Si70xx/Driver/Si70xx.cs @@ -18,8 +18,8 @@ public partial class Si70xx : ByteCommsSensorBase<(Units.Temperature? Temperature, RelativeHumidity? Humidity)>, ITemperatureSensor, IHumiditySensor, II2cPeripheral { - private event EventHandler> _temperatureHandlers; - private event EventHandler> _humidityHandlers; + private event EventHandler> _temperatureHandlers = default!; + private event EventHandler> _humidityHandlers = default!; event EventHandler> ISamplingSensor.Updated { @@ -174,7 +174,6 @@ protected override void RaiseEventsAndNotify(IChangeResult<(Units.Temperature? T { _humidityHandlers?.Invoke(this, new ChangeResult(humidity, changeResult.Old?.Humidity)); } - base.RaiseEventsAndNotify(changeResult); } 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 fc0b811cf0..2312be51ee 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,8 +11,8 @@ 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 9d592d464f..96656b9464 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 @@ -11,7 +11,7 @@ Meadow.Foundation.Sensors.Atmospheric.Th02 https://github.com/WildernessLabs/Meadow.Foundation Meadow.Foundation, Atmospheric, Th02, Temperature, Humidity - 0.1.5 + 1.7.0 true Th02 I2C Relative Humidity and temperature sensor enable @@ -22,8 +22,8 @@ 10.0 - + - + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Th02/Driver/Th02.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Th02/Driver/Th02.cs index 2257e646f0..c29286f8b3 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Th02/Driver/Th02.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Atmospheric.Th02/Driver/Th02.cs @@ -16,8 +16,8 @@ public partial class Th02 : ByteCommsSensorBase<(Units.Temperature? Temperature, RelativeHumidity? Humidity)>, ITemperatureSensor, IHumiditySensor, II2cPeripheral { - private event EventHandler> _temperatureHandlers; - private event EventHandler> _humidityHandlers; + private event EventHandler> _temperatureHandlers = default!; + private event EventHandler> _humidityHandlers = default!; event EventHandler> ISamplingSensor.Updated { 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 b929f0759d..b3bc1c8777 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,8 +10,8 @@ 10.0 - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Camera.Amg8833/Datasheet/Grid-EYE_SPECIFICATIONS(Reference).pdf b/Source/Meadow.Foundation.Peripherals/Sensors.Camera.Amg8833/Datasheet/Grid-EYE_SPECIFICATIONS(Reference).pdf new file mode 100644 index 0000000000..29cdd3953d Binary files /dev/null and b/Source/Meadow.Foundation.Peripherals/Sensors.Camera.Amg8833/Datasheet/Grid-EYE_SPECIFICATIONS(Reference).pdf differ diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Camera.Amg8833/Driver/Amg8833.Enums.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Camera.Amg8833/Driver/Amg8833.Enums.cs new file mode 100644 index 0000000000..8901576180 --- /dev/null +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Camera.Amg8833/Driver/Amg8833.Enums.cs @@ -0,0 +1,62 @@ +namespace Meadow.Foundation.Sensors.Camera; + +public partial class Amg8833 +{ + internal static class Constants + { + public const int StartupDelayMs = 100; + public const double ThermistorConversion = 0.0625; + public const int PixelArraySize = 64; + public const double PixelTempConversion = 0.25; + } + + internal enum InterruptModes : byte + { + Difference = 0x00, + Absolute = 0x01 << 1 + } + + internal enum Addresses : byte + { + Address_0x69 = 0x69, + Default = Address_0x69 + } + + internal enum Registers : byte + { + PCTL = 0x00, + RST = 0x01, + FPSC = 0x02, + INTC = 0x03, + STAT = 0x04, + SCLR = 0x05, + RESERVED = 0x06, + AVE = 0x07, + INTHL = 0x08, + INTHH = 0x09, + INTLL = 0x0A, + INTLH = 0x0B, + IHYSL = 0x0C, + IHYSH = 0x0D, + TTHL = 0x0E, + TTHH = 0x0F, + INT_OFFSET = 0x010, + PIXEL_OFFSET = 0x80 + }; + + internal enum Modes : byte + { + Normal = 0x00, + Sleep = 0x01, + StandBy_60 = 0x20, + StandBy_10 = 0x21 + } + + internal enum Commands : byte + { + RST_FlagReset = 0x30, + RST_InitialReset = 0x3f, + FPS_One = 0x01, + FPS_Ten = 0x00, + } +} diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Camera.Amg8833/Driver/Amg8833.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Camera.Amg8833/Driver/Amg8833.cs new file mode 100644 index 0000000000..f2338dab42 --- /dev/null +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Camera.Amg8833/Driver/Amg8833.cs @@ -0,0 +1,136 @@ +using Meadow.Hardware; +using System; +using System.Runtime.InteropServices; +using System.Threading; + +namespace Meadow.Foundation.Sensors.Camera; + +/// +/// Represents a Panasonic Grid-EYE infrared array sensor +/// +public partial class Amg8833 : II2cPeripheral +{ + private II2cCommunications _i2cComms; + + /// + /// The default I2C address for the peripheral + /// + public byte DefaultI2cAddress => (byte)Addresses.Default; + + /// + /// Creates an instance of an AMG8833 sensor + /// + /// + public Amg8833(II2cBus i2cBus) + { + _i2cComms = new I2cCommunications(i2cBus, (byte)Addresses.Default); + + Initialize(); + } + + private void Initialize() + { + SetPowerMode(Modes.Normal); + WriteRegister(Registers.RST, Commands.RST_InitialReset); + DisableInterrupts(); + WriteRegister(Registers.FPSC, Commands.FPS_Ten); + + Thread.Sleep(Constants.StartupDelayMs); + } + + private void SetPowerMode(Modes mode) + { + WriteRegister(Registers.PCTL, Modes.Normal); + } + + private void DisableInterrupts() + { + WriteRegister(Registers.INTC, (byte)0x00); + } + + /// + /// Reads the temperature of the on-board thermistor + /// + /// + public Units.Temperature ReadThermistor() + { + // read 2 bytes + var raw = _i2cComms.ReadRegisterAsUShort((byte)Registers.TTHL); + // see the data sheet on this calculation + var converted = Convert12BitUShortToFloat(raw) * Constants.ThermistorConversion; + return new Units.Temperature(converted, Units.Temperature.UnitType.Celsius); + } + + /// + /// Reads the raw sensor data into the provided buffer. + /// + /// A span of 64 16-but values + public void ReadRawPixels(Span buffer) + { + if (buffer.Length != Constants.PixelArraySize) + { + throw new ArgumentOutOfRangeException($"Expected a buffer of {Constants.PixelArraySize} shorts"); + } + + Span tx = stackalloc byte[1]; + + tx[0] = (byte)Registers.PIXEL_OFFSET; + _i2cComms.Write(tx); + var rx = MemoryMarshal.Cast(buffer); + _i2cComms.Read(rx); + } + + /// + /// Reads the temperature of each pixel in the sensor + /// + /// + public Units.Temperature[] ReadPixels() + { + var temps = new Units.Temperature[Constants.PixelArraySize]; + Span raw = stackalloc short[Constants.PixelArraySize]; + + ReadRawPixels(raw); + + for (var i = 0; i < raw.Length; i++) + { + var r = Convert12BitUShortToFloat((ushort)raw[i]) * Constants.PixelTempConversion; + temps[i] = new Units.Temperature(r, Units.Temperature.UnitType.Celsius); + } + + return temps; + } + + private float Convert12BitUShortToFloat(ushort s) + { + // take 11 bits of value + var absolute = s & 0x7ff; + // apply any negative + + if ((absolute & 0x800) != 0) + { + return 0 - (float)absolute; + } + + return absolute; + } + + private void EnableInterrupts(InterruptModes mode) + { + WriteRegister(Registers.INTC, (byte)(0x01 | (byte)mode)); + } + + private void WriteRegister(Registers register, byte value) + { + _i2cComms.WriteRegister((byte)register, value); + } + + private void WriteRegister(Registers register, Modes mode) + { + WriteRegister(register, (byte)mode); + } + + private void WriteRegister(Registers register, Commands command) + { + WriteRegister(register, (byte)command); + } +} \ No newline at end of file diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Camera.Amg8833/Driver/Readme.md b/Source/Meadow.Foundation.Peripherals/Sensors.Camera.Amg8833/Driver/Readme.md new file mode 100644 index 0000000000..4ee98fcdef --- /dev/null +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Camera.Amg8833/Driver/Readme.md @@ -0,0 +1,49 @@ +# Meadow.Foundation.Sensors.Camera.Amg8833 + +**Grid-EYE Amg8833 I2C infrared array sensor** + +The **Amg8833** library is designed for the [Wilderness Labs](www.wildernesslabs.co) Meadow .NET IoT platform and is part of [Meadow.Foundation](https://developer.wildernesslabs.co/Meadow/Meadow.Foundation/). + +The **Meadow.Foundation** peripherals library is an open-source repository of drivers and libraries that streamline and simplify adding hardware to your C# .NET Meadow IoT application. + +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/). + +## Usage + +```csharp +Amg8833 camera; + +public override Task Initialize() +{ + Resolver.Log.Info("Initialize..."); + + var i2cBus = Device.CreateI2cBus(I2cBusSpeed.Fast); + camera = new Amg8833(i2cBus); + + return Task.CompletedTask; +} + +public override Task Run() +{ + while (true) + { + var pixels = camera.ReadPixels(); + + //output the first 4 pixels + Resolver.Log.Info($"{pixels[0].Celsius:F1}°C, {pixels[1].Celsius:F1}°C, {pixels[2].Celsius:F1}°C, {pixels[3].Celsius:F1}°C"); + } +} + +``` +## 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/). 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 new file mode 100644 index 0000000000..e60f8bd904 --- /dev/null +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Camera.Amg8833/Driver/Sensors.Camera.Amg8833.csproj @@ -0,0 +1,27 @@ + + + Readme.md + enable + 10.0 + Apache-2.0 + true + icon.png + Wilderness Labs, Inc + netstandard2.1 + Library + Amg8833 + Wilderness Labs, Inc + http://developer.wildernesslabs.co/Meadow/Meadow.Foundation/ + Meadow.Foundation.Sensors.Camera.Amg8833 + https://github.com/WildernessLabs/Meadow.Foundation + Meadow.Foundation,Amg8833,Camera,Infrared,Thermal + 1.7.0 + true + Grid-EYE Amg8833 I2C infrared array sensor + + + + + + + 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 new file mode 100644 index 0000000000..724a6edec0 --- /dev/null +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Camera.Amg8833/Samples/Amg8833_Sample/Amg8833_Sample.csproj @@ -0,0 +1,20 @@ + + + https://github.com/WildernessLabs/Meadow.Foundation + Wilderness Labs, Inc + Wilderness Labs, Inc + true + netstandard2.1 + Library + App + + + + + + + + Always + + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Camera.Amg8833/Samples/Amg8833_Sample/MeadowApp.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Camera.Amg8833/Samples/Amg8833_Sample/MeadowApp.cs new file mode 100644 index 0000000000..6200fe500d --- /dev/null +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Camera.Amg8833/Samples/Amg8833_Sample/MeadowApp.cs @@ -0,0 +1,38 @@ +using Meadow; +using Meadow.Devices; +using Meadow.Foundation.Sensors.Camera; +using Meadow.Hardware; +using System.Threading.Tasks; + +namespace Sensors.Cameras.Amg8833_Sample +{ + public class MeadowApp : App + { + // + + Amg8833 camera; + + public override Task Initialize() + { + Resolver.Log.Info("Initialize..."); + + var i2cBus = Device.CreateI2cBus(I2cBusSpeed.Fast); + camera = new Amg8833(i2cBus); + + return Task.CompletedTask; + } + + public override Task Run() + { + while (true) + { + var pixels = camera.ReadPixels(); + + //output the first 4 pixels + Resolver.Log.Info($"{pixels[0].Celsius:F1}°C, {pixels[1].Celsius:F1}°C, {pixels[2].Celsius:F1}°C, {pixels[3].Celsius:F1}°C"); + } + } + + // + } +} \ No newline at end of file diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Camera.Amg8833/Samples/Amg8833_Sample/meadow.config.yaml b/Source/Meadow.Foundation.Peripherals/Sensors.Camera.Amg8833/Samples/Amg8833_Sample/meadow.config.yaml new file mode 100644 index 0000000000..32363cb69c --- /dev/null +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Camera.Amg8833/Samples/Amg8833_Sample/meadow.config.yaml @@ -0,0 +1,2 @@ +MonoControl: + Options: --jit \ No newline at end of file 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 eb3ec5c1db..cc47f76d8c 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 @@ -15,13 +15,13 @@ Meadow.Foundation.Sensors.Camera.Mlx90640 https://github.com/WildernessLabs/Meadow.Foundation Meadow.Foundation, Mlx90640, Camera - 0.1.54 + 1.7.0 true Mlx90640 I2C far infrared thermal sensor array camera - + - + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Camera.Mlx90640/Samples/Mlx90640_Sample/MeadowApp.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Camera.Mlx90640/Samples/Mlx90640_Sample/MeadowApp.cs index 55b1576328..4aa0f31ce4 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Camera.Mlx90640/Samples/Mlx90640_Sample/MeadowApp.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Camera.Mlx90640/Samples/Mlx90640_Sample/MeadowApp.cs @@ -6,7 +6,7 @@ using System.Threading; using System.Threading.Tasks; -namespace Sensors.Temperature.MLX90640_Sample +namespace Sensors.Cameras.Mlx90640_Sample { public class MeadowApp : App { 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 ae35392b6d..ecc0561afc 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,8 +9,8 @@ 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 29c2accf34..7531fd2249 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 @@ -15,13 +15,13 @@ Meadow.Foundation.Sensors.Camera.Vc0706 https://github.com/WildernessLabs/Meadow.Foundation Meadow.Foundation, VC0706, Camera - 0.1.29 + 1.7.0 true VC0706 serial VGA CMOS camera - + - + 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 9fc9c17e29..bfde75b905 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,8 +12,8 @@ - - + + 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 ce49690cdf..925ae6ebfe 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Distance.A02yyuw/Driver/A02yyuw.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Distance.A02yyuw/Driver/A02yyuw.cs @@ -12,11 +12,6 @@ namespace Meadow.Foundation.Sensors.Distance /// public class A02yyuw : PollingSensorBase, IRangeFinder, ISleepAwarePeripheral, IDisposable { - /// - /// Raised when the value of the reading changes - /// - public event EventHandler> DistanceUpdated = default!; - /// /// Distance from sensor to object /// @@ -95,16 +90,6 @@ protected override Task ReadSensor() return ReadSingleValue(); } - /// - /// Raise distance change event for subscribers - /// - /// - protected override void RaiseEventsAndNotify(IChangeResult changeResult) - { - DistanceUpdated?.Invoke(this, changeResult); - base.RaiseEventsAndNotify(changeResult); - } - /// /// Start updating distances /// diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Distance.A02yyuw/Driver/Readme.md b/Source/Meadow.Foundation.Peripherals/Sensors.Distance.A02yyuw/Driver/Readme.md index 3af9a835b0..051152b467 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Distance.A02yyuw/Driver/Readme.md +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Distance.A02yyuw/Driver/Readme.md @@ -19,7 +19,7 @@ public override Task Initialize() { Resolver.Log.Info("Initialize..."); - a02yyuw = new A02yyuw(Device, Device.PlatformOS.GetSerialPortName("COM1")); + a02yyuw = new A02yyuw(Device, Device.PlatformOS.GetSerialPortName("COM4")); var consumer = A02yyuw.CreateObserver( handler: result => @@ -30,14 +30,14 @@ public override Task Initialize() { if (result.Old is { } old) { - return Math.Abs((result.New - old).Centimeters) > 0.5; + return Math.Abs((result.New - old).Centimeters) > 5.0; } return false; } ); a02yyuw.Subscribe(consumer); - a02yyuw.DistanceUpdated += A02yyuw_DistanceUpdated; + a02yyuw.Updated += A02yyuw_DistanceUpdated; return Task.CompletedTask; } 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 96e5632917..8b91f2461b 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 @@ -15,13 +15,13 @@ Meadow.Foundation.Sensors.Distance.A02yyuw https://github.com/WildernessLabs/Meadow.Foundation Meadow.Foundation,A02yyuw,Ultrasonic,Distance,Sensor - 0.1.0 + 1.7.0 true A02yyuw serial ultrasonic distance sensor - + - + 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 3cca4facde..fe577baaff 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,8 +6,8 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Distance.A02yyuw/Samples/A02yyuw_Sample/MeadowApp.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Distance.A02yyuw/Samples/A02yyuw_Sample/MeadowApp.cs index 8ae74a0642..069b2d702d 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Distance.A02yyuw/Samples/A02yyuw_Sample/MeadowApp.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Distance.A02yyuw/Samples/A02yyuw_Sample/MeadowApp.cs @@ -8,7 +8,7 @@ namespace A02yyuw_Sample { // Change F7FeatherV2 to F7FeatherV1 for V1.x boards - public class MeadowApp : App + public class MeadowApp : App { // @@ -18,7 +18,7 @@ public override Task Initialize() { Resolver.Log.Info("Initialize..."); - a02yyuw = new A02yyuw(Device, Device.PlatformOS.GetSerialPortName("COM1")); + a02yyuw = new A02yyuw(Device, Device.PlatformOS.GetSerialPortName("COM4")); var consumer = A02yyuw.CreateObserver( handler: result => @@ -29,14 +29,14 @@ public override Task Initialize() { if (result.Old is { } old) { - return Math.Abs((result.New - old).Centimeters) > 0.5; + return Math.Abs((result.New - old).Centimeters) > 5.0; } return false; } ); a02yyuw.Subscribe(consumer); - a02yyuw.DistanceUpdated += A02yyuw_DistanceUpdated; + a02yyuw.Updated += A02yyuw_DistanceUpdated; return Task.CompletedTask; } diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Distance.Hcsr04/Driver/Hcsr04.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Distance.Hcsr04/Driver/Hcsr04.cs index dfaedc4e95..e3f5a8ce29 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Distance.Hcsr04/Driver/Hcsr04.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Distance.Hcsr04/Driver/Hcsr04.cs @@ -12,11 +12,6 @@ namespace Meadow.Foundation.Sensors.Distance /// public class Hcsr04 : SamplingSensorBase, IRangeFinder, IDisposable { - /// - /// Raised when an received a rebound trigger signal - /// - public event EventHandler> DistanceUpdated = default!; - /// /// Returns current distance /// @@ -143,16 +138,6 @@ protected override Task ReadSensor() throw new NotImplementedException(); } - /// - /// Raise events for subscribers and notify of value changes - /// - /// The updated sensor data - protected override void RaiseEventsAndNotify(IChangeResult changeResult) - { - DistanceUpdated?.Invoke(this, changeResult); - base.RaiseEventsAndNotify(changeResult); - } - /// /// Starts continuously sampling the sensor /// diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Distance.Hcsr04/Driver/Readme.md b/Source/Meadow.Foundation.Peripherals/Sensors.Distance.Hcsr04/Driver/Readme.md index ac4a7ed352..0e87e9099f 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Distance.Hcsr04/Driver/Readme.md +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Distance.Hcsr04/Driver/Readme.md @@ -22,7 +22,7 @@ public override Task Initialize() hCSR04 = new Hcsr04( triggerPin: Device.Pins.D05, echoPin: Device.Pins.D06); - hCSR04.DistanceUpdated += HCSR04_DistanceUpdated; + hCSR04.Updated += HCSR04_DistanceUpdated; return Task.CompletedTask; } 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 7eff405c76..3a38ec69d6 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 @@ -15,13 +15,13 @@ Meadow.Foundation.Sensors.Distance.Hcsr04 https://github.com/WildernessLabs/Meadow.Foundation Meadow.Foundation, Hcsr04, Distance, Sensor - 0.1.20 + 1.7.0 false HCSR04 digital ultrasonic distance sensor - + - + 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 3a7ce70f29..ca39a07aba 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,8 +9,8 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Distance.Hcsr04/Samples/Hcsr04_Sample/MeadowApp.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Distance.Hcsr04/Samples/Hcsr04_Sample/MeadowApp.cs index 2664d8e640..7d8f6ba70a 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Distance.Hcsr04/Samples/Hcsr04_Sample/MeadowApp.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Distance.Hcsr04/Samples/Hcsr04_Sample/MeadowApp.cs @@ -21,7 +21,7 @@ public override Task Initialize() hCSR04 = new Hcsr04( triggerPin: Device.Pins.D05, echoPin: Device.Pins.D06); - hCSR04.DistanceUpdated += HCSR04_DistanceUpdated; + hCSR04.Updated += HCSR04_DistanceUpdated; return Task.CompletedTask; } diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Distance.MaxBotix/Driver/MaxBotix.I2c.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Distance.MaxBotix/Driver/MaxBotix.I2c.cs index a120826d69..4936141188 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Distance.MaxBotix/Driver/MaxBotix.I2c.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Distance.MaxBotix/Driver/MaxBotix.I2c.cs @@ -11,6 +11,8 @@ public partial class MaxBotix : II2cPeripheral /// public byte DefaultI2cAddress => (byte)Addresses.Default; + II2cCommunications? i2cComms; + /// /// Creates a new MaxBotix object communicating over I2C /// @@ -18,8 +20,9 @@ public partial class MaxBotix : II2cPeripheral /// The distance sensor type /// The I2C address public MaxBotix(II2cBus i2cBus, SensorType sensor, byte address = (byte)Addresses.Default) - : base(i2cBus, address) { + i2cComms = new I2cCommunications(i2cBus, address); + sensorType = sensor; communication = CommunicationType.I2C; @@ -28,13 +31,13 @@ public MaxBotix(II2cBus i2cBus, SensorType sensor, byte address = (byte)Addresse void StartI2cSensor(byte address) { - BusComms.ReadRegister(address); + i2cComms?.ReadRegister(address); Thread.Sleep(100); } Length ReadSensorI2c() { - return new Length(BusComms.ReadRegisterAsUShort(0x51), GetUnitsForSensor(sensorType)); + return new Length(i2cComms!.ReadRegisterAsUShort(0x51), GetUnitsForSensor(sensorType)); } } } \ No newline at end of file diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Distance.MaxBotix/Driver/MaxBotix.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Distance.MaxBotix/Driver/MaxBotix.cs index 5a76b15222..db41b8b40b 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Distance.MaxBotix/Driver/MaxBotix.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Distance.MaxBotix/Driver/MaxBotix.cs @@ -8,13 +8,8 @@ namespace Meadow.Foundation.Sensors.Distance /// /// Represents the MaxBotix series of distance sensors /// - public partial class MaxBotix : ByteCommsSensorBase, IRangeFinder, IDisposable + public partial class MaxBotix : PollingSensorBase, IRangeFinder, IDisposable { - /// - /// Raised when the value of the reading changes - /// - public event EventHandler> DistanceUpdated = default!; - /// /// Distance from sensor to object /// @@ -64,16 +59,6 @@ protected override async Task ReadSensor() }; } - /// - /// Raise distance change event for subscribers - /// - /// - protected override void RaiseEventsAndNotify(IChangeResult changeResult) - { - DistanceUpdated?.Invoke(this, changeResult); - base.RaiseEventsAndNotify(changeResult); - } - /// /// Start updating distances /// @@ -140,9 +125,8 @@ Length.UnitType GetUnitsForSensor(SensorType sensor) } /// - public override void Dispose() + public void Dispose() { - base.Dispose(); Dispose(disposing: true); GC.SuppressFinalize(this); } @@ -151,11 +135,15 @@ public override void Dispose() /// Dispose of the object /// /// Is disposing - protected override void Dispose(bool disposing) + protected void Dispose(bool disposing) { - base.Dispose(disposing); if (!IsDisposed) { + if (disposing) + { + base.StopUpdating(); + } + if (disposing && createdPorts) { analogInputPort?.Dispose(); 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 46b483bdae..4a33e0943e 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 @@ -15,13 +15,13 @@ Meadow.Foundation.Sensors.Distance.MaxBotix https://github.com/WildernessLabs/Meadow.Foundation Meadow.Foundation, MaxBotix, Ultrasonic, Distance, Sensor - 0.1.7 + 1.7.0 true MaxBotix I2C, analog and serial ultrasonic distance sensors - + - + 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 4fa67e2329..a2210ef940 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,8 +6,8 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Distance.MaxBotix/Samples/MaxBotix_Sample/MeadowApp.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Distance.MaxBotix/Samples/MaxBotix_Sample/MeadowApp.cs index e00ce9628a..473b79976e 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Distance.MaxBotix/Samples/MaxBotix_Sample/MeadowApp.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Distance.MaxBotix/Samples/MaxBotix_Sample/MeadowApp.cs @@ -41,7 +41,7 @@ public override Task Initialize() ); maxBotix.Subscribe(consumer); - maxBotix.DistanceUpdated += MaxBotix_DistanceUpdated; + maxBotix.Updated += MaxBotix_DistanceUpdated; return Task.CompletedTask; } 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 254e8c46c6..eacabd2712 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Distance.Me007ys/Driver/Me007ys.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Distance.Me007ys/Driver/Me007ys.cs @@ -12,11 +12,6 @@ namespace Meadow.Foundation.Sensors.Distance /// public class Me007ys : PollingSensorBase, IRangeFinder, ISleepAwarePeripheral, IDisposable { - /// - /// Raised when the value of the reading changes - /// - public event EventHandler> DistanceUpdated = default!; - /// /// Distance from sensor to object /// @@ -95,16 +90,6 @@ protected override Task ReadSensor() return ReadSingleValue(); } - /// - /// Raise distance change event for subscribers - /// - /// - protected override void RaiseEventsAndNotify(IChangeResult changeResult) - { - DistanceUpdated?.Invoke(this, changeResult); - base.RaiseEventsAndNotify(changeResult); - } - /// /// Start updating distances /// diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Distance.Me007ys/Driver/Readme.md b/Source/Meadow.Foundation.Peripherals/Sensors.Distance.Me007ys/Driver/Readme.md index 8badb8fb47..aa5fc9c9ec 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Distance.Me007ys/Driver/Readme.md +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Distance.Me007ys/Driver/Readme.md @@ -30,14 +30,14 @@ public override Task Initialize() { if (result.Old is { } old) { - return Math.Abs((result.New - old).Centimeters) > 0.5; + return Math.Abs((result.New - old).Centimeters) > 5.0; } return false; } ); me007ys.Subscribe(consumer); - me007ys.DistanceUpdated += Me007y_DistanceUpdated; + me007ys.Updated += Me007y_DistanceUpdated; return Task.CompletedTask; } 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 96196aff34..b339d45847 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 @@ -15,13 +15,13 @@ Meadow.Foundation.Sensors.Distance.Me007ys https://github.com/WildernessLabs/Meadow.Foundation Meadow.Foundation,Me007ys,Ultrasonic,Distance,Sensor - 0.1.0 + 1.7.0 true Me007ys serial ultrasonic distance sensor - + - + 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 ed1d3ab0f7..0e2f846b21 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,8 +6,8 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Distance.Me007ys/Samples/Me007ys_Sample/MeadowApp.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Distance.Me007ys/Samples/Me007ys_Sample/MeadowApp.cs index 0c5574f724..51842a3756 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Distance.Me007ys/Samples/Me007ys_Sample/MeadowApp.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Distance.Me007ys/Samples/Me007ys_Sample/MeadowApp.cs @@ -29,14 +29,14 @@ public override Task Initialize() { if (result.Old is { } old) { - return Math.Abs((result.New - old).Centimeters) > 0.5; + return Math.Abs((result.New - old).Centimeters) > 5.0; } return false; } ); me007ys.Subscribe(consumer); - me007ys.DistanceUpdated += Me007y_DistanceUpdated; + me007ys.Updated += Me007y_DistanceUpdated; return Task.CompletedTask; } diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Distance.Vl53l0x/Driver/Readme.md b/Source/Meadow.Foundation.Peripherals/Sensors.Distance.Vl53l0x/Driver/Readme.md index 31740a77d2..d670f23709 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Distance.Vl53l0x/Driver/Readme.md +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Distance.Vl53l0x/Driver/Readme.md @@ -22,7 +22,7 @@ public override Task Initialize() var i2cBus = Device.CreateI2cBus(I2cBusSpeed.FastPlus); sensor = new Vl53l0x(i2cBus); - sensor.DistanceUpdated += Sensor_Updated; + sensor.Updated += Sensor_Updated; return Task.CompletedTask; } 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 f1f479a21c..784e81c566 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 @@ -15,13 +15,13 @@ Meadow.Foundation.Sensors.Distance.Vl53l0x https://github.com/WildernessLabs/Meadow.Foundation Meadow.Foundation, Vl53l0x, distance - 0.1.45 + 1.7.0 true Vl53l0x I2C time of flight ranging distance sensor - + - + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Distance.Vl53l0x/Driver/Vl53l0x.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Distance.Vl53l0x/Driver/Vl53l0x.cs index 696cbb7f31..19174f080e 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Distance.Vl53l0x/Driver/Vl53l0x.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Distance.Vl53l0x/Driver/Vl53l0x.cs @@ -12,11 +12,6 @@ namespace Meadow.Foundation.Sensors.Distance /// public partial class Vl53l0x : ByteCommsSensorBase, IRangeFinder, II2cPeripheral { - /// - /// Distance updated event - /// - public event EventHandler> DistanceUpdated = default!; - /// /// Is the hardware shutdown / off /// @@ -85,16 +80,6 @@ public Vl53l0x(II2cBus i2cBus, IPin? shutdownPin, byte address = (byte)Addresses Initialize().Wait(); } - /// - /// Raise distance change event and notify subscribers - /// - /// - protected override void RaiseEventsAndNotify(IChangeResult changeResult) - { - DistanceUpdated?.Invoke(this, changeResult); - base.RaiseEventsAndNotify(changeResult); - } - /// /// Initializes the VL53L0X /// diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Distance.Vl53l0x/Samples/Vl53l0x_Sample/MeadowApp.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Distance.Vl53l0x/Samples/Vl53l0x_Sample/MeadowApp.cs index 7bbbed3b6c..34b0534531 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Distance.Vl53l0x/Samples/Vl53l0x_Sample/MeadowApp.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Distance.Vl53l0x/Samples/Vl53l0x_Sample/MeadowApp.cs @@ -22,7 +22,7 @@ public override Task Initialize() var i2cBus = Device.CreateI2cBus(I2cBusSpeed.FastPlus); sensor = new Vl53l0x(i2cBus); - sensor.DistanceUpdated += Sensor_Updated; + sensor.Updated += Sensor_Updated; return Task.CompletedTask; } 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 33ac3f5a0c..56390f2937 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,8 +9,8 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.Ags01Db/Driver/Ags01Db.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.Ags01Db/Driver/Ags01Db.cs index e10c6d4ac5..95a9d4cf2b 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.Ags01Db/Driver/Ags01Db.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.Ags01Db/Driver/Ags01Db.cs @@ -1,6 +1,5 @@ using Meadow.Hardware; using Meadow.Units; -using System; using System.Threading.Tasks; namespace Meadow.Foundation.Sensors.Environmental @@ -20,11 +19,6 @@ public partial class Ags01Db : ByteCommsSensorBase, II2cPeriphera const byte ASG_VERSION_MSB = 0x0A; const byte ASG_VERSION_LSB = 0x01; - /// - /// Raised when the concentration changes - /// - public event EventHandler> ConcentrationUpdated = default!; - /// /// The current concentration value /// @@ -86,16 +80,6 @@ public byte GetVersion() return ReadBuffer.Span[0]; } - /// - /// Raise change events for subscribers - /// - /// The change result with the current sensor data - protected void RaiseChangedAndNotify(IChangeResult changeResult) - { - ConcentrationUpdated?.Invoke(this, changeResult); - base.RaiseEventsAndNotify(changeResult); - } - /// /// 8-bit CRC Checksum Calculation /// diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.Ags01Db/Driver/Readme.md b/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.Ags01Db/Driver/Readme.md index cd06094df1..8cc10a6b78 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.Ags01Db/Driver/Readme.md +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.Ags01Db/Driver/Readme.md @@ -32,7 +32,7 @@ public override Task Initialize() ); ags10Db.Subscribe(consumer); - ags10Db.ConcentrationUpdated += (object sender, IChangeResult e) => + ags10Db.Updated += (object sender, IChangeResult e) => { Resolver.Log.Info($"Concentration Updated: {e.New.PartsPerMillion:N2}ppm"); }; 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 d4e870773f..71b4401067 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 @@ -15,13 +15,13 @@ Meadow.Foundation.Sensors.Environmental.Ags01Db https://github.com/WildernessLabs/Meadow.Foundation Meadow.Foundation, Environmental, Ags01Db - 0.1.52 + 1.7.0 true Ags01Db I2C digital MEMS VOC gas sensor - + - + 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 6ab7a0e1b3..eae0f24e88 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,8 +9,8 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.Ags01Db/Samples/Ags01Db_Sample/MeadowApp.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.Ags01Db/Samples/Ags01Db_Sample/MeadowApp.cs index b542619794..94ba976dbf 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.Ags01Db/Samples/Ags01Db_Sample/MeadowApp.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.Ags01Db/Samples/Ags01Db_Sample/MeadowApp.cs @@ -30,7 +30,7 @@ public override Task Initialize() ); ags10Db.Subscribe(consumer); - ags10Db.ConcentrationUpdated += (object sender, IChangeResult e) => + ags10Db.Updated += (object sender, IChangeResult e) => { Resolver.Log.Info($"Concentration Updated: {e.New.PartsPerMillion:N2}ppm"); }; diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.AtlasScientificGravityDOMeter/Driver/AtlasScientificGravityDOMeter.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.AtlasScientificGravityDOMeter/Driver/AtlasScientificGravityDOMeter.cs index 6641ea30c9..ee34e03058 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.AtlasScientificGravityDOMeter/Driver/AtlasScientificGravityDOMeter.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.AtlasScientificGravityDOMeter/Driver/AtlasScientificGravityDOMeter.cs @@ -9,13 +9,8 @@ namespace Meadow.Foundation.Sensors.Environmental; /// /// Atlas Scientific Analog Gravity Dissolved Oxygen Meter /// -public partial class AtlasScientificGravityDOMeter : SamplingSensorBase, IDissolvedOxygenSensor +public partial class AtlasScientificGravityDOMeter : SamplingSensorBase, IDissolvedOxygenSaturationSensor { - /// - /// Raised when a new sensor percentage saturation reading is ready - /// - public event EventHandler> SaturationUpdated = delegate { }; - /// /// The calibration value for the sensor in air /// @@ -113,16 +108,6 @@ public override void StopUpdating() } } - /// - /// Raise change events for subscribers - /// - /// The change result with the current sensor data - protected override void RaiseEventsAndNotify(IChangeResult changeResult) - { - SaturationUpdated?.Invoke(this, changeResult); - base.RaiseEventsAndNotify(changeResult); - } - double VoltageToSaturation(Voltage voltage) { return voltage.Millivolts / CalibrationInAir.Millivolts; diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.AtlasScientificGravityDOMeter/Driver/Readme.md b/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.AtlasScientificGravityDOMeter/Driver/Readme.md index 5ac7023ef6..bde7ce628a 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.AtlasScientificGravityDOMeter/Driver/Readme.md +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.AtlasScientificGravityDOMeter/Driver/Readme.md @@ -35,10 +35,10 @@ public override Task Initialize() sensor.Subscribe(consumer); // optional classical .NET events can also be used: - sensor.SaturationUpdated += (sender, result) => + sensor.Updated += (sender, result) => { - // string oldValue = (result.Old is { } old) ? $"{old * 100:n0}%" : "n/a"; - // Resolver.Log.Info($"Updated - New: {result.New * 100:n0}%, Old: {oldValue}"); + string oldValue = (result.Old is { } old) ? $"{old * 100:n0}%" : "n/a"; + Resolver.Log.Info($"Updated - New: {result.New * 100:n0}%, Old: {oldValue}"); }; return Task.CompletedTask; 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 dd159e8c05..ca3c119414 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 @@ -15,13 +15,13 @@ Meadow.Foundation.Sensors.Environmental.AtlasScientificGravityDOMeter https://github.com/WildernessLabs/Meadow.Foundation Meadow,Meadow.Foundation,Environmental,Atlas,Scientific,Gravity,DO,Dissolved,Oxygen,Meter - 0.1.0 + 1.7.0 true Atlas Scientific analog gravity dissolved oxygen sensor - + - + 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 7f6d842c65..52cdf34a20 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,8 +9,8 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.AtlasScientificGravityDOMeter/Samples/AtlasScientificGravityDOMeter_Sample/MeadowApp.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.AtlasScientificGravityDOMeter/Samples/AtlasScientificGravityDOMeter_Sample/MeadowApp.cs index 9a8f68cbdd..6853f02970 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.AtlasScientificGravityDOMeter/Samples/AtlasScientificGravityDOMeter_Sample/MeadowApp.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.AtlasScientificGravityDOMeter/Samples/AtlasScientificGravityDOMeter_Sample/MeadowApp.cs @@ -33,10 +33,10 @@ public override Task Initialize() sensor.Subscribe(consumer); // optional classical .NET events can also be used: - sensor.SaturationUpdated += (sender, result) => + sensor.Updated += (sender, result) => { - // string oldValue = (result.Old is { } old) ? $"{old * 100:n0}%" : "n/a"; - // Resolver.Log.Info($"Updated - New: {result.New * 100:n0}%, Old: {oldValue}"); + string oldValue = (result.Old is { } old) ? $"{old * 100:n0}%" : "n/a"; + Resolver.Log.Info($"Updated - New: {result.New * 100:n0}%, Old: {oldValue}"); }; return Task.CompletedTask; diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.DFRobotGravityDOMeter/Driver/DFRobotGravityDOMeter.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.DFRobotGravityDOMeter/Driver/DFRobotGravityDOMeter.cs new file mode 100644 index 0000000000..449f7db59c --- /dev/null +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.DFRobotGravityDOMeter/Driver/DFRobotGravityDOMeter.cs @@ -0,0 +1,134 @@ +using Meadow.Hardware; +using Meadow.Peripherals.Sensors.Environmental; +using Meadow.Units; +using System; +using System.Threading.Tasks; + +namespace Meadow.Foundation.Sensors.Environmental; + +/// +/// DFRobot Analog Gravity Dissolved Oxygen Meter +/// +public partial class DFRobotGravityDOMeter : SamplingSensorBase, IDissolvedOxygenConcentrationSensor +{ + /// + /// The current water temperature (default 25C) + /// + public Units.Temperature WaterTemperature { get; set; } = new Units.Temperature(25, Units.Temperature.UnitType.Celsius); + + /// + /// The calibration value for the sensor at 25C (default 1.6V) + /// + public Voltage CalibrationAt25C { get; set; } = new Voltage(1.6, Voltage.UnitType.Volts); + + /// + /// Returns the analog input port + /// + protected IAnalogInputPort AnalogInputPort { get; } + + /// + /// Last concentration value read from the sensor + /// + public ConcentrationInWater? Concentration { get; protected set; } + + /// + /// The disolved oxygen lookup table for temperature values from 0 to 40 degrees C + /// + readonly int[] DO_Table = new int[41] { + 14460, 14220, 13820, 13440, 13090, 12740, 12420, 12110, 11810, 11530, + 11260, 11010, 10770, 10530, 10300, 10080, 9860, 9660, 9460, 9270, + 9080, 8900, 8730, 8570, 8410, 8250, 8110, 7960, 7820, 7690, + 7560, 7430, 7300, 7180, 7070, 6950, 6840, 6730, 6630, 6530, 6410}; + + /// + /// Creates a new DFRobotGravityDOMeter object + /// + /// Analog pin the temperature sensor is connected to + /// How many samples to take during a given reading + /// The time, to wait in between samples during a reading + public DFRobotGravityDOMeter(IPin analogInputPin, int sampleCount = 5, TimeSpan? sampleInterval = null) + : this(analogInputPin.CreateAnalogInputPort(sampleCount, sampleInterval ?? TimeSpan.FromMilliseconds(40), new Voltage(3.3))) + { } + + /// + /// Creates a new DFRobotGravityDOMeter object + /// + /// The port for the analog input pin + public DFRobotGravityDOMeter(IAnalogInputPort analogInputPort) + { + AnalogInputPort = analogInputPort; + + AnalogInputPort.Subscribe + ( + IAnalogInputPort.CreateObserver( + result => + { + ChangeResult changeResult = new() + { + New = VoltageToConcentration(result.New), + Old = Concentration + }; + Concentration = changeResult.New; + RaiseEventsAndNotify(changeResult); + } + ) + ); + } + + /// + /// Get the current voltage, useful for calibration + /// + /// + public Task GetCurrentVoltage() + { + return AnalogInputPort.Read(); + } + + /// + /// Reads data from the sensor + /// + /// The latest sensor reading + protected override async Task ReadSensor() + { + var voltage = await AnalogInputPort.Read(); + var newConcentration = VoltageToConcentration(voltage); + Concentration = newConcentration; + return newConcentration; + } + + /// + /// Starts continuously sampling the sensor + /// + public override void StartUpdating(TimeSpan? updateInterval) + { + lock (samplingLock) + { + if (IsSampling) { return; } + IsSampling = true; + AnalogInputPort.StartUpdating(updateInterval); + } + } + + /// + /// Stops sampling the sensor + /// + public override void StopUpdating() + { + lock (samplingLock) + { + if (!IsSampling) { return; } + IsSampling = false; + AnalogInputPort.StopUpdating(); + } + } + + ConcentrationInWater VoltageToConcentration(Voltage voltage) + { + var calibrationValue = DO_Table[(int)WaterTemperature.Celsius]; + + var voltageSaturationInMilliVolts = CalibrationAt25C.Millivolts + 35 * (WaterTemperature.Celsius - 25); + var concentrationRaw = voltage.Millivolts * calibrationValue / voltageSaturationInMilliVolts; + + return new ConcentrationInWater(concentrationRaw, Units.ConcentrationInWater.UnitType.MicrogramsPerLiter); + } +} \ No newline at end of file diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.DFRobotGravityDOMeter/Driver/Readme.md b/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.DFRobotGravityDOMeter/Driver/Readme.md new file mode 100644 index 0000000000..151e8b27f0 --- /dev/null +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.DFRobotGravityDOMeter/Driver/Readme.md @@ -0,0 +1,71 @@ +# Meadow.Foundation.Sensors.Environmental.DFRobotGravityDOMeter + +**DFRobot analog gravity dissolved oxygen sensor** + +The **DFRobotGravityDOMeter** library is designed for the [Wilderness Labs](www.wildernesslabs.co) Meadow .NET IoT platform and is part of [Meadow.Foundation](https://developer.wildernesslabs.co/Meadow/Meadow.Foundation/). + +The **Meadow.Foundation** peripherals library is an open-source repository of drivers and libraries that streamline and simplify adding hardware to your C# .NET Meadow IoT application. + +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/). + +## Usage + +```csharp +DFRobotGravityDOMeter sensor; + +public override Task Initialize() +{ + Resolver.Log.Info("Initialize..."); + + sensor = new DFRobotGravityDOMeter(Device.Pins.A01); + + // Example that uses an IObservable subscription to only be notified when the saturation changes + var consumer = DFRobotGravityDOMeter.CreateObserver( + handler: result => + { + string oldValue = (result.Old is { } old) ? $"{old.MilligramsPerLiter:n0}" : "n/a"; + string newValue = $"{result.New.MilligramsPerLiter:n0}"; + Resolver.Log.Info($"New: {newValue}mg/l, Old: {oldValue}mg/l"); + }, + filter: null + ); + sensor.Subscribe(consumer); + + // optional classical .NET events can also be used: + sensor.Updated += (sender, result) => + { + string oldValue = (result.Old is { } old) ? $"{old.MilligramsPerLiter}mg/l" : "n/a"; + Resolver.Log.Info($"Updated - New: {result.New.MilligramsPerLiter:n0}mg/l, Old: {oldValue}"); + }; + + return Task.CompletedTask; +} + +public override async Task Run() +{ + Resolver.Log.Info("Run..."); + + await ReadSensor(); + + sensor.StartUpdating(TimeSpan.FromSeconds(2)); +} + +protected async Task ReadSensor() +{ + var concentration = await sensor.Read(); + Resolver.Log.Info($"Initial concentration: {concentration.MilligramsPerLiter:N0}mg/l"); +} + +``` +## 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/). 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 new file mode 100644 index 0000000000..50325e3891 --- /dev/null +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.DFRobotGravityDOMeter/Driver/Sensors.Environmental.DFRobotGravityDOMeter.csproj @@ -0,0 +1,27 @@ + + + Readme.md + enable + 10.0 + Apache-2.0 + true + icon.png + Wilderness Labs, Inc + netstandard2.1 + Library + DFRobotGravityDOMeter + Wilderness Labs, Inc + http://developer.wildernesslabs.co/Meadow/Meadow.Foundation/ + Meadow.Foundation.Sensors.Environmental.DFRobotGravityDOMeter + https://github.com/WildernessLabs/Meadow.Foundation + Meadow,Meadow.Foundation,Environmental,DFRobot,Gravity,DO,Dissolved,Oxygen,Meter + 1.7.0 + true + DFRobot analog gravity dissolved oxygen sensor + + + + + + + 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 new file mode 100644 index 0000000000..ad5d8e1ed6 --- /dev/null +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.DFRobotGravityDOMeter/Samples/DFRobotGravityDOMeter_Sample/DFRobotGravityDOMeter_Sample.csproj @@ -0,0 +1,20 @@ + + + https://github.com/WildernessLabs/Meadow.Foundation + Wilderness Labs, Inc + Wilderness Labs, Inc + true + netstandard2.1 + Library + App + + + + + + + + Always + + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.DFRobotGravityDOMeter/Samples/DFRobotGravityDOMeter_Sample/MeadowApp.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.DFRobotGravityDOMeter/Samples/DFRobotGravityDOMeter_Sample/MeadowApp.cs new file mode 100644 index 0000000000..9da904e236 --- /dev/null +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.DFRobotGravityDOMeter/Samples/DFRobotGravityDOMeter_Sample/MeadowApp.cs @@ -0,0 +1,60 @@ +using Meadow; +using Meadow.Devices; +using Meadow.Foundation.Sensors.Environmental; +using System; +using System.Threading.Tasks; + +namespace Sensors.Environmental.DFRobotGravityDOMeter_Sample +{ + public class MeadowApp : App + { + // + + DFRobotGravityDOMeter sensor; + + public override Task Initialize() + { + Resolver.Log.Info("Initialize..."); + + sensor = new DFRobotGravityDOMeter(Device.Pins.A01); + + // Example that uses an IObservable subscription to only be notified when the saturation changes + var consumer = DFRobotGravityDOMeter.CreateObserver( + handler: result => + { + string oldValue = (result.Old is { } old) ? $"{old.MilligramsPerLiter:n0}" : "n/a"; + string newValue = $"{result.New.MilligramsPerLiter:n0}"; + Resolver.Log.Info($"New: {newValue}mg/l, Old: {oldValue}mg/l"); + }, + filter: null + ); + sensor.Subscribe(consumer); + + // optional classical .NET events can also be used: + sensor.Updated += (sender, result) => + { + string oldValue = (result.Old is { } old) ? $"{old.MilligramsPerLiter}mg/l" : "n/a"; + Resolver.Log.Info($"Updated - New: {result.New.MilligramsPerLiter:n0}mg/l, Old: {oldValue}"); + }; + + return Task.CompletedTask; + } + + public override async Task Run() + { + Resolver.Log.Info("Run..."); + + await ReadSensor(); + + sensor.StartUpdating(TimeSpan.FromSeconds(2)); + } + + protected async Task ReadSensor() + { + var concentration = await sensor.Read(); + Resolver.Log.Info($"Initial concentration: {concentration.MilligramsPerLiter:N0}mg/l"); + } + + // + } +} \ No newline at end of file diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.DFRobotGravityDOMeter/Samples/DFRobotGravityDOMeter_Sample/meadow.config.yaml b/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.DFRobotGravityDOMeter/Samples/DFRobotGravityDOMeter_Sample/meadow.config.yaml new file mode 100644 index 0000000000..32363cb69c --- /dev/null +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.DFRobotGravityDOMeter/Samples/DFRobotGravityDOMeter_Sample/meadow.config.yaml @@ -0,0 +1,2 @@ +MonoControl: + Options: --jit \ No newline at end of file diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.Ens160/Driver/Ens160.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.Ens160/Driver/Ens160.cs index b840a0d918..ca0ea00665 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.Ens160/Driver/Ens160.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.Ens160/Driver/Ens160.cs @@ -15,9 +15,9 @@ public partial class Ens160 : ByteCommsSensorBase<(Concentration? CO2Concentration, Concentration? EthanolConcentration, Concentration? TVOCConcentration)>, - IConcentrationSensor, II2cPeripheral + ICO2ConcentrationSensor, II2cPeripheral { - private event EventHandler> _concentrationHandlers; + private event EventHandler> _concentrationHandlers = default!; event EventHandler> ISamplingSensor.Updated { 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 a09a6aa956..58b0452780 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 @@ -15,13 +15,13 @@ Meadow.Foundation.Sensors.Environmental.Ens160 https://github.com/WildernessLabs/Meadow.Foundation Meadow,Meadow.Foundation,Environmental,ENS160,gas,c02,ethanol,AQI,air,quality - 0.1.0 + 1.7.0 true ENS160 I2C C02, Ethanol and AQI sensor - + - + 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 c287a8d020..7ada483201 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,8 +9,8 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.MiniPID2/Driver/MiniPID2.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.MiniPID2/Driver/MiniPID2.cs index 417fae7211..c258a1cded 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.MiniPID2/Driver/MiniPID2.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.MiniPID2/Driver/MiniPID2.cs @@ -9,22 +9,12 @@ namespace Meadow.Foundation.Sensors.Environmental /// /// Represents an IonScience MiniPID2 analog photoionisation (PID) Volatile Organic Compounds (VOC) sensor /// - public partial class MiniPID2 : SamplingSensorBase, IConcentrationSensor, IDisposable + public partial class MiniPID2 : SamplingSensorBase, IVOCConcentrationSensor, IDisposable { - /// - /// Raised when the VOC concentration changes - /// - public event EventHandler> ConcentrationUpdated = default!; - - /// - /// Raised when the VOC concentration changes - /// - public event EventHandler> VOCConcentrationUpdated = default!; - /// /// The current VOC concentration value /// - public Concentration? Concentration { get; protected set; } + public Concentration? VOCConcentration { get; protected set; } /// /// The MiniPID2 device type @@ -128,9 +118,9 @@ static SensorCalibration GetCalibration(int airOffsetLow, int airOffsetHigh, dou ChangeResult changeResult = new() { New = VoltageToConcentration(result.New), - Old = Concentration + Old = VOCConcentration }; - Concentration = changeResult.New; + VOCConcentration = changeResult.New; RaiseEventsAndNotify(changeResult); } ) @@ -146,7 +136,7 @@ protected override async Task ReadSensor() { var voltage = await AnalogInputPort.Read(); var newConcentration = VoltageToConcentration(voltage); - Concentration = newConcentration; + VOCConcentration = newConcentration; return newConcentration; } @@ -176,16 +166,6 @@ public override void StopUpdating() } } - /// - /// Method to notify subscribers to ConcentrationUpdated event handler - /// - /// - protected override void RaiseEventsAndNotify(IChangeResult changeResult) - { - ConcentrationUpdated?.Invoke(this, changeResult); - base.RaiseEventsAndNotify(changeResult); - } - /// /// Converts voltage to Concentration /// 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 b544e1021b..a25e84740a 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 @@ -15,13 +15,13 @@ Meadow.Foundation.Sensors.Environmental.MiniPID2 https://github.com/WildernessLabs/Meadow.Foundation Meadow,Meadow.Foundation,Environmental,MiniPID2,VOC,photoionisation,PID,gas,AQI,air,quality - 0.1.0 + 1.7.0 true MiniPID2 analog photoionisation (PID) VOC sensor - + - + 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 2cbe0e369f..cbce3a6295 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,8 +9,8 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.NextPm/Driver/NextPm.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.NextPm/Driver/NextPm.cs index 14aa9985e6..4bb3b9568e 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.NextPm/Driver/NextPm.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.NextPm/Driver/NextPm.cs @@ -183,7 +183,7 @@ protected override void RaiseEventsAndNotify(IChangeResult<( } if (changeResult.New.humidity is { } humidity) { - HumidityUpdated?.Invoke(this.serialPort, new ChangeResult(humidity, changeResult.Old?.humidity)); + HumidityUpdated?.Invoke(serialPort, new ChangeResult(humidity, changeResult.Old?.humidity)); } base.RaiseEventsAndNotify(changeResult); } 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 f913c80ee0..ee6a667768 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 @@ -14,16 +14,16 @@ Meadow.Foundation.Sensors.Environmental.NextPm https://github.com/WildernessLabs/Meadow.Foundation Meadow,Meadow.Foundation,Environmental,NextPM,tera,gas,particle,particulate,matter,AQI,air,quality - 0.1.0 + 1.7.0 enable true TERA Sensor NextPM serial particulate matter sensor - + - + 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 dc973a42b6..917776e8e6 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,8 +6,8 @@ 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 f710105027..6cae91714b 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 @@ -15,13 +15,13 @@ Meadow.Foundation.Sensors.Environmental.Pmsa300i https://github.com/WildernessLabs/Meadow.Foundation Meadow,Meadow.Foundation,Environmental,Pmsa300i,gas,particle,particulate,matter,AQI,air,quality - 0.1.0 + 1.7.0 true PMSA300I I2C particulate matter AQI sensor - + - + 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 c1d0371fb1..541cb16675 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,8 +6,8 @@ App - - + + 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 3fe33fa99b..64d10ee814 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.Scd4x/Driver/Scd4xBase.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Environmental.Scd4x/Driver/Scd4xBase.cs @@ -16,11 +16,11 @@ public abstract partial class Scd4xBase : ByteCommsSensorBase<(Concentration? Concentration, Units.Temperature? Temperature, RelativeHumidity? Humidity)>, - ITemperatureSensor, IHumiditySensor, IConcentrationSensor, II2cPeripheral + ITemperatureSensor, IHumiditySensor, ICO2ConcentrationSensor, II2cPeripheral { - private event EventHandler> _temperatureHandlers; - private event EventHandler> _humidityHandlers; - private event EventHandler> _concentrationHandlers; + private event EventHandler> _temperatureHandlers = default!; + private event EventHandler> _humidityHandlers = default!; + private event EventHandler> _concentrationHandlers = default!; event EventHandler> ISamplingSensor.Updated { @@ -43,7 +43,7 @@ event EventHandler> ISamplingSensor. /// /// The current C02 concentration value /// - public Concentration? Concentration => Conditions.Concentration; + public Concentration? CO2Concentration => Conditions.Concentration; /// /// The current temperature 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 10f8bb1aaf..0cac14857f 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 @@ -15,13 +15,13 @@ Meadow.Foundation.Sensors.Environmental.Scd4x https://github.com/WildernessLabs/Meadow.Foundation Meadow,Meadow.Foundation,Environmental,SCD40,SCD41,gas,c02,temperature,relative,humidity - 0.1.0 + 1.7.0 true SCD4x I2C C02, temperature, and relative humidity sensor (SCD40, SCD41) - + - + 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 0234ba68b4..c5b69dc271 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,8 +9,8 @@ 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 0234ba68b4..c5b69dc271 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,8 +9,8 @@ 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 901c6f5342..e6973f2fb7 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 @@ -15,14 +15,14 @@ Meadow.Foundation.Sensors.Environmental.Y4000 https://github.com/WildernessLabs/Meadow.Foundation Meadow,Meadow.Foundation,Environmental,Y4000,water,quality - 0.1.0 + 1.7.0 true Y4000 Sonde RS485 Modbus water quality sensor - + - - + + 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 6e6356f75f..b59e7fbbdc 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,8 +9,8 @@ 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 f2b0279f1d..4836dedfce 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 @@ -15,13 +15,13 @@ Meadow.Foundation.Sensors.Gnss https://github.com/WildernessLabs/Meadow.Foundation Meadow.Foundation,BG95-M3,BG95,GPS,GNSS,Cell,Cellular - 0.1.0 + 1.7.0 true BG95-M3 Cellular / GNSS controller - + - + 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 bd7ba701ba..f74d2dc722 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 fb5020d6ae..e1440b7615 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 @@ -11,7 +11,7 @@ Meadow.Foundation.Sensors.Gnss.Mt3339 https://github.com/WildernessLabs/Meadow.Foundation Meadow.Foundation, Mt3339, GPS, Adafruit Ultimate GPS, GNSS - 0.1.50 + 1.7.0 true MediaTek MT3339 serial GNSS / GPS controller enable @@ -22,8 +22,8 @@ 10.0 - - + + 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 c5d366d6fd..f0800db241 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,8 +9,8 @@ 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 40b5f6bf3c..729a82e3b6 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 @@ -15,13 +15,13 @@ Meadow.Foundation.Sensors.Gnss.NeoM8 https://github.com/WildernessLabs/Meadow.Foundation Meadow.Foundation,NEOM8,NEO,NEO-M8,GPS,GNSS - 0.1.0 + 1.7.0 true NEO M8 serial GNSS / GPS controller - + - + 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 c85def2c6b..2dd0996d4c 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,8 +9,8 @@ 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 3aaee0edd4..4ddecda34e 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 @@ -15,13 +15,13 @@ Meadow.Foundation.Sensors.Hid.ANONavigationEncoder https://github.com/WildernessLabs/Meadow.Foundation Meadow.Foundation,ANONavigationEncoder,direction,directional,navigation,rotary,encoder - 0.1.9 + 1.7.0 true GPIO ANO Directional Navigation and Scroll Wheel Rotary Encoder - + - + 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 6de906e4a2..3df08e2b1d 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,8 +6,8 @@ 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 c7627a35ba..8ef3f59bec 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 @@ -15,13 +15,13 @@ Meadow.Foundation.Sensors.Hid.As5013 https://github.com/WildernessLabs/Meadow.Foundation Meadow.Foundation,As5013,analog,joystick,magnetic,hall - 0.1.5 + 1.7.0 true I2C Hall sensor IC for smart navigation - + - + 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 dcf8b4d578..0dbc5dff77 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,8 +6,8 @@ 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 4792914034..2a755da38a 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 @@ -15,13 +15,13 @@ Meadow.Foundation.Sensors.Hid.Bbq10Keyboard https://github.com/WildernessLabs/Meadow.Foundation Meadow.Foundation, Bbq10Keyboard, BB, Q10, keyboard, keypad - 0.1.9 + 1.7.0 true BB Q10 I2C Keyboard - + - + 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 8b9937db0f..e58a38cc91 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,8 +6,8 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Hid.Keyboard/Driver/Keyboard.Interop.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Hid.Keyboard/Driver/Keyboard.Interop.cs index 2d07b11d60..83e7c5bec6 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Hid.Keyboard/Driver/Keyboard.Interop.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Hid.Keyboard/Driver/Keyboard.Interop.cs @@ -6,7 +6,139 @@ namespace Meadow.Foundation.Sensors.Hid; public partial class Keyboard { - internal class Interop + internal class InteropMac + { + public enum CGEventSourceStateID : int + { + hidSystemState = 1 + } + + // CGEventFlags CGEventSourceFlagsState(CGEventSourceStateID stateID); + [DllImport("/System/Library/Frameworks/ApplicationServices.framework/ApplicationServices")] + public static extern long CGEventSourceFlagsState(CGEventSourceStateID stateID); + + // bool CGEventSourceKeyState(CGEventSourceStateID stateID, CGKeyCode key); + [DllImport("/System/Library/Frameworks/ApplicationServices.framework/ApplicationServices")] + public static extern int CGEventSourceKeyState(CGEventSourceStateID stateID, MacKeyCodes keyCode); + + public enum MacKeyCodes : ushort + { + kVK_ANSI_A = 0x00, + kVK_ANSI_S = 0x01, + kVK_ANSI_D = 0x02, + kVK_ANSI_F = 0x03, + kVK_ANSI_H = 0x04, + kVK_ANSI_G = 0x05, + kVK_ANSI_Z = 0x06, + kVK_ANSI_X = 0x07, + kVK_ANSI_C = 0x08, + kVK_ANSI_V = 0x09, + kVK_ANSI_B = 0x0B, + kVK_ANSI_Q = 0x0C, + kVK_ANSI_W = 0x0D, + kVK_ANSI_E = 0x0E, + kVK_ANSI_R = 0x0F, + kVK_ANSI_Y = 0x10, + kVK_ANSI_T = 0x11, + kVK_ANSI_1 = 0x12, + kVK_ANSI_2 = 0x13, + kVK_ANSI_3 = 0x14, + kVK_ANSI_4 = 0x15, + kVK_ANSI_6 = 0x16, + kVK_ANSI_5 = 0x17, + kVK_ANSI_Equal = 0x18, + kVK_ANSI_9 = 0x19, + kVK_ANSI_7 = 0x1A, + kVK_ANSI_Minus = 0x1B, + kVK_ANSI_8 = 0x1C, + kVK_ANSI_0 = 0x1D, + kVK_ANSI_RightBracket = 0x1E, + kVK_ANSI_O = 0x1F, + kVK_ANSI_U = 0x20, + kVK_ANSI_LeftBracket = 0x21, + kVK_ANSI_I = 0x22, + kVK_ANSI_P = 0x23, + kVK_ANSI_L = 0x25, + kVK_ANSI_J = 0x26, + kVK_ANSI_Quote = 0x27, + kVK_ANSI_K = 0x28, + kVK_ANSI_Semicolon = 0x29, + kVK_ANSI_Backslash = 0x2A, + kVK_ANSI_Comma = 0x2B, + kVK_ANSI_Slash = 0x2C, + kVK_ANSI_N = 0x2D, + kVK_ANSI_M = 0x2E, + kVK_ANSI_Period = 0x2F, + kVK_ANSI_Grave = 0x32, + kVK_ANSI_KeypadDecimal = 0x41, + kVK_ANSI_KeypadMultiply = 0x43, + kVK_ANSI_KeypadPlus = 0x45, + kVK_ANSI_KeypadClear = 0x47, + kVK_ANSI_KeypadDivide = 0x4B, + kVK_ANSI_KeypadEnter = 0x4C, + kVK_ANSI_KeypadMinus = 0x4E, + kVK_ANSI_KeypadEquals = 0x51, + kVK_ANSI_Keypad0 = 0x52, + kVK_ANSI_Keypad1 = 0x53, + kVK_ANSI_Keypad2 = 0x54, + kVK_ANSI_Keypad3 = 0x55, + kVK_ANSI_Keypad4 = 0x56, + kVK_ANSI_Keypad5 = 0x57, + kVK_ANSI_Keypad6 = 0x58, + kVK_ANSI_Keypad7 = 0x59, + kVK_ANSI_Keypad8 = 0x5B, + kVK_ANSI_Keypad9 = 0x5C, + kVK_Return = 0x24, + kVK_Tab = 0x30, + kVK_Space = 0x31, + kVK_Delete = 0x33, + kVK_Escape = 0x35, + kVK_Command = 0x37, + kVK_Shift = 0x38, + kVK_CapsLock = 0x39, + kVK_Option = 0x3A, + kVK_Control = 0x3B, + kVK_RightShift = 0x3C, + kVK_RightOption = 0x3D, + kVK_RightControl = 0x3E, + kVK_Function = 0x3F, + kVK_F17 = 0x40, + kVK_VolumeUp = 0x48, + kVK_VolumeDown = 0x49, + kVK_Mute = 0x4A, + kVK_F18 = 0x4F, + kVK_F19 = 0x50, + kVK_F20 = 0x5A, + kVK_F5 = 0x60, + kVK_F6 = 0x61, + kVK_F7 = 0x62, + kVK_F3 = 0x63, + kVK_F8 = 0x64, + kVK_F9 = 0x65, + kVK_F11 = 0x67, + kVK_F13 = 0x69, + kVK_F16 = 0x6A, + kVK_F14 = 0x6B, + kVK_F10 = 0x6D, + kVK_F12 = 0x6F, + kVK_F15 = 0x71, + kVK_Help = 0x72, + kVK_Home = 0x73, + kVK_PageUp = 0x74, + kVK_ForwardDelete = 0x75, + kVK_F4 = 0x76, + kVK_End = 0x77, + kVK_F2 = 0x78, + kVK_PageDown = 0x79, + kVK_F1 = 0x7A, + kVK_LeftArrow = 0x7B, + kVK_RightArrow = 0x7C, + kVK_DownArrow = 0x7D, + kVK_UpArrow = 0x7E + } + } + + internal class InteropWindows { [Flags] internal enum DosDefineFlags diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Hid.Keyboard/Driver/Keyboard.KeyboardIndicator.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Hid.Keyboard/Driver/Keyboard.KeyboardIndicator.cs index 24df733779..f9ce745098 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Hid.Keyboard/Driver/Keyboard.KeyboardIndicator.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Hid.Keyboard/Driver/Keyboard.KeyboardIndicator.cs @@ -1,6 +1,6 @@ using Meadow.Hardware; using System; -using static Meadow.Foundation.Sensors.Hid.Keyboard.Interop; +using static Meadow.Foundation.Sensors.Hid.Keyboard.InteropWindows; namespace Meadow.Foundation.Sensors.Hid; @@ -42,12 +42,12 @@ internal KeyboardIndicator(IPin pin, IDigitalChannelInfo info, bool? initialStat private void SetState(bool state) { - (_pin.Controller as Keyboard)?.SetIndicatorState((Indicators)(Convert.ToInt16(_pin.Key)), state); + (_pin.Controller as Keyboard)?.SetIndicatorStateWindows((Indicators)(Convert.ToInt16(_pin.Key)), state); } private bool GetState() { - return (_pin.Controller as Keyboard)?.GetIndicatorState((Indicators)(Convert.ToInt16(_pin.Key))) ?? false; + return (_pin.Controller as Keyboard)?.GetIndicatorStateWindows((Indicators)(Convert.ToInt16(_pin.Key))) ?? false; } } } diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Hid.Keyboard/Driver/Keyboard.Mac.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Hid.Keyboard/Driver/Keyboard.Mac.cs new file mode 100644 index 0000000000..15cb0fb37c --- /dev/null +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Hid.Keyboard/Driver/Keyboard.Mac.cs @@ -0,0 +1,32 @@ +using Meadow.Hardware; +using System; +using System.Threading; + +namespace Meadow.Foundation.Sensors.Hid; + +public partial class Keyboard : IDigitalInterruptController, IDigitalOutputController, IDisposable +{ + private void MacKeyScanner() + { + _keepScanning = true; + + // if you're wondering why this method, we cannot use a keyboard hook because we don't have a message pump + while (_keepScanning) + { + foreach (var key in _keys) + { + var keycode = (key.Value.Pin as KeyboardKeyPin)?.MacKeyCode; + if (keycode != null) + { + var state = InteropMac.CGEventSourceKeyState( + InteropMac.CGEventSourceStateID.hidSystemState, + keycode.Value) != 0; + + key.Value.SetState(state); + } + + } + Thread.Sleep(10); + } + } +} diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Hid.Keyboard/Driver/Keyboard.PinDefinitions.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Hid.Keyboard/Driver/Keyboard.PinDefinitions.cs index d4ce724d05..f89427883c 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Hid.Keyboard/Driver/Keyboard.PinDefinitions.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Hid.Keyboard/Driver/Keyboard.PinDefinitions.cs @@ -38,311 +38,311 @@ internal PinDefinitions(Keyboard controller) /// /// An input Pin for the Back key /// - public IPin Back => new KeyboardKeyPin(Controller, "Back", '\u0008'); + public IPin Back => new KeyboardKeyPin(Controller, "Back", '\u0008', InteropMac.MacKeyCodes.kVK_Delete); /// /// An input Pin for the Tab key /// - public IPin Tab => new KeyboardKeyPin(Controller, "Tab", '\u0009'); + public IPin Tab => new KeyboardKeyPin(Controller, "Tab", '\u0009', InteropMac.MacKeyCodes.kVK_Tab); /// /// An input Pin for the Enter key /// - public IPin Enter => new KeyboardKeyPin(Controller, "Enter", '\u000d'); + public IPin Enter => new KeyboardKeyPin(Controller, "Enter", '\u000d', InteropMac.MacKeyCodes.kVK_Return); /// /// An input Pin for the Shift key /// - public IPin Shift => new KeyboardKeyPin(Controller, "Shift", '\u0010'); + public IPin Shift => new KeyboardKeyPin(Controller, "Shift", '\u0010', InteropMac.MacKeyCodes.kVK_Shift); /// /// An input Pin for the Control key /// - public IPin Control => new KeyboardKeyPin(Controller, "Control", '\u0011'); + public IPin Control => new KeyboardKeyPin(Controller, "Control", '\u0011', InteropMac.MacKeyCodes.kVK_Control); /// /// An input Pin for the Escape key /// - public IPin Escape => new KeyboardKeyPin(Controller, "Escape", '\u001b'); + public IPin Escape => new KeyboardKeyPin(Controller, "Escape", '\u001b', InteropMac.MacKeyCodes.kVK_Escape); /// /// An input Pin for the Space bar /// - public IPin Space => new KeyboardKeyPin(Controller, "Space", '\u0020'); + public IPin Space => new KeyboardKeyPin(Controller, "Space", '\u0020', InteropMac.MacKeyCodes.kVK_Space); /// /// An input Pin for the Page Up key /// - public IPin PageUp => new KeyboardKeyPin(Controller, "PageUp", '\u0021'); + public IPin PageUp => new KeyboardKeyPin(Controller, "PageUp", '\u0021', InteropMac.MacKeyCodes.kVK_PageUp); /// /// An input Pin for the Page Down key /// - public IPin PageDown => new KeyboardKeyPin(Controller, "PageDown", '\u0022'); + public IPin PageDown => new KeyboardKeyPin(Controller, "PageDown", '\u0022', InteropMac.MacKeyCodes.kVK_PageDown); /// /// An input Pin for the End key /// - public IPin End => new KeyboardKeyPin(Controller, "End", '\u0023'); + public IPin End => new KeyboardKeyPin(Controller, "End", '\u0023', InteropMac.MacKeyCodes.kVK_End); /// /// An input Pin for the Home key /// - public IPin Home => new KeyboardKeyPin(Controller, "Home", '\u0024'); + public IPin Home => new KeyboardKeyPin(Controller, "Home", '\u0024', InteropMac.MacKeyCodes.kVK_Home); /// /// An input Pin for the Left Arrow key /// - public IPin Left => new KeyboardKeyPin(Controller, "Left", '\u0025'); + public IPin Left => new KeyboardKeyPin(Controller, "Left", '\u0025', InteropMac.MacKeyCodes.kVK_LeftArrow); /// /// An input Pin for the Up Arrow key /// - public IPin Up => new KeyboardKeyPin(Controller, "Up", '\u0026'); + public IPin Up => new KeyboardKeyPin(Controller, "Up", '\u0026', InteropMac.MacKeyCodes.kVK_UpArrow); /// /// An input Pin for the Right Arrow key /// - public IPin Right => new KeyboardKeyPin(Controller, "Right", '\u0027'); + public IPin Right => new KeyboardKeyPin(Controller, "Right", '\u0027', InteropMac.MacKeyCodes.kVK_RightArrow); /// /// An input Pin for the Down Arrow key /// - public IPin Down => new KeyboardKeyPin(Controller, "Down", '\u0028'); + public IPin Down => new KeyboardKeyPin(Controller, "Down", '\u0028', InteropMac.MacKeyCodes.kVK_DownArrow); /// /// An input Pin for the Insert key /// - public IPin Insert => new KeyboardKeyPin(Controller, "Insert", '\u002d'); + public IPin Insert => new KeyboardKeyPin(Controller, "Insert", '\u002d', null); /// /// An input Pin for the Delete key /// - public IPin Delete => new KeyboardKeyPin(Controller, "Delete", '\u002e'); + public IPin Delete => new KeyboardKeyPin(Controller, "Delete", '\u002e', InteropMac.MacKeyCodes.kVK_Delete); /// /// An input Pin for the Back-tick/Tilde key /// - public IPin Tilde => new KeyboardKeyPin(Controller, "Tilde", '\u00c0'); + public IPin Tilde => new KeyboardKeyPin(Controller, "Tilde", '\u00c0', null); /// /// An input Pin for the Semicolon key /// - public IPin Semicolon => new KeyboardKeyPin(Controller, "Semicolon", '\u00ba'); + public IPin Semicolon => new KeyboardKeyPin(Controller, "Semicolon", '\u00ba', InteropMac.MacKeyCodes.kVK_ANSI_Semicolon); /// /// An input Pin for the +/= key /// - public IPin Plus => new KeyboardKeyPin(Controller, "Plus", '\u00bb'); + public IPin Plus => new KeyboardKeyPin(Controller, "Plus", '\u00bb', InteropMac.MacKeyCodes.kVK_ANSI_Equal); /// /// An input Pin for the -/_ key /// - public IPin Minus => new KeyboardKeyPin(Controller, "Minus", '\u00bd'); + public IPin Minus => new KeyboardKeyPin(Controller, "Minus", '\u00bd', InteropMac.MacKeyCodes.kVK_ANSI_Minus); /// /// An input Pin for the Comma key /// - public IPin Comma => new KeyboardKeyPin(Controller, "Comma", '\u00bc'); + public IPin Comma => new KeyboardKeyPin(Controller, "Comma", '\u00bc', InteropMac.MacKeyCodes.kVK_ANSI_Comma); /// /// An input Pin for the Period key /// - public IPin Period => new KeyboardKeyPin(Controller, "Period", '\u00be'); + public IPin Period => new KeyboardKeyPin(Controller, "Period", '\u00be', InteropMac.MacKeyCodes.kVK_ANSI_Period); /// /// An input Pin for the Forward Slash key /// - public IPin ForwardSlash => new KeyboardKeyPin(Controller, "ForwardSlash", '\u00bf'); + public IPin ForwardSlash => new KeyboardKeyPin(Controller, "ForwardSlash", '\u00bf', InteropMac.MacKeyCodes.kVK_ANSI_Slash); /// /// An input Pin for the Back Slash key /// - public IPin BackSlash => new KeyboardKeyPin(Controller, "BackSlash", '\u00dc'); + public IPin BackSlash => new KeyboardKeyPin(Controller, "BackSlash", '\u00dc', InteropMac.MacKeyCodes.kVK_ANSI_Backslash); /// /// An input Pin for the Open Bracket key /// - public IPin OpenBracket => new KeyboardKeyPin(Controller, "OpenBracket", '\u00db'); + public IPin OpenBracket => new KeyboardKeyPin(Controller, "OpenBracket", '\u00db', InteropMac.MacKeyCodes.kVK_ANSI_LeftBracket); /// /// An input Pin for the Close Bracket key /// - public IPin CloseBracket => new KeyboardKeyPin(Controller, "CloseBracket", '\u00dd'); + public IPin CloseBracket => new KeyboardKeyPin(Controller, "CloseBracket", '\u00dd', InteropMac.MacKeyCodes.kVK_ANSI_RightBracket); /// /// An input Pin for the 0 key /// - public IPin Num0 => new KeyboardKeyPin(Controller, "0", '0'); + public IPin Num0 => new KeyboardKeyPin(Controller, "0", '0', InteropMac.MacKeyCodes.kVK_ANSI_0); /// /// An input Pin for the 1 key /// - public IPin Num1 => new KeyboardKeyPin(Controller, "1", '1'); + public IPin Num1 => new KeyboardKeyPin(Controller, "1", '1', InteropMac.MacKeyCodes.kVK_ANSI_1); /// /// An input Pin for the 2 key /// - public IPin Num2 => new KeyboardKeyPin(Controller, "2", '2'); + public IPin Num2 => new KeyboardKeyPin(Controller, "2", '2', InteropMac.MacKeyCodes.kVK_ANSI_2); /// /// An input Pin for the 3 key /// - public IPin Num3 => new KeyboardKeyPin(Controller, "3", '3'); + public IPin Num3 => new KeyboardKeyPin(Controller, "3", '3', InteropMac.MacKeyCodes.kVK_ANSI_3); /// /// An input Pin for the 4 key /// - public IPin Num4 => new KeyboardKeyPin(Controller, "4", '4'); + public IPin Num4 => new KeyboardKeyPin(Controller, "4", '4', InteropMac.MacKeyCodes.kVK_ANSI_4); /// /// An input Pin for the 5 key /// - public IPin Num5 => new KeyboardKeyPin(Controller, "5", '5'); + public IPin Num5 => new KeyboardKeyPin(Controller, "5", '5', InteropMac.MacKeyCodes.kVK_ANSI_5); /// /// An input Pin for the 6 key /// - public IPin Num6 => new KeyboardKeyPin(Controller, "6", '6'); + public IPin Num6 => new KeyboardKeyPin(Controller, "6", '6', InteropMac.MacKeyCodes.kVK_ANSI_6); /// /// An input Pin for the 7 key /// - public IPin Num7 => new KeyboardKeyPin(Controller, "7", '7'); + public IPin Num7 => new KeyboardKeyPin(Controller, "7", '7', InteropMac.MacKeyCodes.kVK_ANSI_7); /// /// An input Pin for the 8 key /// - public IPin Num8 => new KeyboardKeyPin(Controller, "8", '8'); + public IPin Num8 => new KeyboardKeyPin(Controller, "8", '8', InteropMac.MacKeyCodes.kVK_ANSI_8); /// /// An input Pin for the 9 key /// - public IPin Num9 => new KeyboardKeyPin(Controller, "9", '9'); + public IPin Num9 => new KeyboardKeyPin(Controller, "9", '9', InteropMac.MacKeyCodes.kVK_ANSI_9); /// /// An input Pin for the A key /// - public IPin A => new KeyboardKeyPin(Controller, "A", 'A'); + public IPin A => new KeyboardKeyPin(Controller, "A", 'A', InteropMac.MacKeyCodes.kVK_ANSI_A); /// /// An input Pin for the B key /// - public IPin B => new KeyboardKeyPin(Controller, "B", 'B'); + public IPin B => new KeyboardKeyPin(Controller, "B", 'B', InteropMac.MacKeyCodes.kVK_ANSI_B); /// /// An input Pin for the C key /// - public IPin C => new KeyboardKeyPin(Controller, "C", 'C'); + public IPin C => new KeyboardKeyPin(Controller, "C", 'C', InteropMac.MacKeyCodes.kVK_ANSI_C); /// /// An input Pin for the D key /// - public IPin D => new KeyboardKeyPin(Controller, "D", 'D'); + public IPin D => new KeyboardKeyPin(Controller, "D", 'D', InteropMac.MacKeyCodes.kVK_ANSI_D); /// /// An input Pin for the E key /// - public IPin E => new KeyboardKeyPin(Controller, "E", 'E'); + public IPin E => new KeyboardKeyPin(Controller, "E", 'E', InteropMac.MacKeyCodes.kVK_ANSI_E); /// /// An input Pin for the F key /// - public IPin F => new KeyboardKeyPin(Controller, "F", 'F'); + public IPin F => new KeyboardKeyPin(Controller, "F", 'F', InteropMac.MacKeyCodes.kVK_ANSI_F); /// /// An input Pin for the G key /// - public IPin G => new KeyboardKeyPin(Controller, "G", 'G'); + public IPin G => new KeyboardKeyPin(Controller, "G", 'G', InteropMac.MacKeyCodes.kVK_ANSI_G); /// /// An input Pin for the H key /// - public IPin H => new KeyboardKeyPin(Controller, "H", 'H'); + public IPin H => new KeyboardKeyPin(Controller, "H", 'H', InteropMac.MacKeyCodes.kVK_ANSI_H); /// /// An input Pin for the I key /// - public IPin I => new KeyboardKeyPin(Controller, "I", 'I'); + public IPin I => new KeyboardKeyPin(Controller, "I", 'I', InteropMac.MacKeyCodes.kVK_ANSI_I); /// /// An input Pin for the J key /// - public IPin J => new KeyboardKeyPin(Controller, "J", 'J'); + public IPin J => new KeyboardKeyPin(Controller, "J", 'J', InteropMac.MacKeyCodes.kVK_ANSI_J); /// /// An input Pin for the K key /// - public IPin K => new KeyboardKeyPin(Controller, "K", 'K'); + public IPin K => new KeyboardKeyPin(Controller, "K", 'K', InteropMac.MacKeyCodes.kVK_ANSI_K); /// /// An input Pin for the L key /// - public IPin L => new KeyboardKeyPin(Controller, "L", 'L'); + public IPin L => new KeyboardKeyPin(Controller, "L", 'L', InteropMac.MacKeyCodes.kVK_ANSI_L); /// /// An input Pin for the M key /// - public IPin M => new KeyboardKeyPin(Controller, "M", 'M'); + public IPin M => new KeyboardKeyPin(Controller, "M", 'M', InteropMac.MacKeyCodes.kVK_ANSI_M); /// /// An input Pin for the N key /// - public IPin N => new KeyboardKeyPin(Controller, "N", 'N'); + public IPin N => new KeyboardKeyPin(Controller, "N", 'N', InteropMac.MacKeyCodes.kVK_ANSI_N); /// /// An input Pin for the O key /// - public IPin O => new KeyboardKeyPin(Controller, "O", 'O'); + public IPin O => new KeyboardKeyPin(Controller, "O", 'O', InteropMac.MacKeyCodes.kVK_ANSI_O); /// /// An input Pin for the P key /// - public IPin P => new KeyboardKeyPin(Controller, "P", 'P'); + public IPin P => new KeyboardKeyPin(Controller, "P", 'P', InteropMac.MacKeyCodes.kVK_ANSI_P); /// /// An input Pin for the Q key /// - public IPin Q => new KeyboardKeyPin(Controller, "Q", 'Q'); + public IPin Q => new KeyboardKeyPin(Controller, "Q", 'Q', InteropMac.MacKeyCodes.kVK_ANSI_Q); /// /// An input Pin for the R key /// - public IPin R => new KeyboardKeyPin(Controller, "R", 'R'); + public IPin R => new KeyboardKeyPin(Controller, "R", 'R', InteropMac.MacKeyCodes.kVK_ANSI_R); /// /// An input Pin for the S key /// - public IPin S => new KeyboardKeyPin(Controller, "S", 'S'); + public IPin S => new KeyboardKeyPin(Controller, "S", 'S', InteropMac.MacKeyCodes.kVK_ANSI_S); /// /// An input Pin for the T key /// - public IPin T => new KeyboardKeyPin(Controller, "T", 'T'); + public IPin T => new KeyboardKeyPin(Controller, "T", 'T', InteropMac.MacKeyCodes.kVK_ANSI_T); /// /// An input Pin for the U key /// - public IPin U => new KeyboardKeyPin(Controller, "U", 'U'); + public IPin U => new KeyboardKeyPin(Controller, "U", 'U', InteropMac.MacKeyCodes.kVK_ANSI_U); /// /// An input Pin for the V key /// - public IPin V => new KeyboardKeyPin(Controller, "V", 'V'); + public IPin V => new KeyboardKeyPin(Controller, "V", 'V', InteropMac.MacKeyCodes.kVK_ANSI_V); /// /// An input Pin for the W key /// - public IPin W => new KeyboardKeyPin(Controller, "W", 'W'); + public IPin W => new KeyboardKeyPin(Controller, "W", 'W', InteropMac.MacKeyCodes.kVK_ANSI_W); /// /// An input Pin for the X key /// - public IPin X => new KeyboardKeyPin(Controller, "X", 'X'); + public IPin X => new KeyboardKeyPin(Controller, "X", 'X', InteropMac.MacKeyCodes.kVK_ANSI_X); /// /// An input Pin for the Y key /// - public IPin Y => new KeyboardKeyPin(Controller, "Y", 'Y'); + public IPin Y => new KeyboardKeyPin(Controller, "Y", 'Y', InteropMac.MacKeyCodes.kVK_ANSI_Y); /// /// An input Pin for the Z key /// - public IPin Z => new KeyboardKeyPin(Controller, "Z", 'Z'); + public IPin Z => new KeyboardKeyPin(Controller, "Z", 'Z', InteropMac.MacKeyCodes.kVK_ANSI_Z); /// /// An input Pin for Number Pad 0 /// - public IPin NumPad0 => new KeyboardKeyPin(Controller, "NumPad0", '\u0060'); + public IPin NumPad0 => new KeyboardKeyPin(Controller, "NumPad0", '\u0060', InteropMac.MacKeyCodes.kVK_ANSI_Keypad0); /// /// An input Pin for Number Pad 1 /// - public IPin NumPad1 => new KeyboardKeyPin(Controller, "NumPad1", '\u0061'); + public IPin NumPad1 => new KeyboardKeyPin(Controller, "NumPad1", '\u0061', InteropMac.MacKeyCodes.kVK_ANSI_Keypad1); /// /// An input Pin for Number Pad 2 /// - public IPin NumPad2 => new KeyboardKeyPin(Controller, "NumPad2", '\u0062'); + public IPin NumPad2 => new KeyboardKeyPin(Controller, "NumPad2", '\u0062', InteropMac.MacKeyCodes.kVK_ANSI_Keypad2); /// /// An input Pin for Number Pad 3 /// - public IPin NumPad3 => new KeyboardKeyPin(Controller, "NumPad3", '\u0063'); + public IPin NumPad3 => new KeyboardKeyPin(Controller, "NumPad3", '\u0063', InteropMac.MacKeyCodes.kVK_ANSI_Keypad3); /// /// An input Pin for Number Pad 4 /// - public IPin NumPad4 => new KeyboardKeyPin(Controller, "NumPad4", '\u0064'); + public IPin NumPad4 => new KeyboardKeyPin(Controller, "NumPad4", '\u0064', InteropMac.MacKeyCodes.kVK_ANSI_Keypad4); /// /// An input Pin for Number Pad 5 /// - public IPin NumPad5 => new KeyboardKeyPin(Controller, "NumPad5", '\u0065'); + public IPin NumPad5 => new KeyboardKeyPin(Controller, "NumPad5", '\u0065', InteropMac.MacKeyCodes.kVK_ANSI_Keypad5); /// /// An input Pin for Number Pad 6 /// - public IPin NumPad6 => new KeyboardKeyPin(Controller, "NumPad6", '\u0066'); + public IPin NumPad6 => new KeyboardKeyPin(Controller, "NumPad6", '\u0066', InteropMac.MacKeyCodes.kVK_ANSI_Keypad6); /// /// An input Pin for Number Pad 7 /// - public IPin NumPad7 => new KeyboardKeyPin(Controller, "NumPad7", '\u0067'); + public IPin NumPad7 => new KeyboardKeyPin(Controller, "NumPad7", '\u0067', InteropMac.MacKeyCodes.kVK_ANSI_Keypad7); /// /// An input Pin for Number Pad 8 /// - public IPin NumPad8 => new KeyboardKeyPin(Controller, "NumPad8", '\u0068'); + public IPin NumPad8 => new KeyboardKeyPin(Controller, "NumPad8", '\u0068', InteropMac.MacKeyCodes.kVK_ANSI_Keypad8); /// /// An input Pin for Number Pad 9 /// - public IPin NumPad9 => new KeyboardKeyPin(Controller, "NumPad9", '\u0069'); + public IPin NumPad9 => new KeyboardKeyPin(Controller, "NumPad9", '\u0069', InteropMac.MacKeyCodes.kVK_ANSI_Keypad9); /// /// An output Pin for Caps Lock indicator /// - public IPin CapsLock => new KeyboardIndicatorPin(Controller, "CapsLock", Interop.Indicators.KEYBOARD_CAPS_LOCK_ON); + public IPin CapsLock => new KeyboardIndicatorPin(Controller, "CapsLock", InteropWindows.Indicators.KEYBOARD_CAPS_LOCK_ON); /// /// An output Pin for Number Lock indicator /// - public IPin NumLock => new KeyboardIndicatorPin(Controller, "NumLock", Interop.Indicators.KEYBOARD_NUM_LOCK_ON); + public IPin NumLock => new KeyboardIndicatorPin(Controller, "NumLock", InteropWindows.Indicators.KEYBOARD_NUM_LOCK_ON); /// /// An output Pin for Scroll Lock indicator /// - public IPin ScrollLock => new KeyboardIndicatorPin(Controller, "ScrollLock", Interop.Indicators.KEYBOARD_SCROLL_LOCK_ON); + public IPin ScrollLock => new KeyboardIndicatorPin(Controller, "ScrollLock", InteropWindows.Indicators.KEYBOARD_SCROLL_LOCK_ON); /// /// An output Pin for Kana Lock indicator /// - public IPin KanaLock => new KeyboardIndicatorPin(Controller, "KanaLock", Interop.Indicators.KEYBOARD_KANA_LOCK_ON); + public IPin KanaLock => new KeyboardIndicatorPin(Controller, "KanaLock", InteropWindows.Indicators.KEYBOARD_KANA_LOCK_ON); } } diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Hid.Keyboard/Driver/Keyboard.Windows.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Hid.Keyboard/Driver/Keyboard.Windows.cs new file mode 100644 index 0000000000..19ca45ecd0 --- /dev/null +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Hid.Keyboard/Driver/Keyboard.Windows.cs @@ -0,0 +1,160 @@ +using System; +using System.Runtime.InteropServices; +using System.Threading; +using static Meadow.Foundation.Sensors.Hid.Keyboard.InteropWindows; + +namespace Meadow.Foundation.Sensors.Hid; + +public partial class Keyboard +{ + private void WindowsKeyScanner() + { + _keepScanning = true; + + // if you're wondering why this method, we cannot use a keyboard hook because we don't have a message pump + while (_keepScanning) + { + foreach (var key in _keys) + { + var state = InteropWindows.GetAsyncKeyState(key.Key); + + if ((state & 0x8000) != 0) + { + // key is currently down + key.Value.SetState(true); + } + else if ((state & 0x0001) != 0) + { + // state was down since last call (is now up) + key.Value.SetState(true); + key.Value.SetState(false); + } + else + { + key.Value.SetState(false); + } + + } + Thread.Sleep(10); + } + } + + + private void OpenKeyboardDeviceWindows() + { + if (!InteropWindows.DefineDosDeviceW( + InteropWindows.DosDefineFlags.DDD_RAW_TARGET_PATH, + KeyboardDeviceName, + $"\\Device\\KeyboardClass{_keyboardNumber}")) + { + var e = Marshal.GetLastPInvokeError(); + throw new NativeException($"Unable to define native keyboard device (Error {e})"); + } + + var handle = InteropWindows.CreateFile( + @"\\.\Kbd", + System.IO.FileAccess.Write, + System.IO.FileShare.ReadWrite, + IntPtr.Zero, + System.IO.FileMode.Open, + 0, + IntPtr.Zero); + + if (handle == IntPtr.Zero || handle == new IntPtr(-1)) + { + var e = Marshal.GetLastPInvokeError(); + throw new NativeException($"Unable to open keyboard device (Error {e})"); + } + + _deviceHandle = handle; + } + + private void CloseKeyboardDeviceWindows() + { + if (_deviceHandle != null) + { + if (!InteropWindows.DefineDosDeviceW( + InteropWindows.DosDefineFlags.DDD_REMOVE_DEFINITION, + KeyboardDeviceName, + null)) + { + // TODO: log this? + var e = Marshal.GetLastPInvokeError(); + } + + InteropWindows.CloseHandle(_deviceHandle.Value); + _deviceHandle = null; + } + } + + private bool GetIndicatorStateWindows(Indicators indicator) + { + var input = new KEYBOARD_INDICATOR_PARAMETERS(); + var output = new KEYBOARD_INDICATOR_PARAMETERS(); + + if (_deviceHandle == null) return false; + + if (!InteropWindows.DeviceIoControl( + _deviceHandle.Value, + IOCTL_KEYBOARD_QUERY_INDICATORS, + ref input, + Marshal.SizeOf(input), + ref output, + Marshal.SizeOf(output), + out uint returned, + IntPtr.Zero)) + { + var e = Marshal.GetLastPInvokeError(); + throw new NativeException("Unable to query keyboard indicator", e); + } + + return (output.LedFlags & indicator) != 0; + } + + private void SetIndicatorStateWindows(Indicators indicator, bool state) + { + if (_deviceHandle == null) return; + + var input = new KEYBOARD_INDICATOR_PARAMETERS(); + var output = new KEYBOARD_INDICATOR_PARAMETERS(); + + // read current state + if (!InteropWindows.DeviceIoControl( + _deviceHandle.Value, + IOCTL_KEYBOARD_QUERY_INDICATORS, + ref input, + Marshal.SizeOf(input), + ref output, + Marshal.SizeOf(output), + out uint returned, + IntPtr.Zero)) + { + var e = Marshal.GetLastPInvokeError(); + throw new NativeException("Unable to query keyboard indicator", e); + } + + if (state) + { + output.LedFlags |= indicator; + } + else + { + output.LedFlags &= ~indicator; + } + + // toggle + if (!InteropWindows.DeviceIoControl( + _deviceHandle.Value, + IOCTL_KEYBOARD_SET_INDICATORS, + ref output, + Marshal.SizeOf(output), + IntPtr.Zero, + 0, + out returned, + IntPtr.Zero)) + { + var e = Marshal.GetLastPInvokeError(); + throw new NativeException("Unable to set keyboard indicator", e); + } + } +} diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Hid.Keyboard/Driver/Keyboard.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Hid.Keyboard/Driver/Keyboard.cs index 21fffc69e8..7864828127 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Hid.Keyboard/Driver/Keyboard.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Hid.Keyboard/Driver/Keyboard.cs @@ -2,9 +2,7 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Runtime.InteropServices; using System.Threading; -using static Meadow.Foundation.Sensors.Hid.Keyboard.Interop; namespace Meadow.Foundation.Sensors.Hid; @@ -36,40 +34,20 @@ private void Install() { if (_thread != null) return; - _thread = new Thread(KeyScanner); - _thread.Start(); - } - - private void KeyScanner() - { - _keepScanning = true; - - // if you're wondering why this method, we cannot use a keyboard hook because we don't have a message pump - while (_keepScanning) + if (OperatingSystem.IsMacOS()) { - foreach (var key in _keys) - { - var state = Interop.GetAsyncKeyState(key.Key); - - if ((state & 0x8000) != 0) - { - // key is currently down - key.Value.SetState(true); - } - else if ((state & 0x0001) != 0) - { - // state was down since last call (is now up) - key.Value.SetState(true); - key.Value.SetState(false); - } - else - { - key.Value.SetState(false); - } - - } - Thread.Sleep(10); + _thread = new Thread(MacKeyScanner); + } + else if (OperatingSystem.IsWindows()) + { + _thread = new Thread(WindowsKeyScanner); } + else + { + throw new PlatformNotSupportedException(); + } + + _thread.Start(); } /// @@ -135,7 +113,10 @@ protected virtual void Dispose(bool disposing) { if (disposing) { - CloseKeyboardDevice(); + if (OperatingSystem.IsWindows()) + { + CloseKeyboardDeviceWindows(); + } _keepScanning = false; } @@ -164,6 +145,11 @@ public void Dispose() /// public IDigitalOutputPort CreateDigitalOutputPort(IPin pin, bool initialState = false, OutputType initialOutputType = OutputType.PushPull) { + if (!OperatingSystem.IsWindows()) + { + throw new PlatformNotSupportedException(); + } + var kp = pin as KeyboardIndicatorPin; if (kp == null) @@ -173,130 +159,11 @@ public IDigitalOutputPort CreateDigitalOutputPort(IPin pin, bool initialState = if (_deviceHandle == null) { - OpenKeyboardDevice(); + OpenKeyboardDeviceWindows(); } var ci = kp.SupportedChannels?.First() as IDigitalChannelInfo ?? throw new ArgumentException("Pin is not a Digital channel"); return new KeyboardIndicator(pin, ci, initialState ? true : null); - throw new NotImplementedException(); - } - - private void OpenKeyboardDevice() - { - if (!Interop.DefineDosDeviceW( - Interop.DosDefineFlags.DDD_RAW_TARGET_PATH, - KeyboardDeviceName, - $"\\Device\\KeyboardClass{_keyboardNumber}")) - { - var e = Marshal.GetLastPInvokeError(); - throw new NativeException($"Unable to define native keyboard device (Error {e})"); - } - - var handle = Interop.CreateFile( - @"\\.\Kbd", - System.IO.FileAccess.Write, - System.IO.FileShare.ReadWrite, - IntPtr.Zero, - System.IO.FileMode.Open, - 0, - IntPtr.Zero); - - if (handle == IntPtr.Zero || handle == new IntPtr(-1)) - { - var e = Marshal.GetLastPInvokeError(); - throw new NativeException($"Unable to open keyboard device (Error {e})"); - } - - _deviceHandle = handle; - } - - private void CloseKeyboardDevice() - { - if (_deviceHandle != null) - { - if (!Interop.DefineDosDeviceW( - Interop.DosDefineFlags.DDD_REMOVE_DEFINITION, - KeyboardDeviceName, - null)) - { - // TODO: log this? - var e = Marshal.GetLastPInvokeError(); - } - - Interop.CloseHandle(_deviceHandle.Value); - _deviceHandle = null; - } - } - - private bool GetIndicatorState(Indicators indicator) - { - var input = new KEYBOARD_INDICATOR_PARAMETERS(); - var output = new KEYBOARD_INDICATOR_PARAMETERS(); - - if (_deviceHandle == null) return false; - - if (!Interop.DeviceIoControl( - _deviceHandle.Value, - IOCTL_KEYBOARD_QUERY_INDICATORS, - ref input, - Marshal.SizeOf(input), - ref output, - Marshal.SizeOf(output), - out uint returned, - IntPtr.Zero)) - { - var e = Marshal.GetLastPInvokeError(); - throw new NativeException("Unable to query keyboard indicator", e); - } - - return (output.LedFlags & indicator) != 0; - } - - private void SetIndicatorState(Indicators indicator, bool state) - { - if (_deviceHandle == null) return; - - var input = new KEYBOARD_INDICATOR_PARAMETERS(); - var output = new KEYBOARD_INDICATOR_PARAMETERS(); - - // read current state - if (!Interop.DeviceIoControl( - _deviceHandle.Value, - IOCTL_KEYBOARD_QUERY_INDICATORS, - ref input, - Marshal.SizeOf(input), - ref output, - Marshal.SizeOf(output), - out uint returned, - IntPtr.Zero)) - { - var e = Marshal.GetLastPInvokeError(); - throw new NativeException("Unable to query keyboard indicator", e); - } - - if (state) - { - output.LedFlags |= indicator; - } - else - { - output.LedFlags &= ~indicator; - } - - // toggle - if (!Interop.DeviceIoControl( - _deviceHandle.Value, - IOCTL_KEYBOARD_SET_INDICATORS, - ref output, - Marshal.SizeOf(output), - IntPtr.Zero, - 0, - out returned, - IntPtr.Zero)) - { - var e = Marshal.GetLastPInvokeError(); - throw new NativeException("Unable to set keyboard indicator", e); - } } } diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Hid.Keyboard/Driver/KeyboardIndicatorPin.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Hid.Keyboard/Driver/KeyboardIndicatorPin.cs index 07671b97a6..395b78afff 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Hid.Keyboard/Driver/KeyboardIndicatorPin.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Hid.Keyboard/Driver/KeyboardIndicatorPin.cs @@ -1,7 +1,7 @@ using Meadow.Hardware; using System; using System.Collections.Generic; -using static Meadow.Foundation.Sensors.Hid.Keyboard.Interop; +using static Meadow.Foundation.Sensors.Hid.Keyboard.InteropWindows; namespace Meadow.Foundation.Sensors.Hid; diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Hid.Keyboard/Driver/KeyboardKeyPin.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Hid.Keyboard/Driver/KeyboardKeyPin.cs index d9c501f08e..f666e8d99e 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Hid.Keyboard/Driver/KeyboardKeyPin.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Hid.Keyboard/Driver/KeyboardKeyPin.cs @@ -1,6 +1,7 @@ using Meadow.Hardware; using System; using System.Collections.Generic; +using static Meadow.Foundation.Sensors.Hid.Keyboard; namespace Meadow.Foundation.Sensors.Hid; @@ -14,7 +15,9 @@ public class KeyboardKeyPin : Pin /// public new char Key => Convert.ToChar(base.Key); - internal KeyboardKeyPin(IPinController? controller, string name, char key) + internal InteropMac.MacKeyCodes? MacKeyCode { get; } + + internal KeyboardKeyPin(IPinController? controller, string name, char key, InteropMac.MacKeyCodes? macKey) : base(controller, name, char.ToUpper(key), new List() { @@ -25,6 +28,7 @@ internal KeyboardKeyPin(IPinController? controller, string name, char key) { throw new ArgumentException("KeyboardKeyPins are only supported on a Keyboard"); } + MacKeyCode = macKey; } /// 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 2dd105e00d..a2091606cc 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 @@ -14,14 +14,14 @@ Meadow.Foundation.Sensors.Hid.Keyboard https://github.com/WildernessLabs/Meadow.Foundation Meadow.Foundation,windows,keyboard - 0.94.0 + 1.7.0 true Standard 108-key PC keyboard enable - + - + 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 d297e55e78..97d0d32440 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 @@ -15,13 +15,13 @@ Meadow.Foundation.Sensors.Hid.Mpr121 https://github.com/WildernessLabs/Meadow.Foundation Meadow.Foundation, MPR121, capacitive, keypad - 0.1.45 + 1.7.0 true Freescale Semiconductor MPR121 I2C capacitive keypad controller - + - + 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 9ca13f4f02..f5647b9d5b 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,8 +9,8 @@ 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 d410a20742..373d136fea 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 @@ -15,13 +15,13 @@ Meadow.Foundation.Sensors.Hid.Tsc2004 https://github.com/WildernessLabs/Meadow.Foundation Meadow.Foundation,touch,screen,display,capacitive,tsc2004 - 0.1.7 + 1.7.0 true Tsc2004 I2C capacitive touch screen - + - + 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 c16b68710c..e07eaa085f 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,8 +6,8 @@ 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 036bed7ba3..c5abd35906 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 @@ -15,13 +15,13 @@ Meadow.Foundation.Sensors.Hid.WiiExtensionControllers https://github.com/WildernessLabs/Meadow.Foundation Meadow.Foundation,wii,nunchuck,classic,controller,pro,nes,snes - 0.1.5 + 1.7.0 true Nintendo Wii I2C extension controllers (nunchuck, classic controller, snes classic controller, nes classic controller) - + - + 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 8d67f33d5e..9d67b231c7 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,8 +6,8 @@ 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 8d67f33d5e..9d67b231c7 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,8 +6,8 @@ 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 8d67f33d5e..9d67b231c7 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,8 +6,8 @@ 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 8d67f33d5e..9d67b231c7 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,8 +6,8 @@ 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 8d67f33d5e..9d67b231c7 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,8 +6,8 @@ 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 05517711be..a852e558cb 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 @@ -15,13 +15,13 @@ Meadow.Foundation.Sensors.Light.Alspt19315C https://github.com/WildernessLabs/Meadow.Foundation Meadow.Foundation, ALS-PT19, ALSPT19315C, Light - 0.1.52 + 1.7.0 true ALS-PT19-315C analog light sensor - + - + 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 030c3d6252..e7ce135611 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,8 +9,8 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Light.AnalogSolarIntensityGauge/Driver/AnalogSolarIntensityGauge.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Light.AnalogSolarIntensityGauge/Driver/AnalogSolarIntensityGauge.cs index d517c01a77..6bc2071b0f 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Light.AnalogSolarIntensityGauge/Driver/AnalogSolarIntensityGauge.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Light.AnalogSolarIntensityGauge/Driver/AnalogSolarIntensityGauge.cs @@ -12,11 +12,6 @@ namespace Meadow.Foundation.Sensors.Light /// public class AnalogSolarIntensityGauge : SamplingSensorBase, ISolarIntensityGauge, IDisposable { - /// - /// Raised when the solar intensity changes - /// - public event EventHandler> SolarIntensityUpdated = default!; - readonly IAnalogInputPort analogInputPort; /// @@ -150,16 +145,6 @@ public override void StopUpdating() analogInputPort.StopUpdating(); } - /// - /// Raise events for subscribers and notify of value changes - /// - /// The updated sensor data - protected override void RaiseEventsAndNotify(IChangeResult changeResult) - { - this.SolarIntensityUpdated?.Invoke(this, changeResult); - base.RaiseEventsAndNotify(changeResult); - } - /// /// Converts a voltage reading to a solar intensity percentage, taking into /// account the minimum and maximum expected values. diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Light.AnalogSolarIntensityGauge/Driver/Readme.md b/Source/Meadow.Foundation.Peripherals/Sensors.Light.AnalogSolarIntensityGauge/Driver/Readme.md index 0e6b9dd5cf..9cda4e57fd 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Light.AnalogSolarIntensityGauge/Driver/Readme.md +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Light.AnalogSolarIntensityGauge/Driver/Readme.md @@ -22,7 +22,7 @@ public override Task Initialize() solarGauge = new AnalogSolarIntensityGauge(Device.Pins.A02, updateInterval: TimeSpan.FromSeconds(1)); //==== classic .NET Event - solarGauge.SolarIntensityUpdated += (s, result) => Resolver.Log.Info($"SolarIntensityUpdated: {result.New * 100:n2}%"); + solarGauge.Updated += (s, result) => Resolver.Log.Info($"SolarIntensityUpdated: {result.New * 100:n2}%"); //==== Filterable observer var observer = AnalogSolarIntensityGauge.CreateObserver( diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Light.AnalogSolarIntensityGauge/Driver/Sensors.Light.AnalogSolarIntensityGauge.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Light.AnalogSolarIntensityGauge/Driver/Sensors.Light.AnalogSolarIntensityGauge.csproj index af772ec2f5..7d9fa9c303 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 @@ -11,7 +11,7 @@ Meadow.Foundation.Sensors.Light.AnalogSolarIntensityGauge https://github.com/WildernessLabs/Meadow.Foundation Meadow.Foundation, Light, AnalogSolarIntensityGauge - 0.1.13 + 1.7.0 true Analog solar intensity sensor Meadow.Foundation.Sensors.Light @@ -23,8 +23,8 @@ 10.0 - + - + 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 b93ac0abb0..f3d1245dd3 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,8 +6,8 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Light.AnalogSolarIntensityGauge/Samples/AnalogSolarIntensityGauge_Sample/MeadowApp.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Light.AnalogSolarIntensityGauge/Samples/AnalogSolarIntensityGauge_Sample/MeadowApp.cs index 87c0ecd998..db1f6d8c12 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Light.AnalogSolarIntensityGauge/Samples/AnalogSolarIntensityGauge_Sample/MeadowApp.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Light.AnalogSolarIntensityGauge/Samples/AnalogSolarIntensityGauge_Sample/MeadowApp.cs @@ -18,7 +18,7 @@ public override Task Initialize() solarGauge = new AnalogSolarIntensityGauge(Device.Pins.A02, updateInterval: TimeSpan.FromSeconds(1)); //==== classic .NET Event - solarGauge.SolarIntensityUpdated += (s, result) => Resolver.Log.Info($"SolarIntensityUpdated: {result.New * 100:n2}%"); + solarGauge.Updated += (s, result) => Resolver.Log.Info($"SolarIntensityUpdated: {result.New * 100:n2}%"); //==== Filterable observer var observer = AnalogSolarIntensityGauge.CreateObserver( diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Light.Bh1745/Driver/Bh1745.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Light.Bh1745/Driver/Bh1745.cs index c7662f4e1d..7f49b0aa3c 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Light.Bh1745/Driver/Bh1745.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Light.Bh1745/Driver/Bh1745.cs @@ -14,7 +14,7 @@ public partial class Bh1745 : ByteCommsSensorBase<(Illuminance? AmbientLight, Color? Color, bool Valid)>, ILightSensor, II2cPeripheral { - private event EventHandler> _lightHandlers; + private event EventHandler> _lightHandlers = default!; event EventHandler> ISamplingSensor.Updated { 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 75b0817c47..554055fa45 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 @@ -15,14 +15,14 @@ Meadow.Foundation.Sensors.Light.Bh1745 https://github.com/WildernessLabs/Meadow.Foundation Meadow.Foundation, Light, Bh1745 - 0.1.52 + 1.7.0 true Bh1745 I2C luminance and color light sensor Meadow.Foundation.Sensors.Light - + - + 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 8873d8e4d3..f3c1e477bc 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,8 +9,8 @@ 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 49139e98c3..f4279df3bd 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Light.Bh1750/Driver/Bh1750.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Light.Bh1750/Driver/Bh1750.cs @@ -126,14 +126,5 @@ private void SetLightTransmittance(double transmittance) BusComms.Write((byte)((byte)Commands.MeasurementTimeHigh | (val >> 5))); BusComms.Write((byte)((byte)Commands.MeasurementTimeLow | (val & 0b_0001_1111))); } - - /// - /// Raise events for subscribers and notify of value changes - /// - /// The updated sensor data - protected override void RaiseEventsAndNotify(IChangeResult changeResult) - { - base.RaiseEventsAndNotify(changeResult); - } } } \ No newline at end of file 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 d138870152..58af85f410 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 @@ -15,15 +15,15 @@ Meadow.Foundation.Sensors.Light.Bh1750 https://github.com/WildernessLabs/Meadow.Foundation Meadow.Foundation,luminance,color,Light,Bh1750 - 0.1.52 + 1.7.0 true Bh1750 I2C luminance and color light sensor 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 9162629051..550a262223 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,8 +9,8 @@ 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 3cf6012d9f..eb5747cedd 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 @@ -15,14 +15,14 @@ Meadow.Foundation.Sensors.Light.Max44009 https://github.com/WildernessLabs/Meadow.Foundation Meadow.Foundation,Max44009,Light,ultraviolet - 0.1.49 + 1.7.0 true Max44009 I2C ultraviolet and ambient light sensor Meadow.Foundation.Sensors.Light - + - + 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 bac938b59f..b14c3dffd0 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,8 +9,8 @@ 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 45902d7bdf..19d4efa38e 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 @@ -15,14 +15,14 @@ Meadow.Foundation.Sensors.Light.Si1145 https://github.com/WildernessLabs/Meadow.Foundation Meadow.Foundation, Si1145, Light - 0.1.49 + 1.7.0 true SI1145 I2C ultraviolet and ambient light sensor Meadow.Foundation.Sensors.Light - + - + 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 998eff7028..72bba8a7cd 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,8 +9,8 @@ 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 ff33bf9ac3..d63aa71480 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 @@ -15,13 +15,13 @@ Meadow.Foundation.Sensors.Light.Temt6000 https://github.com/WildernessLabs/Meadow.Foundation Meadow.Foundation, Light, Temt6000 - 0.1.52 + 1.7.0 true Temt6000 analog ambient light sensor - + - + 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 3fdfa8f028..c1d8d50bf1 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,8 +9,8 @@ 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 947a8f2bda..57678eb8c1 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 @@ -15,13 +15,13 @@ Meadow.Foundation.Sensors.Light.Tsl2591 https://github.com/WildernessLabs/Meadow.Foundation Meadow.Foundation, Light, Tsl2591 - 0.1.49 + 1.7.0 true Tsl2591 I2C high dynamic range light sensor - + - + 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 83d328440e..0727978b42 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,8 +9,8 @@ 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 e5e6a5477b..859138752b 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 @@ -15,14 +15,14 @@ Meadow.Foundation.Sensors.Light.Veml7700 https://github.com/WildernessLabs/Meadow.Foundation Meadow.Foundation, Light, Veml7700 - 0.1.49 + 1.7.0 true Veml7700 I2C high accuracy ambient light sensor Meadow.Foundation.Sensors.Light - + - + 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 fddbf14b70..ecc7259f46 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Light.Veml7700/Driver/Veml7700.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Light.Veml7700/Driver/Veml7700.cs @@ -12,11 +12,6 @@ namespace Meadow.Foundation.Sensors.Light public partial class Veml7700 : ByteCommsSensorBase, ILightSensor, II2cPeripheral, IDisposable { - /// - /// Raised when the luminosity value changes - /// - public event EventHandler> IlluminanceUpdated = default!; - /// /// Raised when the high range is exceeded /// @@ -153,8 +148,8 @@ private Illuminance ScaleDataToIlluminance(ushort data, int gain, int integratio _ => 1, }; - scale *= integrationTime switch - { + scale *= integrationTime switch + { -2 => 32, // 25ms -1 => 16, // 50ms 0 => 8, // 100ms @@ -167,16 +162,6 @@ private Illuminance ScaleDataToIlluminance(ushort data, int gain, int integratio return CalculateCorrectedLux(scale * 0.0036d * data); } - /// - /// Raise events for subscribers and notify of value changes - /// - /// The updated sensor data - protected override void RaiseEventsAndNotify(IChangeResult changeResult) - { - IlluminanceUpdated?.Invoke(this, changeResult); - base.RaiseEventsAndNotify(changeResult); - } - private Illuminance CalculateCorrectedLux(double lux) { // per the App Note 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 a55c9a38bf..5810b53bff 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,8 +9,8 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.LoadCell.Hx711/Driver/Hx711.cs b/Source/Meadow.Foundation.Peripherals/Sensors.LoadCell.Hx711/Driver/Hx711.cs index d630dea9ae..6242b5540a 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.LoadCell.Hx711/Driver/Hx711.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.LoadCell.Hx711/Driver/Hx711.cs @@ -49,11 +49,6 @@ public partial class Hx711 : PollingSensorBase, IMassSensor, IDisposable /// public uint TareValue { get; set; } = 0; - /// - /// Mass changed event - /// - public event EventHandler> MassUpdated = default!; - /// /// Gets default sample period (1 Second) /// @@ -302,24 +297,6 @@ private unsafe uint ReadADC() return count; } - /// - /// Inheritance-safe way to raise events and notify observers. - /// - /// - protected override void RaiseEventsAndNotify(IChangeResult changeResult) - { - try - { - MassUpdated?.Invoke(this, changeResult); - base.RaiseEventsAndNotify(changeResult); - } - catch (Exception ex) - { - Resolver.Log.Info($"HX711 event handler threw: {ex.Message}"); - throw; - } - } - /// /// Dispose of the object /// diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.LoadCell.Hx711/Driver/Readme.md b/Source/Meadow.Foundation.Peripherals/Sensors.LoadCell.Hx711/Driver/Readme.md index 2c30d0ef46..78541c2357 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.LoadCell.Hx711/Driver/Readme.md +++ b/Source/Meadow.Foundation.Peripherals/Sensors.LoadCell.Hx711/Driver/Readme.md @@ -37,7 +37,7 @@ public override async Task Initialize() loadSensor.Tare(); } - loadSensor.MassUpdated += (sender, values) => Resolver.Log.Info($"Mass is now returned {values.New.Grams:N2}g"); + loadSensor.Updated += (sender, values) => Resolver.Log.Info($"Mass is now returned {values.New.Grams:N2}g"); } public override Task Run() diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.LoadCell.Hx711/Driver/Sensors.LoadCell.Hx711.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.LoadCell.Hx711/Driver/Sensors.LoadCell.Hx711.csproj index 9d806dd0c8..037f86fd31 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 @@ -15,15 +15,15 @@ Meadow.Foundation.Sensors.LoadCell.Hx711 https://github.com/WildernessLabs/Meadow.Foundation Meadow.Foundation,LoadCell,Hx711 - 0.1.49 + 1.7.0 true Hx711 digital load cell amplifier Release;Debug true - + - + 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 005f2328b5..2adcaf2a9e 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,8 +9,8 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.LoadCell.Hx711/Samples/Hx711_Sample/MeadowApp.cs b/Source/Meadow.Foundation.Peripherals/Sensors.LoadCell.Hx711/Samples/Hx711_Sample/MeadowApp.cs index 5230dd78d1..35687a5c0f 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.LoadCell.Hx711/Samples/Hx711_Sample/MeadowApp.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.LoadCell.Hx711/Samples/Hx711_Sample/MeadowApp.cs @@ -36,7 +36,7 @@ public override async Task Initialize() loadSensor.Tare(); } - loadSensor.MassUpdated += (sender, values) => Resolver.Log.Info($"Mass is now returned {values.New.Grams:N2}g"); + loadSensor.Updated += (sender, values) => Resolver.Log.Info($"Mass is now returned {values.New.Grams:N2}g"); } public override Task Run() diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.LoadCell.Nau7802/Driver/Nau7802.cs b/Source/Meadow.Foundation.Peripherals/Sensors.LoadCell.Nau7802/Driver/Nau7802.cs index 3fc8e35b62..42a71b4824 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.LoadCell.Nau7802/Driver/Nau7802.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.LoadCell.Nau7802/Driver/Nau7802.cs @@ -12,11 +12,6 @@ namespace Meadow.Foundation.Sensors.LoadCell /// public partial class Nau7802 : ByteCommsSensorBase, IMassSensor, II2cPeripheral { - /// - /// Raised when the mass value changes - /// - public event EventHandler> MassUpdated = default!; - private readonly byte[] readBuffer = new byte[3]; private double gramsPerAdcUnit = 0; private PU_CTRL_BITS currentPuCTRL; @@ -284,24 +279,5 @@ protected override Task ReadSensor() // convert to desired units return Task.FromResult(new Mass(grams, Units.Mass.UnitType.Grams)); } - - - /// - /// Inheritance-safe way to raise events and notify observers. - /// - /// - protected override void RaiseEventsAndNotify(IChangeResult changeResult) - { - try - { - MassUpdated?.Invoke(this, changeResult); - base.RaiseEventsAndNotify(changeResult); - } - catch (Exception ex) - { - Resolver.Log.Info($"NAU7802 event handler threw: {ex.Message}"); - throw; - } - } } } \ No newline at end of file diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.LoadCell.Nau7802/Driver/Readme.md b/Source/Meadow.Foundation.Peripherals/Sensors.LoadCell.Nau7802/Driver/Readme.md index 963add8f85..9bec44b176 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.LoadCell.Nau7802/Driver/Readme.md +++ b/Source/Meadow.Foundation.Peripherals/Sensors.LoadCell.Nau7802/Driver/Readme.md @@ -37,7 +37,7 @@ public override async Task Initialize() loadSensor.Tare(); } - loadSensor.MassUpdated += (sender, values) => Resolver.Log.Info($"Mass is now returned {values.New.Grams:N2}g"); + loadSensor.Updated += (sender, values) => Resolver.Log.Info($"Mass is now returned {values.New.Grams:N2}g"); } public override Task Run() diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.LoadCell.Nau7802/Driver/Sensors.LoadCell.Nau7802.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.LoadCell.Nau7802/Driver/Sensors.LoadCell.Nau7802.csproj index 1ff8a1e8a2..79792546ea 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 @@ -11,7 +11,7 @@ Meadow.Foundation.Sensors.LoadCell.Nau7802 https://github.com/WildernessLabs/Meadow.Foundation Meadow,Meadow.Foundation,LoadCell,Nau7802 - 0.1.17 + 1.7.0 true NAU7802 I2C 24-Bit dual channel analog to digital converter enable @@ -22,8 +22,8 @@ 10.0 - + - + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.LoadCell.Nau7802/Samples/Nau7802_Sample/MeadowApp.cs b/Source/Meadow.Foundation.Peripherals/Sensors.LoadCell.Nau7802/Samples/Nau7802_Sample/MeadowApp.cs index 0fee3cd3f7..fe711dc1ca 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.LoadCell.Nau7802/Samples/Nau7802_Sample/MeadowApp.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.LoadCell.Nau7802/Samples/Nau7802_Sample/MeadowApp.cs @@ -35,7 +35,7 @@ public override async Task Initialize() loadSensor.Tare(); } - loadSensor.MassUpdated += (sender, values) => Resolver.Log.Info($"Mass is now returned {values.New.Grams:N2}g"); + loadSensor.Updated += (sender, values) => Resolver.Log.Info($"Mass is now returned {values.New.Grams:N2}g"); } public override Task Run() 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 d190535fce..36ba2d8437 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,8 +9,8 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Moisture.Capacitive/Driver/Capacitive.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Moisture.Capacitive/Driver/Capacitive.cs index aecdf88a5f..943a0741b9 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Moisture.Capacitive/Driver/Capacitive.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Moisture.Capacitive/Driver/Capacitive.cs @@ -11,11 +11,6 @@ namespace Meadow.Foundation.Sensors.Moisture /// public class Capacitive : SamplingSensorBase, IMoistureSensor, IDisposable { - /// - /// Raised when a new sensor reading has been made - /// - public event EventHandler> MoistureUpdated = default!; - /// /// Returns the analog input port /// @@ -139,16 +134,6 @@ public override void StopUpdating() } } - /// - /// Raise change events for subscribers - /// - /// The change result with the current sensor data - protected override void RaiseEventsAndNotify(IChangeResult changeResult) - { - MoistureUpdated?.Invoke(this, changeResult); - base.RaiseEventsAndNotify(changeResult); - } - /// /// Converts voltage to moisture value, ranging from 0 (most dry) to 1 (most wet) /// diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Moisture.Capacitive/Driver/Readme.md b/Source/Meadow.Foundation.Peripherals/Sensors.Moisture.Capacitive/Driver/Readme.md index 63bcd392aa..92b2280847 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Moisture.Capacitive/Driver/Readme.md +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Moisture.Capacitive/Driver/Readme.md @@ -39,7 +39,7 @@ public override Task Initialize() capacitive.Subscribe(consumer); // classical .NET events can also be used: - capacitive.MoistureUpdated += (sender, result) => + capacitive.Updated += (sender, result) => { string oldValue = (result.Old is { } old) ? $"{old:n2}" : "n/a"; Resolver.Log.Info($"Updated - New: {result.New}, Old: {oldValue}"); 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 151cda4edd..9d4926546b 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 @@ -11,7 +11,7 @@ Meadow.Foundation.Sensors.Moisture.Capacitive https://github.com/WildernessLabs/Meadow.Foundation Meadow.Foundation, Capacitive, Soil Moisture - 0.5.55 + 1.7.0 true Analog capacitive soil moisture sensor enable @@ -22,8 +22,8 @@ 10.0 - + - + 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 1602ac0941..55def76b96 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,8 +12,8 @@ 9.0 - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Moisture.Capacitive/Samples/Capacitive_Sample/MeadowApp.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Moisture.Capacitive/Samples/Capacitive_Sample/MeadowApp.cs index 9c4fe8d1f5..0c448ce411 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Moisture.Capacitive/Samples/Capacitive_Sample/MeadowApp.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Moisture.Capacitive/Samples/Capacitive_Sample/MeadowApp.cs @@ -37,7 +37,7 @@ public override Task Initialize() capacitive.Subscribe(consumer); // classical .NET events can also be used: - capacitive.MoistureUpdated += (sender, result) => + capacitive.Updated += (sender, result) => { string oldValue = (result.Old is { } old) ? $"{old:n2}" : "n/a"; Resolver.Log.Info($"Updated - New: {result.New}, Old: {oldValue}"); 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 fe35f9af9d..b31f5afdc6 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Moisture.Fc28/Driver/Fc28.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Moisture.Fc28/Driver/Fc28.cs @@ -2,7 +2,6 @@ using Meadow.Peripherals.Sensors.Moisture; using Meadow.Units; using System; -using System.Threading; using System.Threading.Tasks; namespace Meadow.Foundation.Sensors.Moisture @@ -10,13 +9,8 @@ namespace Meadow.Foundation.Sensors.Moisture /// /// FC-28-D Soil Hygrometer Detection Module + Soil Moisture Sensor /// - public class Fc28 : SamplingSensorBase, IMoistureSensor + public class Fc28 : PollingSensorBase, IMoistureSensor, IDisposable { - /// - /// Raised when a new sensor reading has been made. To enable, call StartUpdating(). - /// - public event EventHandler> MoistureUpdated = default!; - /// /// Returns the analog input port /// @@ -30,15 +24,15 @@ public class Fc28 : SamplingSensorBase, IMoistureSensor /// /// Last value read from the moisture sensor /// - public double? Moisture { get; private set; } = double.NaN; + public double? Moisture { get; protected set; } /// - /// Voltage value of most dry soil. Default of `0V` + /// Voltage value of most dry soil - default is 0 volts /// public Voltage MinimumVoltageCalibration { get; set; } = new Voltage(0); /// - /// Voltage value of most moist soil. Default of `3.3V` + /// Voltage value of most moist soil - default of 3.3V /// public Voltage MaximumVoltageCalibration { get; set; } = new Voltage(3.3); @@ -110,81 +104,7 @@ protected override async Task ReadSensor() DigitalOutputPort.State = true; var voltage = await AnalogInputPort.Read(); DigitalOutputPort.State = false; - return (VoltageToMoisture(voltage)); - } - - /// - /// Starts continuously sampling the sensor - /// - public override void StartUpdating(TimeSpan? updateInterval) - { - if (updateInterval == null) - { - UpdateInterval = TimeSpan.FromSeconds(5); - } - else - { - UpdateInterval = updateInterval.Value; - } - - lock (samplingLock) - { - if (IsSampling) { return; } - - IsSampling = true; - - SamplingTokenSource = new CancellationTokenSource(); - CancellationToken ct = SamplingTokenSource.Token; - - double? oldConditions; - ChangeResult result; - Task.Factory.StartNew(async () => - { - while (true) - { - if (ct.IsCancellationRequested) - { - observers.ForEach(x => x.OnCompleted()); - break; - } - oldConditions = Moisture; - - Moisture = await Read(); - - result = new ChangeResult(Moisture.Value, oldConditions); - - RaiseChangedAndNotify(result); - - await Task.Delay(base.UpdateInterval); - } - }, SamplingTokenSource.Token); - } - } - - /// - /// Stops sampling the sensor - /// - public override void StopUpdating() - { - lock (samplingLock) - { - if (!IsSampling) { return; } - if (SamplingTokenSource != null) - { - SamplingTokenSource.Cancel(); - } - IsSampling = false; - } - } - - /// - /// Raise change events for subscribers - /// - /// The change result with the current sensor data - protected void RaiseChangedAndNotify(IChangeResult changeResult) - { - MoistureUpdated?.Invoke(this, changeResult); - NotifyObservers(changeResult); + return VoltageToMoisture(voltage); } /// diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Moisture.Fc28/Driver/Readme.md b/Source/Meadow.Foundation.Peripherals/Sensors.Moisture.Fc28/Driver/Readme.md index 32eaa62286..5e6e350379 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Moisture.Fc28/Driver/Readme.md +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Moisture.Fc28/Driver/Readme.md @@ -39,7 +39,7 @@ public override Task Initialize() ); fc28.Subscribe(consumer); - fc28.MoistureUpdated += (object sender, IChangeResult e) => + fc28.Updated += (object sender, IChangeResult e) => { Resolver.Log.Info($"Moisture Updated: {e.New}"); }; 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 e6ec4793b3..cc81ba194d 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 @@ -11,7 +11,7 @@ Meadow.Foundation.Sensors.Moisture.Fc28 https://github.com/WildernessLabs/Meadow.Foundation Meadow.Foundation,FC28,Soil,Moisture - 0.5.54 + 1.7.0 true FC28 analog soil moisture sensor enable @@ -22,8 +22,8 @@ 10.0 - + - + 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 5f6a628b5f..e2ead677b4 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,8 +9,8 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Moisture.Fc28/Samples/Fc28_Sample/MeadowApp.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Moisture.Fc28/Samples/Fc28_Sample/MeadowApp.cs index 50b088d787..e8264d4606 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Moisture.Fc28/Samples/Fc28_Sample/MeadowApp.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Moisture.Fc28/Samples/Fc28_Sample/MeadowApp.cs @@ -38,7 +38,7 @@ public override Task Initialize() ); fc28.Subscribe(consumer); - fc28.MoistureUpdated += (object sender, IChangeResult e) => + fc28.Updated += (object sender, IChangeResult e) => { Resolver.Log.Info($"Moisture Updated: {e.New}"); }; diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Adxl3xx/Driver/Adxl3xxBase.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Adxl3xx/Driver/Adxl3xxBase.cs index 047fd1a715..8d82d462d9 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Adxl3xx/Driver/Adxl3xxBase.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Adxl3xx/Driver/Adxl3xxBase.cs @@ -11,11 +11,6 @@ namespace Meadow.Foundation.Sensors.Motion /// public abstract class Adxl3xxBase : PollingSensorBase, IAccelerometer, IDisposable { - /// - /// Raised when the acceleration value changes - /// - public event EventHandler> Acceleration3DUpdated = default!; - /// /// The X analog input port /// @@ -82,16 +77,6 @@ protected Adxl3xxBase( } } - /// - /// Raise events for subscribers and notify of value changes - /// - /// The updated sensor data - protected override void RaiseEventsAndNotify(IChangeResult changeResult) - { - Acceleration3DUpdated?.Invoke(this, changeResult); - base.RaiseEventsAndNotify(changeResult); - } - /// /// Reads data from the sensor /// 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 9748829c5c..d2ac0ab408 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 @@ -18,11 +18,6 @@ public partial class Adxl345 : ByteCommsSensorBase, IAcceleromet /// public byte DefaultI2cAddress => (byte)Addresses.Default; - /// - /// Event raised when acceleration changes - /// - public event EventHandler> Acceleration3DUpdated = default!; - readonly double ADXL345_MG2G_MULTIPLIER = 0.004; /// @@ -114,16 +109,6 @@ protected override Task ReadSensor() return Task.FromResult(conditions); } - /// - /// Raise changed event for subscribers - /// - /// - protected override void RaiseEventsAndNotify(IChangeResult changeResult) - { - Acceleration3DUpdated?.Invoke(this, changeResult); - base.RaiseEventsAndNotify(changeResult); - } - /// /// Set the PowerControl register (see pages 25 and 26 of the data sheet) /// diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Adxl3xx/Driver/Drivers/Adxl362.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Adxl3xx/Driver/Drivers/Adxl362.cs index f4289f17b5..c5bc4f83a6 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Adxl3xx/Driver/Drivers/Adxl362.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Adxl3xx/Driver/Drivers/Adxl362.cs @@ -18,8 +18,8 @@ public partial class Adxl362 : ByteCommsSensorBase<(Acceleration3D? Acceleration3D, Units.Temperature? Temperature)>, IAccelerometer, ITemperatureSensor, ISpiPeripheral { - private event EventHandler> _temperatureHandlers; - private event EventHandler> _accelerationHandlers; + private event EventHandler> _temperatureHandlers = default!; + private event EventHandler> _accelerationHandlers = default!; event EventHandler> ISamplingSensor.Updated { 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 ef7ef8e3ec..29374c2507 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 @@ Meadow.Foundation.Sensors.Motion.Adxl3xx https://github.com/WildernessLabs/Meadow.Foundation Meadow.Foundation,ADXL335,ADXL345,ADXL337,ADXL362,ADXL377,Accelerometer,Motion,3-axis - 0.1.13 + 1.7.0 true ADXL3xx Analog and I2C 3-axis accelerometers (ADXL335, 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 54fa70caf7..ddb14703d8 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,8 +9,8 @@ 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 54fa70caf7..ddb14703d8 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,8 +9,8 @@ App - - + + 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 d4210e1e9b..a409066261 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,8 +9,8 @@ App - - + + 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 d4210e1e9b..a409066261 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,8 +9,8 @@ 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 54fa70caf7..ddb14703d8 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,8 +9,8 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Apds9960/Driver/Apds9960.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Apds9960/Driver/Apds9960.cs index fd39ab3abe..5e965ead0f 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Apds9960/Driver/Apds9960.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Apds9960/Driver/Apds9960.cs @@ -122,7 +122,7 @@ public Apds9960(II2cBus i2cBus, IPin? interruptPin) var b = ReadBlueLight() / rgbDivisor; var a = ambient / rgbDivisor; - conditions.Color = Foundation.Color.FromRgba(r, g, b, a); + conditions.Color = Meadow.Color.FromRgba(r, g, b, a); return Task.FromResult(conditions); } @@ -1596,7 +1596,7 @@ private class GestureData } /// - public void Dispose() + public override void Dispose() { Dispose(disposing: true); GC.SuppressFinalize(this); @@ -1606,8 +1606,10 @@ public void Dispose() /// Dispose of the object /// /// Is disposing - protected virtual void Dispose(bool disposing) + protected override void Dispose(bool disposing) { + base.Dispose(disposing); + if (!IsDisposed) { if (disposing && createdPort) 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 723d0aed33..52bdd610cf 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 @@ -15,14 +15,14 @@ Meadow.Foundation.Sensors.Motion.Apds9960 https://github.com/WildernessLabs/Meadow.Foundation Meadow.Foundation,Acceleration,Accelerometer,Apds9960 - 0.1.20 + 1.7.0 false APDS9960 I2C proximity, light, color and gesture sensor Meadow.Foundation.Sensors.Motion - + - + 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 0dd1c372af..665af3f65b 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,8 +9,8 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Bmi270/Driver/Bmi270.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Bmi270/Driver/Bmi270.cs index 344b0d97a3..6c642679d6 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Bmi270/Driver/Bmi270.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Bmi270/Driver/Bmi270.cs @@ -16,9 +16,9 @@ public partial class Bmi270 : PollingSensorBase<(Acceleration3D? Acceleration3D, AngularVelocity3D? AngularVelocity3D, Units.Temperature? Temperature)>, II2cPeripheral, IGyroscope, IAccelerometer, ITemperatureSensor { - private event EventHandler> _angularVelocityHandlers; - private event EventHandler> _accelerationHandlers; - private event EventHandler> _temperatureHandlers; + private event EventHandler> _angularVelocityHandlers = default!; + private event EventHandler> _accelerationHandlers = default!; + private event EventHandler> _temperatureHandlers = default!; /// /// Event raised when linear acceleration changes @@ -70,6 +70,8 @@ public partial class Bmi270 : /// protected readonly II2cCommunications i2cComms; + private byte[] readBuffer; + /// /// Create a new Bmi270 instance /// @@ -77,9 +79,10 @@ public partial class Bmi270 : /// The I2C address public Bmi270(II2cBus i2cBus, byte address = (byte)Addresses.Address_0x68) { - //Read buffer: 16 (needs at least 13) //Write buffer: 256 bytes for the config data + 1 for the address - i2cComms = new I2cCommunications(i2cBus, address, 16, 256 + 1); + i2cComms = new I2cCommunications(i2cBus, address, 256 + 1); + + readBuffer = new byte[12]; var id = i2cComms.ReadRegister(CHIP_ID); @@ -321,7 +324,6 @@ public void SetPowerMode(PowerMode powerMode) private byte[] ReadAccelerationData() { - var readBuffer = new byte[12]; i2cComms.ReadRegister(0x0C, readBuffer); return readBuffer; } 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 9b44b97e6b..433631f58d 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 @@ -15,14 +15,14 @@ Meadow.Foundation.Sensors.Motion.Bmi270 https://github.com/WildernessLabs/Meadow.Foundation Meadow.Foundation,Acceleration,Accelerometer,IMU,Bmi270 - 0.1.0 + 1.7.0 true BMI270 I2C 6-axis accelerometer and motion sensor Meadow.Foundation.Sensors.Motion - + - + 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 02888fed48..daa0831caf 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,8 +9,8 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Bno055/Driver/Bno055.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Bno055/Driver/Bno055.cs index 30221b3e75..fdaee1c64a 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Bno055/Driver/Bno055.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Bno055/Driver/Bno055.cs @@ -59,9 +59,9 @@ public partial class Bno055 : ByteCommsSensorBase<( /// public event EventHandler> EulerOrientationUpdated = default!; - private event EventHandler> _temperatureHandlers; - private event EventHandler> _velocityHandlers; - private event EventHandler> _accelerationHandlers; + private event EventHandler> _temperatureHandlers = default!; + private event EventHandler> _velocityHandlers = default!; + private event EventHandler> _accelerationHandlers = default!; event EventHandler> ISamplingSensor.Updated { 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 3d50723a95..01fab5a231 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 @@ -15,14 +15,14 @@ Meadow.Foundation.Sensors.Motion.Bno055 https://github.com/WildernessLabs/Meadow.Foundation Meadow.Foundation, BNO055, Motion - 0.1.54 + 1.7.0 true Bosch BNO055 I2C 9 axis absolute orientation sensor Meadow.Foundation.Sensors.Motion - + - + 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 c8e77da465..d53a382801 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,8 +9,8 @@ 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 1622ee7756..c312e7a3ef 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 @@ -15,13 +15,13 @@ Meadow.Foundation.Sensors.Motion.Hcsens0040 https://github.com/WildernessLabs/Meadow.Foundation Meadow,Meadow.Foundation,Motion,microwave,HCSENS0040,RCWL-0516 - 0.1.52 + 1.7.0 true HCSENS0040 digital microwave motion sensor - + - + 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 54612466b9..7b573c30fc 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,8 +9,8 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Hmc5883/Driver/Hmc5883.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Hmc5883/Driver/Hmc5883.cs index 65db4fc542..b1341d6b56 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Hmc5883/Driver/Hmc5883.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Hmc5883/Driver/Hmc5883.cs @@ -18,11 +18,6 @@ public partial class Hmc5883 : ByteCommsSensorBase, II2cPeripheral /// public byte DefaultI2cAddress => (byte)Addresses.Default; - /// - /// Event to be raised when the compass changes - /// - public event EventHandler> DirectionUpdated = default!; - internal byte measuringMode; internal byte outputRate; internal byte gain; @@ -84,16 +79,6 @@ protected virtual void Initialize() BusComms?.WriteRegister(Registers.HMC_MODE_REG_ADDR, measuringMode); } - /// - /// Raise events for subscribers and notify of value changes - /// - /// The updated sensor data - protected override void RaiseEventsAndNotify(IChangeResult changeResult) - { - DirectionUpdated?.Invoke(this, changeResult); - base.RaiseEventsAndNotify(changeResult); - } - /// /// Reads data from the sensor /// 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 98a615b46d..6410a1405d 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 @@ -15,14 +15,14 @@ Meadow.Foundation.Sensors.Motion.Hmc5883 https://github.com/WildernessLabs/Meadow.Foundation Meadow.Foundation, Hmc5883, Compass - 0.1.17 + 1.7.0 true Hmc5883 / Qmc5883 I2C digital compass Meadow.Foundation.Sensors.Motion - + - + 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 633cfe3e8c..686f7a8063 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,8 +12,8 @@ 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 633cfe3e8c..686f7a8063 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,8 +12,8 @@ 9.0 - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Lis2Mdl/Driver/Lis2Mdl.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Lis2Mdl/Driver/Lis2Mdl.cs index 3adaf3b32f..31da4abb16 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Lis2Mdl/Driver/Lis2Mdl.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Lis2Mdl/Driver/Lis2Mdl.cs @@ -12,11 +12,6 @@ namespace Meadow.Foundation.Sensors.Motion /// public partial class Lis2Mdl : PollingSensorBase, IMagnetometer, II2cPeripheral { - /// - /// Event raised when magnetic field changes - /// - public event EventHandler> MagneticField3DUpdated = default!; - /// /// Current Magnetic Field 3D /// @@ -53,19 +48,6 @@ void Initialize() i2cComms.WriteRegister(CFG_REG_C, 0x00); // Continuous mode } - /// - /// Raise events for subscribers and notify of value changes - /// - /// The updated sensor data - protected override void RaiseEventsAndNotify(IChangeResult changeResult) - { - if (changeResult.New is { } mag) - { - MagneticField3DUpdated?.Invoke(this, new ChangeResult(mag, changeResult.Old)); - } - base.RaiseEventsAndNotify(changeResult); - } - /// /// Reads data from the sensor /// 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 d117a2e5b6..cbddf82b58 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 @@ -15,14 +15,14 @@ Meadow.Foundation.Sensors.Motion.Lis2Mdl https://github.com/WildernessLabs/Meadow.Foundation Meadow.Foundation,magnetometer,Lis2Mdl - 0.1.0 + 1.7.0 true LIS2MDL I2C 3-axis magnetometer Meadow.Foundation.Sensors.Motion - + - + 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 fa9d819440..36fed0d4b2 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,8 +9,8 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Lis3Mdl/Driver/Lis3Mdl.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Lis3Mdl/Driver/Lis3Mdl.cs index b4aab2dded..76a5abaad8 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Lis3Mdl/Driver/Lis3Mdl.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Lis3Mdl/Driver/Lis3Mdl.cs @@ -14,11 +14,6 @@ namespace Meadow.Foundation.Sensors.Motion public partial class Lis3mdl : PollingSensorBase, IMagnetometer, II2cPeripheral { - /// - /// Event raised when magnetic field changes - /// - public event EventHandler> MagneticField3DUpdated = default!; - /// /// Current Magnetic Field 3D /// @@ -64,19 +59,6 @@ void Initialize() i2cComms.WriteRegister(CTRL_REG3, 0x00); // Normal Power, Continuous conversion mode } - /// - /// Raise events for subscribers and notify of value changes - /// - /// The updated sensor data - protected override void RaiseEventsAndNotify(IChangeResult changeResult) - { - if (changeResult.New is { } mag) - { - MagneticField3DUpdated?.Invoke(this, new ChangeResult(mag, changeResult.Old)); - } - base.RaiseEventsAndNotify(changeResult); - } - /// /// Reads data from the sensor /// 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 acc784f3e8..db17d00008 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 @@ -15,14 +15,14 @@ Meadow.Foundation.Sensors.Motion.Lis3mdl https://github.com/WildernessLabs/Meadow.Foundation Meadow.Foundation,magnetometer,Lis3mdl - 0.1.0 + 1.7.0 true Lis3mdl I2C 3-axis magnetometer Meadow.Foundation.Sensors.Motion - + - + 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 dc690a528f..b39858e5dc 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/Lsm303agr.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Lsm303agr/Driver/Lsm303agr.cs index 3ab4944bf6..cf2ab777c4 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Lsm303agr/Driver/Lsm303agr.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Lsm303agr/Driver/Lsm303agr.cs @@ -14,8 +14,8 @@ public partial class Lsm303agr : PollingSensorBase<(Acceleration3D? Acceleration3D, MagneticField3D? MagneticField3D)>, IMagnetometer, IAccelerometer, II2cPeripheral { - private event EventHandler> _accelerationHandlers; - private event EventHandler> _fieldHandlers; + private event EventHandler> _accelerationHandlers = default!; + private event EventHandler> _fieldHandlers = default!; event EventHandler> ISamplingSensor.Updated { 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 5700e0ce50..77d361a2b8 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 @@ -15,14 +15,14 @@ Meadow.Foundation.Sensors.Motion.Lsm303agr https://github.com/WildernessLabs/Meadow.Foundation Meadow.Foundation,Acceleration,Accelerometer,magnetometer,IMU,Lsm303agr - 0.1.0 + 1.7.0 true Lsm303agr I2C 6-axis accelerometer and magnetometer Meadow.Foundation.Sensors.Motion - + - + 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 676780020b..f22e5e79c0 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,8 +9,8 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Lsm6Dsox/Driver/Lsm6Dsox.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Lsm6Dsox/Driver/Lsm6Dsox.cs index db8ece8772..883023dd2a 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Lsm6Dsox/Driver/Lsm6Dsox.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Lsm6Dsox/Driver/Lsm6Dsox.cs @@ -14,8 +14,8 @@ public partial class Lsm6dsox : PollingSensorBase<(Acceleration3D? Acceleration3D, AngularVelocity3D? AngularVelocity3D)>, IGyroscope, IAccelerometer, II2cPeripheral { - private event EventHandler> _accelerationHandlers; - private event EventHandler> _velocityHandlers; + private event EventHandler> _accelerationHandlers = default!; + private event EventHandler> _velocityHandlers = default!; event EventHandler> ISamplingSensor.Updated { 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 b68ae14e58..988f1742a8 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 @@ -15,14 +15,14 @@ Meadow.Foundation.Sensors.Motion.Lsm6dsox https://github.com/WildernessLabs/Meadow.Foundation Meadow.Foundation,Acceleration,Accelerometer,gyroscope,IMU,Lsm6dsox - 0.1.0 + 1.7.0 true Lsm6Dsox I2C 6-axis accelerometer and gyroscope Meadow.Foundation.Sensors.Motion - + - + 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 868c726255..c8b59eab1d 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/Mag3110.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Mag3110/Driver/Mag3110.cs index 2780ce8bc4..60900becec 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Mag3110/Driver/Mag3110.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Mag3110/Driver/Mag3110.cs @@ -19,8 +19,8 @@ public partial class Mag3110 : /// public byte DefaultI2cAddress => (byte)Addresses.Default; - private event EventHandler> _temperatureHandlers; - private event EventHandler> _fieldHandlers; + private event EventHandler> _temperatureHandlers = default!; + private event EventHandler> _fieldHandlers = default!; event EventHandler> ISamplingSensor.Updated { 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 dbd4981543..f3a7a89f9b 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 @@ -15,14 +15,14 @@ Meadow.Foundation.Sensors.Motion.Mag3110 https://github.com/WildernessLabs/Meadow.Foundation Meadow.Foundation,motion,magnetometer,MAG3110 - 0.1.29 + 1.7.0 true Freescale MAG3110 I2C 3 axis magnetometer Meadow.Foundation.Sensors.Motion - + - + 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 32ea495728..bde9200a9c 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,8 +9,8 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Mma7660fc/Driver/Mma7660fc.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Mma7660fc/Driver/Mma7660fc.cs index ca60e0596b..ea053cb62d 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Mma7660fc/Driver/Mma7660fc.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Mma7660fc/Driver/Mma7660fc.cs @@ -1,7 +1,6 @@ using Meadow.Hardware; using Meadow.Peripherals.Sensors.Motion; using Meadow.Units; -using System; using System.Threading.Tasks; namespace Meadow.Foundation.Sensors.Motion @@ -16,11 +15,6 @@ public partial class Mma7660fc : ByteCommsSensorBase, IAccelerom /// public byte DefaultI2cAddress => (byte)Addresses.Default; - /// - /// Raised when new acceleration data is processed - /// - public event EventHandler> Acceleration3DUpdated = default!; - /// /// Current Acceleration3d value /// @@ -127,15 +121,5 @@ protected override Task ReadSensor() new Acceleration(zAccel * 3.0 / 64.0, Acceleration.UnitType.Gravity)); }); } - - /// - /// Raise event and notify subscribers - /// - /// Acceleration3d data - protected override void RaiseEventsAndNotify(IChangeResult changeResult) - { - Acceleration3DUpdated?.Invoke(this, changeResult); - base.RaiseEventsAndNotify(changeResult); - } } } \ No newline at end of file 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 b87aae80ae..9b13b4b92e 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 @@ -15,13 +15,13 @@ Meadow.Foundation.Sensors.Motion.Mma7660fc https://github.com/WildernessLabs/Meadow.Foundation Meadow.Foundation,Mma7660fc,Accelerometer,Motion - 0.1.7 + 1.7.0 true Mma7660fc I2C 3-axis accelerometer - + - + 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 ef3dcd3bfd..ccfc569716 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,8 +9,8 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Mmc5603/Driver/Mmc5603.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Mmc5603/Driver/Mmc5603.cs index b1deb243b2..3992723513 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Mmc5603/Driver/Mmc5603.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Mmc5603/Driver/Mmc5603.cs @@ -19,11 +19,6 @@ public partial class Mmc5603 : ByteCommsSensorBase, /// public byte DefaultI2cAddress => (byte)Addresses.Default; - /// - /// Raised when the magnetic field value changes - /// - public event EventHandler> MagneticField3DUpdated = default!; - /// /// The current magnetic field value /// @@ -90,19 +85,6 @@ void SetContinuousMode(bool on) } } - /// - /// Raise events for subscribers and notify of value changes - /// - /// The updated sensor data - protected override void RaiseEventsAndNotify(IChangeResult changeResult) - { - if (changeResult is { } mag) - { - MagneticField3DUpdated?.Invoke(this, new ChangeResult(mag.New, changeResult.Old)); - } - base.RaiseEventsAndNotify(changeResult); - } - Task TriggerMagneticFieldReading() { SetRegisterBit(Registers.CONTROL_0, 0, true); 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 972e9f9709..1bcdff9855 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 @@ -15,14 +15,14 @@ Meadow.Foundation.Sensors.Motion.Mmc5603 https://github.com/WildernessLabs/Meadow.Foundation Meadow.Foundation,motion,magnetometer,MMC5603 - 0.1.0 + 1.7.0 true MMC5603 I2C 3 axis digital magnetometer Meadow.Foundation.Sensors.Motion - + - + 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 f46066b876..3ce89d1f89 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,8 +9,8 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Mpu6050/Driver/Mpu6050.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Mpu6050/Driver/Mpu6050.cs index 0ff3f5b841..369eb748ec 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Mpu6050/Driver/Mpu6050.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Motion.Mpu6050/Driver/Mpu6050.cs @@ -20,9 +20,9 @@ public partial class Mpu6050 : /// public byte DefaultI2cAddress => (byte)Addresses.Default; - private event EventHandler> _temperatureHandlers; - private event EventHandler> _accelerationHandlers; - private event EventHandler> _velocityHandlers; + private event EventHandler> _temperatureHandlers = default!; + private event EventHandler> _accelerationHandlers = default!; + private event EventHandler> _velocityHandlers = default!; event EventHandler> ISamplingSensor.Updated { 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 77844077c7..1558ebf86e 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 @@ -13,16 +13,16 @@ Meadow.Foundation.Sensors.Motion.Mpu6050 https://github.com/WildernessLabs/Meadow.Foundation Meadow.Foundation, Motion, Mpu6050 - 0.5.57 + 1.7.0 true Mpu6050 I2C MEMS 3 axis gyroscope accelerometer motion sensor enable Meadow.Foundation.Sensors.Motion - 10.0 + 10.0 - + - + 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 fd7fe9d244..49db743f12 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,8 +12,8 @@ 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 3a019bdf80..7a2fa54b93 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 @@ -15,13 +15,13 @@ Meadow.Foundation.Sensors.Motion.ParallaxPir https://github.com/WildernessLabs/Meadow.Foundation Meadow,Meadow.Foundation,Motion,Parallax,PIR - 0.8.55 + 1.7.0 true Parallax PIR analog motion sensor - + - + 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 7ab4092e36..1dc8b18a03 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,8 +9,8 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Power.CurrentTransducer/Driver/CurrentTransducer.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Power.CurrentTransducer/Driver/CurrentTransducer.cs index c515343df8..bafcc16160 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Power.CurrentTransducer/Driver/CurrentTransducer.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Power.CurrentTransducer/Driver/CurrentTransducer.cs @@ -11,11 +11,6 @@ namespace Meadow.Foundation.Sensors.Power /// public partial class CurrentTransducer : SamplingSensorBase { - /// - /// Raised when the value of the reading changes - /// - public event EventHandler> CurrentUpdated = default!; - /// /// The analog input port connected to the transducer /// @@ -158,15 +153,5 @@ public override void StopUpdating() IsSampling = false; } } - - /// - /// Method to notify subscribers to CurrentUpdated event handler - /// - /// - protected override void RaiseEventsAndNotify(IChangeResult changeResult) - { - CurrentUpdated?.Invoke(this, changeResult); - base.RaiseEventsAndNotify(changeResult); - } } } \ No newline at end of file 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 c3844820db..96359346cb 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 @@ -11,7 +11,7 @@ Meadow.Foundation.Sensors.Power.CurrentTransducer https://github.com/WildernessLabs/Meadow.Foundation Meadow.Foundation,Sensor,Power,current,transducer - 0.1.0 + 1.7.0 true Current transducer library @@ -22,8 +22,8 @@ 10.0 - + - + 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 6cb57f1444..0714ba5fb4 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,8 +11,8 @@ enable - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Power.Ina260/Driver/Sensors.Power.Ina260.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Power.Ina260/Driver/Sensors.Power.Ina260.csproj index c9eed8be19..d793258250 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Power.Ina260/Driver/Sensors.Power.Ina260.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Power.Ina260/Driver/Sensors.Power.Ina260.csproj @@ -11,7 +11,7 @@ Meadow.Foundation.Sensors.Power.Ina260 https://github.com/WildernessLabs/Meadow.Foundation Meadow.Foundation, Sensor, Power, Ina260 - 0.1.49 + 1.7.0 true INA260 I2C current and power monitor @@ -22,8 +22,8 @@ 10.0 - + - + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Power.Ina260/Samples/Ina260_Sample/Ina260_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Sensors.Power.Ina260/Samples/Ina260_Sample/Ina260_Sample.csproj index e91ae8fdf1..6de7f3cfa0 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Power.Ina260/Samples/Ina260_Sample/Ina260_Sample.csproj +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Power.Ina260/Samples/Ina260_Sample/Ina260_Sample.csproj @@ -9,8 +9,8 @@ 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 a96bf73f9d..cce92735cc 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 @@ -15,13 +15,13 @@ Meadow.Foundation.Sensors.Radio.Rfid.IDxxLA https://github.com/WildernessLabs/Meadow.Foundation Meadow,Meadow.Foundation,RFID,ID-2LA,ID-12LA,ID-20LA - 0.1.50 + 1.7.0 true IDxxLA Serial radio frequency ID readers - + - + 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 fa6313beef..c8de0152b5 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,8 +9,8 @@ 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 8ef755bba7..1562855568 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 @@ -15,13 +15,13 @@ Meadow.Foundation.Sensors.Sound.Ky038 https://github.com/WildernessLabs/Meadow.Foundation Meadow.Foundation,KY-038,Sound,KY038 - 0.1.49 + 1.7.0 true KY-038 analog sound sensor - + - + 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 e3b6a15774..8b2bbd07ef 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,8 +9,8 @@ App - - + + 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 00c361971c..34fbb58354 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Lm75/Driver/Lm75.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Lm75/Driver/Lm75.cs @@ -16,11 +16,6 @@ public partial class Lm75 : ByteCommsSensorBase, /// public byte DefaultI2cAddress => (byte)Addresses.Default; - /// - /// Raised when the value of the reading changes - /// - public event EventHandler> TemperatureUpdated = default!; - /// /// The Temperature value from the last reading /// @@ -63,15 +58,5 @@ public Lm75(II2cBus i2cBus, byte address = (byte)Addresses.Default) return Task.FromResult(new Units.Temperature((float)Math.Round(temp, 1), Units.Temperature.UnitType.Celsius)); } - - /// - /// Raise events for subscribers and notify of value changes - /// - /// The updated sensor data - protected override void RaiseEventsAndNotify(IChangeResult changeResult) - { - TemperatureUpdated?.Invoke(this, changeResult); - base.RaiseEventsAndNotify(changeResult); - } } } \ No newline at end of file diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Lm75/Driver/Readme.md b/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Lm75/Driver/Readme.md index c794b35fbf..5fd1c02a50 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Lm75/Driver/Readme.md +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Lm75/Driver/Readme.md @@ -31,7 +31,7 @@ public override Task Initialize() ); lm75.Subscribe(consumer); - lm75.TemperatureUpdated += (object sender, IChangeResult e) => + lm75.Updated += (object sender, IChangeResult e) => { Resolver.Log.Info($"Temperature Updated: {e.New.Celsius:n2}C"); }; 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 3b83dab159..007366efb3 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 @@ -11,7 +11,7 @@ Meadow.Foundation.Sensors.Temperature.Lm75 https://github.com/WildernessLabs/Meadow.Foundation Meadow.Foundation, Temperature, Lm75 - 0.1.51 + 1.7.0 true Lm75 I2C temperature sensor enable @@ -23,8 +23,8 @@ 10.0 - + - + 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 3c9f5c7057..d3811a9b47 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,8 +9,8 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Lm75/Samples/Lm75_Sample/MeadowApp.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Lm75/Samples/Lm75_Sample/MeadowApp.cs index b181f6b162..71c6f56a21 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Lm75/Samples/Lm75_Sample/MeadowApp.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Lm75/Samples/Lm75_Sample/MeadowApp.cs @@ -27,7 +27,7 @@ public override Task Initialize() ); lm75.Subscribe(consumer); - lm75.TemperatureUpdated += (object sender, IChangeResult e) => + lm75.Updated += (object sender, IChangeResult e) => { Resolver.Log.Info($"Temperature Updated: {e.New.Celsius:n2}C"); }; 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 c026f21b38..bc60f570df 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Mcp960x/Driver/Mcp960x.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Mcp960x/Driver/Mcp960x.cs @@ -17,7 +17,7 @@ public abstract partial class Mcp960x : /// public byte DefaultI2cAddress => (byte)Addresses.Default; - private event EventHandler> _temperatureHandlers; + private event EventHandler> _temperatureHandlers = default!; event EventHandler> ISamplingSensor.Updated { 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 cf7e66d32e..ba62dd2145 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 @@ -11,7 +11,7 @@ Meadow.Foundation.Sensors.Temperature.Mcp960x https://github.com/WildernessLabs/Meadow.Foundation Meadow.Foundation,Temperature,Thermocouple,Mcp9600,Mcp9601,Mcp960x - 0.1.0 + 1.7.0 true Mcp960x I2C thermocouple temperature sensor enable @@ -23,8 +23,8 @@ 10.0 - + - + 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 99a09d26f6..7b3429739b 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,8 +9,8 @@ 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 99a09d26f6..7b3429739b 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,8 +9,8 @@ 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 75483cef09..21e8dbfa9a 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Mcp9808/Driver/Mcp9808.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Mcp9808/Driver/Mcp9808.cs @@ -1,6 +1,5 @@ using Meadow.Hardware; using Meadow.Peripherals.Sensors; -using System; using System.Threading.Tasks; namespace Meadow.Foundation.Sensors.Temperature @@ -16,11 +15,6 @@ public partial class Mcp9808 : ByteCommsSensorBase, /// public byte DefaultI2cAddress => (byte)Addresses.Default; - /// - /// Raised when the temperature value changes - /// - public event EventHandler> TemperatureUpdated = default!; - /// /// The temperature, in degrees celsius (°C), from the last reading. /// @@ -109,15 +103,5 @@ public void SetResolution(byte resolution) return Task.FromResult(new Units.Temperature(temp, Units.Temperature.UnitType.Celsius)); } - - /// - /// Raise events for subscribers and notify of value changes - /// - /// The updated sensor data - protected override void RaiseEventsAndNotify(IChangeResult changeResult) - { - TemperatureUpdated?.Invoke(this, changeResult); - base.RaiseEventsAndNotify(changeResult); - } } } \ No newline at end of file diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Mcp9808/Driver/Readme.md b/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Mcp9808/Driver/Readme.md index 226911d021..5133098bb4 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Mcp9808/Driver/Readme.md +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Mcp9808/Driver/Readme.md @@ -31,7 +31,7 @@ public override Task Initialize() ); mcp9808.Subscribe(consumer); - mcp9808.TemperatureUpdated += (object sender, IChangeResult e) => + mcp9808.Updated += (object sender, IChangeResult e) => { Resolver.Log.Info($"Temperature Updated: {e.New.Celsius:N2}C"); }; 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 2276b88a35..4b8f482395 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 @@ -13,15 +13,15 @@ Meadow.Foundation.Sensors.Temperature.Mcp9808 https://github.com/WildernessLabs/Meadow.Foundation Meadow.Foundation, Temperature, MCP9808 - 0.1.21 + 1.7.0 true MCP9808 I2C temperature sensor enable - 10.0 + 10.0 - + - + 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 a2b55bd712..38d62e90b5 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,8 +9,8 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Mcp9808/Samples/Mcp9808_Sample/MeadowApp.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Mcp9808/Samples/Mcp9808_Sample/MeadowApp.cs index ea0d482c5e..3b90abb4f9 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Mcp9808/Samples/Mcp9808_Sample/MeadowApp.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Mcp9808/Samples/Mcp9808_Sample/MeadowApp.cs @@ -28,7 +28,7 @@ public override Task Initialize() ); mcp9808.Subscribe(consumer); - mcp9808.TemperatureUpdated += (object sender, IChangeResult e) => + mcp9808.Updated += (object sender, IChangeResult e) => { Resolver.Log.Info($"Temperature Updated: {e.New.Celsius:N2}C"); }; diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Thermistor/Driver/Readme.md b/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Thermistor/Driver/Readme.md index f38a405d0e..9cf6331440 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Thermistor/Driver/Readme.md +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Thermistor/Driver/Readme.md @@ -31,7 +31,7 @@ public override Task Initialize() ); thermistor.Subscribe(consumer); - thermistor.TemperatureUpdated += (object sender, IChangeResult e) => + thermistor.Updated += (object sender, IChangeResult e) => { Resolver.Log.Info($"Temperature Updated: {e.New.Fahrenheit:N1}F/{e.New.Celsius:N1}C"); }; 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 dcf4b5e7d6..c31e903dc4 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 @@ -11,7 +11,7 @@ Meadow.Foundation.Sensors.Temperature.Thermistor https://github.com/WildernessLabs/Meadow.Foundation Meadow.Foundation,Temperature,Thermistor - 0.1.0 + 1.7.0 true Thermistor analog temperature sensor enable @@ -23,8 +23,8 @@ 10.0 - + - + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Thermistor/Samples/Thermistor_Sample/MeadowApp.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Thermistor/Samples/Thermistor_Sample/MeadowApp.cs index 576d56cf46..41249d34b1 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Thermistor/Samples/Thermistor_Sample/MeadowApp.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Thermistor/Samples/Thermistor_Sample/MeadowApp.cs @@ -29,7 +29,7 @@ public override Task Initialize() ); thermistor.Subscribe(consumer); - thermistor.TemperatureUpdated += (object sender, IChangeResult e) => + thermistor.Updated += (object sender, IChangeResult e) => { Resolver.Log.Info($"Temperature Updated: {e.New.Fahrenheit:N1}F/{e.New.Celsius:N1}C"); }; 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 8455a9007b..bcd664359b 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,8 +9,8 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Tmp102/Driver/Readme.md b/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Tmp102/Driver/Readme.md index 1bf2767264..85f9e974cc 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Tmp102/Driver/Readme.md +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Tmp102/Driver/Readme.md @@ -31,7 +31,7 @@ public override Task Initialize() ); tmp102.Subscribe(consumer); - tmp102.TemperatureUpdated += (object sender, IChangeResult e) => + tmp102.Updated += (object sender, IChangeResult e) => { Resolver.Log.Info($"Temperature Updated: {e.New.Celsius:N2}C"); }; 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 db6250446f..a1039a0c2e 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 @@ -11,7 +11,7 @@ Meadow.Foundation.Sensors.Temperature.Tmp102 https://github.com/WildernessLabs/Meadow.Foundation Meadow.Foundation,Temperature,TMP102 - 0.1.53 + 1.7.0 true TMP102 I2C temperature sensor enable @@ -23,8 +23,8 @@ 10.0 - + - + 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 3da95bf344..cb156d2d09 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Tmp102/Driver/Tmp102.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Tmp102/Driver/Tmp102.cs @@ -1,6 +1,5 @@ using Meadow.Hardware; using Meadow.Peripherals.Sensors; -using System; using System.Threading.Tasks; namespace Meadow.Foundation.Sensors.Temperature @@ -16,11 +15,6 @@ public partial class Tmp102 : ByteCommsSensorBase, /// public byte DefaultI2cAddress => (byte)Addresses.Default; - /// - /// Raised when the temperature value changes - /// - public event EventHandler> TemperatureUpdated = default!; - /// /// Backing variable for the SensorResolution property /// @@ -87,15 +81,5 @@ public Tmp102(II2cBus i2cBus, byte address = (byte)Addresses.Default) return Task.FromResult(new Units.Temperature((float)(sensorReading * 0.0625), Units.Temperature.UnitType.Celsius)); } - - /// - /// Raise change events for subscribers - /// - /// The change result with the current sensor data - protected void RaiseChangedAndNotify(IChangeResult changeResult) - { - TemperatureUpdated?.Invoke(this, changeResult); - base.RaiseEventsAndNotify(changeResult); - } } } \ No newline at end of file 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 62e7408f8b..f9d45862fb 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 @@ -31,7 +31,7 @@ public override Task Initialize() ); tmp102.Subscribe(consumer); - tmp102.TemperatureUpdated += (object sender, IChangeResult e) => + tmp102.Updated += (object sender, IChangeResult e) => { Resolver.Log.Info($"Temperature Updated: {e.New.Celsius:N2}C"); }; 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 9e2297d36f..db00d0b2bb 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,8 +9,8 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Weather.SwitchingAnemometer/Driver/Readme.md b/Source/Meadow.Foundation.Peripherals/Sensors.Weather.SwitchingAnemometer/Driver/Readme.md index 844d68b0ed..4d18a678d9 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Weather.SwitchingAnemometer/Driver/Readme.md +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Weather.SwitchingAnemometer/Driver/Readme.md @@ -22,7 +22,7 @@ public override Task Initialize() anemometer = new SwitchingAnemometer(Device.Pins.A01); //==== classic events example - anemometer.WindSpeedUpdated += (sender, result) => + anemometer.Updated += (sender, result) => { Resolver.Log.Info($"new speed: {result.New.KilometersPerHour:n1}kmh, old: {result.Old?.KilometersPerHour:n1}kmh"); }; 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 d334bb5ccf..8f3eac0867 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 @@ -9,7 +9,7 @@ Meadow.Foundation.Sensors.Weather.SwitchingAnemometer https://github.com/WildernessLabs/Meadow.Foundation Meadow.Foundation,Weather,Wind,Switching,Anemometer - 0.1.17 + 1.7.0 true Digital Switching Anemometer wind speed sensor enable @@ -22,8 +22,8 @@ 10.0 - + - + 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 b48e36c884..4ca8c780ab 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Weather.SwitchingAnemometer/Driver/SwitchingAnemometer.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Weather.SwitchingAnemometer/Driver/SwitchingAnemometer.cs @@ -14,11 +14,6 @@ namespace Meadow.Foundation.Sensors.Weather /// public class SwitchingAnemometer : PollingSensorBase, IAnemometer, IDisposable { - /// - /// Raised when the speed of the wind changes - /// - public event EventHandler> WindSpeedUpdated = default!; - /// /// The current wind speed /// @@ -111,16 +106,6 @@ private void HandleInputPortChange(object sender, DigitalPortResult result) } } - /// - /// Raise events for subscribers and notify of value changes - /// - /// The updated sensor data - protected override void RaiseEventsAndNotify(IChangeResult changeResult) - { - WindSpeedUpdated?.Invoke(this, changeResult); - base.NotifyObservers(changeResult); - } - /// /// Starts continuously sampling the sensor /// diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Weather.SwitchingAnemometer/Samples/SwitchingAnemometer_Sample/MeadowApp.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Weather.SwitchingAnemometer/Samples/SwitchingAnemometer_Sample/MeadowApp.cs index 58da1b055e..bd2efd6a40 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Weather.SwitchingAnemometer/Samples/SwitchingAnemometer_Sample/MeadowApp.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Weather.SwitchingAnemometer/Samples/SwitchingAnemometer_Sample/MeadowApp.cs @@ -18,7 +18,7 @@ public override Task Initialize() anemometer = new SwitchingAnemometer(Device.Pins.A01); //==== classic events example - anemometer.WindSpeedUpdated += (sender, result) => + anemometer.Updated += (sender, result) => { Resolver.Log.Info($"new speed: {result.New.KilometersPerHour:n1}kmh, old: {result.Old?.KilometersPerHour:n1}kmh"); }; 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 651d2fa5e8..6030dce721 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,8 +11,8 @@ - - + + 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 fabcf79bb3..7d1c858928 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 @@ -15,13 +15,13 @@ Meadow.Foundation.Sensors.Weather.SwitchingRainGauge https://github.com/WildernessLabs/Meadow.Foundation Meadow,Meadow.Foundation,Rain,RainGauge - 0.1.7 + 1.7.0 true GPIO rain gauge sensor - + - + 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 ccb6d57e89..e0d7146d44 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,8 +9,8 @@ App - - + + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Weather.WindVane/Driver/Readme.md b/Source/Meadow.Foundation.Peripherals/Sensors.Weather.WindVane/Driver/Readme.md index 086581c9bc..1ec44b9d87 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Weather.WindVane/Driver/Readme.md +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Weather.WindVane/Driver/Readme.md @@ -23,7 +23,7 @@ public override Task Initialize() windVane = new WindVane(Device.Pins.A00); //==== Classic event example: - windVane.WindAzimuthUpdated += (sender, result) => Resolver.Log.Info($"Updated event {result.New.DecimalDegrees}"); + windVane.Updated += (sender, result) => Resolver.Log.Info($"Updated event {result.New.DecimalDegrees}"); //==== IObservable Pattern var observer = WindVane.CreateObserver( 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 6d82686b17..1709ef6e34 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 @@ -15,13 +15,13 @@ Meadow.Foundation.Sensors.Weather.WindVane https://github.com/WildernessLabs/Meadow.Foundation Meadow,Meadow.Foundation,Wind,WindVane - 0.1.22 + 1.7.0 true WindVane analog wind direction sensor - + - + diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Weather.WindVane/Driver/WindVane.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Weather.WindVane/Driver/WindVane.cs index 2cffe57c56..ce27851007 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Weather.WindVane/Driver/WindVane.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Weather.WindVane/Driver/WindVane.cs @@ -20,9 +20,6 @@ namespace Meadow.Foundation.Sensors.Weather /// public partial class WindVane : SamplingSensorBase, IWindVane, IDisposable { - /// - public event EventHandler> WindAzimuthUpdated = default!; - /// /// The last recorded azimuth of the wind /// @@ -159,7 +156,7 @@ protected void HandleAnalogUpdate(IChangeResult result) New = windAzimuth }; WindAzimuth = windAzimuth; - WindAzimuthUpdated?.Invoke(this, windChangeResult); + base.RaiseEventsAndNotify(windChangeResult); } diff --git a/Source/Meadow.Foundation.Peripherals/Sensors.Weather.WindVane/Samples/WindVane_Sample/MeadowApp.cs b/Source/Meadow.Foundation.Peripherals/Sensors.Weather.WindVane/Samples/WindVane_Sample/MeadowApp.cs index 186464c0b3..f6d918c953 100644 --- a/Source/Meadow.Foundation.Peripherals/Sensors.Weather.WindVane/Samples/WindVane_Sample/MeadowApp.cs +++ b/Source/Meadow.Foundation.Peripherals/Sensors.Weather.WindVane/Samples/WindVane_Sample/MeadowApp.cs @@ -21,7 +21,7 @@ public override Task Initialize() windVane = new WindVane(Device.Pins.A00); //==== Classic event example: - windVane.WindAzimuthUpdated += (sender, result) => Resolver.Log.Info($"Updated event {result.New.DecimalDegrees}"); + windVane.Updated += (sender, result) => Resolver.Log.Info($"Updated event {result.New.DecimalDegrees}"); //==== IObservable Pattern var observer = WindVane.CreateObserver( 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 d18077f8fe..150a424bac 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,8 +9,8 @@ App - - + + 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 73da022c4c..15bdb3975c 100644 --- a/Source/Meadow.Foundation.Peripherals/Servos.ServoCore/Driver/Servos.ServoCore.csproj +++ b/Source/Meadow.Foundation.Peripherals/Servos.ServoCore/Driver/Servos.ServoCore.csproj @@ -10,7 +10,7 @@ Meadow.Foundation.Servos.ServoCore https://github.com/WildernessLabs/Meadow.Foundation Meadow,Meadow.Foundation,Servo,Meadow.Foundation.Servo - 0.8.49 + 1.7.0 true PWM generic servo controller enable @@ -22,8 +22,8 @@ 10.0 - + - + 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 d8a0e7895c..b63bd90c8a 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,8 +9,8 @@ App - - + + diff --git a/Source/Meadow.Foundation.sln b/Source/Meadow.Foundation.sln index b3acd6f2ac..b775e6d8f7 100644 --- a/Source/Meadow.Foundation.sln +++ b/Source/Meadow.Foundation.sln @@ -1,3 +1,4 @@ + Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.3.32901.215 @@ -1396,6 +1397,34 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Motors.GpioStepper", "Meado EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GpioStepper_Sample", "Meadow.Foundation.Peripherals\Motors.GpioStepper\Samples\GpioStepper_Sample\GpioStepper_Sample.csproj", "{F570058D-E943-44C6-B0C7-A914009D996F}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "DFRobotGravityDOMeter", "DFRobotGravityDOMeter", "{E144FE5A-48B1-496B-8042-CD0099C04512}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sensors.Environmental.DFRobotGravityDOMeter", "Meadow.Foundation.Peripherals\Sensors.Environmental.DFRobotGravityDOMeter\Driver\Sensors.Environmental.DFRobotGravityDOMeter.csproj", "{CA8E6A39-0CDD-4730-BC37-E33F3348FC1D}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Samples", "Samples", "{EF92E69C-0E9A-4E11-86B2-C0537F440C74}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DFRobotGravityDOMeter_Sample", "Meadow.Foundation.Peripherals\Sensors.Environmental.DFRobotGravityDOMeter\Samples\DFRobotGravityDOMeter_Sample\DFRobotGravityDOMeter_Sample.csproj", "{2C3B5884-5874-4073-AF55-ED01EA4D9FFA}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Amg8833", "Amg8833", "{6CBC4642-3BD1-463B-B759-9AB8A5B22D5C}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sensors.Camera.Amg8833", "Meadow.Foundation.Peripherals\Sensors.Camera.Amg8833\Driver\Sensors.Camera.Amg8833.csproj", "{F15F6DFE-37D1-4E44-973E-E9F7295DAAC5}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Samples", "Samples", "{E608C8E7-1B76-4859-9AF9-C868B5C61994}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Cp2112", "Cp2112", "{087005C6-1E96-490D-94FF-90CF75F10E53}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ICs.IOExpanders.Cp2112", "Meadow.Foundation.Peripherals\ICs.IOExpanders.Cp2112\Driver\ICs.IOExpanders.Cp2112.csproj", "{5A740B20-BD2A-4D8C-B37D-1F5AA0E5355B}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "AsciiConsole", "AsciiConsole", "{E775FF9F-8AC5-4994-B45A-20B50E2B03E2}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Meadow.Displays.AsciiConsole", "Meadow.Foundation.Peripherals\Displays.AsciiConsole\Driver\Meadow.Displays.AsciiConsole.csproj", "{EB5F7986-54CD-4DC0-B045-9C3E1C32E686}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Samples", "Samples", "{40687DAC-F3EF-4F70-850A-0429B9586648}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AsciiConsoleDisplay_Sample", "Meadow.Foundation.Peripherals\Displays.AsciiConsole\Samples\AsciiConsoleDisplay_Sample\AsciiConsoleDisplay_Sample.csproj", "{2F20AD5B-5879-432B-B44F-8540DAEE5C43}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Amg8833_Sample", "Meadow.Foundation.Peripherals\Sensors.Camera.Amg8833\Samples\Amg8833_Sample\Amg8833_Sample.csproj", "{866EA918-39E3-4440-877C-70A3205A3D00}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -3362,6 +3391,46 @@ Global {F570058D-E943-44C6-B0C7-A914009D996F}.Release|Any CPU.ActiveCfg = Release|Any CPU {F570058D-E943-44C6-B0C7-A914009D996F}.Release|Any CPU.Build.0 = Release|Any CPU {F570058D-E943-44C6-B0C7-A914009D996F}.Release|Any CPU.Deploy.0 = Release|Any CPU + {CA8E6A39-0CDD-4730-BC37-E33F3348FC1D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {CA8E6A39-0CDD-4730-BC37-E33F3348FC1D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {CA8E6A39-0CDD-4730-BC37-E33F3348FC1D}.Debug|Any CPU.Deploy.0 = Debug|Any CPU + {CA8E6A39-0CDD-4730-BC37-E33F3348FC1D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {CA8E6A39-0CDD-4730-BC37-E33F3348FC1D}.Release|Any CPU.Build.0 = Release|Any CPU + {CA8E6A39-0CDD-4730-BC37-E33F3348FC1D}.Release|Any CPU.Deploy.0 = Release|Any CPU + {2C3B5884-5874-4073-AF55-ED01EA4D9FFA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2C3B5884-5874-4073-AF55-ED01EA4D9FFA}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2C3B5884-5874-4073-AF55-ED01EA4D9FFA}.Debug|Any CPU.Deploy.0 = Debug|Any CPU + {2C3B5884-5874-4073-AF55-ED01EA4D9FFA}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2C3B5884-5874-4073-AF55-ED01EA4D9FFA}.Release|Any CPU.Build.0 = Release|Any CPU + {2C3B5884-5874-4073-AF55-ED01EA4D9FFA}.Release|Any CPU.Deploy.0 = Release|Any CPU + {F15F6DFE-37D1-4E44-973E-E9F7295DAAC5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F15F6DFE-37D1-4E44-973E-E9F7295DAAC5}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F15F6DFE-37D1-4E44-973E-E9F7295DAAC5}.Debug|Any CPU.Deploy.0 = Debug|Any CPU + {F15F6DFE-37D1-4E44-973E-E9F7295DAAC5}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F15F6DFE-37D1-4E44-973E-E9F7295DAAC5}.Release|Any CPU.Build.0 = Release|Any CPU + {F15F6DFE-37D1-4E44-973E-E9F7295DAAC5}.Release|Any CPU.Deploy.0 = Release|Any CPU + {5A740B20-BD2A-4D8C-B37D-1F5AA0E5355B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5A740B20-BD2A-4D8C-B37D-1F5AA0E5355B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5A740B20-BD2A-4D8C-B37D-1F5AA0E5355B}.Debug|Any CPU.Deploy.0 = Debug|Any CPU + {5A740B20-BD2A-4D8C-B37D-1F5AA0E5355B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5A740B20-BD2A-4D8C-B37D-1F5AA0E5355B}.Release|Any CPU.Build.0 = Release|Any CPU + {5A740B20-BD2A-4D8C-B37D-1F5AA0E5355B}.Release|Any CPU.Deploy.0 = Release|Any CPU + {EB5F7986-54CD-4DC0-B045-9C3E1C32E686}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {EB5F7986-54CD-4DC0-B045-9C3E1C32E686}.Debug|Any CPU.Build.0 = Debug|Any CPU + {EB5F7986-54CD-4DC0-B045-9C3E1C32E686}.Debug|Any CPU.Deploy.0 = Debug|Any CPU + {EB5F7986-54CD-4DC0-B045-9C3E1C32E686}.Release|Any CPU.ActiveCfg = Release|Any CPU + {EB5F7986-54CD-4DC0-B045-9C3E1C32E686}.Release|Any CPU.Build.0 = Release|Any CPU + {EB5F7986-54CD-4DC0-B045-9C3E1C32E686}.Release|Any CPU.Deploy.0 = Release|Any CPU + {2F20AD5B-5879-432B-B44F-8540DAEE5C43}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2F20AD5B-5879-432B-B44F-8540DAEE5C43}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2F20AD5B-5879-432B-B44F-8540DAEE5C43}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2F20AD5B-5879-432B-B44F-8540DAEE5C43}.Release|Any CPU.Build.0 = Release|Any CPU + {866EA918-39E3-4440-877C-70A3205A3D00}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {866EA918-39E3-4440-877C-70A3205A3D00}.Debug|Any CPU.Build.0 = Debug|Any CPU + {866EA918-39E3-4440-877C-70A3205A3D00}.Debug|Any CPU.Deploy.0 = Debug|Any CPU + {866EA918-39E3-4440-877C-70A3205A3D00}.Release|Any CPU.ActiveCfg = Release|Any CPU + {866EA918-39E3-4440-877C-70A3205A3D00}.Release|Any CPU.Build.0 = Release|Any CPU + {866EA918-39E3-4440-877C-70A3205A3D00}.Release|Any CPU.Deploy.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -4060,6 +4129,20 @@ Global {0E21293E-DB39-4B2F-BD3F-639A3C4E521F} = {02E85B22-EA80-46B8-BD76-10926D1D00A3} {88E00348-9C4D-49A2-A927-5923A2A93159} = {FC63A488-29DD-4E30-89BB-507923BC2392} {F570058D-E943-44C6-B0C7-A914009D996F} = {91F3576B-CD16-4364-84E6-3F205F6D9A37} + {E144FE5A-48B1-496B-8042-CD0099C04512} = {78E463DA-0FA1-4AAE-A281-D3297C9388C9} + {CA8E6A39-0CDD-4730-BC37-E33F3348FC1D} = {E144FE5A-48B1-496B-8042-CD0099C04512} + {EF92E69C-0E9A-4E11-86B2-C0537F440C74} = {E144FE5A-48B1-496B-8042-CD0099C04512} + {2C3B5884-5874-4073-AF55-ED01EA4D9FFA} = {EF92E69C-0E9A-4E11-86B2-C0537F440C74} + {6CBC4642-3BD1-463B-B759-9AB8A5B22D5C} = {91DE515A-DFF9-4B75-809C-F56C51222310} + {F15F6DFE-37D1-4E44-973E-E9F7295DAAC5} = {6CBC4642-3BD1-463B-B759-9AB8A5B22D5C} + {E608C8E7-1B76-4859-9AF9-C868B5C61994} = {6CBC4642-3BD1-463B-B759-9AB8A5B22D5C} + {087005C6-1E96-490D-94FF-90CF75F10E53} = {86B81B21-8C90-4A99-B113-FA71F8A6CD8D} + {5A740B20-BD2A-4D8C-B37D-1F5AA0E5355B} = {087005C6-1E96-490D-94FF-90CF75F10E53} + {E775FF9F-8AC5-4994-B45A-20B50E2B03E2} = {2B794146-DFEE-475A-B919-7D3ED48587B8} + {EB5F7986-54CD-4DC0-B045-9C3E1C32E686} = {E775FF9F-8AC5-4994-B45A-20B50E2B03E2} + {40687DAC-F3EF-4F70-850A-0429B9586648} = {E775FF9F-8AC5-4994-B45A-20B50E2B03E2} + {2F20AD5B-5879-432B-B44F-8540DAEE5C43} = {40687DAC-F3EF-4F70-850A-0429B9586648} + {866EA918-39E3-4440-877C-70A3205A3D00} = {E608C8E7-1B76-4859-9AF9-C868B5C61994} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {AF7CA16F-8C38-4546-87A2-5DAAF58A1520}