-
Notifications
You must be signed in to change notification settings - Fork 311
/
ui.c
2296 lines (2074 loc) · 54.9 KB
/
ui.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
/*
* Copyright (c) 2014-2015, TAKAHASHI Tomohiro (TTRFTECH) [email protected]
* 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 "ch.h"
#include "hal.h"
#include "chprintf.h"
#include "nanovna.h"
//#include <stdlib.h>
#include <string.h>
uistat_t uistat = {
digit: 6,
current_trace: 0,
lever_mode: LM_MARKER,
marker_delta: FALSE,
marker_tracking : FALSE,
};
#define NO_EVENT 0
#define EVT_BUTTON_SINGLE_CLICK 0x01
#define EVT_BUTTON_DOUBLE_CLICK 0x02
#define EVT_BUTTON_DOWN_LONG 0x04
#define EVT_UP 0x10
#define EVT_DOWN 0x20
#define EVT_REPEAT 0x40
#define BUTTON_DOWN_LONG_TICKS 5000 /* 1sec */
#define BUTTON_DOUBLE_TICKS 2500 /* 500ms */
#define BUTTON_REPEAT_TICKS 625 /* 125ms */
#define BUTTON_DEBOUNCE_TICKS 200
/* lever switch assignment */
#define BIT_UP1 3
#define BIT_PUSH 2
#define BIT_DOWN1 1
#define READ_PORT() palReadPort(GPIOA)
#define BUTTON_MASK 0b1111
static uint16_t last_button = 0b0000;
static uint32_t last_button_down_ticks;
static uint32_t last_button_repeat_ticks;
static int8_t inhibit_until_release = FALSE;
volatile uint8_t operation_requested = OP_NONE;
int8_t previous_marker = -1;
enum {
UI_NORMAL, UI_MENU, UI_NUMERIC, UI_KEYPAD
};
enum {
KM_START, KM_STOP, KM_CENTER, KM_SPAN, KM_CW, KM_SCALE, KM_REFPOS, KM_EDELAY, KM_VELOCITY_FACTOR, KM_SCALEDELAY
};
#define NUMINPUT_LEN 10
static uint8_t ui_mode = UI_NORMAL;
static uint8_t keypad_mode;
static uint8_t keypads_last_index;
static char kp_buf[NUMINPUT_LEN+1];
static int8_t kp_index = 0;
static uint8_t menu_current_level = 0;
static int8_t selection = 0;
// Set structure align as WORD (save flash memory)
#pragma pack(push, 2)
typedef struct {
uint8_t type;
uint8_t data;
char *label;
const void *reference;
} menuitem_t;
#pragma pack(pop)
// Touch screen
#define EVT_TOUCH_NONE 0
#define EVT_TOUCH_DOWN 1
#define EVT_TOUCH_PRESSED 2
#define EVT_TOUCH_RELEASED 3
static int8_t last_touch_status = EVT_TOUCH_NONE;
static int16_t last_touch_x;
static int16_t last_touch_y;
//int16_t touch_cal[4] = { 1000, 1000, 10*16, 12*16 };
//int16_t touch_cal[4] = { 620, 600, 130, 180 };
//int awd_count;
//int touch_x, touch_y;
#define KP_CONTINUE 0
#define KP_DONE 1
#define KP_CANCEL 2
static void ui_mode_normal(void);
static void ui_mode_menu(void);
static void ui_mode_numeric(int _keypad_mode);
static void ui_mode_keypad(int _keypad_mode);
static void draw_menu(void);
static void leave_ui_mode(void);
static void erase_menu_buttons(void);
static void ui_process_keypad(void);
static void ui_process_numeric(void);
static void menu_move_back(void);
static void menu_push_submenu(const menuitem_t *submenu);
static int btn_check(void)
{
int cur_button = READ_PORT() & BUTTON_MASK;
int changed = last_button ^ cur_button;
int status = 0;
uint32_t ticks = chVTGetSystemTime();
if (changed & (1<<BIT_PUSH)) {
if ((cur_button & (1<<BIT_PUSH))
&& ticks >= last_button_down_ticks + BUTTON_DEBOUNCE_TICKS) {
// button released
status |= EVT_BUTTON_SINGLE_CLICK;
if (inhibit_until_release) {
status = 0;
inhibit_until_release = FALSE;
}
}
}
if (changed & (1<<BIT_UP1)) {
if ((cur_button & (1<<BIT_UP1))
&& (ticks >= last_button_down_ticks + BUTTON_DEBOUNCE_TICKS)) {
status |= EVT_UP;
}
}
if (changed & (1<<BIT_DOWN1)) {
if ((cur_button & (1<<BIT_DOWN1))
&& (ticks >= last_button_down_ticks + BUTTON_DEBOUNCE_TICKS)) {
status |= EVT_DOWN;
}
}
last_button_down_ticks = ticks;
last_button = cur_button;
return status;
}
static int btn_wait_release(void)
{
while (TRUE) {
int cur_button = READ_PORT() & BUTTON_MASK;
int changed = last_button ^ cur_button;
uint32_t ticks = chVTGetSystemTime();
int status = 0;
if (!inhibit_until_release) {
if ((cur_button & (1<<BIT_PUSH))
&& ticks >= last_button_down_ticks + BUTTON_DOWN_LONG_TICKS) {
inhibit_until_release = TRUE;
return EVT_BUTTON_DOWN_LONG;
}
if ((changed & (1<<BIT_PUSH))
&& ticks < last_button_down_ticks + BUTTON_DOWN_LONG_TICKS) {
return EVT_BUTTON_SINGLE_CLICK;
}
}
if (changed) {
// finished
last_button = cur_button;
last_button_down_ticks = ticks;
inhibit_until_release = FALSE;
return 0;
}
if (ticks >= last_button_down_ticks + BUTTON_DOWN_LONG_TICKS
&& ticks >= last_button_repeat_ticks + BUTTON_REPEAT_TICKS) {
if (cur_button & (1<<BIT_DOWN1))
status |= EVT_DOWN | EVT_REPEAT;
if (cur_button & (1<<BIT_UP1))
status |= EVT_UP | EVT_REPEAT;
last_button_repeat_ticks = ticks;
return status;
}
}
}
static int
touch_measure_y(void)
{
int v;
// open Y line
palSetPadMode(GPIOB, 1, PAL_MODE_INPUT_PULLDOWN );
palSetPadMode(GPIOA, 7, PAL_MODE_INPUT_PULLDOWN );
// drive low to high on X line
palSetPadMode(GPIOB, 0, PAL_MODE_OUTPUT_PUSHPULL );
palClearPad(GPIOB, 0);
palSetPadMode(GPIOA, 6, PAL_MODE_OUTPUT_PUSHPULL );
palSetPad(GPIOA, 6);
chThdSleepMilliseconds(2);
v = adc_single_read(ADC_CHSELR_CHSEL7);
//chThdSleepMilliseconds(2);
//v += adc_single_read(ADC1, ADC_CHSELR_CHSEL7);
return v;
}
static int
touch_measure_x(void)
{
int v;
// open X line
palSetPadMode(GPIOB, 0, PAL_MODE_INPUT_PULLDOWN );
palSetPadMode(GPIOA, 6, PAL_MODE_INPUT_PULLDOWN );
// drive low to high on Y line
palSetPadMode(GPIOB, 1, PAL_MODE_OUTPUT_PUSHPULL );
palSetPad(GPIOB, 1);
palSetPadMode(GPIOA, 7, PAL_MODE_OUTPUT_PUSHPULL );
palClearPad(GPIOA, 7);
chThdSleepMilliseconds(2);
v = adc_single_read(ADC_CHSELR_CHSEL6);
//chThdSleepMilliseconds(2);
//v += adc_single_read(ADC1, ADC_CHSELR_CHSEL6);
return v;
}
void
touch_prepare_sense(void)
{
// open Y line
palSetPadMode(GPIOB, 1, PAL_MODE_INPUT_PULLDOWN );
palSetPadMode(GPIOA, 7, PAL_MODE_INPUT_PULLDOWN );
// force high X line
palSetPadMode(GPIOB, 0, PAL_MODE_OUTPUT_PUSHPULL );
palSetPad(GPIOB, 0);
palSetPadMode(GPIOA, 6, PAL_MODE_OUTPUT_PUSHPULL );
palSetPad(GPIOA, 6);
}
void
touch_start_watchdog(void)
{
touch_prepare_sense();
adc_start_analog_watchdogd(ADC_CHSELR_CHSEL7);
}
static int
touch_status(void)
{
touch_prepare_sense();
return adc_single_read(ADC_CHSELR_CHSEL7) > TOUCH_THRESHOLD;
}
static int
touch_check(void)
{
int stat = touch_status();
if (stat) {
chThdSleepMilliseconds(10);
int x = touch_measure_x();
int y = touch_measure_y();
if (touch_status()) {
last_touch_x = x;
last_touch_y = y;
}
touch_prepare_sense();
}
if (stat != last_touch_status) {
last_touch_status = stat;
return stat ? EVT_TOUCH_PRESSED : EVT_TOUCH_RELEASED;
}
return stat ? EVT_TOUCH_DOWN : EVT_TOUCH_NONE;
}
static inline void
touch_wait_release(void)
{
while (touch_check() != EVT_TOUCH_RELEASED)
;
}
static inline void
touch_wait_pressed(void)
{
while (touch_check() != EVT_TOUCH_PRESSED)
;
}
void
touch_cal_exec(void)
{
int x1, x2, y1, y2;
adc_stop();
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);
touch_wait_release();
x1 = last_touch_x;
y1 = last_touch_y;
ili9341_clear_screen();
ili9341_line(320-1, 240-1, 320-1, 240-32);
ili9341_line(320-1, 240-1, 320-32, 240-1);
ili9341_drawstring("TOUCH LOWER RIGHT", 230, 220);
touch_wait_release();
x2 = last_touch_x;
y2 = last_touch_y;
config.touch_cal[0] = x1;
config.touch_cal[1] = y1;
config.touch_cal[2] = (x2 - x1) * 16 / 320;
config.touch_cal[3] = (y2 - y1) * 16 / 240;
//redraw_all();
touch_start_watchdog();
}
void
touch_draw_test(void)
{
int x0, y0;
int x1, y1;
adc_stop();
ili9341_set_foreground(DEFAULT_FG_COLOR);
ili9341_set_background(DEFAULT_BG_COLOR);
ili9341_clear_screen();
ili9341_drawstring("TOUCH TEST: DRAG PANEL", OFFSETX, 233);
touch_wait_pressed();
touch_position(&x0, &y0);
do {
touch_position(&x1, &y1);
ili9341_line(x0, y0, x1, y1);
x0 = x1;
y0 = y1;
chThdSleepMilliseconds(50);
} while (touch_check() != EVT_TOUCH_RELEASED);
touch_start_watchdog();
}
void
touch_position(int *x, int *y)
{
*x = (last_touch_x - config.touch_cal[0]) * 16 / config.touch_cal[2];
*y = (last_touch_y - config.touch_cal[1]) * 16 / config.touch_cal[3];
}
void
show_version(void)
{
int x = 5, y = 5, i = 0;
adc_stop();
ili9341_set_foreground(DEFAULT_FG_COLOR);
ili9341_set_background(DEFAULT_BG_COLOR);
ili9341_clear_screen();
uint16_t shift = 0b0000010000111110;
ili9341_drawstring_size(info_about[i++], x , y, 4);
while (info_about[i]) {
do {shift>>=1; y+=5;} while (shift&1);
ili9341_drawstring(info_about[i++], x, y+=5);
}
while (true) {
if (touch_check() == EVT_TOUCH_PRESSED)
break;
if (btn_check() & EVT_BUTTON_SINGLE_CLICK)
break;
}
touch_start_watchdog();
}
void
enter_dfu(void)
{
adc_stop();
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("DFU: Device Firmware Update Mode", x, y += 10);
ili9341_drawstring("To exit DFU mode, please reset device yourself.", x, y += 10);
// see __early_init in ./NANOVNA_STM32_F072/board.c
*((unsigned long *)BOOT_FROM_SYTEM_MEMORY_MAGIC_ADDRESS) = BOOT_FROM_SYTEM_MEMORY_MAGIC;
NVIC_SystemReset();
}
static void
select_lever_mode(int mode)
{
if (uistat.lever_mode != mode) {
uistat.lever_mode = mode;
redraw_request |= REDRAW_FREQUENCY | REDRAW_MARKER;
}
}
// type of menu item
enum {
MT_NONE,
MT_BLANK,
MT_SUBMENU,
MT_CALLBACK,
MT_CANCEL,
MT_CLOSE
};
typedef void (*menuaction_cb_t)(int item, uint8_t data);
static void
menu_calop_cb(int item, uint8_t data)
{
cal_collect(data);
selection = item+1;
draw_cal_status();
draw_menu();
}
static void
menu_caldone_cb(int item, uint8_t data)
{
extern const menuitem_t menu_save[];
//extern const menuitem_t menu_cal[];
(void)item;
(void)data;
cal_done();
draw_cal_status();
menu_move_back();
menu_push_submenu(menu_save);
}
static void
menu_cal2_cb(int item, uint8_t data)
{
(void)data;
switch (item) {
case 2: // RESET
cal_status = 0;
break;
case 3: // CORRECTION
// toggle applying correction
cal_status ^= CALSTAT_APPLY;
break;
}
draw_menu();
draw_cal_status();
//menu_move_back();
}
static void
menu_recall_cb(int item, uint8_t data)
{
(void)item;
caldata_recall(data);
menu_move_back();
ui_mode_normal();
update_grid();
draw_cal_status();
}
static void
menu_config_cb(int item, uint8_t data)
{
(void)data;
switch (item) {
case 0:
touch_cal_exec();
break;
case 1:
touch_draw_test();
break;
case 3:
show_version();
break;
}
redraw_frame();
request_to_redraw_grid();
draw_menu();
}
static void
menu_config_save_cb(int item, uint8_t data)
{
(void)item;
(void)data;
config_save();
menu_move_back();
ui_mode_normal();
}
static void
menu_dfu_cb(int item, uint8_t data)
{
(void)item;
(void)data;
enter_dfu();
}
static void
menu_save_cb(int item, uint8_t data)
{
(void)item;
if (caldata_save(data) == 0) {
menu_move_back();
ui_mode_normal();
draw_cal_status();
}
}
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 void
menu_trace_cb(int item, uint8_t data)
{
(void)item;
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 void
menu_format_cb(int item, uint8_t data)
{
(void)item;
set_trace_type(uistat.current_trace, data);
request_to_redraw_grid();
ui_mode_normal();
//redraw_all();
}
static void
menu_channel_cb(int item, uint8_t data)
{
(void)item;
set_trace_channel(uistat.current_trace, data);
menu_move_back();
ui_mode_normal();
}
static void
menu_transform_window_cb(int item, uint8_t data)
{
(void)item;
// TODO
domain_mode = (domain_mode & ~TD_WINDOW) | data;
ui_mode_normal();
}
static void
menu_transform_cb(int item, uint8_t data)
{
(void)item;
(void)data;
domain_mode ^= DOMAIN_TIME;
select_lever_mode(LM_MARKER);
draw_frequencies();
ui_mode_normal();
}
static void
menu_velocity_cb(int item, uint8_t data)
{
(void)item;
(void)data;
if (btn_wait_release() & EVT_BUTTON_DOWN_LONG) {
ui_mode_numeric(KM_VELOCITY_FACTOR);
ui_process_numeric();
} else {
ui_mode_keypad(KM_VELOCITY_FACTOR);
ui_process_keypad();
}
}
static void
menu_transform_filter_cb(int item, uint8_t data)
{
(void)item;
domain_mode = (domain_mode & ~TD_FUNC) | data;
ui_mode_normal();
}
static void
menu_bandwidth_cb(int item)
{
bandwidth = item;
draw_menu();
}
static void
choose_active_marker(void)
{
int i;
for (i = 0; i < MARKERS_MAX; i++)
if (markers[i].enabled) {
active_marker = i;
return;
}
active_marker = -1;
}
static void
menu_scale_cb(int item, uint8_t data)
{
(void)item;
if (data == KM_SCALE && trace[uistat.current_trace].type == TRC_DELAY) {
data = KM_SCALEDELAY;
}
if (btn_wait_release() & EVT_BUTTON_DOWN_LONG) {
ui_mode_numeric(data);
ui_process_numeric();
} else {
ui_mode_keypad(data);
ui_process_keypad();
}
}
static void
menu_stimulus_cb(int item, uint8_t data)
{
(void)data;
switch (item) {
case 0: /* START */
case 1: /* STOP */
case 2: /* CENTER */
case 3: /* SPAN */
case 4: /* CW */
if (btn_wait_release() & EVT_BUTTON_DOWN_LONG) {
ui_mode_numeric(item);
ui_process_numeric();
} else {
ui_mode_keypad(item);
ui_process_keypad();
}
break;
case 5: /* PAUSE */
toggle_sweep();
//menu_move_back();
//ui_mode_normal();
draw_menu();
break;
}
}
static uint32_t
get_marker_frequency(int marker)
{
if (marker < 0 || marker >= MARKERS_MAX)
return 0;
if (!markers[marker].enabled)
return 0;
return frequencies[markers[marker].index];
}
static void
menu_marker_op_cb(int item, uint8_t data)
{
uint32_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(data, freq);
break;
case 3: /* MARKERS->SPAN */
{
if (previous_marker == -1 || active_marker == previous_marker) {
// if only 1 marker is active, keep center freq and make span the marker comes to the edge
uint32_t center = get_sweep_frequency(ST_CENTER);
uint32_t span = center > freq ? center - freq : freq - center;
set_sweep_frequency(ST_SPAN, span * 2);
} else {
// if 2 or more marker active, set start and stop freq to each marker
uint32_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;
float (*array)[2] = 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();
}
static void
menu_marker_search_cb(int item, uint8_t data)
{
(void)data;
int i = -1;
if (active_marker == -1)
return;
switch (item) {
case 0: /* maximum */
case 1: /* minimum */
set_marker_search(item);
i = marker_search();
break;
case 2: /* search Left */
i = marker_search_left(markers[active_marker].index);
uistat.marker_tracking = false;
break;
case 3: /* search right */
i = marker_search_right(markers[active_marker].index);
uistat.marker_tracking = false;
break;
case 4: /* tracking */
uistat.marker_tracking = !uistat.marker_tracking;
break;
}
if (i != -1)
markers[active_marker].index = i;
draw_menu();
redraw_marker(active_marker);
select_lever_mode(LM_SEARCH);
}
static void
menu_marker_smith_cb(int item, uint8_t data)
{
(void)item;
marker_smith_format = data;
redraw_marker(active_marker);
draw_menu();
}
static void
active_marker_select(int item)
{
if (item == -1) {
active_marker = previous_marker;
previous_marker = -1;
if (active_marker == -1) {
choose_active_marker();
}
} else {
if (previous_marker != active_marker)
previous_marker = active_marker;
active_marker = item;
}
}
static void
menu_marker_sel_cb(int item, uint8_t data)
{
(void)data;
int t;
if (item >= 0 && item < MARKERS_MAX) {
if (markers[item].enabled) {
if (item == active_marker) {
// disable if active trace is selected
markers[item].enabled = FALSE;
active_marker_select(-1);
} else {
active_marker_select(item);
}
} else {
markers[item].enabled = TRUE;
active_marker_select(item);
}
} else if (item == 4) { /* all off */
for (t = 0; t < MARKERS_MAX; t++)
markers[t].enabled = FALSE;
previous_marker = -1;
active_marker = -1;
} else if (item == 5) { /* marker delta */
uistat.marker_delta = !uistat.marker_delta;
}
redraw_marker(active_marker);
draw_menu();
}
static const menuitem_t menu_calop[] = {
{ MT_CALLBACK, CAL_OPEN, "OPEN", menu_calop_cb },
{ MT_CALLBACK, CAL_SHORT, "SHORT", menu_calop_cb },
{ MT_CALLBACK, CAL_LOAD, "LOAD", menu_calop_cb },
{ MT_CALLBACK, CAL_ISOLN, "ISOLN", menu_calop_cb },
{ MT_CALLBACK, CAL_THRU, "THRU", menu_calop_cb },
{ MT_CALLBACK, 0, "DONE", 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", menu_save_cb },
{ MT_CALLBACK, 1, "SAVE 1", menu_save_cb },
{ MT_CALLBACK, 2, "SAVE 2", menu_save_cb },
{ MT_CALLBACK, 3, "SAVE 3", menu_save_cb },
{ MT_CALLBACK, 4, "SAVE 4", menu_save_cb },
{ MT_CANCEL, 0, S_LARROW" BACK", NULL },
{ MT_NONE, 0, NULL, NULL } // sentinel
};
const menuitem_t menu_cal[] = {
{ MT_SUBMENU, 0, "CALIBRATE", menu_calop },
{ MT_SUBMENU, 0, "SAVE", menu_save },
{ MT_CALLBACK, 0, "RESET", menu_cal2_cb },
{ MT_CALLBACK, 0, "CORRECTION", menu_cal2_cb },
{ MT_CANCEL, 0, S_LARROW" BACK", NULL },
{ MT_NONE, 0, NULL, NULL } // sentinel
};
const menuitem_t menu_trace[] = {
{ MT_CALLBACK, 0, "TRACE 0", menu_trace_cb },
{ MT_CALLBACK, 1, "TRACE 1", menu_trace_cb },
{ MT_CALLBACK, 2, "TRACE 2", menu_trace_cb },
{ MT_CALLBACK, 3, "TRACE 3", menu_trace_cb },
{ MT_CANCEL, 0, S_LARROW" BACK", NULL },
{ MT_NONE, 0, NULL, NULL } // sentinel
};
const menuitem_t menu_format2[] = {
{ MT_CALLBACK, TRC_POLAR, "POLAR", menu_format_cb },
{ MT_CALLBACK, TRC_LINEAR, "LINEAR", menu_format_cb },
{ MT_CALLBACK, TRC_REAL, "REAL", menu_format_cb },
{ MT_CALLBACK, TRC_IMAG, "IMAG", menu_format_cb },
{ MT_CALLBACK, TRC_R, "RESISTANCE", menu_format_cb },
{ MT_CALLBACK, TRC_X, "REACTANCE", menu_format_cb },
{ MT_CALLBACK, TRC_Q, "Q FACTOR", menu_format_cb },
{ MT_CANCEL, 0, S_LARROW" BACK", NULL },
{ MT_NONE, 0, NULL, NULL } // sentinel
};
const menuitem_t menu_format[] = {
{ MT_CALLBACK, TRC_LOGMAG, "LOGMAG", menu_format_cb },
{ MT_CALLBACK, TRC_PHASE, "PHASE", menu_format_cb },
{ MT_CALLBACK, TRC_DELAY, "DELAY", menu_format_cb },
{ MT_CALLBACK, TRC_SMITH, "SMITH", menu_format_cb },
{ MT_CALLBACK, TRC_SWR, "SWR", menu_format_cb },
{ MT_SUBMENU, 0, S_RARROW" MORE", menu_format2 },
//{ MT_CALLBACK, TRC_LINEAR, "LINEAR", menu_format_cb },
//{ MT_CALLBACK, TRC_SWR, "SWR", 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", menu_scale_cb },
{ MT_CALLBACK, KM_REFPOS, "\2REFERENCE\0POSITION", menu_scale_cb },
{ MT_CALLBACK, KM_EDELAY, "\2ELECTRICAL\0DELAY", menu_scale_cb },
{ MT_CANCEL, 0, S_LARROW" BACK", NULL },
{ MT_NONE, 0, NULL, NULL } // sentinel
};
const menuitem_t menu_channel[] = {
{ MT_CALLBACK, 0, "\2CH0\0REFLECT", menu_channel_cb },
{ MT_CALLBACK, 1, "\2CH1\0THROUGH", menu_channel_cb },
{ MT_CANCEL, 0, S_LARROW" BACK", NULL },
{ MT_NONE, 0, NULL, NULL } // sentinel
};
const menuitem_t menu_transform_window[] = {
{ MT_CALLBACK, TD_WINDOW_MINIMUM, "MINIMUM", menu_transform_window_cb },
{ MT_CALLBACK, TD_WINDOW_NORMAL, "NORMAL", menu_transform_window_cb },
{ MT_CALLBACK, TD_WINDOW_MAXIMUM, "MAXIMUM", menu_transform_window_cb },
{ MT_CANCEL, 0, S_LARROW" BACK", NULL },
{ MT_NONE, 0, NULL, NULL } // sentinel
};
const menuitem_t menu_transform[] = {
{ MT_CALLBACK, 0, "\2TRANSFORM\0ON", menu_transform_cb },
{ MT_CALLBACK, TD_FUNC_LOWPASS_IMPULSE, "\2LOW PASS\0IMPULSE", menu_transform_filter_cb },
{ MT_CALLBACK, TD_FUNC_LOWPASS_STEP, "\2LOW PASS\0STEP", menu_transform_filter_cb },
{ MT_CALLBACK, TD_FUNC_BANDPASS, "BANDPASS", menu_transform_filter_cb },
{ MT_SUBMENU, 0, "WINDOW", menu_transform_window },
{ MT_CALLBACK, 0, "\2VELOCITY\0FACTOR", menu_velocity_cb },
{ MT_CANCEL, 0, S_LARROW" BACK", NULL },
{ MT_NONE, 0, NULL, NULL } // sentinel
};
const menuitem_t menu_bandwidth[] = {
{ MT_CALLBACK, 0, "1 kHz", menu_bandwidth_cb },
{ MT_CALLBACK, 0, "300 Hz", menu_bandwidth_cb },
{ MT_CALLBACK, 0, "100 Hz", menu_bandwidth_cb },
{ MT_CALLBACK, 0, "30 Hz", menu_bandwidth_cb },
{ MT_CALLBACK, 0, "10 Hz", menu_bandwidth_cb },
{ MT_CANCEL, 0, S_LARROW" BACK", NULL },
{ MT_NONE, 0, NULL, NULL } // sentinel
};
const menuitem_t menu_display[] = {
{ MT_SUBMENU, 0, "TRACE", menu_trace },
{ MT_SUBMENU, 0, "FORMAT", menu_format },
{ MT_SUBMENU, 0, "SCALE", menu_scale },
{ MT_SUBMENU, 0, "CHANNEL", menu_channel },
{ MT_SUBMENU, 0, "TRANSFORM", menu_transform },
{ MT_SUBMENU, 0, "BANDWIDTH", menu_bandwidth },
{ MT_CANCEL, 0, S_LARROW" BACK", NULL },
{ MT_NONE, 0, NULL, NULL } // sentinel
};
const menuitem_t menu_stimulus[] = {
{ MT_CALLBACK, 0, "START", menu_stimulus_cb },
{ MT_CALLBACK, 0, "STOP", menu_stimulus_cb },
{ MT_CALLBACK, 0, "CENTER", menu_stimulus_cb },
{ MT_CALLBACK, 0, "SPAN", menu_stimulus_cb },
{ MT_CALLBACK, 0, "CW FREQ", menu_stimulus_cb },
{ MT_CALLBACK, 0, "\2PAUSE\0SWEEP", menu_stimulus_cb },
{ MT_CANCEL, 0, S_LARROW" BACK", NULL },
{ MT_NONE, 0, NULL, NULL } // sentinel
};
const menuitem_t menu_marker_sel[] = {
{ MT_CALLBACK, 1, "MARKER 1", menu_marker_sel_cb },
{ MT_CALLBACK, 2, "MARKER 2", menu_marker_sel_cb },
{ MT_CALLBACK, 3, "MARKER 3", menu_marker_sel_cb },
{ MT_CALLBACK, 4, "MARKER 4", menu_marker_sel_cb },
{ MT_CALLBACK, 0, "ALL OFF", menu_marker_sel_cb },
{ MT_CALLBACK, 0, "DELTA", menu_marker_sel_cb },
{ MT_CANCEL, 0, S_LARROW" BACK", NULL },
{ MT_NONE, 0, NULL, NULL } // sentinel
};
const menuitem_t menu_marker_ops[] = {
{ MT_CALLBACK, ST_START, S_RARROW"START", menu_marker_op_cb },
{ MT_CALLBACK, ST_STOP, S_RARROW"STOP", menu_marker_op_cb },
{ MT_CALLBACK, ST_CENTER, S_RARROW"CENTER", menu_marker_op_cb },
{ MT_CALLBACK, ST_SPAN, S_RARROW"SPAN", menu_marker_op_cb },
{ MT_CALLBACK, 0, S_RARROW"EDELAY", menu_marker_op_cb },
{ MT_CANCEL, 0, S_LARROW" BACK", NULL },
{ MT_NONE, 0, NULL, NULL } // sentinel
};
const menuitem_t menu_marker_search[] = {
//{ MT_CALLBACK, "OFF", menu_marker_search_cb },
{ MT_CALLBACK, 0, "MAXIMUM", menu_marker_search_cb },
{ MT_CALLBACK, 0, "MINIMUM", menu_marker_search_cb },
{ MT_CALLBACK, 0, "\2SEARCH\0" S_LARROW" LEFT", menu_marker_search_cb },
{ MT_CALLBACK, 0, "\2SEARCH\0" S_RARROW" RIGHT", menu_marker_search_cb },
{ MT_CALLBACK, 0, "TRACKING", menu_marker_search_cb },