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

util/debounce: Debouncing / hysteresis utility pkg #1268

Merged
merged 1 commit into from Jul 13, 2018

Conversation

ccollins476ad
Copy link
Contributor

I needed this utility for something, and I thought it was generally useful enough to be added to core. Perhaps this would be better placed in a different repo.

I struggled a lot deciding on a width for the integers in struct debouncer. uint32_t requires a bit more memory than I was comfortable with. I thought about using macros to define several instances of the API (debouncer8, debouncer16, debouncer32), but that was making the code too complicated to be readable. I also considered a single syscfg setting which determined the integer width for all debouncers, but I didn't think that was very useful, and it still made the interface difficult to read due to the need for macros. In the end, I just settled on what I think works in most cases: uint16_t.

Copy link
Contributor

@andrzej-kaczmarek andrzej-kaczmarek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, just one comment to consider.

* false if the debouncer is in the low state.
*/
static inline bool
debouncer_high(const debouncer_t *debouncer)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would make it return int instead with 0 for low, 1 for high - just as logic state.
and change name to debouncer_get/state_get/read or something like this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, Andrzej. I have changed debouncer_high to debouncer_state, and made it return 0 or 1 rather than a bool.

@ccollins476ad ccollins476ad merged commit 03c38be into apache:master Jul 13, 2018
@ccollins476ad ccollins476ad deleted the debounce branch July 13, 2018 00:26
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