-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbutton.cpp
More file actions
166 lines (137 loc) · 4.3 KB
/
button.cpp
File metadata and controls
166 lines (137 loc) · 4.3 KB
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#include <Button2.h>
#include <driver/rtc_io.h>
#include "button.h"
#include "debug.h"
#include "network.h"
#include "tft.h"
long _drawGraphCurveType = 0;
long _drawGraphFlightNbr = 0;
bool _displayGraph;
Button2 btn(BUTTON_GPIO); // Initialize the down button
void handleButtonLoop() {
btn.loop();
}
void handleButtonClick() {
Serial.println(F("handleButtonClick!!!!"));
// if (!_displayGraph)
// return;
// long lastFlightNbr = _flightLogger.instance.geFlightNbrsLast();
// _drawGraphCurveType++;
// // Make sure we have not reach the last flight
// if ((lastFlightNbr > _drawGraphFlightNbr) & (_drawGraphCurveType > 4) ) {
// _drawGraphFlightNbr ++;
// _drawGraphCurveType = 0;
// }
// else {
// // if not lets go back to the first one if it exists
// if (!((lastFlightNbr < 1))) {
// if (_drawGraphCurveType > 4) {
// _drawGraphFlightNbr = 1;
// _drawGraphCurveType = 0;
// }
// }
// }
// #ifdef DEBUG
// Serial.print(F("Flight:"));
// Serial.println(_drawGraphFlightNbr);
// Serial.print(F("type:"));
// Serial.println(_drawGraphCurveType);
// #endif
// drawTftGraphFlightNbr(_drawGraphFlightNbr, _drawGraphCurveType);
}
void handleButtonLongClick_Display() {
// Serial.println(F("handleButtonLongClick_Display!!!!"));
// if (!_displayGraph) {
// long lastFlightNbr = _flightLogger.instance.geFlightNbrsLast();
// #ifdef DEBUG
// Serial.print(F("lastFlightNbr:"));
// Serial.println(lastFlightNbr);
// #endif
// if (!(lastFlightNbr < 1)) {
// _displayGraph = true;
// _drawGraphFlightNbr = 1;
// drawTftGraphFlightNbr(_drawGraphFlightNbr, _drawGraphCurveType);
// }
// }
// else {
// _displayGraph = false;
// _tft.init();
// _tft.fillScreen(TFT_BLACK);
// // Graph area is 200 pixels wide, 150 high, dark grey background
// _graphWidget.createGraph(200, 100, _tft.color565(5, 5, 5));
// // x scale units is from 0 to 100, y scale units is 0 to 50
// _graphWidget.setGraphScale(0.0, 100.0, 0, 50.0);
// }
}
void handleButtonLongClick_Exit() {
Serial.println(F("handleButtonLongClick_Exit!!!!"));
//Serial.println(F("Turning off"));
// sleepDevice();
}
void handleButtonLongClick_Network() {
Serial.println(F("Button Command requests - network...."));
if (networkEnabled()) {
Serial.println(F("\tNetwork is currently enabled...."));
Serial.println(F("...disabling network."));
networkDisable();
drawTftSplash();
return;
}
Serial.println(F("...enabling network."));
networkStart();
drawTftSplash();
}
void handleButtonLongClick_FlightLogErase() {
Serial.println(F("handleButtonLongClick_10!!!!"));
// // erasing flights...
// _displayGraph = false;
// _tft.init();
// _tft.fillScreen(TFT_BLACK);
// // Graph area is 200 pixels wide, 150 high, dark grey background
// _graphWidget.createGraph(200, 100, _tft.color565(5, 5, 5));
// // x scale units is from 0 to 100, y scale units is 0 to 50
// _graphWidget.setGraphScale(0.0, 100.0, 0, 50.0);
// Serial.println(F("Erasing flights!!!"));
// // erasing flights
// _flightLogger.instance.clearFlights();
}
void handleButtonLongClick(Button2 button) {
Serial.println(F("handleButtonLongClick!!!!"));
unsigned int time = button.wasPressedFor();
debug(F("time"), time);
// if (time >= 10000) {
// // handleButtonLongClick_FlightLogErase();
// return;
// }
if (time >= 10000) {
handleButtonLongClick_Exit();
return;
}
// Exit
if (time >= 5000 & time < 10000) {
handleButtonLongClick_Network();
return;
}
if (time >= 1000 & time < 5000) {
handleButtonLongClick_Display();
return;
}
}
void setupButton() {
Serial.println(F("\nSetup button..."));
btn.setClickHandler([](Button2 & b) {
// Down
Serial.println(F("Button Down fast")); // It's called upCmd because it increases the index of an array. Visually that would mean the selector goes downwards.
handleButtonClick();
});
btn.setLongClickHandler([](Button2 & b) {
Serial.println(F("Button Down slow"));
handleButtonLongClick(b);
});
Serial.println(F("...button successful."));
}
void setupButtonDeninit() {
pinMode(BUTTON_GPIO, INPUT_PULLUP);
rtc_gpio_hold_en(BUTTON_GPIO);
esp_sleep_enable_ext0_wakeup(BUTTON_GPIO, LOW);
}