-
Notifications
You must be signed in to change notification settings - Fork 87
/
ui.cpp
2218 lines (1988 loc) · 58.3 KB
/
ui.cpp
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
/*
* Copyright (c) 2014-2015, TAKAHASHI Tomohiro (TTRFTECH) edy555@gmail.com
* All rights reserved.
*
* This is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3, or (at your option)
* any later version.
*
* The software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Radio; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street,
* Boston, MA 02110-1301, USA.
*/
#include "common.hpp"
#include "main.hpp"
#include "flash.hpp"
#include "globals.hpp"
#include "ili9341.hpp"
#include "Font.h"
#include "plot.hpp"
#include "ui.hpp"
#include "board.hpp"
#include <stdlib.h>
#include <string.h>
#include <mculib/message_log.hpp>
#include <mculib/printf.hpp>
#include <mculib/printk.hpp>
#include "gitversion.hpp"
using UIHW::UIEvent;
using UIHW::UIEventButtons;
using UIHW::UIEventTypes;
using namespace UIActions;
#define TRUE true
#define FALSE false
int8_t previous_marker = MARKER_INVALID;
enum {
UI_NORMAL, UI_MENU, UI_KEYPAD, UI_USB_MODE
};
enum {
KM_START, KM_STOP, KM_CENTER, KM_SPAN, KM_POINTS, KM_CW, KM_SCALE, KM_REFPOS, KM_EDELAY, KM_VELOCITY_FACTOR, KM_SCALEDELAY
};
uint8_t ui_mode = UI_NORMAL;
uint8_t keypad_mode;
int8_t selection = 0;
bool ui_disabled = false;
// Button definition (used in MT_ADV_CALLBACK for custom)
#define BUTTON_ICON_NONE -1
#define BUTTON_ICON_NOCHECK 0
#define BUTTON_ICON_CHECK 1
#define BUTTON_ICON_GROUP 2
#define BUTTON_ICON_GROUP_CHECKED 3
#define BUTTON_BORDER_NONE 0x00
#define BUTTON_BORDER_WIDTH_MASK 0x0F
// Define mask for draw border (if 1 use light color, if 0 dark)
#define BUTTON_BORDER_TYPE_MASK 0xF0
#define BUTTON_BORDER_TOP 0x10
#define BUTTON_BORDER_BOTTOM 0x20
#define BUTTON_BORDER_LEFT 0x40
#define BUTTON_BORDER_RIGHT 0x80
#define BUTTON_BORDER_FLAT 0x00
#define BUTTON_BORDER_RISE (BUTTON_BORDER_TOP|BUTTON_BORDER_RIGHT)
#define BUTTON_BORDER_FALLING (BUTTON_BORDER_BOTTOM|BUTTON_BORDER_LEFT)
typedef struct {
uint16_t bg;
uint16_t fg;
uint8_t border;
int8_t icon;
} button_t;
// Call back functions for MT_CALLBACK type
typedef void (*menuaction_cb_t)(UIEvent evt, int item, uint16_t data);
#define UI_FUNCTION_CALLBACK(ui_function_name) void ui_function_name(UIEvent evt, int item, uint16_t data)
typedef void (*menuaction_acb_t)(UIEvent evt, int item, uint16_t data, button_t *b);
#define UI_FUNCTION_ADV_CALLBACK(ui_function_name) void ui_function_name(UIEvent evt, int item, uint16_t data, button_t *b)
// Set structure align as WORD (save flash memory)
#pragma pack(push, 2)
typedef struct {
uint8_t type;
uint8_t data;
const char *label;
const void *reference;
} menuitem_t;
#pragma pack(pop)
//int awd_count;
//int touch_x, touch_y;
#define NUMINPUT_LEN 10
#define KP_CONTINUE 0
#define KP_DONE 1
#define KP_CANCEL 2
char kp_buf[11];
int8_t kp_index = 0;
bool uiEventsEnabled = true;
UIEvent lastUIEvent = {};
void ui_mode_menu(void);
void ui_mode_keypad(int _keypad_mode);
void draw_menu(void);
void leave_ui_mode(void);
void erase_menu_buttons(void);
void ui_process_keypad(UIEvent evt);
static void menu_push_submenu(const menuitem_t *submenu);
static int touch_pickup_marker(void);
void
touch_prepare_sense(void)
{
}
// Disable or enable ui_process_* callbacks in order to do synchronous event polling.
// New uses of these functions are heavily discouraged.
// Please use event driven UI processing instead.
void uiEnableProcessing(void) {
uiEventsEnabled = true;
}
void uiDisableProcessing() {
uiEventsEnabled = false;
}
// wait for an UI event when UI processing is disabled.
UIEvent uiWaitEvent() {
while(lastUIEvent.type == UIEventTypes::None)
application_doSingleEvent();
UIEvent ret = lastUIEvent;
lastUIEvent = {};
return ret;
}
void
touch_cal_exec(void)
{
uint16_t x1, x2, y1, y2, t;
UIEvent evt;
uiDisableProcessing();
ili9341_set_foreground(DEFAULT_FG_COLOR);
ili9341_set_background(DEFAULT_BG_COLOR);
ili9341_clear_screen();
ili9341_line(0, 0, 0, 32);
ili9341_line(0, 0, 32, 0);
ili9341_drawstring("TOUCH UPPER LEFT", 10, 10);
do {
evt = uiWaitEvent();
if(evt.isTouchPress())
UIHW::touchPosition(x1, y1);
} while(!evt.isTouchRelease());
ili9341_clear_screen();
ili9341_line(LCD_WIDTH-1, LCD_HEIGHT-1, LCD_WIDTH-1, LCD_HEIGHT-32);
ili9341_line(LCD_WIDTH-1, LCD_HEIGHT-1, LCD_WIDTH-32, LCD_HEIGHT-1);
ili9341_drawstring("TOUCH LOWER RIGHT", LCD_WIDTH-17*(FONT_WIDTH)-10, LCD_HEIGHT-FONT_GET_HEIGHT-10);
do {
evt = uiWaitEvent();
if(evt.isTouchPress())
UIHW::touchPosition(x2, y2);
} while(!evt.isTouchRelease());
// Need swap data if display flip
if(config.ui_options & UI_OPTIONS_FLIP){
t=x1;x1=x2;x2=t;
t=y1;y1=y2;y2=t;
}
config.touch_cal[0] = x1;
config.touch_cal[1] = y1;
config.touch_cal[2] = (x2 - x1) * 16 / LCD_WIDTH;
config.touch_cal[3] = (y2 - y1) * 16 / LCD_HEIGHT;
UIActions::printTouchCal();
uiEnableProcessing();
}
void
touch_draw_test(void)
{
UIEvent evt;
int x0, y0;
int x1, y1;
uiDisableProcessing();
ili9341_set_foreground(DEFAULT_FG_COLOR);
ili9341_set_background(DEFAULT_BG_COLOR);
ili9341_clear_screen();
ili9341_drawstring("TOUCH TEST: DRAG PANEL", OFFSETX, LCD_HEIGHT - FONT_STR_HEIGHT);
do {
evt = uiWaitEvent();
} while(!evt.isTouchPress());
touch_position(&x0, &y0);
while(true) {
if(!touch_position(&x1, &y1))
break;
ili9341_line(x0, y0, x1, y1);
x0 = x1;
y0 = y1;
delay(50);
}
uiEnableProcessing();
}
bool touch_position(int *x, int *y)
{
uint16_t touchX, touchY;
if(!UIHW::touchPosition(touchX, touchY))
return false;
*x = (int(touchX) - config.touch_cal[0]) * 16 / config.touch_cal[2];
*y = (int(touchY) - config.touch_cal[1]) * 16 / config.touch_cal[3];
if(config.ui_options & UI_OPTIONS_FLIP) {
*x = LCD_WIDTH - *x;
*y = LCD_HEIGHT - *y;
}
return true;
}
bool touch_position(int *x, int *y, UIEvent evt) {
return touch_position(x, y);
}
void
show_version(void)
{
int x = 5, y = 5;
const char *fpu;
uint32_t* deviceID = (uint32_t*)0x1FFFF7E8;
char snStr[64];
chsnprintf(snStr, sizeof(snStr), "SN: %08x-%08x-%08x\n", deviceID[0], deviceID[1], deviceID[2]);
ili9341_set_foreground(DEFAULT_FG_COLOR);
ili9341_set_background(DEFAULT_BG_COLOR);
uiDisableProcessing();
ili9341_clear_screen();
ili9341_drawstring_size(BOARD_NAME, x, y, 3);
y += 3*FONT_GET_HEIGHT + 6;
ili9341_drawstring_size(snStr, x, y, 2);
y += 2*FONT_GET_HEIGHT;
int step = FONT_STR_HEIGHT + 3;
ili9341_drawstring("Software copyright @edy555 et al", x, y += step);
ili9341_drawstring("Hardware designed by OwOComm", x, y += step);
ili9341_drawstring("Licensed under GPL. ", x, y += step);
ili9341_drawstring("https://github.com/ttrftech/NanoVNA", x + 10, y += step);
ili9341_drawstring("https://github.com/nanovna/NanoVNA-V2-firmware", x + 10, y += step);
ili9341_drawstring("Version: " GITVERSION, x, y += step);
ili9341_drawstring("Build Time: " __DATE__ " - " __TIME__, x, y += step);
y += 5;
ili9341_drawstring("Compiler: " PORT_COMPILER_NAME, x, y += step);
ili9341_drawstring("Port Info: " PORT_INFO, x, y += step);
ili9341_drawstring("Board: " BOARD_NAME, x, y += step);
while (true) {
UIEvent evt = uiWaitEvent();
if(evt.isTouchPress() || evt.isLeverClick())
break;
}
uiEnableProcessing();
}
void
show_dmesg(void)
{
int x = 5, y = 5;
ili9341_set_foreground(DEFAULT_FG_COLOR);
ili9341_set_background(DEFAULT_BG_COLOR);
uiDisableProcessing();
ili9341_clear_screen();
int maxLines = 23;
const char* msg = dmesg();
int len = strlen(msg);
const char* end = msg + len;
// leave only last maxLines lines
const char* pos = end - 1;
const char* lines[maxLines];
int nextLineIndex = maxLines - 1;
while(pos >= msg && pos < end) {
if((*pos) == '\n') {
lines[nextLineIndex] = pos + 1;
nextLineIndex--;
if(nextLineIndex < 0) break;
}
pos--;
}
if(nextLineIndex >= 0) {
lines[nextLineIndex] = msg;
nextLineIndex--;
}
for(int i = nextLineIndex+1; i<maxLines; i++) {
int len = (i < (maxLines-1)) ? (lines[i+1] - lines[i]) : (end - lines[i]);
if(len > 0) len--;
ili9341_drawstring(lines[i], len, x, y);
y += 10;
}
while (true) {
UIEvent evt = uiWaitEvent();
if(evt.isTouchPress() || evt.isLeverClick())
break;
}
uiEnableProcessing();
}
void ui_mode_usb(void) {
int x = 5, y = 5;
ili9341_set_foreground(DEFAULT_FG_COLOR);
ili9341_set_background(DEFAULT_BG_COLOR);
ili9341_clear_screen();
ili9341_drawstring_size(BOARD_NAME, x, y, 3);
y += 3 * FONT_GET_HEIGHT + 25;
ili9341_drawstring_size("USB MODE", x, y, 3);
ui_mode = UI_USB_MODE;
}
void
show_message(const char* title, const char* message, int fg, int bg)
{
int x = 5, y = 5;
ili9341_set_foreground(fg);
ili9341_set_background(bg);
ili9341_clear_screen();
ili9341_drawstring_size(title, x, y, 3);
y += 3 * FONT_GET_HEIGHT + 25;
ili9341_drawstring_size(message, x, y, 1);
}
void
ui_enter_bootload(void)
{
uiDisableProcessing();
int x = 5, y = 5;
ili9341_set_foreground(DEFAULT_FG_COLOR);
ili9341_set_background(DEFAULT_BG_COLOR);
// leave a last message
ili9341_clear_screen();
ili9341_drawstring("BOOTLOAD: Device Firmware Update Mode", x, y += FONT_STR_HEIGHT);
ili9341_drawstring("To exit Bootload mode, please reset device yourself.", x, y += FONT_STR_HEIGHT);
enterBootload();
}
// type of menu item
enum {
MT_NONE,
MT_BLANK,
MT_SUBMENU,
MT_CALLBACK,
MT_ADV_CALLBACK,
MT_CANCEL,
MT_CLOSE
};
static void menu_move_back(bool leave_ui);
static UI_FUNCTION_ADV_CALLBACK(menu_calop_acb)
{
if (b){
if ((data == CAL_OPEN && (cal_status & CALSTAT_OPEN))
|| (data == CAL_SHORT && (cal_status & CALSTAT_SHORT))
|| (data == CAL_LOAD && (cal_status & CALSTAT_LOAD))
|| (data == CAL_THRU && (cal_status & CALSTAT_THRU)))
b->icon = BUTTON_ICON_CHECK;
return;
}
cal_collect(data);
// selection = item+1;
ui_disabled = true;
// draw_cal_status();
// draw_menu();
}
void ui_cal_collected() {
ui_disabled = false;
draw_cal_status();
draw_menu();
}
extern const menuitem_t menu_save[];
static UI_FUNCTION_CALLBACK(menu_caldone_cb)
{
(void)item;
(void)data;
cal_done();
draw_cal_status();
menu_move_back(false);
menu_push_submenu(menu_save);
}
static UI_FUNCTION_ADV_CALLBACK(menu_cal2_acb)
{
(void)data;
if (b){
if (item == 4) b->icon = (cal_status&CALSTAT_APPLY) ? BUTTON_ICON_CHECK : BUTTON_ICON_NOCHECK;
if (item == 5) b->icon = (cal_status&CALSTAT_ENHANCED_RESPONSE) ? BUTTON_ICON_CHECK : BUTTON_ICON_NOCHECK;
return;
}
switch (item) {
case 2: // RESET
cal_reset();
break;
case 3: // RESET ALL
cal_reset_all();
break;
case 4: // CORRECTION
// toggle applying correction
if (cal_status)
cal_status ^= CALSTAT_APPLY;
break;
case 5: // ENHANCED RESPONSE
cal_status ^= CALSTAT_ENHANCED_RESPONSE;
break;
}
draw_menu();
draw_cal_status();
}
static UI_FUNCTION_CALLBACK(menu_recall_cb)
{
if (caldata_recall(data) == 0) {
menu_move_back(true);
draw_cal_status();
} else {
show_dmesg();
redraw_frame();
request_to_redraw_grid();
draw_menu();
}
}
static UI_FUNCTION_CALLBACK(menu_config_cb)
{
switch (item) {
case 0:
touch_cal_exec();
redraw_frame();
request_to_redraw_grid();
draw_menu();
uiEnableProcessing();
break;
case 1:
touch_draw_test();
redraw_frame();
request_to_redraw_grid();
draw_menu();
break;
case 3:
show_version();
redraw_frame();
request_to_redraw_grid();
draw_menu();
break;
case 4:
show_dmesg();
redraw_frame();
request_to_redraw_grid();
draw_menu();
break;
}
}
static UI_FUNCTION_CALLBACK(menu_config_save_cb)
{
(void)item;
(void)data;
config_save();
menu_move_back(true);
}
static UI_FUNCTION_CALLBACK(menu_bootload_cb)
{
(void)item;
(void)data;
ui_enter_bootload();
}
static UI_FUNCTION_CALLBACK(menu_save_cb)
{
(void)item;
if (caldata_save(data) == 0) {
menu_move_back(true);
draw_cal_status();
} else {
show_dmesg();
redraw_frame();
request_to_redraw_grid();
draw_menu();
}
}
static void
choose_active_trace(void)
{
int i;
if (trace[uistat.current_trace].enabled)
// do nothing
return;
for (i = 0; i < TRACES_MAX; i++)
if (trace[i].enabled) {
uistat.current_trace = i;
return;
}
}
static UI_FUNCTION_ADV_CALLBACK(menu_trace_acb)
{
(void)item;
if (b){
if (trace[data].enabled){
b->bg = config.trace_color[data];
if (data == selection) b->fg = ~config.trace_color[data];
if (uistat.current_trace == data) b->icon = BUTTON_ICON_CHECK;
}
return;
}
if (trace[data].enabled) {
if (data == uistat.current_trace) {
// disable if active trace is selected
trace[data].enabled = FALSE;
choose_active_trace();
} else {
// make active selected trace
uistat.current_trace = data;
}
} else {
trace[data].enabled = TRUE;
uistat.current_trace = data;
}
request_to_redraw_grid();
draw_menu();
}
static UI_FUNCTION_ADV_CALLBACK(menu_format_acb)
{
(void)item;
if (b){
if (uistat.current_trace >=0 && trace[uistat.current_trace].type == data)
b->icon = BUTTON_ICON_CHECK;
return;
}
set_trace_type(uistat.current_trace, data);
request_to_redraw_grid();
ui_mode_normal();
//redraw_all();
}
static UI_FUNCTION_ADV_CALLBACK(menu_channel_acb)
{
(void)item;
if (b){
if (uistat.current_trace >=0 && trace[uistat.current_trace].channel == data)
b->icon = BUTTON_ICON_CHECK;
return;
}
set_trace_channel(uistat.current_trace, data);
menu_move_back(true);
}
static UI_FUNCTION_ADV_CALLBACK(menu_transform_window_acb)
{
(void)item;
// TODO
if(b){
b->icon = (domain_mode & TD_WINDOW) == data ? BUTTON_ICON_GROUP_CHECKED : BUTTON_ICON_GROUP;
return;
}
domain_mode = (domain_mode & ~TD_WINDOW) | data;
ui_mode_normal();
}
static UI_FUNCTION_ADV_CALLBACK(menu_transform_acb)
{
(void)item;
(void)data;
if(b){
if (domain_mode & DOMAIN_TIME) b->icon = BUTTON_ICON_CHECK;
return;
}
domain_mode ^= DOMAIN_TIME;
// uistat.lever_mode = LM_MARKER;
ui_mode_normal();
}
static UI_FUNCTION_ADV_CALLBACK(menu_transform_filter_acb)
{
(void)item;
if(b){
b->icon = (domain_mode & TD_FUNC) == data ? BUTTON_ICON_GROUP_CHECKED : BUTTON_ICON_GROUP;
return;
}
domain_mode = (domain_mode & ~TD_FUNC) | data;
ui_mode_normal();
}
static UI_FUNCTION_ADV_CALLBACK(menu_avg_acb)
{
(void)item;
if(b) {
if (current_props._avg == data)
b->icon = BUTTON_ICON_CHECK;
return;
}
set_averaging(data);
draw_frequencies();
ui_mode_normal();
}
static UI_FUNCTION_ADV_CALLBACK(menu_power_acb)
{
(void)item;
if(b) {
if (current_props._adf4350_txPower == data)
b->icon = BUTTON_ICON_CHECK;
return;
}
set_adf4350_txPower(data);
ui_mode_normal();
}
static UI_FUNCTION_ADV_CALLBACK(menu_display_acb)
{
if(b){
b->icon = config.ui_options & UI_OPTIONS_FLIP ? BUTTON_ICON_CHECK : BUTTON_ICON_NOCHECK;
return;
}
config.ui_options^= UI_OPTIONS_FLIP;
if(config.ui_options & UI_OPTIONS_FLIP)
ili9341_set_flip(true, true);
else ili9341_set_flip(false, false);
redraw_request |= 0xff;
force_set_markmap();
ili9341_set_background(DEFAULT_BG_COLOR);
ili9341_clear_screen();
draw_all(true);
draw_menu();
plot_cancel();
}
static UI_FUNCTION_CALLBACK(menu_keyboard_cb)
{
(void)item;
if (data == KM_SCALE && trace[uistat.current_trace].type == TRC_DELAY) {
data = KM_SCALEDELAY;
}
ui_mode_keypad(data);
}
static UI_FUNCTION_ADV_CALLBACK(measurement_mode)
{
(void) item;
enum MeasurementMode mode = (enum MeasurementMode) data;
enum MeasurementMode cur_mode = (enum MeasurementMode) current_props._measurement_mode;
if (b){
b->icon = (mode == cur_mode) ? BUTTON_ICON_GROUP_CHECKED : BUTTON_ICON_GROUP ;
return;
}
// CW work also as checkbox
if (cur_mode == mode && mode == MEASURE_MODE_REFL_THRU) mode = MEASURE_MODE_FULL;
set_measurement_mode(mode);
draw_menu();
}
static UI_FUNCTION_ADV_CALLBACK(menu_pause_acb)
{
(void)item;
(void)data;
if (b){
b->icon = sweep_enabled ? BUTTON_ICON_NOCHECK : BUTTON_ICON_CHECK;
return;
}
toggle_sweep();
//menu_move_back(true);
draw_menu();
}
static freqHz_t
get_marker_frequency(int marker)
{
if (marker < 0 || marker >= MARKERS_MAX)
return -1;
if (!markers[marker].enabled)
return -1;
return frequencyAt(markers[marker].index);
}
static UI_FUNCTION_CALLBACK(menu_marker_op_cb)
{
freqHz_t freq = get_marker_frequency(active_marker);
if (freq < 0)
return; // no active marker
switch (item) {
case 0: /* MARKER->START */
case 1: /* MARKER->STOP */
case 2: /* MARKER->CENTER */
set_sweep_frequency((SweepParameter)data, freq);
break;
case 3: /* MARKERS->SPAN */
{
if (previous_marker == MARKER_INVALID || active_marker == previous_marker) {
// if only 1 marker is active, keep center freq and make span the marker comes to the edge
freqHz_t center = get_sweep_frequency(ST_CENTER);
freqHz_t span = center - freq;
if (span < 0) span = -span;
set_sweep_frequency(ST_SPAN, span * 2);
} else {
// if 2 or more marker active, set start and stop freq to each marker
freqHz_t freq2 = get_marker_frequency(previous_marker);
if (freq2 < 0)
return;
if (freq > freq2) {
freq2 = freq;
freq = get_marker_frequency(previous_marker);
}
set_sweep_frequency(ST_START, freq);
set_sweep_frequency(ST_STOP, freq2);
}
}
break;
case 4: /* MARKERS->EDELAY */
{
if (uistat.current_trace == -1)
break;
complexf* array = measured[trace[uistat.current_trace].channel];
float v = groupdelay_from_array(markers[active_marker].index, array);
set_electrical_delay(electrical_delay + (v / 1e-12));
}
break;
}
ui_mode_normal();
draw_cal_status();
//redraw_all();
}
#ifdef __USE_LC_MATCHING__
static UI_FUNCTION_ADV_CALLBACK(menu_marker_lc_match_acb)
{
(void)data;
if (b){
b->icon = domain_mode & TD_LC_MATH ? BUTTON_ICON_CHECK : BUTTON_ICON_NOCHECK;
return;
}
domain_mode^=TD_LC_MATH;
ui_mode_normal();
}
#endif
static UI_FUNCTION_CALLBACK(menu_marker_search_cb)
{
int i = -1;
if (active_marker == MARKER_INVALID)
return;
switch (item) {
case 0: /* maximum */
case 1: /* minimum */
uistat.marker_search_mode = (item == 0) ? MarkerSearchModes::Max : MarkerSearchModes::Min;
i = marker_search(uistat.marker_search_mode);
break;
case 2: /* search Left */
i = marker_search_dir(uistat.marker_search_mode, markers[active_marker].index, MK_SEARCH_LEFT);
break;
case 3: /* search right */
i = marker_search_dir(uistat.marker_search_mode, markers[active_marker].index, MK_SEARCH_RIGHT);
break;
case 4: /* tracking */
uistat.marker_tracking = !uistat.marker_tracking;
break;
}
if (i >= 0){
markers[active_marker].index = i;
redraw_marker(active_marker);
}
draw_menu();
// uistat.lever_mode = LM_SEARCH;
}
void ui_marker_track() {
if (uistat.marker_tracking) {
int i = marker_search(uistat.marker_search_mode);
if (i != -1 && active_marker != MARKER_INVALID) {
markers[active_marker].index = i;
redraw_request |= REDRAW_MARKER;
}
}
}
static UI_FUNCTION_ADV_CALLBACK(menu_marker_tracking_acb)
{
(void)item;
(void)data;
if (b){
b->icon = uistat.marker_tracking ? BUTTON_ICON_CHECK : BUTTON_ICON_NOCHECK;
return;
}
uistat.marker_tracking = !uistat.marker_tracking;
draw_menu();
}
static UI_FUNCTION_ADV_CALLBACK(menu_marker_smith_acb)
{
(void)item;
if (b){
b->icon = marker_smith_format == data ? BUTTON_ICON_GROUP_CHECKED : BUTTON_ICON_GROUP;
return;
}
marker_smith_format = data;
redraw_marker(active_marker);
draw_menu();
}
static void
active_marker_check(void)
{
int i;
// Auto select active marker if disabled
if (active_marker == MARKER_INVALID)
for (i = 0; i < MARKERS_MAX; i++)
if (markers[i].enabled) active_marker = i;
// Auto select previous marker if disabled
if (previous_marker == active_marker) previous_marker = MARKER_INVALID;
if (previous_marker == MARKER_INVALID){
for (i = 0; i < MARKERS_MAX; i++)
if (markers[i].enabled && i != active_marker) previous_marker = i;
}
}
#define UI_MARKER_OFF (MARKERS_MAX )
#define UI_MARKER_DELTA (MARKERS_MAX+1)
static UI_FUNCTION_ADV_CALLBACK(menu_marker_sel_acb)
{
int i;
if (b){
if (data < MARKERS_MAX && markers[data].enabled) b->icon = BUTTON_ICON_CHECK;
else if (data == UI_MARKER_DELTA) b->icon = uistat.marker_delta ? BUTTON_ICON_CHECK : BUTTON_ICON_NOCHECK;
return;
}
// Marker select click
if (data < MARKERS_MAX) {
int mk = data;
if (markers[mk].enabled) { // Marker enabled
if (mk == active_marker) { // If active marker:
markers[mk].enabled = FALSE; // disable it
mk = previous_marker; // set select from previous marker
active_marker = MARKER_INVALID; // invalidate active
}
} else {
markers[mk].enabled = TRUE; // Enable marker
}
previous_marker = active_marker; // set previous marker as current active
active_marker = mk; // set new active marker
active_marker_check();
} else if (data == UI_MARKER_OFF) { // all off
for (i = 0; i < MARKERS_MAX; i++)
markers[i].enabled = FALSE;
previous_marker = MARKER_INVALID;
active_marker = MARKER_INVALID;
} else if (data == UI_MARKER_DELTA) { // marker delta
uistat.marker_delta = !uistat.marker_delta;
}
redraw_marker(active_marker);
draw_menu();
}
static const menuitem_t menu_calop[] = {
{ MT_ADV_CALLBACK, CAL_OPEN, "OPEN", (const void *)menu_calop_acb },
{ MT_ADV_CALLBACK, CAL_SHORT, "SHORT", (const void *)menu_calop_acb },
{ MT_ADV_CALLBACK, CAL_LOAD, "LOAD", (const void *)menu_calop_acb },
{ MT_ADV_CALLBACK, CAL_THRU, "THRU", (const void *)menu_calop_acb },
{ MT_CALLBACK, 0, "DONE", (const void *)menu_caldone_cb },
{ MT_CANCEL, 0, S_LARROW" BACK", NULL },
{ MT_NONE, 0, NULL, NULL } // sentinel
};
const menuitem_t menu_save[] = {
{ MT_CALLBACK, 0, "SAVE 0", (const void *)menu_save_cb },
{ MT_CALLBACK, 1, "SAVE 1", (const void *)menu_save_cb },
{ MT_CALLBACK, 2, "SAVE 2", (const void *)menu_save_cb },
{ MT_CALLBACK, 3, "SAVE 3", (const void *)menu_save_cb },
{ MT_CALLBACK, 4, "SAVE 4", (const void *)menu_save_cb },
#if SAVEAREA_MAX > 5
{ MT_CALLBACK, 5, "SAVE 5", (const void *)menu_save_cb },
#endif
#if SAVEAREA_MAX > 6
{ MT_CALLBACK, 6, "SAVE 6", (const void *)menu_save_cb },
#endif
{ MT_CANCEL, 0, S_LARROW" BACK", NULL },
{ MT_NONE, 0, NULL, NULL } // sentinel
};
const menuitem_t menu_cal[] = {
{ MT_SUBMENU, 0, "CALIBRATE", (const void *)menu_calop },
{ MT_SUBMENU, 0, "SAVE", (const void *)menu_save },
{ MT_ADV_CALLBACK, 0, "RESET", (const void *)menu_cal2_acb },
{ MT_ADV_CALLBACK, 0, "RESET\nALL", (const void *)menu_cal2_acb },
{ MT_ADV_CALLBACK, 0, "APPLY", (const void *)menu_cal2_acb },
{ MT_ADV_CALLBACK, 0, "ENHANCED\nRESPONSE", (const void *)menu_cal2_acb },
{ MT_CANCEL, 0, S_LARROW" BACK", NULL },
{ MT_NONE, 0, NULL, NULL } // sentinel
};
const menuitem_t menu_trace[] = {
{ MT_ADV_CALLBACK, 0, "TRACE 0", (const void *)menu_trace_acb },
{ MT_ADV_CALLBACK, 1, "TRACE 1", (const void *)menu_trace_acb },
{ MT_ADV_CALLBACK, 2, "TRACE 2", (const void *)menu_trace_acb },
{ MT_ADV_CALLBACK, 3, "TRACE 3", (const void *)menu_trace_acb },
{ MT_CANCEL, 0, S_LARROW" BACK", NULL },
{ MT_NONE, 0, NULL, NULL } // sentinel
};
const menuitem_t menu_format2[] = {
{ MT_ADV_CALLBACK, TRC_POLAR, "POLAR", (const void *)menu_format_acb },
{ MT_ADV_CALLBACK, TRC_LINEAR, "LINEAR", (const void *)menu_format_acb },
{ MT_ADV_CALLBACK, TRC_REAL, "REAL", (const void *)menu_format_acb },
{ MT_ADV_CALLBACK, TRC_IMAG, "IMAG", (const void *)menu_format_acb },
{ MT_ADV_CALLBACK, TRC_R, "RESISTANCE", (const void *)menu_format_acb },
{ MT_ADV_CALLBACK, TRC_X, "REACTANCE", (const void *)menu_format_acb },
{ MT_ADV_CALLBACK, TRC_Q, "Q FACTOR", (const void *)menu_format_acb },
{ MT_CANCEL, 0, S_LARROW" BACK", NULL },
{ MT_NONE, 0, NULL, NULL } // sentinel
};
const menuitem_t menu_format[] = {
{ MT_ADV_CALLBACK, TRC_LOGMAG, "LOGMAG", (const void *)menu_format_acb },
{ MT_ADV_CALLBACK, TRC_PHASE, "PHASE", (const void *)menu_format_acb },
{ MT_ADV_CALLBACK, TRC_DELAY, "DELAY", (const void *)menu_format_acb },
{ MT_ADV_CALLBACK, TRC_SMITH, "SMITH", (const void *)menu_format_acb },
{ MT_ADV_CALLBACK, TRC_SWR, "SWR", (const void *)menu_format_acb },
{ MT_SUBMENU, 0, S_RARROW" MORE", (const void *)menu_format2 },
//{ MT_CALLBACK, TRC_LINEAR, "LINEAR", (const void *)menu_format_cb },
//{ MT_CALLBACK, TRC_SWR, "SWR", (const void *)menu_format_cb },
{ MT_CANCEL, 0, S_LARROW" BACK", NULL },
{ MT_NONE, 0, NULL, NULL } // sentinel
};
const menuitem_t menu_scale[] = {
{ MT_CALLBACK, KM_SCALE, "SCALE/DIV", (const void *)menu_keyboard_cb },
{ MT_CALLBACK, KM_REFPOS, "REFERENCE\nPOSITION", (const void *)menu_keyboard_cb },
{ MT_CALLBACK, KM_EDELAY, "ELECTRICAL\nDELAY", (const void *)menu_keyboard_cb },
{ MT_CANCEL, 0, S_LARROW" BACK", NULL },
{ MT_NONE, 0, NULL, NULL } // sentinel
};