Todo : Allow the selection of debounce algorithm from the sketch instead of adding a define to the source #87

Open
opened 2022-03-29 03:00:40 +03:00 by thomasfredericks · 1 comment
thomasfredericks commented 2022-03-29 03:00:40 +03:00 (Migrated from github.com)
  • The debounce algorithm can only be changed by adding a #define in the source file Bounce.h.
  • Selection of the debounce algorithm should be allowed from the sketch instead.
- The _debounce_ algorithm can only be changed by adding a `#define` in the source file `Bounce.h`. - Selection of the _debounce_ algorithm should be allowed from the sketch instead.
username115 commented 2023-06-18 15:56:04 +03:00 (Migrated from github.com)

A quick glance through the source tells me that this is because the defines are tested using precompiler statements in Bounce2.cpp instead of Bounce2.h.

An easy solution for this is to define each behavior in their own member functions and have an inline function in the header call the appropriate one based on the state of the precompiler definitions.

If these can be mixed within the same execution, making these individual functions public could allow users to call them depending on the desired behavior at any point during run, defaulting to the one specified by precompiler. If they can't be mixed, these should be made private or protected.

If more flexibility is desired, the desired method could be made an enumeration and passed as part of the constructor, so multiple Bounce objects could be instantiated using different methods for debouncing. This approach would break the existing interface as it pertains to selection of debouncing method.

If you'd like, I can try implementing the first method I suggested and create a Pull Request. I don't have a good way to validate the fix easily accessible, however.

A quick glance through the source tells me that this is because the defines are tested using precompiler statements in `Bounce2.cpp` instead of `Bounce2.h`. An easy solution for this is to define each behavior in their own member functions and have an inline function in the header call the appropriate one based on the state of the precompiler definitions. If these can be mixed within the same execution, making these individual functions public could allow users to call them depending on the desired behavior at any point during run, defaulting to the one specified by precompiler. If they can't be mixed, these should be made `private` or `protected`. If more flexibility is desired, the desired method could be made an enumeration and passed as part of the constructor, so multiple `Bounce` objects could be instantiated using different methods for debouncing. This approach would break the existing interface as it pertains to selection of debouncing method. If you'd like, I can try implementing the first method I suggested and create a Pull Request. I don't have a good way to validate the fix easily accessible, however.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Max/thomasfredericks_Bounce2#87