forked from meshtastic/firmware
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMenuApplet.cpp
More file actions
2027 lines (1659 loc) · 73.3 KB
/
Copy pathMenuApplet.cpp
File metadata and controls
2027 lines (1659 loc) · 73.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
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
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#ifdef MESHTASTIC_INCLUDE_INKHUD
#include "./MenuApplet.h"
#include "DisplayFormatters.h"
#include "GPS.h"
#include "MeshService.h"
#include "RTC.h"
#include "Router.h"
#include "airtime.h"
#include "main.h"
#include "mesh/generated/meshtastic/deviceonly.pb.h"
#include "power.h"
#include <RadioLibInterface.h>
#include <target_specific.h>
#if defined(ARCH_ESP32) && HAS_WIFI
#include "mesh/wifi/WiFiAPClient.h"
#include <WiFi.h>
#include <esp_wifi.h>
#endif
using namespace NicheGraphics;
static constexpr uint8_t MENU_TIMEOUT_SEC = 60; // How many seconds before menu auto-closes
// Options for the "Recents" menu
// These are offered to users as possible values for settings.recentlyActiveSeconds
static constexpr uint8_t RECENTS_OPTIONS_MINUTES[] = {2, 5, 10, 30, 60, 120};
struct PositionPrecisionOption {
uint8_t value; // proto value
const char *metric;
const char *imperial;
};
static constexpr PositionPrecisionOption POSITION_PRECISION_OPTIONS[] = {
{32, "Precise", "Precise"}, {19, "50 m", "150 ft"}, {18, "90 m", "300 ft"}, {17, "200 m", "600 ft"},
{16, "350 m", "0.2 mi"}, {15, "700 m", "0.5 mi"}, {14, "1.5 km", "0.9 mi"}, {13, "2.9 km", "1.8 mi"},
{12, "5.8 km", "3.6 mi"}, {11, "12 km", "7.3 mi"}, {10, "23 km", "15 mi"},
};
InkHUD::MenuApplet::MenuApplet() : concurrency::OSThread("MenuApplet")
{
// No timer tasks at boot
OSThread::disable();
// Note: don't get instance if we're not actually using the backlight,
// or else you will unintentionally instantiate it
if (settings->optionalMenuItems.backlight) {
backlight = Drivers::LatchingBacklight::getInstance();
}
// Initialize the Canned Message store
// This is a shared nicheGraphics component
// - handles loading & parsing the canned messages
// - handles setting / getting of canned messages via apps (Client API Admin Messages)
cm.store = CannedMessageStore::getInstance();
}
void InkHUD::MenuApplet::onForeground()
{
// We do need this before we render, but we can optimize by just calculating it once now
systemInfoPanelHeight = getSystemInfoPanelHeight();
// Force Region page ONLY when explicitly requested (one-shot)
if (inkhud->forceRegionMenu) {
inkhud->forceRegionMenu = false; // consume one-shot flag
showPage(MenuPage::REGION);
} else {
showPage(MenuPage::ROOT);
}
// If device has a backlight which isn't controlled by aux button:
// backlight on always when menu opens.
// Courtesy to T-Echo users who removed the capacitive touch button
if (settings->optionalMenuItems.backlight) {
assert(backlight);
if (!backlight->isOn())
backlight->peek();
}
// Prevent user applets requesting update while menu is open
// Handle button input with this applet
SystemApplet::lockRequests = true;
SystemApplet::handleInput = true;
// Begin the auto-close timeout
OSThread::setIntervalFromNow(MENU_TIMEOUT_SEC * 1000UL);
OSThread::enabled = true;
freeTextMode = false;
// Upgrade the refresh to FAST, for guaranteed responsiveness
inkhud->forceUpdate(EInk::UpdateTypes::FAST);
}
void InkHUD::MenuApplet::onBackground()
{
// Discard any data we generated while selecting a canned message
// Frees heap mem
freeCannedMessageResources();
// If device has a backlight which isn't controlled by aux button:
// Item in options submenu allows keeping backlight on after menu is closed
// If this item is deselected we will turn backlight off again, now that menu is closing
if (settings->optionalMenuItems.backlight) {
assert(backlight);
if (!backlight->isLatched())
backlight->off();
}
// Stop the auto-timeout
OSThread::disable();
// Resume normal rendering and button behavior of user applets
SystemApplet::lockRequests = false;
SystemApplet::handleInput = false;
handleFreeText = false;
// Restore the user applet whose tile we borrowed
if (borrowedTileOwner)
borrowedTileOwner->bringToForeground();
Tile *t = getTile();
t->assignApplet(borrowedTileOwner); // Break our link with the tile, (and relink it with real owner, if it had one)
borrowedTileOwner = nullptr;
// Need to force an update, as a polite request wouldn't be honored, seeing how we are now in the background
// We're only updating here to upgrade from UNSPECIFIED to FAST, to ensure responsiveness when exiting menu
inkhud->forceUpdate(EInk::UpdateTypes::FAST);
}
// Open the menu
// Parameter specifies which user-tile the menu will use
// The user applet originally on this tile will be restored when the menu closes
void InkHUD::MenuApplet::show(Tile *t)
{
// Remember who *really* owns this tile
borrowedTileOwner = t->getAssignedApplet();
// Hide the owner, if it is a valid applet
if (borrowedTileOwner)
borrowedTileOwner->sendToBackground();
// Break the owner's link with tile
// Relink it to menu applet
t->assignApplet(this);
// Show menu
bringToForeground();
}
// Auto-exit the menu applet after a period of inactivity
// The values shown on the root menu are only a snapshot: they are not re-rendered while the menu remains open.
// By exiting the menu, we prevent users mistakenly believing that the data will update.
int32_t InkHUD::MenuApplet::runOnce()
{
// runOnce's interval is pushed back when a button is pressed
// If we do actually run, it means no button input occurred within MENU_TIMEOUT_SEC,
// so we close the menu.
showPage(EXIT);
// Timer should disable after firing
// This is redundant, as onBackground() will also disable
return OSThread::disable();
}
static void applyLoRaRegion(meshtastic_Config_LoRaConfig_RegionCode region)
{
if (config.lora.region == region)
return;
config.lora.region = region;
auto changes = SEGMENT_CONFIG;
#if !(MESHTASTIC_EXCLUDE_PKI_KEYGEN || MESHTASTIC_EXCLUDE_PKI)
if (crypto) {
crypto->ensurePkiKeys(config.security, owner);
}
#endif
config.lora.tx_enabled = true;
initRegion();
if (myRegion && myRegion->dutyCycle < 100) {
config.lora.ignore_mqtt = true;
}
if (strncmp(moduleConfig.mqtt.root, default_mqtt_root, strlen(default_mqtt_root)) == 0) {
sprintf(moduleConfig.mqtt.root, "%s/%s", default_mqtt_root, myRegion->name);
changes |= SEGMENT_MODULECONFIG;
}
// Notify UI that changes are being applied
InkHUD::InkHUD::getInstance()->notifyApplyingChanges();
service->reloadConfig(changes);
rebootAtMsec = millis() + DEFAULT_REBOOT_SECONDS * 1000;
}
static void applyDeviceRole(meshtastic_Config_DeviceConfig_Role role)
{
if (config.device.role == role)
return;
config.device.role = role;
nodeDB->saveToDisk(SEGMENT_CONFIG);
service->reloadConfig(SEGMENT_CONFIG);
// Notify UI that changes are being applied
InkHUD::InkHUD::getInstance()->notifyApplyingChanges();
rebootAtMsec = millis() + DEFAULT_REBOOT_SECONDS * 1000;
}
static void applyLoRaPreset(meshtastic_Config_LoRaConfig_ModemPreset preset)
{
if (config.lora.modem_preset == preset)
return;
config.lora.use_preset = true;
config.lora.modem_preset = preset;
nodeDB->saveToDisk(SEGMENT_CONFIG);
service->reloadConfig(SEGMENT_CONFIG);
// Notify UI that changes are being applied
InkHUD::InkHUD::getInstance()->notifyApplyingChanges();
rebootAtMsec = millis() + DEFAULT_REBOOT_SECONDS * 1000;
}
static const char *getTimezoneLabelFromValue(const char *tzdef)
{
if (!tzdef || !*tzdef)
return "Unset";
// Must match TIMEZONE menu entries
if (strcmp(tzdef, "HST10") == 0)
return "US/Hawaii";
if (strcmp(tzdef, "AKST9AKDT,M3.2.0,M11.1.0") == 0)
return "US/Alaska";
if (strcmp(tzdef, "PST8PDT,M3.2.0,M11.1.0") == 0)
return "US/Pacific";
if (strcmp(tzdef, "MST7") == 0)
return "US/Arizona";
if (strcmp(tzdef, "MST7MDT,M3.2.0,M11.1.0") == 0)
return "US/Mountain";
if (strcmp(tzdef, "CST6CDT,M3.2.0,M11.1.0") == 0)
return "US/Central";
if (strcmp(tzdef, "EST5EDT,M3.2.0,M11.1.0") == 0)
return "US/Eastern";
if (strcmp(tzdef, "BRT3") == 0)
return "BR/Brasilia";
if (strcmp(tzdef, "UTC0") == 0)
return "UTC";
if (strcmp(tzdef, "GMT0BST,M3.5.0/1,M10.5.0") == 0)
return "EU/Western";
if (strcmp(tzdef, "CET-1CEST,M3.5.0,M10.5.0/3") == 0)
return "EU/Central";
if (strcmp(tzdef, "EET-2EEST,M3.5.0/3,M10.5.0/4") == 0)
return "EU/Eastern";
if (strcmp(tzdef, "IST-5:30") == 0)
return "Asia/Kolkata";
if (strcmp(tzdef, "HKT-8") == 0)
return "Asia/Hong Kong";
if (strcmp(tzdef, "AWST-8") == 0)
return "AU/AWST";
if (strcmp(tzdef, "ACST-9:30ACDT,M10.1.0,M4.1.0/3") == 0)
return "AU/ACST";
if (strcmp(tzdef, "AEST-10AEDT,M10.1.0,M4.1.0/3") == 0)
return "AU/AEST";
if (strcmp(tzdef, "NZST-12NZDT,M9.5.0,M4.1.0/3") == 0)
return "Pacific/NZ";
return tzdef; // fallback for unknown/custom values
}
static void applyTimezone(const char *tz)
{
if (!tz || strcmp(config.device.tzdef, tz) == 0)
return;
strncpy(config.device.tzdef, tz, sizeof(config.device.tzdef));
config.device.tzdef[sizeof(config.device.tzdef) - 1] = '\0';
setenv("TZ", config.device.tzdef, 1);
nodeDB->saveToDisk(SEGMENT_CONFIG);
service->reloadConfig(SEGMENT_CONFIG);
}
// Perform action for a menu item, then change page
// Behaviors for MenuActions are defined here
void InkHUD::MenuApplet::execute(MenuItem item)
{
// Perform an action
// ------------------
switch (item.action) {
// Open a submenu without performing any action
// Also handles exit
case NO_ACTION:
if (currentPage == MenuPage::NODE_CONFIG_CHANNELS && item.nextPage == MenuPage::NODE_CONFIG_CHANNEL_DETAIL) {
// cursor - 1 because index 0 is "Back"
selectedChannelIndex = cursor - 1;
}
break;
case NEXT_TILE:
inkhud->nextTile();
// Unselect menu item after tile change
cursorShown = false;
cursor = 0;
break;
case SEND_PING:
service->refreshLocalMeshNode();
service->trySendPosition(NODENUM_BROADCAST, true);
// Force the next refresh to use FULL, to protect the display, as some users will probably spam this button
inkhud->forceUpdate(Drivers::EInk::UpdateTypes::FULL);
break;
case FREE_TEXT:
OSThread::enabled = false;
handleFreeText = true;
cm.freeTextItem.rawText.erase(); // clear the previous freetext message
freeTextMode = true; // render input field instead of normal menu
// Open the on-screen keyboard only for full joystick devices
if (settings->joystick.enabled && !inkhud->twoWayRocker)
inkhud->openKeyboard();
break;
case STORE_CANNEDMESSAGE_SELECTION:
if (!settings->joystick.enabled || inkhud->twoWayRocker)
cm.selectedMessageItem = &cm.messageItems.at(cursor - 1); // Minus one: offset for the initial "Send Ping" entry
else
cm.selectedMessageItem = &cm.messageItems.at(cursor - 2); // Minus two: offset for the "Send Ping" and free text entry
break;
case SEND_CANNEDMESSAGE:
cm.selectedRecipientItem = &cm.recipientItems.at(cursor);
// send selected message
sendText(cm.selectedRecipientItem->dest, cm.selectedRecipientItem->channelIndex, cm.selectedMessageItem->rawText.c_str());
inkhud->forceUpdate(Drivers::EInk::UpdateTypes::FULL); // Next refresh should be FULL. Lots of button pressing to get here
break;
case ROTATE:
inkhud->rotate();
break;
case ALIGN_JOYSTICK:
inkhud->openAlignStick();
break;
case LAYOUT:
// Todo: smarter incrementing of tile count
settings->userTiles.count++;
if (settings->userTiles.count == 3) // Skip 3 tiles: not done yet
settings->userTiles.count++;
if (settings->userTiles.count > settings->userTiles.maxCount) // Loop around if tile count now too high
settings->userTiles.count = 1;
inkhud->updateLayout();
break;
case TOGGLE_APPLET:
if (item.checkState) {
*item.checkState = !(*item.checkState);
inkhud->updateAppletSelection();
}
break;
case TOGGLE_AUTOSHOW_APPLET:
// Toggle settings.userApplets.autoshow[] value, via MenuItem::checkState pointer set in populateAutoshowPage()
if (item.checkState) {
*item.checkState = !(*item.checkState);
}
break;
case TOGGLE_NOTIFICATIONS:
if (item.checkState) {
*item.checkState = !(*item.checkState);
}
break;
case TOGGLE_INVERT_COLOR:
if (config.display.displaymode == meshtastic_Config_DisplayConfig_DisplayMode_INVERTED)
config.display.displaymode = meshtastic_Config_DisplayConfig_DisplayMode_DEFAULT;
else
config.display.displaymode = meshtastic_Config_DisplayConfig_DisplayMode_INVERTED;
nodeDB->saveToDisk(SEGMENT_CONFIG);
break;
case SET_RECENTS: {
// cursor - 1 because index 0 is "Back"
const uint8_t index = cursor - 1;
constexpr uint8_t optionCount = sizeof(RECENTS_OPTIONS_MINUTES) / sizeof(RECENTS_OPTIONS_MINUTES[0]);
assert(index < optionCount);
settings->recentlyActiveSeconds = RECENTS_OPTIONS_MINUTES[index] * 60;
break;
}
case SHUTDOWN:
LOG_INFO("Shutting down from menu");
shutdownAtMsec = millis();
// Menu is then sent to background via onShutdown
break;
case TOGGLE_BATTERY_ICON:
inkhud->toggleBatteryIcon();
break;
case TOGGLE_BACKLIGHT:
// Note: backlight is already on in this situation
// We're marking that it should *remain* on once menu closes
assert(backlight);
if (backlight->isLatched())
backlight->off();
else
backlight->latch();
break;
case TOGGLE_12H_CLOCK:
config.display.use_12h_clock = !config.display.use_12h_clock;
nodeDB->saveToDisk(SEGMENT_CONFIG);
break;
case TOGGLE_GPS:
#if !MESHTASTIC_EXCLUDE_GPS && HAS_GPS
if (config.position.gps_mode == meshtastic_Config_PositionConfig_GpsMode_DISABLED) {
config.position.gps_mode = meshtastic_Config_PositionConfig_GpsMode_ENABLED;
} else if (config.position.gps_mode == meshtastic_Config_PositionConfig_GpsMode_ENABLED) {
config.position.gps_mode = meshtastic_Config_PositionConfig_GpsMode_DISABLED;
} else {
// NOT_PRESENT do nothing
break;
}
nodeDB->saveToDisk(SEGMENT_CONFIG);
service->reloadConfig(SEGMENT_CONFIG);
#endif
break;
case ENABLE_BLUETOOTH:
// This helps users recover from a bad wifi config
LOG_INFO("Enabling Bluetooth");
config.network.wifi_enabled = false;
config.bluetooth.enabled = true;
nodeDB->saveToDisk(SEGMENT_CONFIG);
InkHUD::InkHUD::getInstance()->notifyApplyingChanges();
rebootAtMsec = millis() + 2000;
break;
// Power / Network (ESP32-only)
#if defined(ARCH_ESP32)
case TOGGLE_POWER_SAVE:
config.power.is_power_saving = !config.power.is_power_saving;
nodeDB->saveToDisk(SEGMENT_CONFIG);
InkHUD::InkHUD::getInstance()->notifyApplyingChanges();
rebootAtMsec = millis() + DEFAULT_REBOOT_SECONDS * 1000;
break;
case TOGGLE_WIFI:
config.network.wifi_enabled = !config.network.wifi_enabled;
if (config.network.wifi_enabled) {
// Switch behavior: WiFi ON forces Bluetooth OFF
config.bluetooth.enabled = false;
}
nodeDB->saveToDisk(SEGMENT_CONFIG);
InkHUD::InkHUD::getInstance()->notifyApplyingChanges();
rebootAtMsec = millis() + DEFAULT_REBOOT_SECONDS * 1000;
break;
#endif
// ADC Calibration
case CALIBRATE_ADC: {
// Read current measured voltage
float measuredV = powerStatus->getBatteryVoltageMv() / 1000.0f;
// Sanity check
if (measuredV < 3.0f || measuredV > 4.5f) {
LOG_WARN("ADC calibration aborted, unreasonable voltage: %.2fV", measuredV);
break;
}
// Determine the base multiplier currently in effect
float baseMult = 0.0f;
if (config.power.adc_multiplier_override > 0.0f) {
baseMult = config.power.adc_multiplier_override;
}
#ifdef ADC_MULTIPLIER
else {
baseMult = ADC_MULTIPLIER;
}
#endif
if (baseMult <= 0.0f) {
LOG_WARN("ADC calibration failed: no base multiplier");
break;
}
// Target voltage considered 100% by UI
constexpr float TARGET_VOLTAGE = 4.19f;
// Calculate new multiplier
float newMult = baseMult * (TARGET_VOLTAGE / measuredV);
config.power.adc_multiplier_override = newMult;
nodeDB->saveToDisk(SEGMENT_CONFIG);
LOG_INFO("ADC calibrated: measured=%.3fV base=%.4f new=%.4f", measuredV, baseMult, newMult);
break;
}
// Display
case TOGGLE_DISPLAY_UNITS:
if (config.display.units == meshtastic_Config_DisplayConfig_DisplayUnits_IMPERIAL)
config.display.units = meshtastic_Config_DisplayConfig_DisplayUnits_METRIC;
else
config.display.units = meshtastic_Config_DisplayConfig_DisplayUnits_IMPERIAL;
nodeDB->saveToDisk(SEGMENT_CONFIG);
break;
// Bluetooth
case TOGGLE_BLUETOOTH:
config.bluetooth.enabled = !config.bluetooth.enabled;
if (config.bluetooth.enabled) {
// Switch behavior: Bluetooth ON forces WiFi OFF
config.network.wifi_enabled = false;
}
nodeDB->saveToDisk(SEGMENT_CONFIG);
InkHUD::InkHUD::getInstance()->notifyApplyingChanges();
rebootAtMsec = millis() + DEFAULT_REBOOT_SECONDS * 1000;
break;
case TOGGLE_BLUETOOTH_PAIR_MODE:
config.bluetooth.fixed_pin = !config.bluetooth.fixed_pin;
nodeDB->saveToDisk(SEGMENT_CONFIG);
break;
// Regions
case SET_REGION_US:
applyLoRaRegion(meshtastic_Config_LoRaConfig_RegionCode_US);
break;
case SET_REGION_EU_868:
applyLoRaRegion(meshtastic_Config_LoRaConfig_RegionCode_EU_868);
break;
case SET_REGION_EU_433:
applyLoRaRegion(meshtastic_Config_LoRaConfig_RegionCode_EU_433);
break;
case SET_REGION_CN:
applyLoRaRegion(meshtastic_Config_LoRaConfig_RegionCode_CN);
break;
case SET_REGION_JP:
applyLoRaRegion(meshtastic_Config_LoRaConfig_RegionCode_JP);
break;
case SET_REGION_ANZ:
applyLoRaRegion(meshtastic_Config_LoRaConfig_RegionCode_ANZ);
break;
case SET_REGION_KR:
applyLoRaRegion(meshtastic_Config_LoRaConfig_RegionCode_KR);
break;
case SET_REGION_TW:
applyLoRaRegion(meshtastic_Config_LoRaConfig_RegionCode_TW);
break;
case SET_REGION_RU:
applyLoRaRegion(meshtastic_Config_LoRaConfig_RegionCode_RU);
break;
case SET_REGION_IN:
applyLoRaRegion(meshtastic_Config_LoRaConfig_RegionCode_IN);
break;
case SET_REGION_NZ_865:
applyLoRaRegion(meshtastic_Config_LoRaConfig_RegionCode_NZ_865);
break;
case SET_REGION_TH:
applyLoRaRegion(meshtastic_Config_LoRaConfig_RegionCode_TH);
break;
case SET_REGION_LORA_24:
applyLoRaRegion(meshtastic_Config_LoRaConfig_RegionCode_LORA_24);
break;
case SET_REGION_UA_433:
applyLoRaRegion(meshtastic_Config_LoRaConfig_RegionCode_UA_433);
break;
case SET_REGION_UA_868:
applyLoRaRegion(meshtastic_Config_LoRaConfig_RegionCode_UA_868);
break;
case SET_REGION_MY_433:
applyLoRaRegion(meshtastic_Config_LoRaConfig_RegionCode_MY_433);
break;
case SET_REGION_MY_919:
applyLoRaRegion(meshtastic_Config_LoRaConfig_RegionCode_MY_919);
break;
case SET_REGION_SG_923:
applyLoRaRegion(meshtastic_Config_LoRaConfig_RegionCode_SG_923);
break;
case SET_REGION_PH_433:
applyLoRaRegion(meshtastic_Config_LoRaConfig_RegionCode_PH_433);
break;
case SET_REGION_PH_868:
applyLoRaRegion(meshtastic_Config_LoRaConfig_RegionCode_PH_868);
break;
case SET_REGION_PH_915:
applyLoRaRegion(meshtastic_Config_LoRaConfig_RegionCode_PH_915);
break;
case SET_REGION_ANZ_433:
applyLoRaRegion(meshtastic_Config_LoRaConfig_RegionCode_ANZ_433);
break;
case SET_REGION_KZ_433:
applyLoRaRegion(meshtastic_Config_LoRaConfig_RegionCode_KZ_433);
break;
case SET_REGION_KZ_863:
applyLoRaRegion(meshtastic_Config_LoRaConfig_RegionCode_KZ_863);
break;
case SET_REGION_NP_865:
applyLoRaRegion(meshtastic_Config_LoRaConfig_RegionCode_NP_865);
break;
case SET_REGION_BR_902:
applyLoRaRegion(meshtastic_Config_LoRaConfig_RegionCode_BR_902);
break;
// Roles
case SET_ROLE_CLIENT:
applyDeviceRole(meshtastic_Config_DeviceConfig_Role_CLIENT);
break;
case SET_ROLE_CLIENT_MUTE:
applyDeviceRole(meshtastic_Config_DeviceConfig_Role_CLIENT_MUTE);
break;
case SET_ROLE_ROUTER:
applyDeviceRole(meshtastic_Config_DeviceConfig_Role_ROUTER);
break;
case SET_ROLE_REPEATER:
applyDeviceRole(meshtastic_Config_DeviceConfig_Role_REPEATER);
break;
// Presets
case SET_PRESET_LONG_SLOW:
applyLoRaPreset(meshtastic_Config_LoRaConfig_ModemPreset_LONG_SLOW);
break;
case SET_PRESET_LONG_MODERATE:
applyLoRaPreset(meshtastic_Config_LoRaConfig_ModemPreset_LONG_MODERATE);
break;
case SET_PRESET_LONG_FAST:
applyLoRaPreset(meshtastic_Config_LoRaConfig_ModemPreset_LONG_FAST);
break;
case SET_PRESET_MEDIUM_SLOW:
applyLoRaPreset(meshtastic_Config_LoRaConfig_ModemPreset_MEDIUM_SLOW);
break;
case SET_PRESET_MEDIUM_FAST:
applyLoRaPreset(meshtastic_Config_LoRaConfig_ModemPreset_MEDIUM_FAST);
break;
case SET_PRESET_SHORT_SLOW:
applyLoRaPreset(meshtastic_Config_LoRaConfig_ModemPreset_SHORT_SLOW);
break;
case SET_PRESET_SHORT_FAST:
applyLoRaPreset(meshtastic_Config_LoRaConfig_ModemPreset_SHORT_FAST);
break;
case SET_PRESET_SHORT_TURBO:
applyLoRaPreset(meshtastic_Config_LoRaConfig_ModemPreset_SHORT_TURBO);
break;
// Timezones
case SET_TZ_US_HAWAII:
applyTimezone("HST10");
break;
case SET_TZ_US_ALASKA:
applyTimezone("AKST9AKDT,M3.2.0,M11.1.0");
break;
case SET_TZ_US_PACIFIC:
applyTimezone("PST8PDT,M3.2.0,M11.1.0");
break;
case SET_TZ_US_ARIZONA:
applyTimezone("MST7");
break;
case SET_TZ_US_MOUNTAIN:
applyTimezone("MST7MDT,M3.2.0,M11.1.0");
break;
case SET_TZ_US_CENTRAL:
applyTimezone("CST6CDT,M3.2.0,M11.1.0");
break;
case SET_TZ_US_EASTERN:
applyTimezone("EST5EDT,M3.2.0,M11.1.0");
break;
case SET_TZ_BR_BRAZILIA:
applyTimezone("BRT3");
break;
case SET_TZ_UTC:
applyTimezone("UTC0");
break;
case SET_TZ_EU_WESTERN:
applyTimezone("GMT0BST,M3.5.0/1,M10.5.0");
break;
case SET_TZ_EU_CENTRAL:
applyTimezone("CET-1CEST,M3.5.0,M10.5.0/3");
break;
case SET_TZ_EU_EASTERN:
applyTimezone("EET-2EEST,M3.5.0/3,M10.5.0/4");
break;
case SET_TZ_ASIA_KOLKATA:
applyTimezone("IST-5:30");
break;
case SET_TZ_ASIA_HONG_KONG:
applyTimezone("HKT-8");
break;
case SET_TZ_AU_AWST:
applyTimezone("AWST-8");
break;
case SET_TZ_AU_ACST:
applyTimezone("ACST-9:30ACDT,M10.1.0,M4.1.0/3");
break;
case SET_TZ_AU_AEST:
applyTimezone("AEST-10AEDT,M10.1.0,M4.1.0/3");
break;
case SET_TZ_PACIFIC_NZ:
applyTimezone("NZST-12NZDT,M9.5.0,M4.1.0/3");
break;
// Channels
case TOGGLE_CHANNEL_UPLINK: {
auto &ch = channels.getByIndex(selectedChannelIndex);
ch.settings.uplink_enabled = !ch.settings.uplink_enabled;
nodeDB->saveToDisk(SEGMENT_CHANNELS);
service->reloadConfig(SEGMENT_CHANNELS);
break;
}
case TOGGLE_CHANNEL_DOWNLINK: {
auto &ch = channels.getByIndex(selectedChannelIndex);
ch.settings.downlink_enabled = !ch.settings.downlink_enabled;
nodeDB->saveToDisk(SEGMENT_CHANNELS);
service->reloadConfig(SEGMENT_CHANNELS);
break;
}
case TOGGLE_CHANNEL_POSITION: {
auto &ch = channels.getByIndex(selectedChannelIndex);
if (!ch.settings.has_module_settings)
ch.settings.has_module_settings = true;
if (ch.settings.module_settings.position_precision > 0)
ch.settings.module_settings.position_precision = 0;
else
ch.settings.module_settings.position_precision = 13; // default
nodeDB->saveToDisk(SEGMENT_CHANNELS);
service->reloadConfig(SEGMENT_CHANNELS);
break;
}
case SET_CHANNEL_PRECISION: {
auto &ch = channels.getByIndex(selectedChannelIndex);
if (!ch.settings.has_module_settings)
ch.settings.has_module_settings = true;
// Cursor - 1 because of "Back"
uint8_t index = cursor - 1;
constexpr uint8_t optionCount = sizeof(POSITION_PRECISION_OPTIONS) / sizeof(POSITION_PRECISION_OPTIONS[0]);
if (index < optionCount) {
ch.settings.module_settings.position_precision = POSITION_PRECISION_OPTIONS[index].value;
}
nodeDB->saveToDisk(SEGMENT_CHANNELS);
service->reloadConfig(SEGMENT_CHANNELS);
break;
}
case RESET_NODEDB_ALL:
InkHUD::getInstance()->notifyApplyingChanges();
nodeDB->resetNodes();
rebootAtMsec = millis() + DEFAULT_REBOOT_SECONDS * 1000;
break;
case RESET_NODEDB_KEEP_FAVORITES:
InkHUD::getInstance()->notifyApplyingChanges();
nodeDB->resetNodes(1);
rebootAtMsec = millis() + DEFAULT_REBOOT_SECONDS * 1000;
break;
default:
LOG_WARN("Action not implemented");
}
// Move to next page, as defined for the MenuItem
showPage(item.nextPage);
}
// Display a new page of MenuItems
// May reload same page, or exit menu applet entirely
// Fills the MenuApplet::items vector
void InkHUD::MenuApplet::showPage(MenuPage page)
{
items.clear();
items.shrink_to_fit();
nodeConfigLabels.clear();
switch (page) {
case ROOT:
previousPage = MenuPage::EXIT;
// Optional: next applet
if (settings->optionalMenuItems.nextTile && settings->userTiles.count > 1)
items.push_back(MenuItem("Next Tile", MenuAction::NEXT_TILE, MenuPage::ROOT)); // Only if multiple applets shown
items.push_back(MenuItem("Send", MenuPage::SEND));
items.push_back(MenuItem("Options", MenuPage::OPTIONS));
// items.push_back(MenuItem("Display Off", MenuPage::EXIT)); // TODO
items.push_back(MenuItem("Node Config", MenuPage::NODE_CONFIG));
items.push_back(MenuItem("Save & Shut Down", MenuAction::SHUTDOWN));
items.push_back(MenuItem("Exit", MenuPage::EXIT));
break;
case SEND:
populateSendPage();
previousPage = MenuPage::ROOT;
break;
case CANNEDMESSAGE_RECIPIENT:
populateRecipientPage();
previousPage = MenuPage::SEND;
break;
case OPTIONS:
previousPage = MenuPage::ROOT;
items.push_back(MenuItem("Back", previousPage));
// Optional: backlight
if (settings->optionalMenuItems.backlight)
items.push_back(MenuItem(backlight->isLatched() ? "Backlight Off" : "Keep Backlight On", // Label
MenuAction::TOGGLE_BACKLIGHT, // Action
MenuPage::EXIT // Exit once complete
));
// Options Toggles
items.push_back(MenuItem("Applets", MenuPage::APPLETS));
items.push_back(MenuItem("Auto-show", MenuPage::AUTOSHOW));
items.push_back(MenuItem("Recents Duration", MenuPage::RECENTS));
if (settings->userTiles.maxCount > 1)
items.push_back(MenuItem("Layout", MenuAction::LAYOUT, MenuPage::OPTIONS));
items.push_back(MenuItem("Rotate", MenuAction::ROTATE, MenuPage::OPTIONS));
if (settings->joystick.enabled && !inkhud->twoWayRocker)
items.push_back(MenuItem("Align Joystick", MenuAction::ALIGN_JOYSTICK, MenuPage::EXIT));
items.push_back(MenuItem("Notifications", MenuAction::TOGGLE_NOTIFICATIONS, MenuPage::OPTIONS,
&settings->optionalFeatures.notifications));
items.push_back(MenuItem("Battery Icon", MenuAction::TOGGLE_BATTERY_ICON, MenuPage::OPTIONS,
&settings->optionalFeatures.batteryIcon));
invertedColors = (config.display.displaymode == meshtastic_Config_DisplayConfig_DisplayMode_INVERTED);
items.push_back(MenuItem("Invert Color", MenuAction::TOGGLE_INVERT_COLOR, MenuPage::OPTIONS, &invertedColors));
items.push_back(MenuItem("Exit", MenuPage::EXIT));
break;
case APPLETS:
previousPage = MenuPage::OPTIONS;
populateAppletPage(); // must be first
items.insert(items.begin(), MenuItem("Back", previousPage));
items.push_back(MenuItem("Exit", MenuPage::EXIT));
break;
case AUTOSHOW:
previousPage = MenuPage::OPTIONS;
populateAutoshowPage(); // must be first
items.insert(items.begin(), MenuItem("Back", previousPage));
items.push_back(MenuItem("Exit", MenuPage::EXIT));
break;
case RECENTS:
previousPage = MenuPage::OPTIONS;
populateRecentsPage(); // builds only the options
items.insert(items.begin(), MenuItem("Back", previousPage));
items.push_back(MenuItem("Exit", MenuPage::EXIT));
break;
case NODE_CONFIG:
previousPage = MenuPage::ROOT;
items.push_back(MenuItem("Back", previousPage));
// Radio Config Section
items.push_back(MenuItem::Header("Radio Config"));
items.push_back(MenuItem("LoRa", MenuPage::NODE_CONFIG_LORA));
items.push_back(MenuItem("Channel", MenuPage::NODE_CONFIG_CHANNELS));
// Device Config Section
items.push_back(MenuItem::Header("Device Config"));
items.push_back(MenuItem("Device", MenuPage::NODE_CONFIG_DEVICE));
items.push_back(MenuItem("Position", MenuPage::NODE_CONFIG_POSITION));
items.push_back(MenuItem("Power", MenuPage::NODE_CONFIG_POWER));
#if defined(ARCH_ESP32)
items.push_back(MenuItem("Network", MenuPage::NODE_CONFIG_NETWORK));
#endif
items.push_back(MenuItem("Display", MenuPage::NODE_CONFIG_DISPLAY));
items.push_back(MenuItem("Bluetooth", MenuPage::NODE_CONFIG_BLUETOOTH));
// Administration Section
items.push_back(MenuItem::Header("Administration"));
items.push_back(MenuItem("Reset NodeDB", MenuPage::NODE_CONFIG_ADMIN_RESET));
// Exit
items.push_back(MenuItem("Exit", MenuPage::EXIT));
break;
case NODE_CONFIG_DEVICE: {
previousPage = MenuPage::NODE_CONFIG;
items.push_back(MenuItem("Back", previousPage));
const char *role = DisplayFormatters::getDeviceRole(config.device.role);
nodeConfigLabels.emplace_back("Role: " + std::string(role));
items.push_back(MenuItem(nodeConfigLabels.back().c_str(), MenuAction::NO_ACTION, MenuPage::NODE_CONFIG_DEVICE_ROLE));
const char *tzLabel = getTimezoneLabelFromValue(config.device.tzdef);
nodeConfigLabels.emplace_back("Timezone: " + std::string(tzLabel));
items.push_back(MenuItem(nodeConfigLabels.back().c_str(), MenuAction::NO_ACTION, MenuPage::TIMEZONE));
items.push_back(MenuItem("Exit", MenuPage::EXIT));
break;
}
case NODE_CONFIG_POSITION: {
previousPage = MenuPage::NODE_CONFIG;
items.push_back(MenuItem("Back", previousPage));
#if !MESHTASTIC_EXCLUDE_GPS && HAS_GPS
const auto mode = config.position.gps_mode;
if (mode == meshtastic_Config_PositionConfig_GpsMode_NOT_PRESENT) {
items.push_back(MenuItem("GPS None", MenuAction::NO_ACTION, MenuPage::NODE_CONFIG_POSITION));
} else {
gpsEnabled = (mode == meshtastic_Config_PositionConfig_GpsMode_ENABLED);
items.push_back(MenuItem("GPS", MenuAction::TOGGLE_GPS, MenuPage::NODE_CONFIG_POSITION, &gpsEnabled));
}
#endif
items.push_back(MenuItem("Exit", MenuPage::EXIT));
break;
}
case NODE_CONFIG_POWER: {
previousPage = MenuPage::NODE_CONFIG;