-
Notifications
You must be signed in to change notification settings - Fork 0
/
input.h
57 lines (36 loc) · 1.13 KB
/
input.h
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#ifndef INPUT_HANDLER_H
#define INPUT_HANDLER_H
#include <Encoder.h>
#define DEBOUNCE_MILLIS 150
#define LONG_PRESS_MILLIS 1500
#define MAIN_BUTTON_PIN 5
#define ENCODER_CLOCK_PIN 12
#define ENCODER_DATA_PIN 14
#define PING_BUTTON_PIN 4
class InputHandler {
public:
void setupInputs();
void checkInputs();
// Must set this before setupInputs() to work!
void setOnStartupMainDown(void(*functionPointer)());
void setOnRotation(void(*functionPointer)(long));
void setOnPushedRotation(void(*functionPointer)(long));
void setOnMainDown(void(*functionPointer)());
void setOnMainLongDown(void(*functionPointer)());
void setOnPingDown(void(*functionPointer)());
private:
Encoder encoder{ENCODER_DATA_PIN, ENCODER_CLOCK_PIN};
long oldEncoderPos = 0;
int oldMainButtonState = HIGH;
unsigned long lastMainButtonUpdate = 0;
bool wasLongMainPress = false;
int oldPingButtonState = HIGH;
unsigned long lastPingButtonUpdate = 0;
void (*onStartupMainDown)();
void (*onRotation)(long);
void (*onPushedRotation)(long);
void (*onMainDown)();
void (*onMainLongDown)();
void (*onPingDown)();
};
#endif