forked from erikkaashoek/tinySA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ui_sa.c
2734 lines (2537 loc) · 84.9 KB
/
ui_sa.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) 2020, Erik Kaashoek [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.
*/
#define FORM_ICON_WIDTH 16
#define FORM_ICON_HEIGHT 16
static const uint8_t left_icons [] =
{
#define I_EMPTY (0*16)
_BMP16(0b0000000000000000),
_BMP16(0b0000000000000000),
_BMP16(0b0000000000000000),
_BMP16(0b0000000000000001),
_BMP16(0b0000000000000001),
_BMP16(0b0000000000000001),
_BMP16(0b0000000000000000),
_BMP16(0b0000000000000000),
_BMP16(0b0000000000000000),
_BMP16(0b0000000000000000),
_BMP16(0b0000000000000001),
_BMP16(0b0000000000000001),
_BMP16(0b0000000000000001),
_BMP16(0b0000000000000000),
_BMP16(0b0000000000000000),
_BMP16(0b0000000000000000),
#define I_HIGH_INPUT (1*16)
// +----------------+
_BMP16(0b0000000000000000), // | |
_BMP16(0b0000000000000000), // | |
_BMP16(0b0000000001100000), // | ** |
_BMP16(0b0000000000111001), // | *** *|
_BMP16(0b0000111111111111), // | *************|
_BMP16(0b0000000000111001), // | *** *|
_BMP16(0b0000000001100000), // | ** |
_BMP16(0b0000000000000000), // | |
_BMP16(0b0000000000000000), // | |
_BMP16(0b0000000000000000), // | |
_BMP16(0b0000000000000001), // | |
_BMP16(0b0000000000000001), // | |
_BMP16(0b0000000000000001), // | |
_BMP16(0b0000000000000000), // | |
_BMP16(0b0000000000000000), // | |
_BMP16(0b0000000000000000), // | |
// +----------------+
#define I_LOW_INPUT (2*16)
// +----------------+
_BMP16(0b0000000000000000), // | |
_BMP16(0b0000000000000000), // | |
_BMP16(0b0000000000000000), // | |
_BMP16(0b0000000000000001), // | |
_BMP16(0b0000000000000001), // | |
_BMP16(0b0000000000000001), // | |
_BMP16(0b0000000000000000), // | |
_BMP16(0b0000000000000000), // | |
_BMP16(0b0000000000000000), // | |
_BMP16(0b0000000001100000), // | ** |
_BMP16(0b0000000000111001), // | **** *|
_BMP16(0b0000111111111111), // | *************|
_BMP16(0b0000000000111001), // | **** *|
_BMP16(0b0000000001100000), // | ** |
_BMP16(0b0000000000000000), // | |
_BMP16(0b0000000000000000), // | |
// +----------------+
#define I_LOW_OUTPUT (3*16)
_BMP16(0b0000000000000000),
_BMP16(0b0000000000000000),
_BMP16(0b0000000000000000),
_BMP16(0b0000000000000001),
_BMP16(0b0000000000000001),
_BMP16(0b0000000000000001),
_BMP16(0b0000000000000000),
_BMP16(0b0000000000000000),
_BMP16(0b0000000000000000),
_BMP16(0b0000000110000000),
_BMP16(0b0000011100000001),
_BMP16(0b0000111111111111),
_BMP16(0b0000011100000001),
_BMP16(0b0000000110000000),
_BMP16(0b0000000000000000),
_BMP16(0b0000000000000000),
#define I_HIGH_OUTPUT (4*16)
_BMP16(0b0000000000000000),
_BMP16(0b0000000000000000),
_BMP16(0b0000000110000000),
_BMP16(0b0000011100000001),
_BMP16(0b0000111111111111),
_BMP16(0b0000011100000001),
_BMP16(0b0000000110000000),
_BMP16(0b0000000000000000),
_BMP16(0b0000000000000000),
_BMP16(0b0000000000000000),
_BMP16(0b0000000000000001),
_BMP16(0b0000000000000001),
_BMP16(0b0000000000000001),
_BMP16(0b0000000000000000),
_BMP16(0b0000000000000000),
_BMP16(0b0000000000000000),
#define I_CONNECT (5*16)
_BMP16(0b0000000000000000),
_BMP16(0b0000000000000000),
_BMP16(0b0000000000110000),
_BMP16(0b0000000000111101),
_BMP16(0b0000001111111111),
_BMP16(0b0000010000111101),
_BMP16(0b0000100000110000),
_BMP16(0b0001000000000000),
_BMP16(0b0001000000000000),
_BMP16(0b0000100000110000),
_BMP16(0b0000010000111101),
_BMP16(0b0000001111111111),
_BMP16(0b0000000000111101),
_BMP16(0b0000000000110000),
_BMP16(0b0000000000000000),
_BMP16(0b0000000000000000),
};
const uint8_t right_icons [] =
{
#define I_SA 0
// +----------------+
_BMP16(0b0000000000000000), // | |
_BMP16(0b0111111111111111), // | ***************|
_BMP16(0b0100000000000001), // | * *|
_BMP16(0b1100000000000001), // |** *|
_BMP16(0b1100000000000001), // |** * *|
_BMP16(0b1100000000000001), // |** * *|
_BMP16(0b0100100000000001), // | * * * *|
_BMP16(0b0100100000000001), // | * * * *|
_BMP16(0b0100101010001001), // | * * * * *|
_BMP16(0b0100101010101001), // | * * * * * *|
_BMP16(0b1100101010101001), // |** * * * * * *|
_BMP16(0b1101111111111101), // |** * * * * * *|
_BMP16(0b1100000000000001), // |** *********** *|
_BMP16(0b0100000000000001), // | * *|
_BMP16(0b0111111111111111), // | ***************|
_BMP16(0b0000000000000000), // | |
// +----------------+
#define I_GEN 1
// +----------------+
_BMP16(0b0000000000000000), // | |
_BMP16(0b0111111111111111), // | ***************|
_BMP16(0b0100000000000001), // | * *|
_BMP16(0b1100000000000001), // |** *|
_BMP16(0b1100111110001101), // |** ***** ** *|
_BMP16(0b1100100010001001), // |** * * * *|
_BMP16(0b0100100010001001), // | * * * * *|
_BMP16(0b0100100010001001), // | * * * * *|
_BMP16(0b0100100010001001), // | * * * * *|
_BMP16(0b0100100010001001), // | * * * * *|
_BMP16(0b1100100010001001), // |** * * * *|
_BMP16(0b1101100011111001), // |** ** ***** *|
_BMP16(0b1100000000000001), // |** *|
_BMP16(0b0100000000000001), // | * *|
_BMP16(0b0111111111111111), // | ***************|
_BMP16(0b0000000000000000), // | |
// +----------------+
#define I_CONFIG 2
_BMP16(0b0000000000000000),
_BMP16(0b0111111111111111),
_BMP16(0b0100000000000001),
_BMP16(0b1100000010000001),
_BMP16(0b1100001111000001),
_BMP16(0b1100011110001001),
_BMP16(0b0100011100011101),
_BMP16(0b0100011110111001),
_BMP16(0b0100001111111001),
_BMP16(0b0100011111110001),
_BMP16(0b1100111110000001),
_BMP16(0b1101111100000001),
_BMP16(0b1100111000000001),
_BMP16(0b0100000000000001),
_BMP16(0b0111111111111111),
_BMP16(0b0000000000000000),
#define I_SINUS 3
_BMP16(0b0000000000000000),
_BMP16(0b0111111111111111), // 1
_BMP16(0b0100000000000001), // 2
_BMP16(0b1100000000000001), // 3
_BMP16(0b1100000000110001), // 4
_BMP16(0b1100000001001001), // 5
_BMP16(0b0100000010000101), // 6
_BMP16(0b0101000010000101), // 7
_BMP16(0b0101000010000101), // 8
_BMP16(0b0101000010000001), // 9
_BMP16(0b1100100100000001), //10
_BMP16(0b1100011000000001), //11
_BMP16(0b1100000000000001), //12
_BMP16(0b0100000000000001), //13
_BMP16(0b0111111111111111), //14
_BMP16(0b0000000000000000),
};
#define KP_X(x) (48*(x) + 2 + (LCD_WIDTH-BUTTON_WIDTH-192))
#define KP_Y(y) (48*(y) + 2)
#define KP_PERIOD 10
#define KP_MINUS 11
#define KP_X1 12
#define KP_K 13
#define KP_M 14
#define KP_G 15
#define KP_BS 16
#define KP_INF 17
#define KP_DB 18
#define KP_PLUSMINUS 19
#define KP_KEYPAD 20
#define KP_m 21
#define KP_u 22
#define KP_n 23
#define KP_p 24
#define KP_0 31
#define KP_1 32
#define KP_2 33
#define KP_5 34
#define KP_10 35
#define KP_20 36
#define KP_50 37
#define KP_100 38
#define KP_200 39
#define KP_500 40
typedef struct {
uint8_t x:4;
uint8_t y:4;
int8_t c;
} keypads_t;
static const keypads_t *keypads;
static uint8_t keypads_last_index;
// 7 8 9 G
// 4 5 6 M
// 1 2 3 k
// 0 . < x
static const keypads_t keypads_freq[] = {
{ 1, 3, KP_PERIOD },
{ 0, 3, 0 },
{ 0, 2, 1 },
{ 1, 2, 2 },
{ 2, 2, 3 },
{ 0, 1, 4 },
{ 1, 1, 5 },
{ 2, 1, 6 },
{ 0, 0, 7 },
{ 1, 0, 8 },
{ 2, 0, 9 },
{ 3, 0, KP_G },
{ 3, 1, KP_M },
{ 3, 2, KP_K },
{ 3, 3, KP_X1 },
{ 2, 3, KP_BS },
{ 0, 0, -1 }
};
// 7 8 9
// 4 5 6
// 1 2 3
// 0 . < x
static const keypads_t keypads_positive[] = {
{ 1, 3, KP_PERIOD },
{ 0, 3, 0 },
{ 0, 2, 1 },
{ 1, 2, 2 },
{ 2, 2, 3 },
{ 0, 1, 4 },
{ 1, 1, 5 },
{ 2, 1, 6 },
{ 0, 0, 7 },
{ 1, 0, 8 },
{ 2, 0, 9 },
{ 3, 3, KP_X1 },
{ 2, 3, KP_BS },
{ 0, 0, -1 }
};
// 100 200 500 n
// 10 20 50 u
// 1 2 5 m
// 0 . < x
static const keypads_t keypads_pos_unit[] = {
{ 1, 3, KP_PERIOD },
{ 0, 3, 0 },
{ 0, 2, 1 },
{ 1, 2, 2 },
{ 2, 2, 5 },
{ 0, 1, KP_10 },
{ 1, 1, KP_20 },
{ 2, 1, KP_50 },
{ 0, 0, KP_100 },
{ 1, 0, KP_200 },
{ 2, 0, KP_500 },
{ 3, 0, KP_n },
{ 3, 1, KP_u },
{ 3, 2, KP_m },
{ 3, 3, KP_X1 },
{ 2, 3, KP_BS },
{ 0, 0, -1 }
};
// 7 8 9 m
// 4 5 6 u
// 1 2 3 -
// 0 . < x
static const keypads_t keypads_plusmin_unit[] = {
{ 1, 3, KP_PERIOD },
{ 0, 3, 0 },
{ 0, 2, 1 },
{ 1, 2, 2 },
{ 2, 2, 3 },
{ 0, 1, 4 },
{ 1, 1, 5 },
{ 2, 1, 6 },
{ 0, 0, 7 },
{ 1, 0, 8 },
{ 2, 0, 9 },
{ 3, 0, KP_u},
{ 3, 1, KP_m},
{ 3, 2, KP_MINUS },
{ 3, 3, KP_X1 },
{ 2, 3, KP_BS },
{ 0, 0, -1 }
};
// 7 8 9
// 4 5 6
// 1 2 3 -
// 0 . < x
static const keypads_t keypads_plusmin[] = {
{ 1, 3, KP_PERIOD },
{ 0, 3, 0 },
{ 0, 2, 1 },
{ 1, 2, 2 },
{ 2, 2, 3 },
{ 0, 1, 4 },
{ 1, 1, 5 },
{ 2, 1, 6 },
{ 0, 0, 7 },
{ 1, 0, 8 },
{ 2, 0, 9 },
{ 3, 0, KP_u},
{ 3, 1, KP_m},
{ 3, 2, KP_MINUS },
{ 3, 3, KP_X1 },
{ 2, 3, KP_BS },
{ 0, 0, -1 }
};
// 7 8 9
// 4 5 6
// 1 2 3 m
// 0 . < x
static const keypads_t keypads_time[] = {
{ 1, 3, KP_PERIOD },
{ 0, 3, 0 },
{ 0, 2, 1 },
{ 1, 2, 2 },
{ 2, 2, 3 },
{ 0, 1, 4 },
{ 1, 1, 5 },
{ 2, 1, 6 },
{ 0, 0, 7 },
{ 1, 0, 8 },
{ 2, 0, 9 },
// { 3, 0, KP_n},
// { 3, 1, KP_u},
{ 3, 2, KP_m },
{ 3, 3, KP_X1 },
{ 2, 3, KP_BS },
{ 0, 0, -1 }
};
enum {
KM_START, KM_STOP, KM_CENTER, KM_SPAN, KM_CW, // These must be first to share common help text
KM_REFLEVEL, KM_SCALE, KM_ATTENUATION,
KM_ACTUALPOWER, KM_IF, KM_SAMPLETIME, KM_DRIVE, KM_LOWOUTLEVEL, KM_DECAY, KM_NOISE,
KM_10MHZ, KM_REPEAT, KM_OFFSET, KM_TRIGGER, KM_LEVELSWEEP, KM_SWEEP_TIME, KM_OFFSET_DELAY,
KM_FAST_SPEEDUP, KM_GRIDLINES, KM_MARKER, KM_MODULATION, KM_HIGHOUTLEVEL,
#if 0
KM_COR_AM,KM_COR_WFM, KM_COR_NFM,
#endif
KM_ATTACK,
KM_NONE // always at enum end
};
static const struct {
const keypads_t *keypad_type;
char * name;
} keypads_mode_tbl[KM_NONE] = {
{keypads_freq , "START"}, // start
{keypads_freq , "STOP"}, // stop
{keypads_freq , "CENTER"}, // center
{keypads_freq , "SPAN"}, // span
{keypads_freq , "FREQ"}, // cw freq
{keypads_plusmin_unit, "REF\nLEVEL"}, // reflevel
{keypads_pos_unit , "SCALE"}, // scale
{keypads_positive , "ATTENUATE"}, // attenuation
{keypads_plusmin_unit, "ACTUAL\nPOWER"}, // actual power
{keypads_freq , "IF"}, // IF
{keypads_positive , "SAMPLE\nDELAY"}, // sample delay
{keypads_positive , "DRIVE"}, // KM_DRIVE
{keypads_plusmin , "LEVEL"}, // KM_LOWOUTLEVEL
{keypads_positive , "DECAY"}, // KM_DECAY
{keypads_positive , "NOISE\nLEVEL"}, // KM_NOISE
{keypads_freq , "FREQ"}, // KM_10MHz
{keypads_positive , "SAMPLE\nREPEAT"}, // KM_REPEA
{keypads_plusmin , "OFFSET"}, // KM_OFFSET
{keypads_plusmin_unit, "TRIGGER\nLEVEL"}, // KM_TRIGGER
{keypads_plusmin , "LEVEL\nSWEEP"}, // KM_LEVELSWEEP
{keypads_time , "SWEEP\nSECONDS"}, // KM_SWEEP_TIME
{keypads_positive , "OFFSET\nDELAY"}, // KM_OFFSET_DELAY
{keypads_positive , "FAST\nSPEEDUP"}, // KM_FAST_SPEEDUP
{keypads_positive , "MINIMUM\nGRIDLINES"}, // KM_GRIDLINES
{keypads_freq , "MARKER\nFREQ"}, // KM_MARKER
{keypads_freq , "MODULATION\nFREQ"}, // KM_MODULATION
{keypads_plusmin , "LEVEL"}, // KM_HIGHOUTLEVEL
#if 0
{keypads_plusmin , "COR\nAM"}, // KM_COR_AM
{keypads_plusmin , "COR\nWFM"}, // KM_COR_WFM
{keypads_plusmin , "COR\nNFM"}, // KM_COR_NFM
#endif
{keypads_positive , "ATTACK"}, // KM_ATTACK
};
#if 0 // Not used
ui_slider_t ui_sliders [] =
{
{ KM_CENTER, true, 0, 1000000, 0, 350000000, M_GENLOW},
{ KM_CENTER, true, 0, 1000000, 240000000, 960000000, M_GENHIGH},
{ KM_LOWOUTLEVEL, false,0, 1, -76, -6, M_GENLOW},
{ KM_HIGHOUTLEVEL, false,0, 1, -38, +6, M_GENHIGH},
};
#endif
// ===[MENU CALLBACKS]=========================================================
static const menuitem_t menu_lowoutputmode[];
static const menuitem_t menu_highoutputmode[];
static const menuitem_t menu_modulation[];
static const menuitem_t menu_top[];
static const menuitem_t menu_reffer[];
static const menuitem_t menu_modulation[];
static const menuitem_t menu_drive_wide[];
static const menuitem_t menu_sweep[];
#ifdef __ULTRA__
static const menuitem_t menu_tophigh[];
static const menuitem_t menu_topultra[];
#endif
#define AUTO_ICON(S) (S>=2?BUTTON_ICON_CHECK_AUTO:S) // Depends on order of ICONs!!!!!
static UI_FUNCTION_ADV_CALLBACK(menu_sweep_acb)
{
(void)data;
(void)item;
if (b){
if (setting.level_sweep != 0 || get_sweep_frequency(ST_SPAN) != 0) {
plot_printf(uistat.text, sizeof uistat.text, "SW:%3.2fMHz %+ddB %.3Fs",
get_sweep_frequency(ST_SPAN) / 1000000.0,
(int)setting.level_sweep,
setting.sweep_time_us/(float)ONE_SECOND_TIME);
b->param_1.text = uistat.text;
}
else
b->param_1.text = "SWEEP: OFF";
return;
}
menu_push_submenu(menu_sweep);
}
static UI_FUNCTION_ADV_CALLBACK(menu_mode_acb)
{
(void)data;
if (b){
if (item == setting.mode) {
b->param_1.text = "Return";
b->bg = LCD_MENU_ACTIVE_COLOR;
b->border = BUTTON_BORDER_FALLING | MENU_BUTTON_BORDER;
}
else
b->param_1.text = "Switch";
return;
}
set_mode(item);
// draw_cal_status();
switch (item) {
case 0:
// if (setting.mode != M_LOW)
// set_mode(M_LOW);
menu_move_back_and_leave_ui();
break;
case 1:
// if (setting.mode != M_HIGH)
// set_mode(M_HIGH);
menu_move_back_and_leave_ui();
break;
case 2:
menu_push_submenu(menu_lowoutputmode);
break;
case 3:
menu_push_submenu(menu_highoutputmode);
break;
#ifdef __ULTRA__
case 7:
menu_push_submenu(menu_topultra);
break;
#endif
}
redraw_request |= REDRAW_CAL_STATUS;
}
static UI_FUNCTION_ADV_CALLBACK(menu_load_preset_acb)
{
(void)item;
if(b){
b->param_1.u = data;
return;
}
if (caldata_recall(data) == -1) {
if (data == 0)
reset_settings(setting.mode); // Restore factory defaults
else {
draw_menu();
return;
}
}
menu_move_back_and_leave_ui();
}
static UI_FUNCTION_ADV_CALLBACK(menu_store_preset_acb)
{
(void)item;
if(b){
b->param_1.u = data;
return;
}
if (data == 100) {
reset_settings(M_LOW); // Restore all defaults in Low mode
set_refer_output(-1);
// setting.mode = -1;
data = 0;
}
caldata_save(data);
menu_move_back_and_leave_ui();
}
extern int dirty;
UI_FUNCTION_CALLBACK(menu_autosettings_cb)
{
(void)item;
(void)data;
reset_settings(setting.mode);
active_marker = 0;
for (int i = 1; i<MARKER_COUNT; i++ ) {
markers[i].enabled = M_DISABLED;
}
markers[0].enabled = M_ENABLED;
markers[0].mtype = M_REFERENCE | M_TRACKING;
// set_refer_output(1);
// SetPowerLevel(100); // Reset
set_clear_storage();
dirty = true;
// menu_move_back(); // stay in input menu
ui_mode_normal();
// draw_cal_status();
}
static UI_FUNCTION_CALLBACK(menu_calibrate_cb)
{
(void)data;
switch (item) {
case 1:
sweep_mode = SWEEP_CALIBRATE;
menu_move_back_and_leave_ui();
break;
case 2:
reset_calibration();
draw_menu();
break;
}
}
static UI_FUNCTION_ADV_CALLBACK(menu_scanning_speed_acb)
{
(void)item;
if(b){
b->icon = data == setting.step_delay_mode ? BUTTON_ICON_GROUP_CHECKED : BUTTON_ICON_GROUP;
return;
}
set_step_delay(data);
// menu_move_back();
ui_mode_normal();
}
#define CONFIG_MENUITEM_TOUCH_CAL 0
#define CONFIG_MENUITEM_TOUCH_TEST 1
#define CONFIG_MENUITEM_SELFTEST 2
#define CONFIG_MENUITEM_VERSION 3
static UI_FUNCTION_CALLBACK(menu_config_cb)
{
(void)item;
switch (data) {
case CONFIG_MENUITEM_TOUCH_CAL:
touch_cal_exec();
redraw_frame();
request_to_redraw_grid();
draw_menu();
break;
case CONFIG_MENUITEM_TOUCH_TEST:
touch_draw_test();
redraw_frame();
request_to_redraw_grid();
draw_menu();
break;
case CONFIG_MENUITEM_SELFTEST:
sweep_mode = 0; // Suspend sweep to save time
menu_move_back_and_leave_ui();
setting.test = 0;
setting.test_argument = 0;
sweep_mode = SWEEP_SELFTEST;
break;
case CONFIG_MENUITEM_VERSION:
show_version();
redraw_frame();
request_to_redraw_grid();
draw_menu();
}
}
static UI_FUNCTION_CALLBACK(menu_dfu_cb)
{
(void)data;
(void)item;
enter_dfu();
}
// const int menu_modulation_value[]={MO_NONE,MO_AM, MO_NFM, MO_WFM, MO_EXTERNAL};
const char *menu_modulation_text[]={"None", "AM", "NFM", "WFM", "External"};
static UI_FUNCTION_ADV_CALLBACK(menu_modulation_acb)
{
(void)item;
if (b){
b->icon = data == setting.modulation ? BUTTON_ICON_GROUP_CHECKED : BUTTON_ICON_GROUP;
return;
}
//Serial.println(item);
if (data) {
set_sweep_frequency(ST_SPAN, 0); // No other scanning allowed when modulation is on!!!!!
set_level_sweep(0);
}
set_modulation(data);
menu_move_back();
// ui_mode_normal(); // Stay in menu mode
// draw_cal_status();
}
static UI_FUNCTION_ADV_CALLBACK(menu_smodulation_acb){
(void)item;
(void)data;
if(b){
if (setting.modulation == MO_NONE || setting.modulation == MO_EXTERNAL)
b->param_1.text = menu_modulation_text[setting.modulation];
else {
plot_printf(uistat.text, sizeof uistat.text, "%5.3fkHz %s", setting.modulation_frequency / 1000.0, menu_modulation_text[setting.modulation]);
b->param_1.text = uistat.text;
}
return;
}
menu_push_submenu(menu_modulation);
}
// 0 1 2 3 4 5 6 7
const char *menu_reffer_text[]={"OFF","30MHz","15MHz","10MHz","4MHz","3MHz","2MHz","1MHz"};
static UI_FUNCTION_ADV_CALLBACK(menu_reffer_acb)
{
(void)item;
if (b){
b->icon = setting.refer == ((int)data-1) ? BUTTON_ICON_GROUP_CHECKED : BUTTON_ICON_GROUP;
b->param_1.text = menu_reffer_text[data];
return;
}
//Serial.println(item);
set_refer_output((int)data - 1);
menu_move_back();
// ui_mode_normal(); // Stay in menu mode
// draw_cal_status();
}
static UI_FUNCTION_ADV_CALLBACK(menu_sreffer_acb){
(void)item;
(void)data;
if(b){
b->param_1.text = menu_reffer_text[setting.refer+1];
return;
}
menu_push_submenu(menu_reffer);
}
const int8_t menu_drive_value[]={-38,-35,-33,-30,-27,-24,-21,-19, -7,-4,-2,1,4,7,10,13};
static UI_FUNCTION_ADV_CALLBACK(menu_lo_drive_acb)
{
(void)item;
if(b){
b->param_1.i = menu_drive_value[data] + (setting.mode==M_GENHIGH ? setting.offset : 0);
b->icon = data == setting.lo_drive ? BUTTON_ICON_GROUP_CHECKED : BUTTON_ICON_GROUP;
return;
}
//Serial.println(item);
set_lo_drive(data);
menu_move_back();
// ui_mode_normal();
// draw_cal_status();
}
#if 0
static UI_FUNCTION_ADV_CALLBACK(menu_sdrive_acb){
(void)item;
(void)data;
if(b){
b->param_1.i = menu_drive_value[setting.lo_drive] + (setting.mode==M_GENHIGH ? setting.offset : 0);
return;
}
menu_push_submenu(menu_drive_wide);
}
#endif
#ifdef __SPUR__
static UI_FUNCTION_ADV_CALLBACK(menu_spur_acb)
{
(void)data;
(void)item;
if (b){
if (setting.mode == M_LOW) {
b->param_1.text = "SPUR\nREMOVAL";
b->icon = AUTO_ICON(setting.spur_removal);
} else {
b->param_1.text = "MIRROR\nMASKING";
b->icon = setting.mirror_masking == 0 ? BUTTON_ICON_NOCHECK : BUTTON_ICON_CHECK;
}
return;
}
if (setting.mode == M_LOW) {
toggle_spur();
} else
toggle_mirror_masking();
// menu_move_back();
ui_mode_normal();
}
#endif
static UI_FUNCTION_ADV_CALLBACK(menu_measure_acb)
{
(void)item;
if (b){
b->icon = data == setting.measurement ? BUTTON_ICON_GROUP_CHECKED : BUTTON_ICON_GROUP;
return;
}
menu_move_back();
#ifdef __MEASURE__
switch(data) {
case M_OFF: // Off
// reset_settings(setting.mode);
set_measurement(M_OFF);
break;
case M_IMD: // IMD
reset_settings(setting.mode);
for (int i = 0; i< MARKERS_MAX; i++) {
markers[i].enabled = M_ENABLED;
markers[i].mtype = M_DELTA | M_TRACKING;
}
markers[0].mtype = M_REFERENCE | M_TRACKING;
kp_help_text = "Frequency of fundamental";
ui_mode_keypad(KM_CENTER);
ui_process_keypad();
set_sweep_frequency(ST_START, 0);
set_sweep_frequency(ST_STOP, uistat.value*5);
set_measurement(M_IMD);
break;
case M_OIP3: // OIP3
reset_settings(setting.mode);
for (int i = 0; i< MARKERS_MAX; i++) {
markers[i].enabled = M_ENABLED;
markers[i].mtype = M_DELTA;
}
markers[0].mtype = M_REFERENCE | M_TRACKING;
markers[1].mtype = M_TRACKING;
kp_help_text = "Frequency of left signal";
ui_mode_keypad(KM_CENTER);
ui_process_keypad();
int left = uistat.value;
kp_help_text = "Right signal";
ui_mode_keypad(KM_CENTER);
ui_process_keypad();
int right = uistat.value;
set_sweep_frequency(ST_CENTER, (left+right)/2);
set_sweep_frequency(ST_SPAN, (right - left)*5);
set_measurement(M_OIP3);
break;
case M_PHASE_NOISE: // Phase noise
reset_settings(setting.mode);
for (int i = 0; i< MARKERS_MAX; i++) {
markers[i].enabled = M_DISABLED;
markers[i].mtype = M_NORMAL;
}
markers[0].enabled = M_ENABLED;
markers[0].mtype = M_REFERENCE | M_TRACKING;
markers[1].enabled = M_ENABLED;
markers[1].mtype = M_DELTA | M_NOISE;
kp_help_text = "Frequency of signal";
ui_mode_keypad(KM_CENTER);
ui_process_keypad();
kp_help_text = "Frequency offset";
ui_mode_keypad(KM_SPAN);
ui_process_keypad();
set_sweep_frequency(ST_SPAN, uistat.value*4);
set_measurement(M_PHASE_NOISE);
set_average(4);
break;
case M_STOP_BAND: // STop band measurement
reset_settings(setting.mode);
markers[1].enabled = M_ENABLED;
markers[1].mtype = M_DELTA;
markers[2].enabled = M_ENABLED;
markers[2].mtype = M_DELTA;
kp_help_text = "Frequency of signal";
ui_mode_keypad(KM_CENTER);
ui_process_keypad();
kp_help_text = "Width of signal";
ui_mode_keypad(KM_SPAN);
ui_process_keypad();
set_sweep_frequency(ST_SPAN, uistat.value*4);
set_measurement(M_STOP_BAND);
// SetAverage(4);
break;
case M_PASS_BAND: // pass band measurement
// reset_settings(setting.mode);
markers[0].enabled = M_ENABLED;
markers[0].mtype = M_REFERENCE | M_TRACKING;
markers[1].enabled = M_ENABLED;
markers[1].mtype = M_DELTA;
markers[2].enabled = M_ENABLED;
markers[2].mtype = M_DELTA;
// kp_help_text = "Frequency of signal";
// ui_mode_keypad(KM_CENTER);
// ui_process_keypad();
// kp_help_text = "Width of signal";
// ui_mode_keypad(KM_SPAN);
// ui_process_keypad();
// set_sweep_frequency(ST_SPAN, uistat.value*2);
set_measurement(M_PASS_BAND);
// SetAverage(4);
break;
#ifdef __LINEARITY__
case M_LINEARITY:
set_measurement(M_LINEARITY);
break;
#endif
case M_AM: // AM
reset_settings(setting.mode);
for (int i = 0; i< 3; i++) {
markers[i].enabled = M_ENABLED;
markers[i].mtype = M_DELTA;// | M_TRACKING;
}
freq_t center, span;
markers[0].mtype = M_REFERENCE;// | M_TRACKING;
kp_help_text = "Frequency of signal";
ui_mode_keypad(KM_CENTER);
ui_process_keypad();
center = uistat.value;
kp_help_text = "Modulation frequency, 3 .. 10 kHz";
ui_mode_keypad(KM_SPAN);
ui_process_keypad();
if (uistat.value < 3000)
break;
span = uistat.value;
set_sweep_frequency(ST_SPAN, 50000); // 100kHz
// update_frequencies(); // To ensure markers are positioned right!!!!!!
set_measurement(M_AM);
set_marker_frequency(0, center);
set_marker_frequency(1, center-span);
set_marker_frequency(2, center+span);
set_average(4);
break;
case M_FM: // FM
reset_settings(setting.mode);
for (int i = 0; i< 3; i++) {
markers[i].enabled = M_ENABLED;
markers[i].mtype = M_DELTA;
}
markers[0].mtype = M_REFERENCE;
kp_help_text = "Frequency of signal";
ui_mode_keypad(KM_CENTER);
ui_process_keypad();
set_marker_frequency(0, uistat.value);
kp_help_text = "Modulation frequency: 1 .. 2.5kHz";
ui_mode_keypad(KM_SPAN);
ui_process_keypad();
if (uistat.value < 1000 || uistat.value > 2500)
break;
set_RBW(uistat.value/100);
// actual_rbw_x10
kp_help_text = "Frequency deviation: 3 .. 500kHz";
ui_mode_keypad(KM_SPAN);
ui_process_keypad();
if (uistat.value < 12000)
uistat.value = 12000; // minimum span
set_sweep_frequency(ST_SPAN, uistat.value*4);
set_measurement(M_FM);
break;
case M_THD:
set_measurement(M_THD);
break;
}
#endif
// selection = -1;
ui_mode_normal();
// draw_cal_status();
}
static UI_FUNCTION_ADV_CALLBACK(menu_atten_acb)
{
(void)item;
(void)data;
if(b){
b->icon = setting.auto_attenuation ? BUTTON_ICON_GROUP_CHECKED : BUTTON_ICON_GROUP;
return;
}
set_auto_attenuation();
menu_move_back_and_leave_ui();
}
static UI_FUNCTION_ADV_CALLBACK(menu_atten_high_acb)
{
(void)item;
if(b){
b->icon = (setting.atten_step*30 == data) ? BUTTON_ICON_GROUP_CHECKED : BUTTON_ICON_GROUP;
return;
}
setting.auto_attenuation = false;
set_attenuation(data);
menu_move_back_and_leave_ui();
}
static UI_FUNCTION_ADV_CALLBACK(menu_reflevel_acb)
{
(void)item;
(void)data;
if(b){
b->icon = setting.auto_reflevel ? BUTTON_ICON_GROUP_CHECKED : BUTTON_ICON_GROUP;
return;
}
set_auto_reflevel(true);
menu_move_back_and_leave_ui();
}
static UI_FUNCTION_ADV_CALLBACK(menu_storage_acb)
{
(void)item;
if(b){
if (data == 0 && setting.show_stored)