-
Notifications
You must be signed in to change notification settings - Fork 5
/
buttons.h
66 lines (57 loc) · 1.41 KB
/
buttons.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
58
59
60
61
62
63
64
65
// ASM Keypad class
// Created 2012 By Colin G http://www.diydrones.com/profile/ColinG
enum BUTTON_IDS {
B_NONE = 0,
B_UP,
B_DOWN,
B_LEFT,
B_RIGHT,
B_OK,
B_CANCEL,
B_ENCODER,
// Extra enumerations for holding buttons
B_OK_HOLD,
B_CANCEL_HOLD
};
//#define B_UP 1
//#define B_DOWN 2
//#define B_LEFT 3
//#define B_RIGHT 4
//#define B_OK 5
//#define B_CANCEL 6
//#define B_ENCODER 7
enum KEYPAD_ORIENTATIONS {
// Define which side the connector is on (jDrones v1.2 button board)
KP_CONN_RIGHT = 0,
KP_CONN_DOWN,
KP_CONN_LEFT,
KP_CONN_UP
};
/// Button timing behaviour
#define BUTTON_DEBOUNCE_TIMER 10 /// Debounce timer (milliseconds)
#define BUTTON_HOLD_TIMER 500 /// Button repeat/hold delay (milliseconds)
#define BUTTON_REPEAT_TIMER 150 /// Button repeat period (milliseconds)
class Buttons {
public:
Buttons() {
_scanStart = millis();
_lastPress = millis();
_currentButton = 0;
_buttonHolding = 0;
_scanCode = 0;
_scanCodeLast = 0;
};
uint8_t pressed(void);
private:
uint8_t _scan(void); // Determine which button is being pressed
uint8_t _scanDebounced(void); // Perform debounce
uint8_t _currentButton;
long _scanStart;
uint8_t _scanCode;
uint8_t _scanCodeLast;
long _lastPress;
boolean _buttonHolding;
/// Functions for talking to the i2c expander
void expanderWrite(byte _data);
byte expanderRead(void);
};