forked from g0orx/pihpsdr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnew_menu.c
504 lines (420 loc) · 12.2 KB
/
new_menu.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
/* Copyright (C)
* 2015 - John Melton, G0ORX/N6LYT
*
* This program 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 2
* of the License, or (at your option) any later version.
*
* This program 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 this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*/
#include <gtk/gtk.h>
#include <semaphore.h>
#include <stdio.h>
#include <string.h>
#include "audio.h"
#include "new_menu.h"
#include "exit_menu.h"
#include "radio_menu.h"
#include "rx_menu.h"
#include "ant_menu.h"
#include "display_menu.h"
#include "dsp_menu.h"
#include "pa_menu.h"
#include "oc_menu.h"
#ifdef FREEDV
#include "freedv_menu.h"
#endif
#include "xvtr_menu.h"
#include "equalizer_menu.h"
#include "radio.h"
#include "step_menu.h"
#include "meter_menu.h"
#include "band_menu.h"
#include "bandstack_menu.h"
#include "mode_menu.h"
#include "filter_menu.h"
#include "noise_menu.h"
#include "agc_menu.h"
#include "test_menu.h"
#include "vox_menu.h"
#include "diversity_menu.h"
#include "freqent_menu.h"
#include "tx_menu.h"
#ifdef GPIO
#include "encoder_menu.h"
#endif
#include "vfo_menu.h"
#include "main.h"
static GtkWidget *menu_b=NULL;
static GtkWidget *dialog=NULL;
GtkWidget *sub_menu=NULL;
int active_menu=NO_MENU;
static cleanup() {
if(dialog!=NULL) {
gtk_widget_destroy(dialog);
dialog=NULL;
}
if(sub_menu!=NULL) {
gtk_widget_destroy(sub_menu);
sub_menu=NULL;
}
active_menu=NO_MENU;
}
static gboolean close_cb (GtkWidget *widget, GdkEventButton *event, gpointer data) {
cleanup();
return TRUE;
}
static gboolean exit_cb (GtkWidget *widget, GdkEventButton *event, gpointer data) {
cleanup();
exit_menu(top_window);
return TRUE;
}
static gboolean radio_cb (GtkWidget *widget, GdkEventButton *event, gpointer data) {
cleanup();
radio_menu(top_window);
return TRUE;
}
static gboolean rx_cb (GtkWidget *widget, GdkEventButton *event, gpointer data) {
cleanup();
rx_menu(top_window);
return TRUE;
}
static gboolean ant_cb (GtkWidget *widget, GdkEventButton *event, gpointer data) {
cleanup();
ant_menu(top_window);
return TRUE;
}
static gboolean display_cb (GtkWidget *widget, GdkEventButton *event, gpointer data) {
cleanup();
display_menu(top_window);
return TRUE;
}
static gboolean dsp_cb (GtkWidget *widget, GdkEventButton *event, gpointer data) {
cleanup();
dsp_menu(top_window);
return TRUE;
}
static gboolean pa_cb (GtkWidget *widget, GdkEventButton *event, gpointer data) {
cleanup();
pa_menu(top_window);
return TRUE;
}
static gboolean cw_cb (GtkWidget *widget, GdkEventButton *event, gpointer data) {
cleanup();
cw_menu(top_window);
return TRUE;
}
static gboolean oc_cb (GtkWidget *widget, GdkEventButton *event, gpointer data) {
cleanup();
oc_menu(top_window);
return TRUE;
}
#ifdef FREEDV
static gboolean freedv_cb (GtkWidget *widget, GdkEventButton *event, gpointer data) {
cleanup();
freedv_menu(top_window);
return TRUE;
}
#endif
static gboolean xvtr_cb (GtkWidget *widget, GdkEventButton *event, gpointer data) {
cleanup();
xvtr_menu(top_window);
return TRUE;
}
static gboolean equalizer_cb (GtkWidget *widget, GdkEventButton *event, gpointer data) {
cleanup();
equalizer_menu(top_window);
return TRUE;
}
void start_step() {
cleanup();
step_menu(top_window);
}
static gboolean step_cb (GtkWidget *widget, GdkEventButton *event, gpointer data) {
start_step();
return TRUE;
}
void start_meter() {
cleanup();
meter_menu(top_window);
}
static gboolean meter_cb (GtkWidget *widget, GdkEventButton *event, gpointer data) {
start_meter();
return TRUE;
}
void start_band() {
int old_menu=active_menu;
cleanup();
if(old_menu!=BAND_MENU) {
band_menu(top_window);
active_menu=BAND_MENU;
}
}
static gboolean band_cb (GtkWidget *widget, GdkEventButton *event, gpointer data) {
start_band();
return TRUE;
}
void start_bandstack() {
int old_menu=active_menu;
cleanup();
if(old_menu!=BANDSTACK_MENU) {
bandstack_menu(top_window);
active_menu=BANDSTACK_MENU;
}
}
static gboolean bandstack_cb (GtkWidget *widget, GdkEventButton *event, gpointer data) {
start_bandstack();
return TRUE;
}
void start_mode() {
int old_menu=active_menu;
cleanup();
if(old_menu!=MODE_MENU) {
mode_menu(top_window);
active_menu=MODE_MENU;
}
}
static gboolean mode_cb (GtkWidget *widget, GdkEventButton *event, gpointer data) {
start_mode();
return TRUE;
}
void start_filter() {
int old_menu=active_menu;
cleanup();
if(old_menu!=FILTER_MENU) {
filter_menu(top_window);
active_menu=FILTER_MENU;
}
}
static gboolean filter_cb (GtkWidget *widget, GdkEventButton *event, gpointer data) {
start_filter();
return TRUE;
}
void start_noise() {
int old_menu=active_menu;
cleanup();
if(old_menu!=NOISE_MENU) {
noise_menu(top_window);
active_menu=NOISE_MENU;
}
}
static gboolean noise_cb (GtkWidget *widget, GdkEventButton *event, gpointer data) {
start_noise();
return TRUE;
}
void start_agc() {
int old_menu=active_menu;
cleanup();
if(old_menu!=AGC_MENU) {
agc_menu(top_window);
active_menu=AGC_MENU;
}
}
static gboolean agc_cb (GtkWidget *widget, GdkEventButton *event, gpointer data) {
start_agc();
return TRUE;
}
void start_vox() {
cleanup();
vox_menu(top_window);
}
static gboolean vox_b_cb (GtkWidget *widget, GdkEventButton *event, gpointer data) {
start_vox();
return TRUE;
}
void start_diversity() {
cleanup();
diversity_menu(top_window);
}
static gboolean diversity_cb (GtkWidget *widget, GdkEventButton *event, gpointer data) {
start_diversity();
return TRUE;
}
void start_freqent() {
cleanup();
freqent_menu(top_window);
}
static gboolean freqent_cb (GtkWidget *widget, GdkEventButton *event, gpointer data) {
start_freqent();
return TRUE;
}
void start_vfo() {
cleanup();
vfo_menu(top_window);
}
static gboolean vfo_cb (GtkWidget *widget, GdkEventButton *event, gpointer data) {
start_vfo();
return TRUE;
}
void start_store() {
cleanup();
store_menu(top_window);
}
static gboolean store_cb (GtkWidget *widget, GdkEventButton *event, gpointer data) {
start_store();
return TRUE;
}
void start_tx() {
cleanup();
tx_menu(top_window);
}
static gboolean tx_cb (GtkWidget *widget, GdkEventButton *event, gpointer data) {
start_tx();
return TRUE;
}
#ifdef GPIO
void start_encoder(int encoder) {
int old_menu=active_menu;
fprintf(stderr,"start_encoder: encoder=%d active_menu=%d\n",encoder,active_menu);
cleanup();
switch(encoder) {
case 1:
if(old_menu!=E1_MENU) {
encoder_menu(top_window,encoder);
active_menu=E1_MENU;
}
break;
case 2:
if(old_menu!=E2_MENU) {
encoder_menu(top_window,encoder);
active_menu=E2_MENU;
}
break;
case 3:
if(old_menu!=E3_MENU) {
encoder_menu(top_window,encoder);
active_menu=E3_MENU;
}
break;
}
}
static gboolean encoder_cb (GtkWidget *widget, GdkEventButton *event, gpointer data) {
int encoder=(int)data;
start_encoder(encoder);
return TRUE;
}
#endif
void start_test() {
cleanup();
test_menu(top_window);
}
static gboolean test_cb (GtkWidget *widget, GdkEventButton *event, gpointer data) {
start_test();
return TRUE;
}
void new_menu()
{
int i, j, id;
if(dialog==NULL) {
if(sub_menu!=NULL) {
gtk_widget_destroy(sub_menu);
sub_menu=NULL;
}
dialog=gtk_dialog_new();
gtk_window_set_transient_for(GTK_WINDOW(dialog),GTK_WINDOW(top_window));
gtk_window_set_decorated(GTK_WINDOW(dialog),FALSE);
GdkRGBA color;
color.red = 1.0;
color.green = 1.0;
color.blue = 1.0;
color.alpha = 1.0;
gtk_widget_override_background_color(dialog,GTK_STATE_FLAG_NORMAL,&color);
GtkWidget *content=gtk_dialog_get_content_area(GTK_DIALOG(dialog));
GtkWidget *grid=gtk_grid_new();
gtk_grid_set_column_spacing (GTK_GRID(grid),10);
gtk_grid_set_row_spacing (GTK_GRID(grid),10);
gtk_grid_set_row_homogeneous(GTK_GRID(grid),TRUE);
gtk_grid_set_column_homogeneous(GTK_GRID(grid),TRUE);
GtkWidget *close_b=gtk_button_new_with_label("Close Menu");
g_signal_connect (close_b, "button-press-event", G_CALLBACK(close_cb), NULL);
gtk_grid_attach(GTK_GRID(grid),close_b,0,0,2,1);
GtkWidget *exit_b=gtk_button_new_with_label("Exit piHPSDR");
g_signal_connect (exit_b, "button-press-event", G_CALLBACK(exit_cb), NULL);
gtk_grid_attach(GTK_GRID(grid),exit_b,4,0,2,1);
i=5;
GtkWidget *radio_b=gtk_button_new_with_label("Radio");
g_signal_connect (radio_b, "button-press-event", G_CALLBACK(radio_cb), NULL);
gtk_grid_attach(GTK_GRID(grid),radio_b,(i%5),i/5,1,1);
i++;
GtkWidget *rx_b=gtk_button_new_with_label("RX");
g_signal_connect (rx_b, "button-press-event", G_CALLBACK(rx_cb), NULL);
gtk_grid_attach(GTK_GRID(grid),rx_b,(i%5),i/5,1,1);
i++;
GtkWidget *tx_b=gtk_button_new_with_label("TX");
g_signal_connect (tx_b, "button-press-event", G_CALLBACK(tx_cb), NULL);
gtk_grid_attach(GTK_GRID(grid),tx_b,(i%5),i/5,1,1);
i++;
GtkWidget *pa_b=gtk_button_new_with_label("PA");
g_signal_connect (pa_b, "button-press-event", G_CALLBACK(pa_cb), NULL);
gtk_grid_attach(GTK_GRID(grid),pa_b,(i%5),i/5,1,1);
i++;
GtkWidget *cw_b=gtk_button_new_with_label("CW");
g_signal_connect (cw_b, "button-press-event", G_CALLBACK(cw_cb), NULL);
gtk_grid_attach(GTK_GRID(grid),cw_b,(i%5),i/5,1,1);
i++;
GtkWidget *ant_b=gtk_button_new_with_label("Ant");
g_signal_connect (ant_b, "button-press-event", G_CALLBACK(ant_cb), NULL);
gtk_grid_attach(GTK_GRID(grid),ant_b,(i%5),i/5,1,1);
i++;
GtkWidget *dsp_b=gtk_button_new_with_label("DSP");
g_signal_connect (dsp_b, "button-press-event", G_CALLBACK(dsp_cb), NULL);
gtk_grid_attach(GTK_GRID(grid),dsp_b,(i%5),i/5,1,1);
i++;
GtkWidget *oc_b=gtk_button_new_with_label("OC");
g_signal_connect (oc_b, "button-press-event", G_CALLBACK(oc_cb), NULL);
gtk_grid_attach(GTK_GRID(grid),oc_b,(i%5),i/5,1,1);
i++;
#ifdef FREEDV
GtkWidget *freedv_b=gtk_button_new_with_label("FreeDV");
g_signal_connect (freedv_b, "button-press-event", G_CALLBACK(freedv_cb), NULL);
gtk_grid_attach(GTK_GRID(grid),freedv_b,(i%5),i/5,1,1);
i++;
#endif
GtkWidget *display_b=gtk_button_new_with_label("Display");
g_signal_connect (display_b, "button-press-event", G_CALLBACK(display_cb), NULL);
gtk_grid_attach(GTK_GRID(grid),display_b,(i%5),i/5,1,1);
i++;
GtkWidget *xvtr_b=gtk_button_new_with_label("XVTR");
g_signal_connect (xvtr_b, "button-press-event", G_CALLBACK(xvtr_cb), NULL);
gtk_grid_attach(GTK_GRID(grid),xvtr_b,(i%5),i/5,1,1);
i++;
GtkWidget *equalizer_b=gtk_button_new_with_label("Equalizer");
g_signal_connect (equalizer_b, "button-press-event", G_CALLBACK(equalizer_cb), NULL);
gtk_grid_attach(GTK_GRID(grid),equalizer_b,(i%5),i/5,1,1);
i++;
GtkWidget *step_b=gtk_button_new_with_label("Step");
g_signal_connect (step_b, "button-press-event", G_CALLBACK(step_cb), NULL);
gtk_grid_attach(GTK_GRID(grid),step_b,(i%5),i/5,1,1);
i++;
GtkWidget *meter_b=gtk_button_new_with_label("Meter");
g_signal_connect (meter_b, "button-press-event", G_CALLBACK(meter_cb), NULL);
gtk_grid_attach(GTK_GRID(grid),meter_b,(i%5),i/5,1,1);
i++;
GtkWidget *vox_b=gtk_button_new_with_label("VOX");
g_signal_connect (vox_b, "button-press-event", G_CALLBACK(vox_b_cb), NULL);
gtk_grid_attach(GTK_GRID(grid),vox_b,(i%5),i/5,1,1);
i++;
#ifdef DIVERSITY
if(RECEIVERS==2) {
GtkWidget *diversity_b=gtk_button_new_with_label("Diversity");
g_signal_connect (diversity_b, "button-press-event", G_CALLBACK(diversity_cb), NULL);
gtk_grid_attach(GTK_GRID(grid),diversity_b,(i%5),i/5,1,1);
i++;
}
#endif
gtk_container_add(GTK_CONTAINER(content),grid);
gtk_widget_show_all(dialog);
} else {
gtk_widget_destroy(dialog);
dialog=NULL;
}
}