|
RSeries astromech firmware
|
|
Go to the documentation of this file.
21 PushButton(
const int pin,
const bool activeLow =
true,
const bool pullupActive =
true) :
23 fButtonPressed(activeLow ? LOW : HIGH),
35 fDebounceTicks = ticks;
60 fClickFunc = callback;
69 fParamClickFunc = callback;
70 fClickFuncParam = param;
79 fDoubleClickFunc = callback;
80 fMaxClicks = max(fMaxClicks, 2);
89 fParamDoubleClickFunc = callback;
90 fDoubleClickFuncParam = param;
91 fMaxClicks = max(fMaxClicks, 2);
100 fMultiClickFunc = callback;
101 fMaxClicks = max(fMaxClicks, 100);
110 fParamMultiClickFunc = callback;
111 fMultiClickFuncParam = param;
112 fMaxClicks = max(fMaxClicks, 100);
121 fLongPressStartFunc = callback;
130 fParamLongPressStartFunc = callback;
131 fLongPressStartFuncParam = param;
140 fLongPressStopFunc = callback;
149 fParamLongPressStopFunc = callback;
150 fLongPressStopFuncParam = param;
159 fDuringLongPressFunc = callback;
168 fParamDuringLongPressFunc = callback;
169 fDuringLongPressFuncParam = param;
177 pinMode(fPin, INPUT_PULLUP);
182 pinMode(fPin, INPUT);
191 unsigned long now = millis();
192 unsigned long waitTime = (now - fStartTime);
194 bool activeLevel = (digitalRead(fPin) == fButtonPressed);
210 if ((!activeLevel) && (waitTime < fDebounceTicks))
213 newState(fLastState);
215 else if (!activeLevel)
220 else if ((activeLevel) && (waitTime > fPressTicks))
222 if (fLongPressStartFunc)
223 fLongPressStartFunc();
224 if (fParamLongPressStartFunc)
225 fParamLongPressStartFunc(fLongPressStartFuncParam);
232 if ((activeLevel) && (waitTime < fDebounceTicks))
235 newState(fLastState);
237 else if (waitTime >= fDebounceTicks)
253 else if ((waitTime > fClickTicks) || (fNClicks == fMaxClicks))
262 fParamClickFunc(fClickFuncParam);
264 else if (fNClicks == 2)
267 if (fDoubleClickFunc)
269 if (fParamDoubleClickFunc)
270 fParamDoubleClickFunc(fDoubleClickFuncParam);
277 if (fParamMultiClickFunc)
278 fParamMultiClickFunc(fMultiClickFuncParam);
288 newState(kPB_PRESSEND);
294 if (fDuringLongPressFunc)
295 fDuringLongPressFunc();
296 if (fParamDuringLongPressFunc)
297 fParamDuringLongPressFunc(fDuringLongPressFuncParam);
303 if ((activeLevel) && (waitTime < fDebounceTicks))
306 newState(fLastState);
308 else if (waitTime >= fDebounceTicks)
310 if (fLongPressStopFunc)
311 fLongPressStopFunc();
312 if (fParamLongPressStopFunc)
313 fParamLongPressStopFunc(fLongPressStopFuncParam);
331 fLastState = kPB_INIT;
351 return fState == kPB_INIT;
359 return fState == kPB_PRESS;
364 unsigned int fDebounceTicks = 50;
365 unsigned int fClickTicks = 400;
366 unsigned int fPressTicks = 800;
374 void *fClickFuncParam = NULL;
378 void *fDoubleClickFuncParam = NULL;
382 void *fMultiClickFuncParam = NULL;
386 void *fLongPressStartFuncParam = NULL;
390 void *fLongPressStopFuncParam;
394 void *fDuringLongPressFuncParam = NULL;
407 void newState(State nextState)
413 State fState = kPB_INIT;
414 State fLastState = kPB_INIT;
416 unsigned long fStartTime;
Base class for all animated devices. AnimatedEvent::animate() is called for each device once through ...
Definition: AnimatedEvent.h:18
Base class for all devices that require setup that cannot happen in the constructor....
Definition: SetupEvent.h:15