forked from melkati/CO2-Gadget
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCO2_Gadget_Buttons.h
80 lines (70 loc) · 2.42 KB
/
CO2_Gadget_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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include "Button2.h"
#define LONGCLICK_TIME_MS 300 // https://github.com/LennartHennigs/Button2/issues/10
Button2 btnUp(BTN_UP); // Initialize the up button
Button2 btnDwn(BTN_DWN); // Initialize the down button
void IRAM_ATTR buttonUpISR() {
if(actualDisplayBrightness==0) // Turn on the display only if it's OFF
{
setDisplayBrightness(DisplayBrightness); // Turn on the display at DisplayBrightness brightness
actualDisplayBrightness = DisplayBrightness;
nextTimeToDisplayOff = millis() + (timeToDisplayOff*1000);
}
}
void doubleClick(Button2& btn) {
Serial.println("-->[BUTT] Test double click...");
displayNotification("Test functionality", "double click", notifyInfo);
}
void buttonsInit() {
// Interrupt Service Routine to turn on the display on button UP press
attachInterrupt(BTN_UP, buttonUpISR, RISING);
btnUp.setLongClickTime(LONGCLICK_TIME_MS);
btnUp.setLongClickHandler([](Button2 &b) { nav.doNav(enterCmd); });
btnUp.setClickHandler([](Button2 &b) {
// Up
nav.doNav(downCmd);
});
btnDwn.setLongClickTime(LONGCLICK_TIME_MS);
btnDwn.setLongClickHandler([](Button2 &b) { nav.doNav(escCmd); });
btnDwn.setClickHandler([](Button2 &b) {
// Down
nav.doNav(upCmd);
});
btnDwn.setDoubleClickHandler(doubleClick);
}
void reverseButtons(bool reversed) {
if (reversed) {
// Interrupt Service Routine to turn on the display on button UP press
attachInterrupt(BTN_UP, buttonUpISR, RISING);
btnDwn.setLongClickTime(LONGCLICK_TIME_MS);
btnDwn.setLongClickHandler([](Button2 &b) { nav.doNav(enterCmd); });
btnDwn.setClickHandler([](Button2 &b) {
// Up
nav.doNav(downCmd);
});
btnUp.setLongClickTime(LONGCLICK_TIME_MS);
btnUp.setLongClickHandler([](Button2 &b) { nav.doNav(escCmd); });
btnUp.setClickHandler([](Button2 &b) {
// Down
nav.doNav(upCmd);
});
} else {
attachInterrupt(BTN_DWN, buttonUpISR, RISING);
btnUp.setLongClickTime(LONGCLICK_TIME_MS);
btnUp.setLongClickHandler([](Button2 &b) { nav.doNav(enterCmd); });
btnUp.setClickHandler([](Button2 &b) {
// Up
nav.doNav(downCmd);
});
btnDwn.setLongClickTime(LONGCLICK_TIME_MS);
btnDwn.setLongClickHandler([](Button2 &b) { nav.doNav(escCmd); });
btnDwn.setClickHandler([](Button2 &b) {
// Down
nav.doNav(upCmd);
});
}
}
void buttonsLoop() {
// Check for button presses
btnUp.loop();
btnDwn.loop();
}