Library for detecting button clicks, doubleclicks and long press pattern on a single button. Updated to use Callback class when mbed lib >= 122 is used. Then also member functions can be used as callbacks.

Dependents:   ECH_V004

Fork of OneButton by Zibin Zheng

Files at this revision

API Documentation at this revision

Comitter:
JojoS
Date:
Thu Sep 22 21:46:37 2016 +0000
Parent:
2:26960fb1d783
Commit message:
reverted to original state machine behaviour by mh. This works better for detecting click / double click events.

Changed in this revision

OneButton.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/OneButton.cpp	Thu Sep 22 20:36:52 2016 +0000
+++ b/OneButton.cpp	Thu Sep 22 21:46:37 2016 +0000
@@ -143,7 +143,6 @@
     switch (_state) {
         case 0:
             if(button_level == active) {	//start press
-                if(clickFn) clickFn();
                 timer->reset();
                 _state = 1;
             }
@@ -154,6 +153,7 @@
                 _state = 2;
 
             } else if(ticks > _pressTicks) {
+                if(pressFn) pressFn();	//press event
                 if(longPressStartFn) longPressStartFn();
                 _isLongPressed = 1;
                 _state = 5;
@@ -162,12 +162,10 @@
 
         case 2:
             if(ticks > _clickTicks) {	//released
-                //press event
-                if(pressFn) pressFn();	//press event
+                if (clickFn) clickFn();
                 _state = 0;	//reset
 
             } else if(button_level == active) { //press again
-                if(clickFn) clickFn();
                 _state = 3;
             }
             break;