@@ -56,7 +56,7 @@ class OneButton
56
56
*/
57
57
[[deprecated(" Use setDebounceMs() instead." )]]
58
58
void setDebounceTicks (const unsigned int ms) { setDebounceMs (ms); }; // deprecated
59
- void setDebounceMs (const unsigned int ms);
59
+ void setDebounceMs (const int ms);
60
60
61
61
/* *
62
62
* set # millisec after single click is assumed.
@@ -85,6 +85,13 @@ class OneButton
85
85
86
86
// ----- Attach events functions -----
87
87
88
+ /* *
89
+ * Attach an event to be called immediately when a depress is detected.
90
+ * @param newFunction This function will be called when the event has been detected.
91
+ */
92
+ void attachPress (callbackFunction newFunction);
93
+ void attachPress (parameterizedCallbackFunction newFunction, void *parameter);
94
+
88
95
/* *
89
96
* Attach an event to be called when a single click is detected.
90
97
* @param newFunction This function will be called when the event has been detected.
@@ -177,7 +184,7 @@ class OneButton
177
184
178
185
private:
179
186
int _pin = -1 ; // hardware pin number.
180
- unsigned int _debounce_ms = 50 ; // number of msecs for debounce times.
187
+ int _debounce_ms = 50 ; // number of msecs for debounce times.
181
188
unsigned int _click_ms = 400 ; // number of msecs before a click is detected.
182
189
unsigned int _press_ms = 800 ; // number of msecs before a long button press is detected
183
190
unsigned int _idle_ms = 1000 ; // number of msecs before idle is detected
@@ -187,6 +194,10 @@ class OneButton
187
194
// HIGH if the button connects the input pin to VCC when pressed.
188
195
189
196
// These variables will hold functions acting as event source.
197
+ callbackFunction _pressFunc = NULL ;
198
+ parameterizedCallbackFunction _paramPressFunc = NULL ;
199
+ void *_pressFuncParam = NULL ;
200
+
190
201
callbackFunction _clickFunc = NULL ;
191
202
parameterizedCallbackFunction _paramClickFunc = NULL ;
192
203
void *_clickFuncParam = NULL ;
@@ -241,8 +252,8 @@ class OneButton
241
252
242
253
bool _idleState = false ;
243
254
244
- int debouncedPinLevel = - 1 ;
245
- int _lastDebouncePinLevel = - 1 ; // used for pin debouncing
255
+ bool debouncedLevel = false ;
256
+ bool _lastDebounceLevel = false ; // used for pin debouncing
246
257
unsigned long _lastDebounceTime = 0 ; // millis()
247
258
unsigned long now = 0 ; // millis()
248
259
@@ -256,8 +267,8 @@ class OneButton
256
267
public:
257
268
int pin () const { return _pin; };
258
269
stateMachine_t state () const { return _state; };
259
- int debounce (const int value);
260
- int debouncedValue () const { return debouncedPinLevel ; };
270
+ bool debounce (const bool value);
271
+ int debouncedValue () const { return debouncedLevel ; };
261
272
262
273
/* *
263
274
* @brief Use this function in the DuringLongPress and LongPressStop events to get the time since the button was pressed.
0 commit comments