mathertel / OneButton

An Arduino library for using a single button for multiple purpose input.
http://www.mathertel.de/Arduino/OneButtonLibrary.aspx
Other
920 stars 230 forks source link

Feature request to supplement the callback model with an explicit call model. #107

Closed 6v6gt-duino closed 1 year ago

6v6gt-duino commented 1 year ago

Feature request to supplement the callback model with an explicit call model. The callback model as implemented in this library is useful in that it allows the user specifies a custom function to be called on an button event. However, a direct call model such as: if ( button1.wasPressed() ) { /* do something*/} would also be useful. Of course, the user could implement such features in his/her own code using the existing library mechanism by specifying a call back function which sets a global variable, say bool button1_pressed, and a matching function, say button1_wasPressed() which returns the value of button1_pressed and also resets it. But this is clumsy, does not scale up well and it would be better (and easy to do) if this were implemented in the library itself. Minor additional feature request. Replace intwith int16_t(or something smaller if possible), to minimise storage use especially on platforms where int is actually 4 bytes. BTW the state machine used in this library is very nicely presented here: https://www.mathertel.de/Arduino/OneButtonLibrary.aspx

mathertel commented 1 year ago

Thank. You gave the answer in your question. :) your wasPressed() can be implemented as you line out. However this is already implementing functionality above the state machine level and should be application (sketch) specific. e.g. your wasPressed() function is auto-clearing the event ? -> more parameter to the library to control the behavior. and every addition will make the firmware bigger and I try to keep it small to be used in Arduino Projects.