PushDuration maps n callback functions to the duration of a button press. E.g. foo() is called when a button is released after 1 second where bar() is called after 3 seconds.
Fork of PushDuration by
Revision 3:d2aec01c8227, committed 2016-08-20
- Comitter:
- jensstruemper
- Date:
- Sat Aug 20 18:58:48 2016 +0000
- Parent:
- 2:126fed923ada
- Commit message:
- few changes on Pushduration (reversed pullup and rise / fall logic)
Changed in this revision
PushDuration.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 126fed923ada -r d2aec01c8227 PushDuration.cpp --- a/PushDuration.cpp Wed Aug 17 09:29:41 2016 +0000 +++ b/PushDuration.cpp Sat Aug 20 18:58:48 2016 +0000 @@ -32,17 +32,18 @@ ticker.detach(); } -void ButtonHandler::press() { +void ButtonHandler::release() { counter = 0; ticker.attach(this, &ButtonHandler::secondsCount, intervalInSeconds); } +void ButtonHandler::press() { + ticker.detach(); + react(counter); + counter = 0; +} + void ButtonHandler::secondsCount() { ++counter; + printf("counter: %d\n", counter); } - -void ButtonHandler::release() { - ticker.detach(); - react(counter); - counter = 0; -} \ No newline at end of file