/
menu.c
1409 lines (1106 loc) · 42.8 KB
/
menu.c
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
/*! \file menu.c
\brief Menu hooks and extensions.
*/
//#define DEBUG
#define TRACE_MENU
#define CONFIG_MENU
#include "menu.h"
#include <string.h>
#include "debug.h"
#include "dmesg.h"
#include "md380.h"
#include "version.h"
#include "config.h"
#include "os.h"
#include "spiflash.h"
#include "addl_config.h"
#include "radio_config.h"
#include "usersdb.h"
#include "util.h"
#include "printf.h"
#include "keyb.h"
#include "config.h" // need to know CONFIG_DIMMED_LIGHT (defined in config.h since 2017-01-03)
const static wchar_t wt_addl_func[] = L"MD380Tools";
const static wchar_t wt_datef[] = L"Date format";
const static wchar_t wt_debug[] = L"USB logging";
//const static wchar_t wt_netmon[] = L"NetMon";
const static wchar_t wt_netmon[] = L"DevOnly!!"; // for now, later a true submenu.
const static wchar_t wt_disable[] = L"Disable";
const static wchar_t wt_enable[] = L"Enable";
const static wchar_t wt_rbeep[] = L"M. RogerBeep";
const static wchar_t wt_bootopts[] = L"Boot Options";
const static wchar_t wt_demoscr[] = L"Demo Screen";
const static wchar_t wt_demoscr_enable[] = L"Enable";
const static wchar_t wt_demoscr_disable[] = L"Disable";
const static wchar_t wt_splash[] = L"Splash Mode";
const static wchar_t wt_userscsv[] = L"UsersCSV";
const static wchar_t wt_datef_original[] = L"YYYY/MM/DD";
const static wchar_t wt_datef_germany[] = L"DD.MM.YYYY";
const static wchar_t wt_datef_italy[] = L"DD/MM/YYYY";
const static wchar_t wt_datef_american[] = L"MM/DD/YYYY";
const static wchar_t wt_datef_iso[] = L"YYYY-MM-DD";
const static wchar_t wt_datef_alt[] = L"Alt. Status";
const static wchar_t wt_promtg[] = L"Promiscuous";
const static wchar_t wt_edit[] = L"Edit";
const static wchar_t wt_edit_dmr_id[] = L"Edit DMR-ID";
const static wchar_t wt_no_w25q128[] = L"No W25Q128";
const static wchar_t wt_experimental[] = L"Experimental";
const static wchar_t wt_micbargraph[] = L"Mic bargraph";
const static wchar_t wt_backlight[] = L"Backlight Tmr";
const static wchar_t wt_blunchanged[] = L"Unchanged";
const static wchar_t wt_bl5[] = L"5 sec";
const static wchar_t wt_bl30[] = L"30 sec";
const static wchar_t wt_bl60[] = L"60 sec";
const static wchar_t wt_backlight_menu[] = L"Backlight";
#ifndef CONFIG_DIMMED_LIGHT // want 'dimmed backlight', two adjustable intensities ?
# define CONFIG_DIMMED_LIGHT 0 // guess not (unless defined AS ONE in config.h)
#endif
#if( CONFIG_DIMMED_LIGHT ) // support pulse-width modulated backlight ?
const static wchar_t wt_bl_intensity_lo[] = L"Level Low";
const static wchar_t wt_bl_intensity_hi[] = L"Level High";
#define NUM_BACKLIGHT_INTENSITIES 10 /* number of intensity steps (0..9) for the menu */
const static wchar_t *wt_bl_intensity[NUM_BACKLIGHT_INTENSITIES] =
{ L"0 (off)", L"1 (lowest)", L"2", L"3 (medium)", L"4",
L"5", L"6", L"7", L"8", L"9 (bright)" };
#endif // CONFIG_DIMMED_LIGHT ?
const static wchar_t wt_cp_override[] = L"CoPl Override";
const static wchar_t wt_splash_manual[] = L"Disabled";
const static wchar_t wt_splash_callid[] = L"Callsign+DMRID";
const static wchar_t wt_splash_callname[] = L"Callsign+Name";
const static wchar_t wt_cp_override_dmrid[] = L"ID Override";
const static wchar_t wt_config_reset[] = L"Config Reset";
const static wchar_t wt_config_reset_doit[] = L"Config Reset2";
const static wchar_t wt_sidebutton_menu[] = L"Side Buttons";
const static wchar_t wt_button_top_press[] = L"Top Pressed";
const static wchar_t wt_button_bot_press[] = L"Bottom Pressed";
const static wchar_t wt_button_top_held[] = L"Top Held";
const static wchar_t wt_button_bot_held[] = L"Bottom Held";
const static wchar_t wt_button_func_set[] = L"Function Set";
const static wchar_t wt_button_unassigned[] = L"Unassigned";
const static wchar_t wt_button_alert_tone[] = L"All Tone Tog";
const static wchar_t wt_button_emerg_on[] = L"Emergency On";
const static wchar_t wt_button_emerg_off[] = L"Emergency Off";
const static wchar_t wt_button_power[] = L"High/Low Pwr";
const static wchar_t wt_button_monitor[] = L"Monitor";
const static wchar_t wt_button_nuisance[] = L"Nuisance Del";
const static wchar_t wt_button_ot1[] = L"One Touch 1";
const static wchar_t wt_button_ot2[] = L"One Touch 2";
const static wchar_t wt_button_ot3[] = L"One Touch 3";
const static wchar_t wt_button_ot4[] = L"One Touch 4";
const static wchar_t wt_button_ot5[] = L"One Touch 5";
const static wchar_t wt_button_ot6[] = L"One Touch 6";
const static wchar_t wt_button_rep_talk[] = L"Talkaround";
const static wchar_t wt_button_scan[] = L"Scan On/Off";
const static wchar_t wt_button_squelch[] = L"Squelch Tight";
const static wchar_t wt_button_privacy[] = L"Privacy On/Off";
const static wchar_t wt_button_vox[] = L"Vox On/Off";
const static wchar_t wt_button_zone[] = L"Zone Inc.";
const static wchar_t wt_button_zone_tog[] = L"Zone Toggle";
const static wchar_t wt_button_bat_ind[] = L"Bat Indicator";
const static wchar_t wt_button_man_dial[] = L"Manual Dial";
const static wchar_t wt_button_lone_work[] = L"Lone wk On/Off";
const static wchar_t wt_button_1750_hz[] = L"1750hz Tone";
const static wchar_t wt_button_bklt_en[] = L"Toggle bklight";
const static uint8_t button_functions[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a,
0x0b, 0x0c, 0x0d, 0x0e, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1e,
0x1f, 0x26, 0x50};
uint8_t button_selected = 0;
uint8_t button_function = 0;
typedef struct {
const wchar_t* label ; // [0]
void* green ; // [4]
void* red ; // [8]
uint8_t off12 ; // [12]
uint8_t off13 ; // [13]
uint16_t item_count ; // [14]
uint8_t off16 ; // [16]
uint8_t off17 ; // [17]
uint16_t unknown2 ; // [18]
// sizeof() == 20 (0x14)
} menu_entry_t ;
typedef struct {
const wchar_t *menu_title; // [0]
menu_entry_t *entries; // [4]
uint8_t numberof_menu_entries; // [8]
uint8_t unknown_00;
uint8_t unknown_01;
uint8_t filler ;
} menu_t ; // sizeof() == 12
extern menu_t md380_menu_memory[];
extern menu_entry_t md380_menu_mem_base[];
//Old macro, schedule for deletion.
//#define MKTHUMB(adr) ((void(*))(((uint32_t)adr) | 0x1))
//New macro, prints warnings where needed.
#define MKTHUMB(adr) (printf(((int)adr)&1?"":"Warning, 0x%08x function pointer is even.\n",adr),(void(*))(((uint32_t)adr) | 0x1))
void create_menu_entry_rev(int menuid, const wchar_t * label , void (*green_key)(), void (*red_key)(), int e, int f ,int item_count)
{
// PRINT("create_menu_entry_rev %x %S %x %x %x\n", menuid, label, e, f, item_count );
// PRINT("%x\n", green_key);
// green_key = MKTHUMB(green_key);
// PRINT("%x\n", green_key);
// red_key = MKTHUMB(red_key);
#ifdef TRACE_MENU
#ifdef DEBUG
char lbl2[10];
char *lp = (void*)label ;
for(int i=0;i<10;i++) {
char c = lp[(i*2)];
if( c == ' ' ) {
c = '_' ;
}
lbl2[i] = c ;
if( c == 0 ) {
break ;
}
}
lbl2[9] = 0 ;
void *gp = ((uint8_t*)green_key) - 1 ;
PRINT("f menugreen.%s.%x 0 0x%x\n", lbl2, gp, gp );
#endif
#if 0
register uint32_t *sp asm("sp");
for(int i=15;i<20;i++) {
printf( "%d : 0x%x\n", i, sp[i] );
}
printf( "f menucall.%s 0 0x%x\n", lbl2, (sp[15] - 1 - 4) );
#endif
#endif
// e f
// 6,2 confirmation popup misc.
// 6,f confirmation popup scanlist.
// 6,f confirmation popup zone.
// 6,1 invalid number popup.
// a,0 ctcss (only editable in FM)
// 9,0 fullscr msg without timeout (my num,versions)
// 81,0 enter radio number (new contact,manual dial,edit dmrid,rxf,txf)
// 85,0 msgbox without timeout (rxf,txf)
// 8a,0 utilities menu items
// 8b,0 simple yes no list items.
// 8c,0 single menu entry for complete contacts list.
// 93,0 message
// 98,0 radio settings
// item_count
// 0 = not visible
// f
// 0 = stable
// 2 = remove after timeout
// if( global_addl_config.experimental == 1 ) {
// switch( item_count ) {
// case 0 :
// item_count = 1 ; // cheating.
// break ;
// }
// }
menu_entry_t *poi = &md380_menu_mem_base[menuid];
poi->label = label ;
poi->green = green_key ;
poi->red = red_key ;
poi->off12 = e ;
poi->off13 = f ;
poi->item_count = item_count ;
#ifdef FW_D13_020
// supress language menu.
if( green_key == (void*)(0x801ab84 + 1) ) {
poi->item_count = 0 ;
}
#else
#warning TODO find language menu on this firmware version
#endif
}
uint8_t index_of(uint8_t value, uint8_t arr[], uint8_t len)
{
uint8_t i = 0;
while(i < len)
{
if (arr[i] == value) return i;
i++;
}
return 0;
}
//void md380_create_menu_entry(int menuid, const wchar_t * label , void * green_key, void * red_key, int e, int f ,int enabled) {
//#ifdef DEBUG
// printf("0x%x Text: 0x%x GreenKey 0x%x RedKey 0x%x 0x%x 0x%x 0x%x\n", menuid,label,green_key,red_key,e,f,enabled);
// printf("b: ");
// printhex2((char *) label,14);
// printf("\n");
// printf(" md380_menu_depth: %d\n", md380_menu_depth);
//#endif
// md380_create_menu_entry(menuid,label,green_key,red_key,e,f,enabled);
//}
menu_t *get_menu_stackpoi()
{
return &md380_menu_memory[md380_menu_depth+1];
}
void mn_create_single_timed_ack( const wchar_t *title, const wchar_t *label )
{
menu_t *menu_mem;
menu_mem = get_menu_stackpoi();
menu_mem->menu_title = title;
menu_mem->entries = &md380_menu_mem_base[md380_menu_id];
menu_mem->numberof_menu_entries = 1;
menu_mem->unknown_00 = 0;
menu_mem->unknown_01 = 0;
md380_create_menu_entry(md380_menu_id, label, MKTHUMB(md380_menu_entry_back), MKTHUMB(md380_menu_entry_back), 6, 2, 1);
}
void mn_submenu_init(const wchar_t *title)
{
menu_t *menu_mem = get_menu_stackpoi();
menu_mem->menu_title = title;
menu_mem->entries = &md380_menu_mem_base[md380_menu_id];
menu_mem->numberof_menu_entries = 0;
menu_mem->unknown_00 = 0;
menu_mem->unknown_01 = 0;
}
void mn_submenu_add(const wchar_t * label, void (*func)())
{
menu_t *menu_mem = get_menu_stackpoi();
func = MKTHUMB(func);
md380_create_menu_entry(md380_menu_id + menu_mem->numberof_menu_entries, label, func, MKTHUMB(md380_menu_entry_back), 0x8b, 0, 1);
menu_mem->numberof_menu_entries++ ;
}
void mn_submenu_add_98(const wchar_t * label, void (*func)())
{
menu_t *menu_mem = get_menu_stackpoi();
func = MKTHUMB(func);
md380_create_menu_entry(md380_menu_id + menu_mem->numberof_menu_entries, label, func, MKTHUMB(md380_menu_entry_back), 0x98, 0, 1);
menu_mem->numberof_menu_entries++ ;
}
void mn_submenu_add_8a(const wchar_t * label, void (*func)(), int enabled)
{
menu_t *menu_mem = get_menu_stackpoi();
func = MKTHUMB(func);
md380_create_menu_entry(md380_menu_id + menu_mem->numberof_menu_entries, label, func, MKTHUMB(md380_menu_entry_back), 0x8a, 0, enabled);
menu_mem->numberof_menu_entries++ ;
}
void mn_submenu_finalize()
{
menu_t *menu_mem = get_menu_stackpoi();
for (int i = 0; i < menu_mem->numberof_menu_entries; i++) {
// conflicts with 'selected' icon.
// no icons.
md380_menu_mem_base[md380_menu_id + i].off16 = 0;
}
}
void mn_submenu_finalize2()
{
menu_t *menu_mem = get_menu_stackpoi();
for (int i = 0; i < menu_mem->numberof_menu_entries; i++) {
md380_menu_mem_base[md380_menu_id + i].off16 = 2; // numbered icons
}
}
void create_menu_entry_promtg_enable_screen(void)
{
mn_create_single_timed_ack(wt_promtg,wt_enable);
global_addl_config.promtg = 1;
cfg_save();
}
void create_menu_entry_promtg_disable_screen(void)
{
mn_create_single_timed_ack(wt_promtg,wt_disable);
global_addl_config.promtg = 0;
cfg_save();
}
void create_menu_entry_micbargraph_enable_screen(void)
{
mn_create_single_timed_ack(wt_micbargraph,wt_enable);
global_addl_config.micbargraph = 1;
cfg_save();
}
void create_menu_entry_micbargraph_disable_screen(void)
{
mn_create_single_timed_ack(wt_micbargraph,wt_disable);
global_addl_config.micbargraph = 0;
cfg_save();
}
void create_menu_entry_rbeep_enable_screen(void)
{
mn_create_single_timed_ack(wt_rbeep,wt_enable);
global_addl_config.rbeep = 1;
cfg_save();
}
void create_menu_entry_rbeep_disable_screen(void)
{
mn_create_single_timed_ack(wt_rbeep,wt_disable);
global_addl_config.rbeep = 0;
cfg_save();
}
void create_menu_entry_demo_enable_screen(void)
{
mn_create_single_timed_ack(wt_demoscr, wt_enable);
global_addl_config.boot_demo = 0;
cfg_save();
}
void create_menu_entry_demo_disable_screen(void)
{
mn_create_single_timed_ack(wt_demoscr, wt_disable);
global_addl_config.boot_demo = 1;
cfg_save();
}
void create_menu_entry_demo_screen(void)
{
mn_submenu_init(wt_demoscr);
md380_menu_entry_selected = global_addl_config.boot_demo;
mn_submenu_add(wt_demoscr_enable, create_menu_entry_demo_enable_screen);
mn_submenu_add(wt_demoscr_disable, create_menu_entry_demo_disable_screen);
mn_submenu_finalize();
}
void mn_cp_override_off(void)
{
mn_create_single_timed_ack(wt_cp_override, wt_splash_manual);
//global_addl_config.boot_splash = 0;
global_addl_config.cp_override &= ~CPO_BL1 ;
global_addl_config.cp_override &= ~CPO_BL2 ;
cfg_save();
}
uint32_t get_effective_dmrid()
{
return global_addl_config.dmrid ;
}
void mn_cp_override_call_dmrid(void)
{
mn_create_single_timed_ack(wt_cp_override, wt_splash_callid);
//global_addl_config.boot_splash = 1;
global_addl_config.cp_override |= CPO_BL1 ;
global_addl_config.cp_override |= CPO_BL2 ;
user_t usr ;
uint32_t dmrid = get_effective_dmrid();
int r = usr_find_by_dmrid(&usr,dmrid);
if( r ) {
snprintf(global_addl_config.bootline1, 10, "%s", usr.callsign);
} else {
snprintf(global_addl_config.bootline1, 10, "%s", "unknown");
}
snprintf( global_addl_config.bootline2, 10, "%d", (int)dmrid );
cfg_save();
}
void mn_cp_override_call_name(void)
{
mn_create_single_timed_ack(wt_cp_override, wt_splash_callname);
//global_addl_config.boot_splash = 2;
global_addl_config.cp_override |= CPO_BL1 ;
global_addl_config.cp_override |= CPO_BL2 ;
user_t usr ;
uint32_t dmrid = get_effective_dmrid();
int r = usr_find_by_dmrid(&usr,dmrid);
if( r ) {
snprintf(global_addl_config.bootline1, 10, "%s", usr.callsign);
} else {
snprintf(global_addl_config.bootline1, 10, "%s", "unknown");
}
if( r ) {
snprintf(global_addl_config.bootline2, 10, "%s", usr.firstname);
} else {
snprintf(global_addl_config.bootline2, 10, "%s", "unknown");
}
cfg_save();
}
void mn_cp_override_dmrid_on(void)
{
mn_create_single_timed_ack(wt_cp_override_dmrid, wt_enable);
global_addl_config.cp_override |= CPO_DMR ;
// set to override dmrid.
md380_radio_config.dmrid = global_addl_config.dmrid ;
cfg_save();
}
void mn_cp_override_dmrid_off(void)
{
mn_create_single_timed_ack(wt_cp_override_dmrid, wt_disable);
global_addl_config.cp_override &= ~CPO_DMR ;
// restore codeplug dmrid.
md380_spiflash_read(&md380_radio_config.dmrid, FLASH_OFFSET_DMRID, 4);
cfg_save();
}
void mn_cp_override_dmrid(void)
{
mn_submenu_init(wt_cp_override_dmrid);
mn_submenu_add(wt_demoscr_enable, mn_cp_override_dmrid_on);
mn_submenu_add(wt_demoscr_disable, mn_cp_override_dmrid_off);
mn_submenu_finalize();
}
void mn_cp_override(void)
{
mn_submenu_init(wt_cp_override);
mn_submenu_add(wt_splash_manual, mn_cp_override_off);
mn_submenu_add(wt_splash_callid, mn_cp_override_call_dmrid);
mn_submenu_add(wt_splash_callname, mn_cp_override_call_name);
mn_submenu_add(wt_cp_override_dmrid, mn_cp_override_dmrid);
mn_submenu_finalize();
}
void create_menu_entry_bootopts_screen(void)
{
mn_submenu_init(wt_bootopts);
mn_submenu_add_98(wt_demoscr, create_menu_entry_demo_screen);
// mn_submenu_add_98(wt_splash, create_menu_entry_splash_screen);
mn_submenu_finalize2();
}
void create_menu_entry_datef_original_screen(void)
{
mn_create_single_timed_ack(wt_datef,wt_datef_original);
global_addl_config.datef = 0;
cfg_save();
}
void create_menu_entry_datef_germany_screen(void)
{
mn_create_single_timed_ack(wt_datef,wt_datef_germany);
global_addl_config.datef = 1;
cfg_save();
}
void create_menu_entry_datef_italy_screen(void)
{
mn_create_single_timed_ack(wt_datef,wt_datef_italy);
global_addl_config.datef = 2;
cfg_save();
}
void create_menu_entry_datef_american_screen(void)
{
mn_create_single_timed_ack(wt_datef,wt_datef_american);
global_addl_config.datef = 3;
cfg_save();
}
void create_menu_entry_datef_iso_screen(void)
{
mn_create_single_timed_ack(wt_datef,wt_datef_iso);
global_addl_config.datef = 4;
cfg_save();
}
void create_menu_entry_datef_alt_screen(void)
{
mn_create_single_timed_ack(wt_datef,wt_datef_alt);
global_addl_config.datef = 5;
cfg_save();
}
void create_menu_entry_userscsv_enable_screen(void)
{
mn_create_single_timed_ack(wt_userscsv,wt_enable);
global_addl_config.userscsv = 1;
cfg_save();
cfg_set_radio_name();
}
void create_menu_entry_userscsv_disable_screen(void)
{
mn_create_single_timed_ack(wt_userscsv,wt_disable);
global_addl_config.userscsv = 0;
cfg_save();
}
void create_menu_entry_experimental_enable_screen(void)
{
mn_create_single_timed_ack(wt_experimental,wt_enable);
global_addl_config.experimental = 1;
}
void create_menu_entry_experimental_disable_screen(void)
{
mn_create_single_timed_ack(wt_experimental,wt_disable);
global_addl_config.experimental = 0;
}
void create_menu_entry_debug_enable_screen(void)
{
mn_create_single_timed_ack(wt_debug,wt_enable);
global_addl_config.debug = 1;
cfg_save();
}
void create_menu_entry_debug_disable_screen(void)
{
mn_create_single_timed_ack(wt_debug,wt_disable);
global_addl_config.debug = 0;
cfg_save();
}
void create_menu_entry_promtg_screen(void)
{
mn_submenu_init(wt_promtg);
if( global_addl_config.promtg == 1 ) {
md380_menu_entry_selected = 0;
} else {
md380_menu_entry_selected = 1;
}
mn_submenu_add(wt_enable, create_menu_entry_promtg_enable_screen);
mn_submenu_add(wt_disable, create_menu_entry_promtg_disable_screen);
mn_submenu_finalize();
}
void create_menu_entry_micbargraph_screen(void)
{
mn_submenu_init(wt_micbargraph);
if( global_addl_config.micbargraph == 1 ) {
md380_menu_entry_selected = 0;
} else {
md380_menu_entry_selected = 1;
}
mn_submenu_add(wt_enable, create_menu_entry_micbargraph_enable_screen);
mn_submenu_add(wt_disable, create_menu_entry_micbargraph_disable_screen);
mn_submenu_finalize();
}
void create_menu_entry_rbeep_screen(void)
{
mn_submenu_init(wt_rbeep);
if( global_addl_config.rbeep == 1 ) {
md380_menu_entry_selected = 0;
} else {
md380_menu_entry_selected = 1;
}
mn_submenu_add(wt_enable, create_menu_entry_rbeep_enable_screen);
mn_submenu_add(wt_disable, create_menu_entry_rbeep_disable_screen);
mn_submenu_finalize();
}
void create_menu_entry_datef_screen(void)
{
mn_submenu_init(wt_datef);
md380_menu_entry_selected = global_addl_config.datef;
mn_submenu_add(wt_datef_original, create_menu_entry_datef_original_screen);
mn_submenu_add(wt_datef_germany, create_menu_entry_datef_germany_screen);
mn_submenu_add(wt_datef_italy, create_menu_entry_datef_italy_screen);
mn_submenu_add(wt_datef_american, create_menu_entry_datef_american_screen);
mn_submenu_add(wt_datef_iso, create_menu_entry_datef_iso_screen);
mn_submenu_add(wt_datef_alt, create_menu_entry_datef_alt_screen);
mn_submenu_finalize();
}
void create_menu_entry_userscsv_screen(void)
{
mn_submenu_init(wt_userscsv);
if( global_addl_config.userscsv == 1 ) {
md380_menu_entry_selected = 0;
} else {
md380_menu_entry_selected = 1;
}
mn_submenu_add(wt_enable, create_menu_entry_userscsv_enable_screen);
mn_submenu_add(wt_disable, create_menu_entry_userscsv_disable_screen);
mn_submenu_finalize();
}
void create_menu_entry_debug_screen(void)
{
mn_submenu_init(wt_debug);
if( global_addl_config.debug == 1 ) {
md380_menu_entry_selected = 0;
} else {
md380_menu_entry_selected = 1;
}
mn_submenu_add(wt_enable, create_menu_entry_debug_enable_screen);
mn_submenu_add(wt_disable, create_menu_entry_debug_disable_screen);
mn_submenu_finalize();
}
void create_menu_entry_netmon_disable_screen(void)
{
mn_create_single_timed_ack(wt_netmon,wt_disable);
global_addl_config.netmon = 0;
cfg_save();
}
void create_menu_entry_netmon_enable_screen(void)
{
mn_create_single_timed_ack(wt_netmon,wt_enable);
global_addl_config.netmon = 1;
cfg_save();
}
#if defined(FW_D13_020) || defined(FW_S13_020)
int enabled = 1;
#else
int enabled = 0;
#endif
void create_menu_entry_netmon_screen(void)
{
if( !enabled ) {
return;
}
mn_submenu_init(wt_netmon);
md380_menu_entry_selected = global_addl_config.netmon;
mn_submenu_add(wt_disable, create_menu_entry_netmon_disable_screen);
mn_submenu_add(wt_enable, create_menu_entry_netmon_enable_screen);
mn_submenu_finalize();
}
void create_menu_entry_experimental_screen(void)
{
mn_submenu_init(wt_experimental);
if( global_addl_config.experimental == 1 ) {
md380_menu_entry_selected = 0;
} else {
md380_menu_entry_selected = 1;
}
mn_submenu_add(wt_enable, create_menu_entry_experimental_enable_screen);
mn_submenu_add(wt_disable, create_menu_entry_experimental_disable_screen);
mn_submenu_finalize();
}
//-------------------------------------------------------------
// Backlight configuration: Timer adjustable 5, 30, 60 seconds,
// besides those in the original firmware.
// Please don't remove the 5 second option,
// it's the preferred one in combination with DIMMING .
//-------------------------------------------------------------
void mn_backlight_set(int sec5, const wchar_t *label)
{
mn_create_single_timed_ack(wt_backlight,label);
md380_radio_config.backlight_time = sec5 ; // in 5 sec incr.
rc_write_radio_config_to_flash();
}
void mn_backlight_unchanged()
{
}
void mn_backlight_5sec()
{
mn_backlight_set(1,wt_bl5);
}
void mn_backlight_30sec()
{
mn_backlight_set(6,wt_bl30);
}
void mn_backlight_60sec()
{
mn_backlight_set(12,wt_bl60);
}
void mn_backlight(void) // menu for the backlight-TIME (longer than Tytera's, but sets the same parameter)
{
mn_submenu_init(wt_backlight);
if ( md380_radio_config.backlight_time == 12 ) {
md380_menu_entry_selected = 2;
} else if ( md380_radio_config.backlight_time == 6 ) {
md380_menu_entry_selected = 1;
} else {
md380_menu_entry_selected = 0;
}
switch( md380_radio_config.backlight_time ) // inspired by fix stargo0's fix #674
{ // (fixes the selection of the current backlight-time in the menu)
case 1 /* times 5sec */ : md380_menu_entry_selected = 1; break;
case 6 /* times 5sec */ : md380_menu_entry_selected = 2; break;
case 12/* times 5sec */ : md380_menu_entry_selected = 3; break;
default/* unchanged */ : md380_menu_entry_selected = 0; break;
}
mn_submenu_add(wt_blunchanged, mn_backlight_unchanged);
mn_submenu_add(wt_bl5, mn_backlight_5sec );
mn_submenu_add(wt_bl30, mn_backlight_30sec);
mn_submenu_add(wt_bl60, mn_backlight_60sec);
mn_submenu_finalize();
}
#if( CONFIG_DIMMED_LIGHT ) // Setup for pulse-width modulated backlight ? (DL4YHF 2017-01-08)
typedef void(*tMenuFunctionPtr)(void);
static uint8_t bIntensityMenuIndex; // 0 = modifying "backlight intensity low" (used during idle time),
// 1 = modifying "backlight intensity high" (used when 'radio active').
void mn_backlight_intens( int intensity ) // common 'menu handler' for all <NUM_BACKLIGHT_INTENSITIES> intensity steps
{ // Caller: create_menu_entry_addl_functions_screen() -> mn_backlight_hi() + mn_backlight_lo()
// -> mn_submenu_add() -> ?..
// -> mn_backlight_intens_0/1/../9() -> mn_backlight_intens( intensity=0..9 )
//
switch( bIntensityMenuIndex ) // what's being edited, "low" (idle) or "high" (active) backlight intensity ?
{ case 0 : // selected a new LOW backlight intensity ...
default:
mn_create_single_timed_ack( wt_bl_intensity_lo, wt_bl_intensity[intensity]/*label*/ );
global_addl_config.backlight_intensities &= 0xF0; // strip old nibble (lower 4 bits for "lower" intensity)
global_addl_config.backlight_intensities |= (uint8_t)intensity;
break;
case 1 : // selected a new HIGH backlight intensity :
mn_create_single_timed_ack( wt_bl_intensity_hi, wt_bl_intensity[intensity]/*label*/ );
global_addl_config.backlight_intensities &= 0x0F; // strip old nibble (upper 4 bits for "high" intensity)
global_addl_config.backlight_intensities |= ((uint8_t)intensity << 4);
break;
}
// The upper 4 bits must never be ZERO, to avoid 'complete darkness' of the display when ACTIVE .
// Because in some radios, the PWM caused audible hum, use max brightness per default:
if( !(global_addl_config.backlight_intensities & 0xF0) )
{ global_addl_config.backlight_intensities |= 0xF0;
}
cfg_save();
} // end mn_backlight_intens()
// 'menu callback' for backlight intensity steps 0 .. 9
// (kludge required because the callback doesn't pass the item-index)
void mn_backlight_intens_0(void) { mn_backlight_intens(0); }
void mn_backlight_intens_1(void) { mn_backlight_intens(1); }
void mn_backlight_intens_2(void) { mn_backlight_intens(2); }
void mn_backlight_intens_3(void) { mn_backlight_intens(3); }
void mn_backlight_intens_4(void) { mn_backlight_intens(4); }
void mn_backlight_intens_5(void) { mn_backlight_intens(5); }
void mn_backlight_intens_6(void) { mn_backlight_intens(6); }
void mn_backlight_intens_7(void) { mn_backlight_intens(7); }
void mn_backlight_intens_8(void) { mn_backlight_intens(8); }
void mn_backlight_intens_9(void) { mn_backlight_intens(9); }
tMenuFunctionPtr nm_backlight_intensity_funcs[ NUM_BACKLIGHT_INTENSITIES ] =
{ mn_backlight_intens_0, mn_backlight_intens_1, mn_backlight_intens_2, mn_backlight_intens_3, mn_backlight_intens_4,
mn_backlight_intens_5, mn_backlight_intens_6, mn_backlight_intens_7, mn_backlight_intens_8, mn_backlight_intens_9
};
void mn_backlight_lo(void) // configure LOW backlight intensity (used when "idle")
{
int i;
bIntensityMenuIndex = 0; // "now selecting the LOW backlight intensity" ...
i = (global_addl_config.backlight_intensities & 15) % NUM_BACKLIGHT_INTENSITIES;
if( i>= NUM_BACKLIGHT_INTENSITIES )
{ i = NUM_BACKLIGHT_INTENSITIES-1; // valid ITEM indices: 0..9 (with NUM_BACKLIGHT_INTENSITIES=10)
}
md380_menu_entry_selected = i; // <- always a zero-based item index
mn_submenu_init(wt_bl_intensity_lo);
for(i=0; i<NUM_BACKLIGHT_INTENSITIES; ++i)
{ mn_submenu_add(wt_bl_intensity[i], nm_backlight_intensity_funcs[i] );
}
mn_submenu_finalize();
}
void mn_backlight_hi(void) // configure HIGH backlight intensity (used when "active")
{
int i;
bIntensityMenuIndex = 1; // "now selecting the HIGH backlight intensity" ...
// intensity value '0' (off) NOT ALLOWED for the 'HIGH' setting, thus SUBTRACT ONE below:
i = ( (global_addl_config.backlight_intensities>>4) & 15) - 1;
if( i>= (NUM_BACKLIGHT_INTENSITIES-1) )
{ i = NUM_BACKLIGHT_INTENSITIES-2; // valid ITEM indices: 0..8 (with NUM_BACKLIGHT_INTENSITIES=10)
}
if( i<0 )
{ i=0;
}
md380_menu_entry_selected = i; // <- always a zero-based item index
mn_submenu_init(wt_bl_intensity_hi);
for(i=1/*!!*/; i<NUM_BACKLIGHT_INTENSITIES; ++i)
{ mn_submenu_add(wt_bl_intensity[i], nm_backlight_intensity_funcs[i] );
}
mn_submenu_finalize();
}
#endif // CONFIG_DIMMED_LIGHT ?
#if defined(FW_D13_020) || defined(FW_S13_020)
void set_sidebutton_function(void)
{
button_function = button_functions[currently_selected_menu_entry];
switch ( button_selected ) {
case 0:
top_side_button_pressed_function = button_function;
md380_spiflash_write(&button_function, 0x2102, 1);
mn_create_single_timed_ack(wt_button_top_press,wt_button_func_set);
break;
case 1:
bottom_side_button_pressed_function = button_function;
md380_spiflash_write(&button_function, 0x2104, 1);
mn_create_single_timed_ack(wt_button_bot_press,wt_button_func_set);
break;
case 2:
top_side_button_held_function = button_function;
md380_spiflash_write(&button_function, 0x2103, 1);
mn_create_single_timed_ack(wt_button_top_held,wt_button_func_set);
break;
case 3:
bottom_side_button_held_function = button_function;