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

InputPin debounce support #49

Open
TheBerkin opened this issue Jun 3, 2020 · 0 comments
Open

InputPin debounce support #49

TheBerkin opened this issue Jun 3, 2020 · 0 comments

Comments

@TheBerkin
Copy link

TheBerkin commented Jun 3, 2020

I'm using this library on a Pi Zero W to interface with an old rotary phone, and switch transitions definitely aren't clean 100% of the time.

Previously I have used the gpiozero Python library, which has the option to "debounce" inputs: a user-supplied time delay controls how soon before new input states can be registered. As far as I can tell, this crate does not have any such capability.

What I would love to see is a new method for InputPin that sets a debounce time using a Duration. This might work something like the following:

const BCM_INPUT: u8 = 2;
let gpio = Gpio::new()?;
// Ignore state changes on `button` less than 50 ms apart.
let debounce_time = Duration::from_millis(50);
let button = gpio.get(BCM_INPUT)?.into_input_pulldown().debounce(debounce_time);
// ...

Of course, I could implement my own debouncing code on top of rppal, but I strongly feel that this is something that should be implemented in this crate directly, as debouncing digital inputs from switches is an extremely common practice.

@TheBerkin TheBerkin changed the title input debounce support InputPin debounce support Jun 3, 2020
@golemparts golemparts self-assigned this Feb 14, 2021
@golemparts golemparts added this to To do in Release 0.14.0 Apr 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

No branches or pull requests

2 participants