Skip to content

Button transition is not detected correctly when an external resistor is used #2012

@raffaeler

Description

@raffaeler

If an external pull up resistor is wired to the pin button and the user creates the button with PinMode.Input (without internal resistors), the transition in PinStateChanged is not detected correctly.
See: https://github.com/dotnet/iot/blob/main/src/devices/Button/GpioButton.cs#L78

Steps to reproduce

  1. Use an external pull-up resistor
  2. Configure the button with PinMode.Input

The gpio button always need either a pull-up or pull-down. It then can be internal (provided by the board) and configured by PinMode or external.

In order to fix this problem, we may use one of the following strategies:

  1. add a boolean IsExternalResistor (defaulting to false) parameter specifying whether the the PinMode is either InputPullUp or InputPullDown. This is a binary breaking change, but does not break the compilation.
  2. completely remove the the PinMode parameter and add two boolean values:
  • IsPullUp (false means pull-down)
  • IsExternalResistor (false means configured through PinMode)
    This requires the user to make changes in her code.
  1. Add a new constructor overload (eventuallty deprecating the previous ones). This does not break any code (not even binary) but still exhibit the bug when using the old constructors.

With regards to option 2, instead of the two booleans we may introduce an enum with the following fields:

  • PullUpInternal
  • PullUpExternal
  • PullDownInternal
  • PullDownExternal

Metadata

Metadata

Assignees

Labels

Priority:2Work that is important, but not critical for the releasebugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions