-
Notifications
You must be signed in to change notification settings - Fork 62
/
sbitx_gtk.c
4719 lines (4108 loc) · 133 KB
/
sbitx_gtk.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
/*
The initial sync between the gui values, the core radio values, settings, et al are manually set.
*/
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <linux/types.h>
#include <math.h>
#include <fcntl.h>
#include <complex.h>
#include <fftw3.h>
#include <linux/fb.h>
#include <sys/types.h>
#include <stdint.h>
#include <ctype.h>
#include <sys/mman.h>
#include <sys/ioctl.h>
#include <ncurses.h>
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <errno.h>
#include <cairo.h>
#include <sys/file.h>
#include <errno.h>
#include <sys/file.h>
#include <errno.h>
#include <wiringPi.h>
#include <wiringSerial.h>
#include "sdr.h"
#include "sound.h"
#include "sdr_ui.h"
#include "ini.h"
#include "hamlib.h"
#include "remote.h"
#include "modem_ft8.h"
#include "i2cbb.h"
#include "webserver.h"
#include "logbook.h"
#include "oled.h"
#define FT8_START_QSO 1
#define FT8_CONTINUE_QSO 0
void ft8_process(char *received, int operation);
void change_band(char *request);
/* command buffer for commands received from the remote */
struct Queue q_remote_commands;
struct Queue q_tx_text;
/* Front Panel controls */
char pins[15] = {0, 2, 3, 6, 7,
10, 11, 12, 13, 14,
21, 22, 23, 25, 27};
#define ENC1_A (13)
#define ENC1_B (12)
#define ENC1_SW (14)
#define ENC2_A (0)
#define ENC2_B (2)
#define ENC2_SW (3)
#define SW5 (22)
#define PTT (7)
#define DASH (21)
#define ENC_FAST 1
#define ENC_SLOW 5
#define DS3231_I2C_ADD 0x68
//time sync, when the NTP time is not synced, this tracks the number of seconds
//between the system cloc and the actual time set by \utc command
static long time_delta = 0;
//mouse/touch screen state
static int mouse_down = 0;
static int last_mouse_x = -1;
static int last_mouse_y = -1;
//encoder state
struct encoder {
int pin_a, pin_b;
int speed;
int prev_state;
int history;
};
void tuning_isr(void);
#define COLOR_SELECTED_TEXT 0
#define COLOR_TEXT 1
#define COLOR_TEXT_MUTED 2
#define COLOR_SELECTED_BOX 3
#define COLOR_BACKGROUND 4
#define COLOR_FREQ 5
#define COLOR_LABEL 6
#define SPECTRUM_BACKGROUND 7
#define SPECTRUM_GRID 8
#define SPECTRUM_PLOT 9
#define SPECTRUM_NEEDLE 10
#define COLOR_CONTROL_BOX 11
#define SPECTRUM_BANDWIDTH 12
#define COLOR_RX_PITCH 13
#define SELECTED_LINE 14
#define COLOR_FIELD_SELECTED 15
#define COLOR_TX_PITCH 16
float palette[][3] = {
{1,1,1}, // COLOR_SELECTED_TEXT
{0,1,1}, // COLOR_TEXT
{0.5,0.5,0.5}, //COLOR_TEXT_MUTED
{1,1,0}, // COLOR_SELECTED_BOX
{0,0,0}, // COLOR_BACKGROUND
{1,1,0}, //COLOR_FREQ
{1,0,1}, //COLOR_LABEL
//spectrum
{0,0,0}, //SPECTRUM_BACKGROUND
{0.1, 0.1, 0.1}, //SPECTRUM_GRID
{1,1,0}, //SPECTRUM_PLOT
{0.2,0.2,0.2}, //SPECTRUM_NEEDLE
{0.5,0.5,0.5}, //COLOR_CONTROL_BOX
{0.2, 0.2, 0.2}, //SPECTRUM_BANDWIDTH
{0,1,0}, //COLOR_RX__PITCH
{0.1, 0.1, 0.2}, //SELECTED_LINE
{0.1, 0.1, 0.2}, // COLOR_FIELD_SELECTED
{1,0,0}, //COLOR_TX_PITCH
};
char *ui_font = "Sans";
int field_font_size = 12;
int screen_width=800, screen_height=480;
// we just use a look-up table to define the fonts used
// the struct field indexes into this table
struct font_style {
int index;
double r, g, b;
char name[32];
int height;
int weight;
int type;
};
guint key_modifier = 0;
struct font_style font_table[] = {
{FONT_FIELD_LABEL, 0, 1, 1, "Mono", 14, CAIRO_FONT_WEIGHT_NORMAL, CAIRO_FONT_SLANT_NORMAL},
{FONT_FIELD_VALUE, 1, 1, 1, "Mono", 14, CAIRO_FONT_WEIGHT_NORMAL, CAIRO_FONT_SLANT_NORMAL},
{FONT_LARGE_FIELD, 0, 1, 1, "Mono", 14, CAIRO_FONT_WEIGHT_NORMAL, CAIRO_FONT_SLANT_NORMAL},
{FONT_LARGE_VALUE, 1, 1, 1, "Arial", 24, CAIRO_FONT_WEIGHT_NORMAL, CAIRO_FONT_SLANT_NORMAL},
{FONT_SMALL, 0, 1, 1, "Mono", 10, CAIRO_FONT_WEIGHT_NORMAL, CAIRO_FONT_SLANT_NORMAL},
{FONT_LOG, 1, 1, 1, "Mono", 11, CAIRO_FONT_WEIGHT_NORMAL, CAIRO_FONT_SLANT_NORMAL},
{FONT_FT8_RX, 0, 1, 0, "Mono", 11, CAIRO_FONT_WEIGHT_NORMAL, CAIRO_FONT_SLANT_NORMAL},
{FONT_FT8_TX, 1, 0.6, 0, "Mono", 11, CAIRO_FONT_WEIGHT_NORMAL, CAIRO_FONT_SLANT_NORMAL},
{FONT_SMALL_FIELD_VALUE, 1, 1, 1, "Mono", 11, CAIRO_FONT_WEIGHT_NORMAL, CAIRO_FONT_SLANT_NORMAL},
{FONT_CW_RX, 0, 1, 0, "Mono", 11, CAIRO_FONT_WEIGHT_NORMAL, CAIRO_FONT_SLANT_NORMAL},
{FONT_CW_TX, 1, 0.6, 0, "Mono", 11, CAIRO_FONT_WEIGHT_NORMAL, CAIRO_FONT_SLANT_NORMAL},
{FONT_FLDIGI_RX, 0, 1, 0, "Mono", 11, CAIRO_FONT_WEIGHT_NORMAL, CAIRO_FONT_SLANT_NORMAL},
{FONT_FLDIGI_TX, 1, 0.6, 0, "Mono", 11, CAIRO_FONT_WEIGHT_NORMAL, CAIRO_FONT_SLANT_NORMAL},
{FONT_TELNET, 0, 1, 0, "Mono", 11, CAIRO_FONT_WEIGHT_NORMAL, CAIRO_FONT_SLANT_NORMAL},
{FONT_FT8_QUEUED, 0.5, 0.5, 0.5, "Mono", 11, CAIRO_FONT_WEIGHT_NORMAL, CAIRO_FONT_SLANT_NORMAL},
{FONT_FT8_REPLY, 1, 0.6, 0, "Mono", 11, CAIRO_FONT_WEIGHT_NORMAL, CAIRO_FONT_SLANT_NORMAL},
};
struct encoder enc_a, enc_b;
#define MAX_FIELD_LENGTH 128
#define FIELD_NUMBER 0
#define FIELD_BUTTON 1
#define FIELD_TOGGLE 2
#define FIELD_SELECTION 3
#define FIELD_TEXT 4
#define FIELD_STATIC 5
#define FIELD_CONSOLE 6
// The console is a series of lines
#define MAX_CONSOLE_BUFFER 10000
#define MAX_LINE_LENGTH 128
#define MAX_CONSOLE_LINES 500
static int console_cols = 50;
//we use just one text list in our user interface
struct console_line {
char text[MAX_LINE_LENGTH];
int style;
};
static int console_style = FONT_LOG;
static struct console_line console_stream[MAX_CONSOLE_LINES];
int console_current_line = 0;
int console_selected_line = -1;
struct Queue q_web;
//oled stuf
static uint8_t oled_available = 0;
// event ids, some of them are mapped from gtk itself
#define FIELD_DRAW 0
#define FIELD_UPDATE 1
#define FIELD_EDIT 2
#define MIN_KEY_UP 0xFF52
#define MIN_KEY_DOWN 0xFF54
#define MIN_KEY_LEFT 0xFF51
#define MIN_KEY_RIGHT 0xFF53
#define MIN_KEY_ENTER 0xFF0D
#define MIN_KEY_ESC 0xFF1B
#define MIN_KEY_BACKSPACE 0xFF08
#define MIN_KEY_TAB 0xFF09
#define MIN_KEY_CONTROL 0xFFE3
#define MIN_KEY_F1 0xFFBE
#define MIN_KEY_F2 0xFFBF
#define MIN_KEY_F3 0xFFC0
#define MIN_KEY_F4 0xFFC1
#define MIN_KEY_F5 0xFFC2
#define MIN_KEY_F6 0xFFC3
#define MIN_KEY_F7 0xFFC4
#define MIN_KEY_F8 0xFFC5
#define MIN_KEY_F9 0xFFC6
#define MIN_KEY_F9 0xFFC6
#define MIN_KEY_F10 0xFFC7
#define MIN_KEY_F11 0xFFC8
#define MIN_KEY_F12 0xFFC9
#define COMMAND_ESCAPE '\\'
void set_ui(int id);
void set_bandwidth(int hz);
/* the field in focus will be exited when you hit an escape
the field in focus will be changeable until it loses focus
hover will always be on the field in focus.
if the focus is -1,then hover works
*/
/*
Warning: The field selection is used for TOGGLE and SELECTION fields
each selection by the '/' should be unique. otherwise, the simple logic will
get confused
*/
//the main app window
GtkWidget *window;
GtkWidget *display_area = NULL;
GtkWidget *text_area = NULL;
extern void settings_ui(GtkWidget*p);
extern int logbook_open();
// these are callbacks called by the operating system
static gboolean on_draw_event( GtkWidget* widget, cairo_t *cr,
gpointer user_data);
static gboolean on_key_release (GtkWidget *widget, GdkEventKey *event,
gpointer user_data);
static gboolean on_key_press (GtkWidget *widget, GdkEventKey *event,
gpointer user_data);
static gboolean on_mouse_press (GtkWidget *widget, GdkEventButton *event,
gpointer data);
static gboolean on_mouse_move (GtkWidget *widget, GdkEventButton *event,
gpointer data);
static gboolean on_mouse_release (GtkWidget *widget, GdkEventButton *event,
gpointer data);
static gboolean on_scroll (GtkWidget *widget, GdkEventScroll *event,
gpointer data);
static gboolean on_window_state (GtkWidget *widget, GdkEventKey *event,
gpointer user_data);
static gboolean on_resize(GtkWidget *widget, GdkEventConfigure *event,
gpointer user_data);
gboolean ui_tick(gpointer gook);
static int measure_text(cairo_t *gfx, char *text, int font_entry){
cairo_text_extents_t ext;
struct font_style *s = font_table + font_entry;
cairo_select_font_face(gfx, s->name, s->type, s->weight);
cairo_set_font_size(gfx, s->height);
cairo_move_to(gfx, 0, 0);
cairo_text_extents(gfx, text, &ext);
return (int) ext.x_advance;
}
static void draw_text(cairo_t *gfx, int x, int y, char *text, int font_entry){
struct font_style *s = font_table + font_entry;
cairo_set_source_rgb( gfx, s->r, s->g, s->b);
cairo_select_font_face(gfx, s->name, s->type, s->weight);
cairo_set_font_size(gfx, s->height);
cairo_move_to(gfx, x, y + s->height);
cairo_show_text(gfx, text);
}
static void fill_rect(cairo_t *gfx, int x, int y, int w, int h, int color){
cairo_set_source_rgb( gfx, palette[color][0], palette[color][1], palette[color][2]);
cairo_rectangle(gfx, x, y, w, h);
cairo_fill(gfx);
}
static void rect(cairo_t *gfx, int x, int y, int w, int h,
int color, int thickness){
cairo_set_source_rgb( gfx,
palette[color][0],
palette[color][1],
palette[color][2]);
cairo_set_line_width(gfx, thickness);
cairo_rectangle(gfx, x, y, w, h);
cairo_stroke(gfx);
}
/****************************************************************************
Using the above hooks and primitives, we build user interface controls,
All of them are defined by the struct field
****************************************************************************/
struct field {
char *cmd;
int (*fn)(struct field *f, cairo_t *gfx, int event, int param_a, int param_b, int param_c);
int x, y, width, height;
char label[30];
int label_width;
char value[MAX_FIELD_LENGTH];
char value_type; //NUMBER, SELECTION, TEXT, TOGGLE, BUTTON
int font_index; //refers to font_style table
char selection[1000];
long int min, max;
int step;
int section;
char is_dirty;
char update_remote;
void *data;
};
#define STACK_DEPTH 4
struct band {
char name[10];
int start;
int stop;
//int power;
//int max;
int index;
int freq[STACK_DEPTH];
int mode[STACK_DEPTH];
};
struct cmd {
char *cmd;
int (*fn)(char *args[]);
};
static unsigned long focus_since = 0;
static struct field *f_focus = NULL;
static struct field *f_hover = NULL;
static struct field *f_last_text = NULL;
//variables to power up and down the tx
static int in_tx = TX_OFF;
static int key_down = 0;
static int tx_start_time = 0;
static int *tx_mod_buff = NULL;
static int tx_mod_index = 0;
static int tx_mod_max = 0;
char*mode_name[MAX_MODES] = {
"USB", "LSB", "CW", "CWR", "NBFM", "AM", "FT8", "PSK31", "RTTY",
"DIGITAL", "2TONE"
};
static int serial_fd = -1;
static int xit = 512;
static long int tuning_step = 1000;
static int tx_mode = MODE_USB;
#define BAND80M 0
#define BAND40M 1
#define BAND30M 2
#define BAND20M 3
#define BAND17M 4
#define BAND15M 5
#define BAND12M 6
#define BAND10M 7
struct band band_stack[] = {
{"80M", 3500000, 4000000, 0,
{3500000,3574000,3600000,3700000},{MODE_CW, MODE_USB, MODE_CW,MODE_LSB}},
{"40M", 7000000,7300000, 0,
{7000000,7040000,7074000,7150000},{MODE_CW, MODE_CW, MODE_USB, MODE_LSB}},
{"30M", 10100000, 10150000, 0,
{10100000, 10100000, 10136000, 10150000}, {MODE_CW, MODE_CW, MODE_USB, MODE_USB}},
{"20M", 14000000, 14400000, 0,
{14010000, 14040000, 14074000, 14200000}, {MODE_CW, MODE_CW, MODE_USB, MODE_USB}},
{"17M", 18068000, 18168000, 0,
{18068000, 18100000, 18110000, 18160000}, {MODE_CW, MODE_CW, MODE_USB, MODE_USB}},
{"15M", 21000000, 21500000, 0,
{21010000, 21040000, 21074000, 21250000}, {MODE_CW, MODE_CW, MODE_USB, MODE_USB}},
{"12M", 24890000, 24990000, 0,
{24890000, 24910000, 24950000, 24990000}, {MODE_CW, MODE_CW, MODE_USB, MODE_USB}},
{"10M", 28000000, 29700000, 0,
{28000000, 28040000, 28074000, 28250000}, {MODE_CW, MODE_CW, MODE_USB, MODE_USB}},
};
#define VFO_A 0
#define VFO_B 1
//int vfo_a_freq = 7000000;
//int vfo_b_freq = 14000000;
char vfo_a_mode[10];
char vfo_b_mode[10];
//usefull data for macros, logging, etc
int tx_id = 0;
//recording duration in seconds
time_t record_start = 0;
int data_delay = 700;
#define MAX_RIT 25000
int spectrum_span = 48000;
extern int spectrum_plot[];
extern int fwdpower, vswr;
void do_control_action(char *cmd);
void cmd_exec(char *cmd);
int do_spectrum(struct field *f, cairo_t *gfx, int event, int a, int b, int c);
int do_waterfall(struct field *f, cairo_t *gfx, int event, int a, int b, int c);
int do_tuning(struct field *f, cairo_t *gfx, int event, int a, int b, int c);
int do_text(struct field *f, cairo_t *gfx, int event, int a, int b, int c);
int do_status(struct field *f, cairo_t *gfx, int event, int a, int b, int c);
int do_console(struct field *f, cairo_t *gfx, int event, int a, int b, int c);
int do_pitch(struct field *f, cairo_t *gfx, int event, int a, int b, int c);
int do_kbd(struct field *f, cairo_t *gfx, int event, int a, int b, int c);
int do_toggle_kbd(struct field *f, cairo_t *gfx, int event, int a, int b, int c);
int do_mouse_move(struct field *f, cairo_t *gfx, int event, int a, int b, int c);
int do_macro(struct field *f, cairo_t *gfx, int event, int a, int b, int c);
int do_record(struct field *f, cairo_t *gfx, int event, int a, int b, int c);
int do_bandwidth(struct field *f, cairo_t *gfx, int event, int a, int b, int c);
struct field *active_layout = NULL;
char settings_updated = 0;
#define LAYOUT_KBD 0
#define LAYOUT_MACROS 1
int current_layout = LAYOUT_KBD;
#define COMMON_CONTROL 1
#define FT8_CONTROL 2
#define CW_CONTROL 4
#define VOICE_CONTROL 8
#define DIGITAL_CONTROL 16
// the cmd fields that have '#' are not to be sent to the sdr
struct field main_controls[] = {
/* band stack registers */
{"#10m", NULL, 50, 5, 40, 40, "10M", 1, "", FIELD_BUTTON, FONT_FIELD_VALUE,
"", 0,0,0,COMMON_CONTROL},
{"#12m", NULL, 90, 5, 40, 40, "12M", 1, "", FIELD_BUTTON, FONT_FIELD_VALUE,
"", 0,0,0,COMMON_CONTROL},
{"#15m", NULL, 130, 5, 40, 40, "15M", 1, "", FIELD_BUTTON, FONT_FIELD_VALUE,
"", 0,0,0i,COMMON_CONTROL},
{"#17m", NULL, 170, 5, 40, 40, "17M", 1, "", FIELD_BUTTON, FONT_FIELD_VALUE,
"", 0,0,0,COMMON_CONTROL},
{"#20m", NULL, 210, 5, 40, 40, "20M", 1, "", FIELD_BUTTON, FONT_FIELD_VALUE,
"", 0,0,0,COMMON_CONTROL},
{"#30m", NULL, 250, 5, 40, 40, "30M", 1, "", FIELD_BUTTON, FONT_FIELD_VALUE,
"", 0,0,0,COMMON_CONTROL},
{"#40m", NULL, 290, 5, 40, 40, "40M", 1, "", FIELD_BUTTON, FONT_FIELD_VALUE,
"", 0,0,0,COMMON_CONTROL},
{"#80m", NULL, 330, 5, 40, 40, "80M", 1, "", FIELD_BUTTON, FONT_FIELD_VALUE,
"", 0,0,0,COMMON_CONTROL},
{ "#record", do_record, 380, 5, 40, 40, "REC", 40, "OFF", FIELD_TOGGLE, FONT_FIELD_VALUE,
"ON/OFF", 0,0, 0,COMMON_CONTROL},
{ "#web", NULL, 420,5, 40, 40, "WEB", 40, "", FIELD_BUTTON, FONT_FIELD_VALUE,
"", 0,0, 0,COMMON_CONTROL},
{"#set", NULL, 460, 5, 40, 40, "SET", 1, "", FIELD_BUTTON, FONT_FIELD_VALUE,"", 0,0,0,COMMON_CONTROL},
{ "r1:gain", NULL, 375, 5, 40, 40, "IF", 40, "60", FIELD_NUMBER, FONT_FIELD_VALUE,
"", 0, 100, 1,COMMON_CONTROL},
{ "r1:agc", NULL, 415, 5, 40, 40, "AGC", 40, "SLOW", FIELD_SELECTION, FONT_FIELD_VALUE,
"OFF/SLOW/MED/FAST", 0, 1024, 1,COMMON_CONTROL},
{ "tx_power", NULL, 455, 5, 40, 40, "DRIVE", 40, "40", FIELD_NUMBER, FONT_FIELD_VALUE,
"", 1, 100, 1,COMMON_CONTROL},
{ "r1:freq", do_tuning, 600, 0, 150, 49, "FREQ", 5, "14000000", FIELD_NUMBER, FONT_LARGE_VALUE,
"", 500000, 30000000, 100,COMMON_CONTROL},
{ "r1:volume", NULL, 755, 5, 40, 40, "AUDIO", 40, "60", FIELD_NUMBER, FONT_FIELD_VALUE,
"", 0, 100, 1,COMMON_CONTROL},
{"#step", NULL, 560, 5 ,40, 40, "STEP", 1, "10Hz", FIELD_SELECTION, FONT_FIELD_VALUE,
"10K/1K/500H/100H/10H", 0,0,0,COMMON_CONTROL},
{"#span", NULL, 560, 50 , 40, 40, "SPAN", 1, "A", FIELD_SELECTION, FONT_FIELD_VALUE,
"25K/10K/6K/2.5K", 0,0,0,COMMON_CONTROL},
{"#rit", NULL, 600, 50, 40, 40, "RIT", 40, "OFF", FIELD_TOGGLE, FONT_FIELD_VALUE,
"ON/OFF", 0,0,0,COMMON_CONTROL},
{"#vfo", NULL, 640, 50 , 40, 40, "VFO", 1, "A", FIELD_SELECTION, FONT_FIELD_VALUE,
"A/B", 0,0,0,COMMON_CONTROL},
{"#split", NULL, 680, 50, 40, 40, "SPLIT", 40, "OFF", FIELD_TOGGLE, FONT_FIELD_VALUE,
"ON/OFF", 0,0,0,COMMON_CONTROL},
{ "#bw", do_bandwidth, 495, 5, 40, 40, "BW", 40, "", FIELD_NUMBER, FONT_FIELD_VALUE,
"", 50, 5000, 50,COMMON_CONTROL},
{ "r1:mode", NULL, 5, 5, 40, 40, "MODE", 40, "USB", FIELD_SELECTION, FONT_FIELD_VALUE,
"USB/LSB/CW/CWR/FT8/AM/DIGITAL/2TONE", 0,0,0, COMMON_CONTROL},
/* logger controls */
{"#contact_callsign", do_text, 5, 50, 85, 20, "CALL", 70, "", FIELD_TEXT, FONT_LOG,
"", 0,11,0,COMMON_CONTROL},
{"#rst_sent", do_text, 90, 50, 50, 20, "SENT", 70, "", FIELD_TEXT, FONT_LOG,
"", 0, 7,0,COMMON_CONTROL},
{"#rst_received", do_text, 140, 50, 50, 20, "RECV", 70, "", FIELD_TEXT, FONT_LOG,
"", 0, 7,0,COMMON_CONTROL},
{"#exchange_received", do_text, 190, 50, 50, 20, "EXCH", 70, "", FIELD_TEXT, FONT_LOG,
"", 0, 7,0,COMMON_CONTROL},
{"#exchange_sent", do_text, 240, 50, 50, 20, "NR", 70, "", FIELD_TEXT, FONT_LOG,
"", 0, 7,0,COMMON_CONTROL},
{"#enter_qso", NULL, 290, 50, 40, 40, "SAVE", 1, "", FIELD_BUTTON, FONT_FIELD_VALUE,
"", 0,0,0,COMMON_CONTROL},
{"#wipe", NULL, 330, 50, 40, 40, "WIPE", 1, "", FIELD_BUTTON, FONT_FIELD_VALUE,"", 0,0,0,COMMON_CONTROL},
{"#mfqrz", NULL, 370, 50, 40, 40, "QRZ", 1, "", FIELD_BUTTON, FONT_FIELD_VALUE,"", 0,0,0,COMMON_CONTROL},
{"#logbook", NULL, 410, 50, 40, 40, "LOG", 1, "", FIELD_BUTTON, FONT_FIELD_VALUE,"", 0,0,0,COMMON_CONTROL},
{"#text_in", do_text, 5, 70, 285, 20, "TEXT", 70, "text box", FIELD_TEXT, FONT_LOG,
"nothing valuable", 0,128,0,COMMON_CONTROL},
{ "#toggle_kbd", do_toggle_kbd, 495, 50, 40, 40, "KBD", 40, "OFF", FIELD_TOGGLE, FONT_FIELD_VALUE,
"ON/OFF", 0,0, 0,COMMON_CONTROL},
/* end of common controls */
//tx
{ "tx_gain", NULL, 550, -350, 50, 50, "MIC", 40, "50", FIELD_NUMBER, FONT_FIELD_VALUE,
"", 0, 100, 1, VOICE_CONTROL},
{ "tx_compress", NULL, 600, -350, 50, 50, "COMP", 40, "0", FIELD_NUMBER, FONT_FIELD_VALUE,
"ON/OFF", 0,100,10, VOICE_CONTROL},
{ "#tx_wpm", NULL, 650, -350, 50, 50, "WPM", 40, "12", FIELD_NUMBER, FONT_FIELD_VALUE,
"", 1, 50, 1, CW_CONTROL},
{ "rx_pitch", do_pitch, 700, -350, 50, 50, "PITCH", 40, "600", FIELD_NUMBER, FONT_FIELD_VALUE,
"", 100, 3000, 10, FT8_CONTROL | DIGITAL_CONTROL},
{ "#tx", NULL, 1000, -1000, 50, 50, "TX", 40, "", FIELD_BUTTON, FONT_FIELD_VALUE,
"RX/TX", 0,0, 0, VOICE_CONTROL},
{ "#rx", NULL, 650, -400, 50, 50, "RX", 40, "", FIELD_BUTTON, FONT_FIELD_VALUE,
"RX/TX", 0,0, 0, VOICE_CONTROL | DIGITAL_CONTROL},
{"r1:low", NULL, 660, -350, 50, 50, "LOW", 40, "300", FIELD_NUMBER, FONT_FIELD_VALUE,
"", 100,4000, 50, 0, DIGITAL_CONTROL},
{"r1:high", NULL, 580, -350, 50, 50, "HIGH", 40, "3000", FIELD_NUMBER, FONT_FIELD_VALUE,
"", 100, 10000, 50, 0, DIGITAL_CONTROL},
{"spectrum", do_spectrum, 400, 101, 400, 100, "SPECTRUM", 70, "7000 KHz", FIELD_STATIC, FONT_SMALL,
"", 0,0,0, COMMON_CONTROL},
{"#status", do_status, -1000, -1000, 400, 29, "STATUS", 70, "7000 KHz", FIELD_STATIC, FONT_SMALL,
"status", 0,0,0, 0},
{"waterfall", do_waterfall, 400, 201 , 400, 99, "WATERFALL", 70, "7000 KHz", FIELD_STATIC, FONT_SMALL,
"", 0,0,0, COMMON_CONTROL},
{"#console", do_console, 0, 100, 400, 200, "CONSOLE", 70, "console box", FIELD_CONSOLE, FONT_LOG,
"nothing valuable", 0,0,0, COMMON_CONTROL},
{"#log_ed", NULL, 0, 480, 480, 20, "", 70, "", FIELD_STATIC, FONT_LOG,
"nothing valuable", 0,128,0, 0},
// other settings - currently off screen
{ "reverse_scrolling", NULL, 1000, -1000, 50, 50, "RS", 40, "ON", FIELD_TOGGLE, FONT_FIELD_VALUE,
"ON/OFF", 0,0,0, 0},
{ "tuning_acceleration", NULL, 1000, -1000, 50, 50, "TA", 40, "ON", FIELD_TOGGLE, FONT_FIELD_VALUE,
"ON/OFF", 0,0,0, 0},
{ "tuning_accel_thresh1", NULL, 1000, -1000, 50, 50, "TAT1", 40, "10000", FIELD_NUMBER, FONT_FIELD_VALUE,
"", 100,99999,100, 0},
{ "tuning_accel_thresh2", NULL, 1000, -1000, 50, 50, "TAT2", 40, "500", FIELD_NUMBER, FONT_FIELD_VALUE,
"", 100,99999,100, 0},
{ "mouse_pointer", NULL, 1000, -1000, 50, 50, "MP", 40, "LEFT", FIELD_SELECTION, FONT_FIELD_VALUE,
"BLANK/LEFT/RIGHT/CROSSHAIR", 0,0,0,0},
// Settings Panel
{"#mycallsign", NULL, 1000, -1000, 400, 149, "MYCALLSIGN", 70, "CALL", FIELD_TEXT, FONT_SMALL,
"", 3,10,1,0},
{"#mygrid", NULL, 1000, -1000, 400, 149, "MYGRID", 70, "NOWHERE", FIELD_TEXT, FONT_SMALL,
"", 4,6,1,0},
{"#passkey", NULL, 1000, -1000, 400, 149, "PASSKEY", 70, "123", FIELD_TEXT, FONT_SMALL,
"", 0,32,1,0},
//moving global variables into fields
{ "#vfo_a_freq", NULL, 1000, -1000, 50, 50, "VFOA", 40, "14000000", FIELD_NUMBER, FONT_FIELD_VALUE,
"", 500000,30000000,1,0},
{"#vfo_b_freq", NULL, 1000, -1000, 50, 50, "VFOB", 40, "7000000", FIELD_NUMBER, FONT_FIELD_VALUE,
"", 500000,30000000,1,0},
{"#rit_delta", NULL, 1000, -1000, 50, 50, "RIT_DELTA", 40, "000000", FIELD_NUMBER, FONT_FIELD_VALUE,
"", -25000,25000,1,0},
{ "#cwinput", NULL, 1000, -1000, 50, 50, "CW_INPUT", 40, "KEYBOARD", FIELD_SELECTION, FONT_FIELD_VALUE,
"IAMBIC/IAMBICB/STRAIGHT", 0,0,0, CW_CONTROL},
{ "#cwdelay", NULL, 1000, -1000, 50, 50, "CW_DELAY", 40, "300", FIELD_NUMBER, FONT_FIELD_VALUE,
"", 50, 1000, 50, CW_CONTROL},
{ "#tx_pitch", NULL, 400, -1000, 50, 50, "TX_PITCH", 40, "600", FIELD_NUMBER, FONT_FIELD_VALUE,
"", 300, 3000, 10, FT8_CONTROL},
{ "sidetone", NULL, 1000, -1000, 50, 50, "SIDETONE", 40, "25", FIELD_NUMBER, FONT_FIELD_VALUE,
"", 0, 100, 5, CW_CONTROL},
{"#sent_exchange", NULL, 1000, -1000, 400, 149, "SENT_EXCHANGE", 70, "", FIELD_TEXT, FONT_SMALL,
"", 0,10,1, COMMON_CONTROL},
{ "#contest_serial", NULL, 1000, -1000, 50, 50, "CONTEST_SERIAL", 40, "0", FIELD_NUMBER, FONT_FIELD_VALUE,
"", 0,1000000,1, COMMON_CONTROL},
{"#current_macro", NULL, 1000, -1000, 400, 149, "MACRO", 70, "", FIELD_TEXT, FONT_SMALL,
"", 0,32,1, COMMON_CONTROL},
{ "#fwdpower", NULL, 1000, -1000, 50, 50, "POWER", 40, "300", FIELD_NUMBER, FONT_FIELD_VALUE,
"", 0,10000,1, COMMON_CONTROL},
{ "#vswr", NULL, 1000, -1000, 50, 50, "REF", 40, "300", FIELD_NUMBER, FONT_FIELD_VALUE,
"", 0,10000, 1, COMMON_CONTROL},
{ "bridge", NULL, 1000, -1000, 50, 50, "BRIDGE", 40, "100", FIELD_NUMBER, FONT_FIELD_VALUE,
"", 10,100, 1, COMMON_CONTROL},
//cw, ft8 and many digital modes need abort
{"#abort", NULL, 370, 50, 40, 40, "ESC", 1, "", FIELD_BUTTON, FONT_FIELD_VALUE,"", 0,0,0,CW_CONTROL},
//FT8 should be 4000 Hz
{"#bw_voice", NULL, 1000, -1000, 50, 50, "BW_VOICE", 40, "2200", FIELD_NUMBER, FONT_FIELD_VALUE,
"", 300, 3000, 50, 0},
{"#bw_cw", NULL, 1000, -1000, 50, 50, "BW_CW", 40, "400", FIELD_NUMBER, FONT_FIELD_VALUE,
"", 300, 3000, 50, 0},
{"#bw_digital", NULL, 1000, -1000, 50, 50, "BW_DIGITAL", 40, "3000", FIELD_NUMBER, FONT_FIELD_VALUE,
"", 300, 3000, 50, 0},
//FT8 controls
{"#ft8_auto", NULL, 1000, -1000, 50, 50, "FT8_AUTO", 40, "ON", FIELD_TOGGLE, FONT_FIELD_VALUE,
"ON/OFF", 0,0,0, FT8_CONTROL},
{"#ft8_tx1st", NULL, 1000, -1000, 50, 50, "FT8_TX1ST", 40, "ON", FIELD_TOGGLE, FONT_FIELD_VALUE,
"ON/OFF", 0,0,0, FT8_CONTROL},
{ "#ft8_repeat", NULL, 1000, -1000, 50, 50, "FT8_REPEAT", 40, "5", FIELD_NUMBER, FONT_FIELD_VALUE,
"", 1, 10, 1, FT8_CONTROL},
{"#telneturl", NULL, 1000, -1000, 400, 149, "TELNETURL", 70, "dxc.nc7j.com:7373", FIELD_TEXT, FONT_SMALL,
"", 0,32,1, 0},
//soft keyboard
{"#kbd_q", do_kbd, 0, 300 ,50, 50, "", 1, "Q", FIELD_BUTTON, FONT_FIELD_VALUE,"", 0,0,0,0},
{"#kbd_w", do_kbd, 50, 300, 50, 50, "", 1, "W", FIELD_BUTTON, FONT_FIELD_VALUE,"", 0,0,0,0},
{"#kbd_e", do_kbd, 100, 300, 50, 50, "", 1, "E", FIELD_BUTTON, FONT_FIELD_VALUE,"", 0,0,0,0},
{"#kbd_r", do_kbd, 150, 300, 50, 50, "", 1, "R", FIELD_BUTTON, FONT_FIELD_VALUE,"", 0,0,0,0},
{"#kbd_t", do_kbd, 200, 300, 50, 50, "", 1, "T", FIELD_BUTTON, FONT_FIELD_VALUE,"", 0,0,0,0},
{"#kbd_y", do_kbd, 250, 300, 50, 50, "", 1, "Y", FIELD_BUTTON, FONT_FIELD_VALUE,"", 0,0,0,0},
{"#kbd_u", do_kbd, 300, 300, 50, 50, "", 1, "U", FIELD_BUTTON, FONT_FIELD_VALUE,"", 0,0,0,0},
{"#kbd_i", do_kbd, 350, 300, 50, 50, "", 1, "I", FIELD_BUTTON, FONT_FIELD_VALUE,"", 0,0,0,0},
{"#kbd_o", do_kbd, 400, 300, 50, 50, "", 1, "O", FIELD_BUTTON, FONT_FIELD_VALUE,"", 0,0,0,0},
{"#kbd_p", do_kbd, 450, 300, 50, 50, "", 1, "P", FIELD_BUTTON, FONT_FIELD_VALUE,"", 0,0,0,0},
{"#kbd_@", do_kbd, 500, 300, 50, 50, "", 1, "@", FIELD_BUTTON, FONT_FIELD_VALUE,"", 0,0,0,0},
{"#kbd_1", do_kbd, 550, 300, 50, 50, "", 1, "1", FIELD_BUTTON, FONT_FIELD_VALUE,"", 0,0,0,0},
{"#kbd_2", do_kbd, 600, 300, 50, 50, "", 1, "2", FIELD_BUTTON, FONT_FIELD_VALUE,"", 0,0,0,0},
{"#kbd_3", do_kbd, 650, 300, 50, 50, "", 1, "3", FIELD_BUTTON, FONT_FIELD_VALUE,"", 0,0,0,0},
{"#kbd_bs", do_kbd, 700, 300, 100, 50, "", 1, "DEL", FIELD_BUTTON, FONT_FIELD_VALUE,"", 0,0,0,0},
{"#kbd_alt", do_kbd, 0, 350 ,50, 50, "", 1, "CMD", FIELD_BUTTON, FONT_FIELD_VALUE,"", 0,0,0,0},
{"#kbd_a", do_kbd, 50, 350 ,50, 50, "*", 1, "A", FIELD_BUTTON, FONT_FIELD_VALUE,"", 0,0,0,0},
{"#kbd_s", do_kbd, 100, 350, 50, 50, "", 1, "S", FIELD_BUTTON, FONT_FIELD_VALUE,"", 0,0,0,0},
{"#kbd_d", do_kbd, 150, 350, 50, 50, "", 1, "D", FIELD_BUTTON, FONT_FIELD_VALUE,"", 0,0,0,0},
{"#kbd_f", do_kbd, 200, 350, 50, 50, "", 1, "F", FIELD_BUTTON, FONT_FIELD_VALUE,"", 0,0,0,0},
{"#kbd_g", do_kbd, 250, 350, 50, 50, "", 1, "G", FIELD_BUTTON, FONT_FIELD_VALUE,"", 0,0,0,0},
{"#kbd_h", do_kbd, 300, 350, 50, 50, "", 1, "H", FIELD_BUTTON, FONT_FIELD_VALUE,"", 0,0,0,0},
{"#kbd_j", do_kbd, 350, 350, 50, 50, "", 1, "J", FIELD_BUTTON, FONT_FIELD_VALUE,"", 0,0,0,0},
{"#kbd_k", do_kbd, 400, 350, 50, 50, "'", 1, "K", FIELD_BUTTON, FONT_FIELD_VALUE,"", 0,0,0,0},
{"#kbd_l", do_kbd, 450, 350, 50, 50, "", 1, "L", FIELD_BUTTON, FONT_FIELD_VALUE,"", 0,0,0,0},
{"#kbd_/", do_kbd, 500, 350, 50, 50, "", 1, "/", FIELD_BUTTON, FONT_FIELD_VALUE,"", 0,0,0,0},
{"#kbd_4", do_kbd, 550, 350, 50, 50, "", 1, "4", FIELD_BUTTON, FONT_FIELD_VALUE,"", 0,0,0,0},
{"#kbd_5", do_kbd, 600, 350, 50, 50, "", 1, "5", FIELD_BUTTON, FONT_FIELD_VALUE,"", 0,0,0,0},
{"#kbd_6", do_kbd, 650, 350, 50, 50, "", 1, "6", FIELD_BUTTON, FONT_FIELD_VALUE,"", 0,0,0,0},
{"#kbd_enter", do_kbd, 700, 400, 100, 50, "", 1, "Enter", FIELD_BUTTON, FONT_FIELD_VALUE,"", 0,0,0,0},
{"#kbd_ ", do_kbd, 0, 400, 50, 50, "", 1, "SPACE", FIELD_BUTTON, FONT_FIELD_VALUE,"", 0,0,0,0},
{"#kbd_z", do_kbd, 50, 400, 50, 50, "", 1, "Z", FIELD_BUTTON, FONT_FIELD_VALUE,"", 0,0,0,0},
{"#kbd_x", do_kbd, 100, 400, 50, 50, "", 1, "X", FIELD_BUTTON, FONT_FIELD_VALUE,"", 0,0,0,0},
{"#kbd_c", do_kbd, 150, 400, 50, 50, "", 1, "C", FIELD_BUTTON, FONT_FIELD_VALUE,"", 0,0,0,0},
{"#kbd_v", do_kbd, 200, 400, 50, 50, "", 1, "V", FIELD_BUTTON, FONT_FIELD_VALUE,"", 0,0,0,0},
{"#kbd_b", do_kbd, 250, 400, 50, 50, "", 1, "B", FIELD_BUTTON, FONT_FIELD_VALUE,"", 0,0,0,0},
{"#kbd_n", do_kbd, 300, 400, 50, 50, "", 1, "N", FIELD_BUTTON, FONT_FIELD_VALUE,"", 0,0,0,0},
{"#kbd_m", do_kbd, 350, 400, 50, 50, "", 1, "M", FIELD_BUTTON, FONT_FIELD_VALUE,"", 0,0,0,0},
{"#kbd_,", do_kbd, 400, 400, 50, 50, "", 1, ",", FIELD_BUTTON, FONT_FIELD_VALUE,"", 0,0,0,0},
{"#kbd_.", do_kbd, 450, 400, 50, 50, "", 1, ".", FIELD_BUTTON, FONT_FIELD_VALUE,"", 0,0,0,0},
{"#kbd_?", do_kbd, 500, 400, 50, 50, "", 1, "?", FIELD_BUTTON, FONT_FIELD_VALUE,"", 0,0,0,0},
{"#kbd_7", do_kbd, 550, 400, 50, 50, "", 1, "7", FIELD_BUTTON, FONT_FIELD_VALUE,"", 0,0,0,0},
{"#kbd_8", do_kbd, 600, 400, 50, 50, "", 1, "8", FIELD_BUTTON, FONT_FIELD_VALUE,"", 0,0,0,0},
{"#kbd_9", do_kbd, 650, 400, 50, 50, "", 1, "9", FIELD_BUTTON, FONT_FIELD_VALUE,"", 0,0,0,0},
{"#kbd_0", do_kbd, 700, 350, 50, 50, "", 1, "0", FIELD_BUTTON, FONT_FIELD_VALUE,"", 0,0,0,0},
//macros keyboard
//row 1
{"#mf1", do_macro, 0, 1360, 65, 40, "F1", 1, "CQ", FIELD_BUTTON, FONT_FIELD_VALUE,"", 0,0,0,0},
{"#mf2", do_macro, 65, 1360, 65, 40, "F2", 1, "Call", FIELD_BUTTON, FONT_FIELD_VALUE,"", 0,0,0,0},
{"#mf3", do_macro, 130, 1360, 65, 40, "F3", 1, "Reply", FIELD_BUTTON, FONT_FIELD_VALUE,"", 0,0,0,0},
{"#mf4", do_macro, 195, 1360, 65, 40, "F4", 1, "RRR", FIELD_BUTTON, FONT_FIELD_VALUE,"", 0,0,0,0},
{"#mf5", do_macro, 260, 1360, 70, 40, "F5", 1, "73", FIELD_BUTTON, FONT_FIELD_VALUE,"", 0,0,0,0},
{"#mf6", do_macro, 330, 1360, 70, 40, "F6", 1, "Call", FIELD_BUTTON, FONT_FIELD_VALUE,"", 0,0,0,0},
//row 2
{"#mf7", do_macro, 0, 1400, 65, 40, "F7", 1, "Exch", FIELD_BUTTON, FONT_FIELD_VALUE,"", 0,0,0,0},
{"#mf8", do_macro, 65, 1400, 65, 40, "F8", 1, "Tu", FIELD_BUTTON, FONT_FIELD_VALUE,"", 0,0,0,0},
{"#mf9", do_macro, 130, 1400, 65, 40, "F9", 1, "Rpt", FIELD_BUTTON, FONT_FIELD_VALUE,"", 0,0,0,0},
{"#mf10", do_macro, 195, 1400, 65, 40, "F10", 1, "", FIELD_BUTTON, FONT_FIELD_VALUE,"", 0,0,0,0},
{"#mf11", do_macro, 260, 1400, 70, 40, "F11", 1, "", FIELD_BUTTON, FONT_FIELD_VALUE,"", 0,0,0,0},
{"#mf12", do_macro, 330, 1400, 70, 40, "F12", 1, "", FIELD_BUTTON, FONT_FIELD_VALUE,"", 0,0,0,0},
//row 3
{"#mfedit", do_macro, 195, 1440, 65, 40, "Edit", 1, "", FIELD_BUTTON, FONT_FIELD_VALUE,"", 0,0,0,0},
{"#mfspot" , do_macro, 260, 1440, 70, 40, "Spot", 1, "", FIELD_BUTTON, FONT_FIELD_VALUE,"", 0,0,0,0},
{"#mfkbd", do_macro, 330, 1440, 70, 40, "Kbd", 1, "", FIELD_BUTTON, FONT_FIELD_VALUE,"", 0,0,0,0},
//the last control has empty cmd field
{"", NULL, 0, 0 ,0, 0, "#", 1, "Q", FIELD_BUTTON, FONT_FIELD_VALUE, "", 0,0,0,0},
};
struct field *get_field(const char *cmd);
void update_field(struct field *f);
void tx_on();
void tx_off();
//#define MAX_CONSOLE_LINES 1000
//char *console_lines[MAX_CONSOLE_LINES];
int last_log = 0;
struct field *get_field(const char *cmd){
for (int i = 0; active_layout[i].cmd[0] > 0; i++)
if (!strcmp(active_layout[i].cmd, cmd))
return active_layout + i;
return NULL;
}
//set the field directly to a particuarl value, programmatically
int set_field(const char *id, const char *value){
struct field *f = get_field(id);
int v;
int debug = 0;
if (!f){
printf("*Error: field[%s] not found. Check for typo?\n", id);
return 1;
}
if (f->value_type == FIELD_NUMBER){
int v = atoi(value);
if (v < f->min)
v = f->min;
if (v > f->max)
v = f->max;
sprintf(f->value, "%d", v);
}
else if (f->value_type == FIELD_SELECTION || f->value_type == FIELD_TOGGLE){
// toggle and selection are the same type: toggle has just two values instead of many more
char *p, *prev, *next, b[100];
//search the current text in the selection
prev = NULL;
if (debug)
printf("field selection [%s]\n");
strcpy(b, f->selection);
p = strtok(b, "/");
if (debug)
printf("first token [%s]\n", p);
while(p){
if (!strcmp(value, p))
break;
else
prev = p;
p = strtok(NULL, "/");
if (debug)
printf("second token [%s]\n", p);
}
//set to the first option
if (p == NULL){
if (prev)
strcpy(f->value, prev);
printf("*Error: setting field[%s] to [%s] not permitted\n", f->cmd, value);
return 1;
}
else{
if (debug)
printf("Setting field to %s\n", value);
strcpy(f->value, value);
}
}
else if (f->value_type == FIELD_BUTTON){
strcpy(f->value, value);
do_control_action(f->label);
}
else if (f->value_type == FIELD_TEXT){
if (strlen(value) > f->max || strlen(value) < f->min){
printf("*Error: field[%s] can't be set to [%s], improper size.\n", f->cmd, value);
return 1;
}
else
strcpy(f->value, value);
}
if (!strcmp(id, "#rit") || !strcmp(id, "#ft8_auto"))
debug = 1;
//send a command to the radio
char buff[200];
sprintf(buff, "%s %s", f->label, f->value);
do_control_action(buff);
update_field(f);
return 0;
}
struct field *get_field_by_label(const char *label){
for (int i = 0; active_layout[i].cmd[0] > 0; i++)
if (!strcasecmp(active_layout[i].label, label))
return active_layout + i;
return NULL;
}
const char *field_str(char *label){
struct field *f = get_field_by_label(label);
if (f)
return f->value;
else
return NULL;
}
int field_int(char *label){
struct field *f = get_field_by_label(label);
if (f){
return atoi(f->value);
}
else {
printf("field_int: %s not found\n", label);
return -1;
}
}
int field_set(const char *label, const char *new_value){
struct field *f = get_field_by_label(label);
if (!f)
return -1;
int r = set_field(f->cmd, new_value);
update_field(f);
}
int get_field_value(char *cmd, char *value){
struct field *f = get_field(cmd);
if (!f)
return -1;
strcpy(value, f->value);
return 0;
}
int get_field_value_by_label(char *label, char *value){
struct field *f = get_field_by_label(label);
if (!f)
return -1;
strcpy(value, f->value);
return 0;
}
int remote_update_field(int i, char *text){
struct field * f = active_layout + i;
if (f->cmd[0] == 0)
return -1;
//always send status afresh
if (!strcmp(f->label, "STATUS")){
//send time
time_t now = time_sbitx();
struct tm *tmp = gmtime(&now);
sprintf(text, "STATUS %04d/%02d/%02d %02d:%02d:%02dZ",
tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday, tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
return 1;
}
strcpy(text, f->label);
strcat(text, " ");
strcat(text, f->value);
int update = f->update_remote;
f->update_remote = 0;
//debug on
// if (!strcmp(f->cmd, "#text_in") && strlen(f->value))
// printf("#text_in [%s] %d\n", f->value, update);
//debug off
return update;
}
// log is a special field that essentially is a like text
// on a terminal
void console_init(){
for (int i =0; i < MAX_CONSOLE_LINES; i++){
console_stream[i].text[0] = 0;
console_stream[i].style = console_style;
}
struct field *f = get_field("#console");
console_current_line = 0;
f->is_dirty = 1;
}
void web_add_string(char *string){
while (*string){
q_write(&q_web, *string++);
}
}
void web_write(int style, char *data){
char tag[20];
switch(style){
case FONT_FT8_REPLY:
case FONT_FT8_RX:
strcpy(tag, "WSJTX-RX");
break;
case FONT_FLDIGI_RX:
strcpy(tag, "FLDIGI-RX");
break;
case FONT_CW_RX:
strcpy(tag, "CW-RX");
break;
case FONT_FT8_TX:
strcpy(tag, "WSJTX-TX");
break;
case FONT_FT8_QUEUED:
strcpy(tag, "WSJTX-Q");
break;
case FONT_FLDIGI_TX:
strcpy(tag, "FLDIGI-TX");
break;
case FONT_CW_TX:
strcpy(tag, "CW-TX");
break;
case FONT_TELNET:
strcpy(tag, "TELNET");
break;
default:
strcpy(tag, "LOG");
}
web_add_string("<");
web_add_string(tag);
web_add_string(">");
while (*data){
switch(*data){
case '<':
q_write(&q_web, '&');
q_write(&q_web, 'l');
q_write(&q_web, 't');
q_write(&q_web, ';');
break;
case '>':
q_write(&q_web, '&');
q_write(&q_web, 'g');
q_write(&q_web, 't');
q_write(&q_web, ';');
break;
case '"':
q_write(&q_web, '&');
q_write(&q_web, 'q');
q_write(&q_web, 'u');
q_write(&q_web, 't');
q_write(&q_web, 'e');
q_write(&q_web, ';');
break;
case '\'':
q_write(&q_web, '&');