dotnet / dotnet/iot

ButtonBase.IsPressed not properly initialized

Open
#2,328 1 comment 0 reactions 1 assignee Claimed by @raffaeler View on GitHub
bug Priority:3 up-for-grabs
Dominant language
C#
Stars
2.4k
Forks
630
Avg merge
11d 3h
Merged PRs (30d)
2

Description

**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.
```csharp
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**
- net8.0 self-contained
- Version of `System.Device.Gpio` package: 3.1.0

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.