Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Obsolete PinNumberingScheme #2358

Merged
merged 14 commits into from
Nov 14, 2024
4 changes: 2 additions & 2 deletions eng/ArduinoCsCI.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ REM Second argument is either "Debug" or "Release"
if %1!==! goto :usage

REM Defines the revision to check out in the ExtendedConfigurableFirmata repo
set FIRMATA_SIMULATOR_CHECKOUT_REVISION=66b1863f3a4b0999f2c1cb7133332cbd25730252
set FIRMATA_SIMULATOR_CHECKOUT_REVISION=18ef6b3a890b34904904663fb2cece9141600849
set RUN_COMPILER_TESTS=FALSE

choco install -y --no-progress arduino-cli
Expand All @@ -22,7 +22,7 @@ powershell -ExecutionPolicy ByPass -command "%~dp0common\Build.ps1" -restore -bu
set ArduinoRootDir=%1\Documents\Arduino
set acspath=%~dp0\..\artifacts\bin\Frontend\%2\net6.0\acs.exe

git clone https://github.com/firmata/ConfigurableFirmata %ArduinoRootDir%\libraries\ConfigurableFirmata
git clone https://github.com/firmata/ConfigurableFirmata %ArduinoRootDir%\libraries\ConfigurableFirmata --branch BuildIssueEsp
git clone https://github.com/pgrawehr/ExtendedConfigurableFirmata %ArduinoRootDir%\ExtendedConfigurableFirmata
arduino-cli core install esp32:esp32

Expand Down
2 changes: 1 addition & 1 deletion samples/M5StackRemoteDisplay/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public static int Main(string[] args)

private static GpioController GetGpioControllerFromFt4222()
{
return new GpioController(PinNumberingScheme.Logical, new Ft4222Gpio());
return new GpioController(new Ft4222Gpio());
}

private static SpiDevice GetSpiFromFt4222()
Expand Down
2 changes: 1 addition & 1 deletion samples/led-more-blinking-lights/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
volume = Volume.EnableVolume();

Console.WriteLine($"Let's blink some LEDs!");
using GpioController controller = new GpioController(PinNumberingScheme.Logical);
using GpioController controller = new GpioController();
controller.OpenPin(ledOne, PinMode.Output);
controller.OpenPin(ledTwo, PinMode.Output);
controller.OpenPin(ledThree, PinMode.Output);
Expand Down
354 changes: 243 additions & 111 deletions src/Iot.Device.Bindings/CompatibilitySuppressions.xml

Large diffs are not rendered by default.

26 changes: 14 additions & 12 deletions src/System.Device.Gpio.Tests/GpioControllerSoftwareTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ public void Dispose()
[Fact]
public void PinCountReportedCorrectly()
{
var ctrl = new GpioController(PinNumberingScheme.Logical, _mockedGpioDriver.Object);
var ctrl = new GpioController(_mockedGpioDriver.Object);
Assert.Equal(28, ctrl.PinCount);
}

[Fact]
public void OpenTwiceGpioPinAndClosedTwiceThrows()
{
var ctrl = new GpioController(PinNumberingScheme.Logical, _mockedGpioDriver.Object);
var ctrl = new GpioController(_mockedGpioDriver.Object);
_mockedGpioDriver.Setup(x => x.OpenPinEx(1));
_mockedGpioDriver.Setup(x => x.ClosePinEx(1));
GpioPin gpioPin1 = ctrl.OpenPin(1);
Expand All @@ -50,7 +50,7 @@ public void WriteInputPinDoesNotThrow()
_mockedGpioDriver.Setup(x => x.IsPinModeSupportedEx(1, It.IsAny<PinMode>())).Returns(true);
_mockedGpioDriver.Setup(x => x.SetPinModeEx(1, It.IsAny<PinMode>()));
_mockedGpioDriver.Setup(x => x.GetPinModeEx(1)).Returns(PinMode.Input);
var ctrl = new GpioController(PinNumberingScheme.Logical, _mockedGpioDriver.Object);
var ctrl = new GpioController(_mockedGpioDriver.Object);

ctrl.OpenPin(1, PinMode.Input);
ctrl.Write(1, PinValue.High);
Expand All @@ -64,7 +64,7 @@ public void GpioControllerCreateOpenClosePin()
_mockedGpioDriver.Setup(x => x.GetPinModeEx(1)).Returns(PinMode.Output);
_mockedGpioDriver.Setup(x => x.WriteEx(1, PinValue.High));
_mockedGpioDriver.Setup(x => x.ClosePinEx(1));
var ctrl = new GpioController(PinNumberingScheme.Logical, _mockedGpioDriver.Object);
var ctrl = new GpioController(_mockedGpioDriver.Object);
Assert.NotNull(ctrl);
ctrl.OpenPin(1, PinMode.Output);
Assert.True(ctrl.IsPinOpen(1));
Expand All @@ -77,7 +77,7 @@ public void GpioControllerCreateOpenClosePin()
public void IsPinModeSupported()
{
_mockedGpioDriver.Setup(x => x.IsPinModeSupportedEx(1, PinMode.Input)).Returns(true);
var ctrl = new GpioController(PinNumberingScheme.Logical, _mockedGpioDriver.Object);
var ctrl = new GpioController(_mockedGpioDriver.Object);
Assert.NotNull(ctrl);
Assert.True(ctrl.IsPinModeSupported(1, PinMode.Input));
}
Expand All @@ -87,7 +87,7 @@ public void GetPinMode()
{
_mockedGpioDriver.Setup(x => x.OpenPinEx(1));
_mockedGpioDriver.Setup(x => x.GetPinModeEx(1)).Returns(PinMode.Output);
var ctrl = new GpioController(PinNumberingScheme.Logical, _mockedGpioDriver.Object);
var ctrl = new GpioController(_mockedGpioDriver.Object);
Assert.NotNull(ctrl);
// Not open
Assert.Throws<InvalidOperationException>(() => ctrl.GetPinMode(1));
Expand All @@ -96,6 +96,7 @@ public void GetPinMode()
}

[Fact]
[Obsolete("Tests an obsolete feature")]
public void UsingBoardNumberingWorks()
{
// Our mock driver maps physical pin 2 to logical pin 1
Expand All @@ -122,14 +123,15 @@ public void UsingLogicalNumberingDisposesTheRightPin()
_mockedGpioDriver.Setup(x => x.ClosePinEx(1));
_mockedGpioDriver.Setup(x => x.IsPinModeSupportedEx(1, PinMode.Output)).Returns(true);
_mockedGpioDriver.Setup(x => x.GetPinModeEx(1)).Returns(PinMode.Output);
var ctrl = new GpioController(PinNumberingScheme.Logical, _mockedGpioDriver.Object);
var ctrl = new GpioController(_mockedGpioDriver.Object);
ctrl.OpenPin(1, PinMode.Output);
ctrl.Write(1, PinValue.High);
// No close on the pin here, we want to check that the Controller's Dispose works correctly
ctrl.Dispose();
}

[Fact]
[Obsolete("Tests obsolete features")]
public void UsingBoardNumberingDisposesTheRightPin()
pgrawehr marked this conversation as resolved.
Show resolved Hide resolved
{
// Our mock driver maps physical pin 2 to logical pin 1
Expand All @@ -151,7 +153,7 @@ public void CallbackOnEventWorks()
_mockedGpioDriver.Setup(x => x.OpenPinEx(1));
_mockedGpioDriver.Setup(x => x.AddCallbackForPinValueChangedEventEx(1,
PinEventTypes.Rising, It.IsAny<PinChangeEventHandler>()));
var ctrl = new GpioController(PinNumberingScheme.Logical, _mockedGpioDriver.Object);
var ctrl = new GpioController(_mockedGpioDriver.Object);
ctrl.OpenPin(1); // logical pin 1 on our test board
bool callbackSeen = false;
PinChangeEventHandler eventHandler = (sender, args) =>
Expand Down Expand Up @@ -183,7 +185,7 @@ public void WriteSpan()
_mockedGpioDriver.Setup(x => x.WriteEx(2, PinValue.Low));
_mockedGpioDriver.Setup(x => x.ClosePinEx(1));
_mockedGpioDriver.Setup(x => x.ClosePinEx(2));
var ctrl = new GpioController(PinNumberingScheme.Logical, _mockedGpioDriver.Object);
var ctrl = new GpioController(_mockedGpioDriver.Object);
Assert.NotNull(ctrl);
ctrl.OpenPin(1, PinMode.Output);
ctrl.OpenPin(2, PinMode.Output);
Expand All @@ -208,7 +210,7 @@ public void ReadSpan()
_mockedGpioDriver.Setup(x => x.ReadEx(2)).Returns(PinValue.High);
_mockedGpioDriver.Setup(x => x.ClosePinEx(1));
_mockedGpioDriver.Setup(x => x.ClosePinEx(2));
var ctrl = new GpioController(PinNumberingScheme.Logical, _mockedGpioDriver.Object);
var ctrl = new GpioController(_mockedGpioDriver.Object);
Assert.NotNull(ctrl);
ctrl.OpenPin(1, PinMode.Input);
ctrl.OpenPin(2, PinMode.Input);
Expand Down Expand Up @@ -238,7 +240,7 @@ public void ReadSpan()
[Fact]
public async Task WaitForEventAsyncFail()
{
var ctrl = new GpioController(PinNumberingScheme.Logical, _mockedGpioDriver.Object);
var ctrl = new GpioController(_mockedGpioDriver.Object);
_mockedGpioDriver.Setup(x => x.OpenPinEx(1));
_mockedGpioDriver.Setup(x => x.IsPinModeSupportedEx(1, PinMode.Input)).Returns(true);
_mockedGpioDriver.Setup(x => x.WaitForEventEx(1, PinEventTypes.Rising | PinEventTypes.Falling, It.IsAny<CancellationToken>()))
Expand All @@ -260,7 +262,7 @@ public async Task WaitForEventAsyncFail()
[Fact]
public void WaitForEventSuccess()
{
var ctrl = new GpioController(PinNumberingScheme.Logical, _mockedGpioDriver.Object);
var ctrl = new GpioController(_mockedGpioDriver.Object);
_mockedGpioDriver.Setup(x => x.OpenPinEx(1));
_mockedGpioDriver.Setup(x => x.IsPinModeSupportedEx(1, PinMode.Input)).Returns(true);
_mockedGpioDriver.Setup(x => x.WaitForEventEx(1, PinEventTypes.Rising | PinEventTypes.Falling, It.IsAny<CancellationToken>()))
Expand Down
Loading