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

Revision:
3:48a593e2d4cf
Parent:
2:26960fb1d783
diff -r 26960fb1d783 -r 48a593e2d4cf OneButton.cpp
--- 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;