25 #ifndef ACE_BUTTON_ACE_BUTTON_H 26 #define ACE_BUTTON_ACE_BUTTON_H 29 #include "ButtonConfig.h" 124 explicit AceButton(uint8_t pin = 0, uint8_t defaultReleasedState = HIGH,
139 void init(uint8_t pin = 0, uint8_t defaultReleasedState = HIGH,
144 return mButtonConfig;
153 mButtonConfig = buttonConfig;
171 uint8_t
getPin() ACE_BUTTON_INLINE {
return mPin; }
174 uint8_t
getId() ACE_BUTTON_INLINE {
return mId; }
193 return mLastButtonState;
247 void setPin(uint8_t pin) ACE_BUTTON_INLINE { mPin = pin; }
256 void setDefaultReleasedState(uint8_t state);
259 void setId(uint8_t
id) ACE_BUTTON_INLINE { mId = id; }
264 static const uint8_t kFlagDefaultReleasedState = 0x01;
265 static const uint8_t kFlagDebouncing = 0x02;
266 static const uint8_t kFlagPressed = 0x04;
267 static const uint8_t kFlagClicked = 0x08;
268 static const uint8_t kFlagDoubleClicked = 0x10;
269 static const uint8_t kFlagLongPressed = 0x20;
270 static const uint8_t kFlagRepeatPressed = 0x40;
271 static const uint8_t kFlagClickPostponed = 0x80;
277 bool isDebouncing() ACE_BUTTON_INLINE {
278 return mFlags & kFlagDebouncing;
281 void setDebouncing() ACE_BUTTON_INLINE {
282 mFlags |= kFlagDebouncing;
285 void clearDebouncing() ACE_BUTTON_INLINE {
286 mFlags &= ~kFlagDebouncing;
290 bool isPressed() ACE_BUTTON_INLINE {
291 return mFlags & kFlagPressed;
294 void setPressed() ACE_BUTTON_INLINE {
295 mFlags |= kFlagPressed;
298 void clearPressed() ACE_BUTTON_INLINE {
299 mFlags &= ~kFlagPressed;
303 bool isClicked() ACE_BUTTON_INLINE {
304 return mFlags & kFlagClicked;
307 void setClicked() ACE_BUTTON_INLINE {
308 mFlags |= kFlagClicked;
311 void clearClicked() ACE_BUTTON_INLINE {
312 mFlags &= ~kFlagClicked;
317 bool isDoubleClicked() ACE_BUTTON_INLINE {
318 return mFlags & kFlagDoubleClicked;
321 void setDoubleClicked() ACE_BUTTON_INLINE {
322 mFlags |= kFlagDoubleClicked;
325 void clearDoubleClicked() ACE_BUTTON_INLINE {
326 mFlags &= ~kFlagDoubleClicked;
331 bool isLongPressed() ACE_BUTTON_INLINE {
332 return mFlags & kFlagLongPressed;
335 void setLongPressed() ACE_BUTTON_INLINE {
336 mFlags |= kFlagLongPressed;
339 void clearLongPressed() ACE_BUTTON_INLINE {
340 mFlags &= ~kFlagLongPressed;
344 bool isRepeatPressed() ACE_BUTTON_INLINE {
345 return mFlags & kFlagRepeatPressed;
348 void setRepeatPressed() ACE_BUTTON_INLINE {
349 mFlags |= kFlagRepeatPressed;
352 void clearRepeatPressed() ACE_BUTTON_INLINE {
353 mFlags &= ~kFlagRepeatPressed;
356 bool isClickPostponed() ACE_BUTTON_INLINE {
357 return mFlags & kFlagClickPostponed;
360 void setClickPostponed() ACE_BUTTON_INLINE {
361 mFlags |= kFlagClickPostponed;
364 void clearClickPostponed() ACE_BUTTON_INLINE {
365 mFlags &= ~kFlagClickPostponed;
373 bool checkDebounced(uint16_t now, uint8_t buttonState);
381 bool checkInitialized(uint16_t buttonState);
384 void checkEvent(uint16_t now, uint8_t buttonState);
387 void checkLongPress(uint16_t now, uint8_t buttonState);
390 void checkRepeatPress(uint16_t now, uint8_t buttonState);
393 void checkChanged(uint16_t now, uint8_t buttonState);
399 void checkReleased(uint16_t now, uint8_t buttonState);
402 void checkPressed(uint16_t now, uint8_t buttonState);
405 void checkClicked(uint16_t now);
411 void checkDoubleClicked(uint16_t now);
421 void checkOrphanedClick(uint16_t now);
427 void checkPostponedClick(uint16_t now);
475 void handleEvent(uint8_t eventType);
483 uint16_t mLastDebounceTime;
484 uint16_t mLastClickTime;
485 uint16_t mLastPressTime;
486 uint16_t mLastRepeatPressTime;
495 uint8_t mLastButtonState;