dotnet / iot

This repo includes .NET Core implementations for various IoT boards, chips, displays and PCBs.
MIT License
2.12k stars 574 forks source link

ButtonBase.IsPressed not properly initialized #2328

Open RevZero opened 5 days ago

RevZero commented 5 days ago

Describe the bug

After initializing a GpioButton, the IsPressed property is always false, even if the logical state (depending on active low/high configuration) of the pin is true.

Steps to reproduce This examples assumes pin 16 being externally pulled up, having a switch connected which is currently pulling the input low.

var gpio = new GpioController(PinNumberingScheme.Logical, new RaspberryPi3Driver());
var input = new GpioButton(16, true, false, gpio, false);
Assert.That(input.IsPressed); // This fails but IsPressed should be true, because the input is low active and being pulled down.
var pin = gpio.OpenPin(16, PinMode.InputPullUp);
Assert.That(pin.Read() == PinValue.Low); // Passes as expected
input.IsPressed = pin.Read() == PinValue.Low;  // Manually set the initial state as a workaround.

Expected behavior IsPressed should be initialized according to the initial pin state instead after the first transition.

Versions used

krwq commented 3 days ago

[Triage] @RevZero can you try with both LibGpiodDriver, SysFsDriver and RaspberryPi3Driver directly and see if that makes any difference? If you haven't done yet please make sure you have installed libgpiod (with i.e. apt)