@@ -78,6 +78,11 @@ class OneButton
78
78
*/
79
79
void setLongPressIntervalMs (const unsigned int ms) { _long_press_interval_ms = ms; };
80
80
81
+ /* *
82
+ * set # millisec after idle is assumed.
83
+ */
84
+ void setIdleMs (const unsigned int ms);
85
+
81
86
// ----- Attach events functions -----
82
87
83
88
/* *
@@ -123,6 +128,12 @@ class OneButton
123
128
void attachDuringLongPress (callbackFunction newFunction);
124
129
void attachDuringLongPress (parameterizedCallbackFunction newFunction, void *parameter);
125
130
131
+ /* *
132
+ * Attach an event when the button is in idle position.
133
+ * @param newFunction
134
+ */
135
+ void attachIdle (callbackFunction newFunction);
136
+
126
137
// ----- State machine functions -----
127
138
128
139
/* *
@@ -169,6 +180,7 @@ class OneButton
169
180
unsigned int _debounce_ms = 50 ; // number of msecs for debounce times.
170
181
unsigned int _click_ms = 400 ; // number of msecs before a click is detected.
171
182
unsigned int _press_ms = 800 ; // number of msecs before a long button press is detected
183
+ unsigned int _idle_ms = 1000 ; // number of msecs before idle is detected
172
184
173
185
int _buttonPressed = 0 ; // this is the level of the input pin when the button is pressed.
174
186
// LOW if the button connects the input pin to GND when pressed.
@@ -199,6 +211,8 @@ class OneButton
199
211
parameterizedCallbackFunction _paramDuringLongPressFunc = NULL ;
200
212
void *_duringLongPressFuncParam = NULL ;
201
213
214
+ callbackFunction _idleFunc = NULL ;
215
+
202
216
// These variables that hold information across the upcoming tick calls.
203
217
// They are initialized once on program start and are updated every time the
204
218
// tick function is called.
@@ -225,6 +239,8 @@ class OneButton
225
239
226
240
stateMachine_t _state = OCS_INIT;
227
241
242
+ bool _idleState = false ;
243
+
228
244
int debouncedPinLevel = -1 ;
229
245
int _lastDebouncePinLevel = -1 ; // used for pin debouncing
230
246
unsigned long _lastDebounceTime = 0 ; // millis()
0 commit comments