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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support setting custom active_state for InputDevice #1099

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Makman2
Copy link

@Makman2 Makman2 commented Oct 28, 2023

I hit the same limitation as described in #921. I use normally-closed switches for my experimental setup and needed to change the active_state parameter of Button to something else while using an internal pull-up or pull-down resistor to avoid soldering something and keep the experimental setup simple.

As I commented in the issue, I went with following approach from the possibilities proposed by the original author of the issue @pmlk:

Only when active_state is None should active_state be set automatically based on pull_up.

I left the other suggestion (which I think would be useful too), because it can be discussed separately and done in another PR:

When both active_state is None and pull_up is None ("floating"), set active_state=True as a sensible default, rather than throwing an exception.

Please refer to my other reasonings in my above mentioned comment. I am now lazy to copy them here 馃槢

Unit tests execute successfully skipping the real-pin tests.

I hope I have read everything correctly under the contributing page.

Properly supports now normally-closed switches with an internal
pull-up/pull-down resistor as well together with normally-open switches.

Before an exception was raised when attempting to modify the active state
while specifying the `pull_up` parameter. This was rather an artificial
limitation which is now lifted.

Like before, by default it assumed that a button or switch is normally-open
which is a common assumption and keeps the code backwards-compatible.
In this case specifying the `active_state` parameter is not necessary.

Closes gpiozero#921.
@fuslwusl
Copy link

Is there any progress with this topic? I have the same problem and need a way to handle normally-closed switches.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants