8 #ifndef COMPONENTS_ESPECTRO32_SRC_ESPECTRO32_BUTTON_H_
9 #define COMPONENTS_ESPECTRO32_SRC_ESPECTRO32_BUTTON_H_
12 #include "ESPectro32_Constants.h"
19 #define ESPECTRO32_BUTTON_DEBOUNCE_DURATION_MS 30
20 #define ESPECTRO32_BUTTON_PRESS_DURATION_MS 750
21 #define ESPECTRO32_BUTTON_CLICK_DURATION_MS 250
48 ESPectro32ButtonUnknown = 0,
49 ESPectro32ButtonPressed,
50 ESPectro32ButtonReleased,
51 ESPectro32ButtonSecondPressed,
52 ESPectro32ButtonWaitingForLongPressed,
53 ESPectro32ButtonLongPressed
56 typedef std::function<void()> ButtonActionCallback;
66 void start(
void *taskData=
nullptr);
67 Button_State getState();
70 void onButtonDown(ButtonActionCallback cb);
71 void onButtonUp(ButtonActionCallback cb);
72 void onPressed(ButtonActionCallback cb);
73 void onLongPressed(ButtonActionCallback cb);
74 void onDoublePressed(ButtonActionCallback cb);
83 bool activeHigh_ =
false;
84 bool trackLongPressed_ =
false;
85 Button_State buttonState_ = ESPectro32ButtonUnknown;
87 unsigned long lastButtonChangedMillis_ = 0, lastButtonPressedMillis_ = 0;
88 unsigned long checkingStartTime_ = 0, checkingEndTime_ = 0;
89 volatile bool interruptTriggered_ =
false;
90 volatile bool runAlreadyCalled_ =
false;
92 ButtonActionCallback btnDownCallback_;
93 ButtonActionCallback btnUpCallback_;
94 ButtonActionCallback pressedCallback_;
95 ButtonActionCallback longPressedCallback_;
96 ButtonActionCallback doublePressedCallback_;
99 uint8_t pressCount_ = 0;
Encapsulate a runnable task.
Definition: Task.h:34