-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathConfigMenu.cpp
More file actions
358 lines (323 loc) · 15 KB
/
ConfigMenu.cpp
File metadata and controls
358 lines (323 loc) · 15 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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
#include "ConfigMenu.h"
#include "core/display.h"
#include "core/i2c_finder.h"
#include "core/main_menu.h"
#include "core/settings.h"
#include "core/utils.h"
#include "core/wifi/wifi_common.h"
#include "../mykeyboard.h"
#ifdef HAS_RGB_LED
#include "core/led_control.h"
#endif
/*********************************************************************
** Function: optionsMenu
** Main Config menu entry point
**********************************************************************/
void ConfigMenu::optionsMenu() {
returnToMenu = false;
while (true) {
// Check if we need to exit to Main Menu (e.g., DevMode disabled)
if (returnToMenu) {
returnToMenu = false; // Reset flag
return;
}
std::vector<Option> localOptions = {
{"Display & UI", [this]() { displayUIMenu(); }},
#ifdef HAS_RGB_LED
{"LED Config", [this]() { ledMenu(); } },
#endif
{"Audio Config", [this]() { audioMenu(); } },
{"System Config", [this]() { systemMenu(); } },
{"Power", [this]() { powerMenu(); } },
};
if (bruceConfig.devMode) {
localOptions.push_back({"Dev Mode", [this]() { devMenu(); }});
}
localOptions.push_back({"About", showDeviceInfo});
localOptions.push_back({"Main Menu", []() {}});
int selected = loopOptions(localOptions, MENU_TYPE_SUBMENU, "Config");
// Exit to Main Menu only if user pressed Back
if (selected == -1 || selected == localOptions.size() - 1) { return; }
// Otherwise rebuild Config menu after submenu returns
}
}
/*********************************************************************
** Function: displayUIMenu
** Display & UI configuration submenu with auto-rebuild
**********************************************************************/
void ConfigMenu::displayUIMenu() {
while (true) {
std::vector<Option> localOptions = {
{"Brightness", [this]() { setBrightnessMenu(); } },
{"Dim Time", [this]() { setDimmerTimeMenu(); } },
{"Orientation", [this]() { lambdaHelper(gsetRotation, true)(); }},
{"UI Color", [this]() { setUIColor(); } },
{"UI Theme", [this]() { setTheme(); } },
{"Back", []() {} },
};
int selected = loopOptions(localOptions, MENU_TYPE_SUBMENU, "Display & UI");
// Exit only if user pressed Back or ESC
if (selected == -1 || selected == localOptions.size() - 1) { return; }
// Otherwise loop continues and menu rebuilds
}
}
/*********************************************************************
** Function: ledMenu
** LED configuration submenu with auto-rebuild for toggles
**********************************************************************/
#ifdef HAS_RGB_LED
void ConfigMenu::ledMenu() {
while (true) {
std::vector<Option> localOptions = {
{"LED Color",
[this]() {
beginLed();
setLedColorConfig();
} },
{"LED Effect",
[this]() {
beginLed();
setLedEffectConfig();
} },
{"LED Brightness",
[this]() {
beginLed();
setLedBrightnessConfig();
} },
{String("LED Blink: ") + (bruceConfig.ledBlinkEnabled ? "ON" : "OFF"),
[this]() {
// Toggle LED blink setting
bruceConfig.ledBlinkEnabled = !bruceConfig.ledBlinkEnabled;
bruceConfig.saveFile();
} },
{"Back", []() {}},
};
int selected = loopOptions(localOptions, MENU_TYPE_SUBMENU, "LED Config");
// Exit only if user pressed Back or ESC
if (selected == -1 || selected == localOptions.size() - 1) { return; }
// Menu rebuilds to update toggle label
}
}
#endif
/*********************************************************************
** Function: audioMenu
** Audio configuration submenu with auto-rebuild for toggles
**********************************************************************/
void ConfigMenu::audioMenu() {
while (true) {
std::vector<Option> localOptions = {
#if !defined(LITE_VERSION)
#if defined(BUZZ_PIN) || defined(HAS_NS4168_SPKR)
{String("Sound: ") + (bruceConfig.soundEnabled ? "ON" : "OFF"),
[this]() {
// Toggle sound setting
bruceConfig.soundEnabled = !bruceConfig.soundEnabled;
bruceConfig.saveFile();
} },
#if defined(HAS_NS4168_SPKR)
{"Sound Volume", [this]() { setSoundVolume(); }},
#endif // BUZZ_PIN || HAS_NS4168_SPKR
#endif // HAS_NS4168_SPKR
#endif // LITE_VERSION
{"Back", []() {} },
};
int selected = loopOptions(localOptions, MENU_TYPE_SUBMENU, "Audio Config");
// Exit only if user pressed Back or ESC
if (selected == -1 || selected == localOptions.size() - 1) { return; }
// Menu rebuilds to update toggle label
}
}
/*********************************************************************
** Function: systemMenu
** System configuration submenu with auto-rebuild for toggles
**********************************************************************/
void ConfigMenu::systemMenu() {
while (true) {
std::vector<Option> localOptions = {
{String("InstaBoot: ") + (bruceConfig.instantBoot ? "ON" : "OFF"),
[this]() {
// Toggle InstaBoot setting
bruceConfig.instantBoot = !bruceConfig.instantBoot;
bruceConfig.saveFile();
} },
{String("WiFi Startup: ") + (bruceConfig.wifiAtStartup ? "ON" : "OFF"),
[this]() {
// Toggle WiFi at startup setting
bruceConfig.wifiAtStartup = !bruceConfig.wifiAtStartup;
bruceConfig.saveFile();
} },
{"Startup App", [this]() { setStartupApp(); } },
{"Hide/Show Apps", [this]() { mainMenu.hideAppsMenu(); }},
{"Clock", [this]() { setClock(); } },
{String("Keyboard Language: ") + bruceConfig.keyboardLang, [this]() { setKeyboardLanguage(); } },
{"Advanced", [this]() { advancedMenu(); } },
{"Back", []() {} },
};
int selected = loopOptions(localOptions, MENU_TYPE_SUBMENU, "System Config");
// Exit only if user pressed Back or ESC
if (selected == -1 || selected == localOptions.size() - 1) { return; }
// Menu rebuilds to update toggle labels
}
}
/*********************************************************************
** Function: advancedMenu
** Advanced settings submenu (nested under System Config)
**********************************************************************/
void ConfigMenu::advancedMenu() {
while (true) {
std::vector<Option> localOptions = {
#if !defined(LITE_VERSION)
{"Toggle BLE API", [this]() { enableBLEAPI(); } },
{"BadUSB/BLE", [this]() { setBadUSBBLEMenu(); } },
#endif
{"Network Creds", [this]() { setNetworkCredsMenu(); }},
{"Factory Reset",
[]() {
// Confirmation dialog for destructive action
drawMainBorder(true);
int8_t choice = displayMessage(
"Are you sure you want\nto Factory Reset?\nAll data will be lost!",
"No",
nullptr,
"Yes",
TFT_RED
);
if (choice == 1) {
// User confirmed - perform factory reset
bruceConfigPins.factoryReset();
bruceConfig.factoryReset(); // Restarts ESP
}
// If cancelled, loop continues and menu rebuilds
} },
{"Back", []() {} },
};
int selected = loopOptions(localOptions, MENU_TYPE_SUBMENU, "Advanced");
// Exit to System Config menu
if (selected == -1 || selected == localOptions.size() - 1) { return; }
// Menu rebuilds after each action
}
}
/*********************************************************************
** Function: powerMenu
** Power management submenu with auto-rebuild
**********************************************************************/
void ConfigMenu::powerMenu() {
while (true) {
std::vector<Option> localOptions = {
{"Deep Sleep", goToDeepSleep },
{"Sleep", setSleepMode },
{"Restart", []() { ESP.restart(); }},
{"Power Off",
[]() {
// Confirmation dialog for power off
drawMainBorder(true);
int8_t choice = displayMessage("Power Off Device?", "No", nullptr, "Yes", TFT_RED);
if (choice == 1) { powerOff(); }
} },
{"Back", []() {} },
};
int selected = loopOptions(localOptions, MENU_TYPE_SUBMENU, "Power Menu");
// Exit to Config menu
if (selected == -1 || selected == localOptions.size() - 1) { return; }
// Menu rebuilds after each action
}
}
/*********************************************************************
** Function: devMenu
** Developer mode menu for advanced hardware configuration
**********************************************************************/
void ConfigMenu::devMenu() {
while (true) {
std::vector<Option> localOptions = {
{"I2C Finder", [this]() { find_i2c_addresses(); } },
{"CC1101 Pins", [this]() { setSPIPinsMenu(bruceConfigPins.CC1101_bus); }},
{"NRF24 Pins", [this]() { setSPIPinsMenu(bruceConfigPins.NRF24_bus); } },
#if !defined(LITE_VERSION)
{"LoRa Pins", [this]() { setSPIPinsMenu(bruceConfigPins.LoRa_bus); } },
{"W5500 Pins", [this]() { setSPIPinsMenu(bruceConfigPins.W5500_bus); } },
#endif
{"SDCard Pins", [this]() { setSPIPinsMenu(bruceConfigPins.SDCARD_bus); }},
{"I2C Pins", [this]() { setI2CPinsMenu(bruceConfigPins.i2c_bus); } },
{"UART Pins", [this]() { setUARTPinsMenu(bruceConfigPins.uart_bus); } },
{"GPS Pins", [this]() { setUARTPinsMenu(bruceConfigPins.gps_bus); } },
{"Serial USB", [this]() { switchToUSBSerial(); } },
{"Serial UART", [this]() { switchToUARTSerial(); } },
{"Disable DevMode", [this]() { bruceConfig.setDevMode(false); } },
{"Back", []() {} },
};
int selected = loopOptions(localOptions, MENU_TYPE_SUBMENU, "Dev Mode");
// Check if "Disable DevMode" was pressed (second-to-last option)
if (selected == localOptions.size() - 2) {
returnToMenu = true; // Signal to exit all Config menus
return;
}
// Exit to Config menu on Back or ESC
if (selected == -1 || selected == localOptions.size() - 1) { return; }
// Menu rebuilds after each action
}
}
/*********************************************************************
** Function: switchToUSBSerial
** Switch serial output to USB Serial
**********************************************************************/
void ConfigMenu::switchToUSBSerial() {
USBserial.setSerialOutput(&Serial);
Serial1.end();
}
/*********************************************************************
** Function: switchToUARTSerial
** Switch serial output to UART (handles pin conflicts)
**********************************************************************/
void ConfigMenu::switchToUARTSerial() {
// Check and resolve SD card pin conflicts
if (bruceConfigPins.SDCARD_bus.checkConflict(bruceConfigPins.uart_bus.rx) ||
bruceConfigPins.SDCARD_bus.checkConflict(bruceConfigPins.uart_bus.tx)) {
sdcardSPI.end();
}
// Check and resolve CC1101/NRF24 pin conflicts
if (bruceConfigPins.CC1101_bus.checkConflict(bruceConfigPins.uart_bus.rx) ||
bruceConfigPins.CC1101_bus.checkConflict(bruceConfigPins.uart_bus.tx) ||
bruceConfigPins.NRF24_bus.checkConflict(bruceConfigPins.uart_bus.rx) ||
bruceConfigPins.NRF24_bus.checkConflict(bruceConfigPins.uart_bus.tx)) {
CC_NRF_SPI.end();
}
// Configure UART pins and switch serial output
pinMode(bruceConfigPins.uart_bus.rx, INPUT);
pinMode(bruceConfigPins.uart_bus.tx, OUTPUT);
Serial1.begin(115200, SERIAL_8N1, bruceConfigPins.uart_bus.rx, bruceConfigPins.uart_bus.tx);
USBserial.setSerialOutput(&Serial1);
}
/*********************************************************************
** Function: drawIcon
** Draw config gear icon
**********************************************************************/
void ConfigMenu::drawIcon(float scale) {
clearIconArea();
int radius = scale * 9;
// Draw 6 gear teeth segments
for (int i = 0; i < 6; i++) {
tft.drawArc(
iconCenterX,
iconCenterY,
3.5 * radius,
2 * radius,
15 + 60 * i,
45 + 60 * i,
bruceConfig.priColor,
bruceConfig.bgColor,
true
);
}
// Draw inner circle
tft.drawArc(
iconCenterX,
iconCenterY,
2.5 * radius,
radius,
0,
360,
bruceConfig.priColor,
bruceConfig.bgColor,
false
);
}