@@ -82,13 +82,29 @@ void OneButton::attachClick(callbackFunction newFunction)
82
82
} // attachClick
83
83
84
84
85
+ // save function for parameterized click event
86
+ void OneButton::attachClick (parameterizedCallbackFunction newFunction, void * parameter)
87
+ {
88
+ _paramClickFunc = newFunction;
89
+ _clickFuncParam = parameter;
90
+ } // attachClick
91
+
92
+
85
93
// save function for doubleClick event
86
94
void OneButton::attachDoubleClick (callbackFunction newFunction)
87
95
{
88
96
_doubleClickFunc = newFunction;
89
97
} // attachDoubleClick
90
98
91
99
100
+ // save function for parameterized doubleClick event
101
+ void OneButton::attachDoubleClick (parameterizedCallbackFunction newFunction, void * parameter)
102
+ {
103
+ _paramDoubleClickFunc = newFunction;
104
+ _doubleClickFuncParam = parameter;
105
+ } // attachDoubleClick
106
+
107
+
92
108
// save function for press event
93
109
// DEPRECATED, is replaced by attachLongPressStart, attachLongPressStop,
94
110
// attachDuringLongPress,
@@ -103,18 +119,39 @@ void OneButton::attachLongPressStart(callbackFunction newFunction)
103
119
_longPressStartFunc = newFunction;
104
120
} // attachLongPressStart
105
121
122
+ // save function for parameterized longPressStart event
123
+ void OneButton::attachLongPressStart (parameterizedCallbackFunction newFunction, void * parameter)
124
+ {
125
+ _paramLongPressStartFunc = newFunction;
126
+ _longPressStartFuncParam = parameter;
127
+ } // attachLongPressStart
128
+
106
129
// save function for longPressStop event
107
130
void OneButton::attachLongPressStop (callbackFunction newFunction)
108
131
{
109
132
_longPressStopFunc = newFunction;
110
133
} // attachLongPressStop
111
134
135
+ // save function for parameterized longPressStop event
136
+ void OneButton::attachLongPressStop (parameterizedCallbackFunction newFunction, void * parameter)
137
+ {
138
+ _paramLongPressStopFunc = newFunction;
139
+ _longPressStopFuncParam = parameter;
140
+ } // attachLongPressStop
141
+
112
142
// save function for during longPress event
113
143
void OneButton::attachDuringLongPress (callbackFunction newFunction)
114
144
{
115
145
_duringLongPressFunc = newFunction;
116
146
} // attachDuringLongPress
117
147
148
+ // save function for parameterized during longPress event
149
+ void OneButton::attachDuringLongPress (parameterizedCallbackFunction newFunction, void * parameter)
150
+ {
151
+ _paramDuringLongPressFunc = newFunction;
152
+ _duringLongPressFuncParam = parameter;
153
+ } // attachDuringLongPress
154
+
118
155
// function to get the current long pressed state
119
156
bool OneButton::isLongPressed (){
120
157
return _isLongPressed;
@@ -178,8 +215,12 @@ void OneButton::tick(bool activeLevel)
178
215
_pressFunc ();
179
216
if (_longPressStartFunc)
180
217
_longPressStartFunc ();
218
+ if (_paramLongPressStartFunc)
219
+ _paramLongPressStartFunc (_longPressStartFuncParam);
181
220
if (_duringLongPressFunc)
182
221
_duringLongPressFunc ();
222
+ if (_paramDuringLongPressFunc)
223
+ _paramDuringLongPressFunc (_duringLongPressFuncParam);
183
224
_state = 6 ; // step to state 6
184
225
_stopTime = now; // remember stopping time
185
226
} else {
@@ -188,11 +229,13 @@ void OneButton::tick(bool activeLevel)
188
229
189
230
} else if (_state == 2 ) {
190
231
// waiting for menu pin being pressed the second time or timeout.
191
- if (_doubleClickFunc == NULL ||
232
+ if (( _doubleClickFunc == NULL && _paramDoubleClickFunc == NULL ) ||
192
233
(unsigned long )(now - _startTime) > _clickTicks) {
193
234
// this was only a single short click
194
235
if (_clickFunc)
195
236
_clickFunc ();
237
+ if (_paramClickFunc)
238
+ _paramClickFunc (_clickFuncParam);
196
239
_state = 0 ; // restart.
197
240
198
241
} else if ((activeLevel) &&
@@ -209,6 +252,8 @@ void OneButton::tick(bool activeLevel)
209
252
// this was a 2 click sequence.
210
253
if (_doubleClickFunc)
211
254
_doubleClickFunc ();
255
+ if (_paramDoubleClickFunc)
256
+ _paramDoubleClickFunc (_doubleClickFuncParam);
212
257
_state = 0 ; // restart.
213
258
_stopTime = now; // remember stopping time
214
259
} // if
@@ -219,13 +264,17 @@ void OneButton::tick(bool activeLevel)
219
264
_isLongPressed = false ; // Keep track of long press state
220
265
if (_longPressStopFunc)
221
266
_longPressStopFunc ();
267
+ if (_paramLongPressStopFunc)
268
+ _paramLongPressStopFunc (_longPressStopFuncParam);
222
269
_state = 0 ; // restart.
223
270
_stopTime = now; // remember stopping time
224
271
} else {
225
272
// button is being long pressed
226
273
_isLongPressed = true ; // Keep track of long press state
227
274
if (_duringLongPressFunc)
228
275
_duringLongPressFunc ();
276
+ if (_paramDuringLongPressFunc)
277
+ _paramDuringLongPressFunc (_duringLongPressFuncParam);
229
278
} // if
230
279
231
280
} // if
0 commit comments