-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbutton_handler.h
More file actions
39 lines (29 loc) · 847 Bytes
/
button_handler.h
File metadata and controls
39 lines (29 loc) · 847 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#pragma once
#include <Arduino.h>
class ButtonHandler {
public:
ButtonHandler(uint8_t pin, unsigned long longPressTime = 3000);
void begin();
virtual void onShortPress() {};
virtual void onLongPress() {};
private:
static void buttonTask(void *parameter);
const uint8_t buttonPin;
const unsigned long longPressTime;
struct ButtonState {
bool lastState = HIGH;
bool currentState = HIGH;
unsigned long pressedTime = 0;
bool isLongPressHandled = false;
SemaphoreHandle_t mutex;
};
ButtonState state;
};
// Main button
class BindicatorButton : public ButtonHandler {
public:
BindicatorButton(uint8_t pin, unsigned long longPressTime = 3000)
: ButtonHandler(pin, longPressTime) {}
void onShortPress() override;
void onLongPress() override;
};