forked from g0orx/pihpsdr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c.orig
885 lines (757 loc) · 26.6 KB
/
main.c.orig
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
/* 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 <gdk/gdk.h>
#include <math.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <semaphore.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include "audio.h"
#include "band.h"
#include "bandstack.h"
#include "main.h"
#include "channel.h"
#include "discovered.h"
#include "configure.h"
#include "gpio.h"
<<<<<<< HEAD
#include "old_discovery.h"
#include "new_discovery.h"
#ifdef LIMESDR
#include "lime_discovery.h"
#endif
#ifdef RADIOBERRY
#include "radioberry_discovery.h"
#endif
#include "old_protocol.h"
#include "new_protocol.h"
#ifdef LIMESDR
#include "lime_protocol.h"
#endif
#ifdef RADIOBERRY
#include "radioberry.h"
#endif
=======
>>>>>>> upstream/master
#include "wdsp.h"
#include "new_menu.h"
#include "radio.h"
#include "version.h"
#include "button_text.h"
#ifdef I2C
#include "i2c.h"
#endif
#include "discovery.h"
struct utsname unameData;
gint display_width;
gint display_height;
gint full_screen=1;
static GtkWidget *discovery_dialog;
static sem_t wisdom_sem;
static GdkCursor *cursor_arrow;
static GdkCursor *cursor_watch;
static GtkWidget *splash;
GtkWidget *top_window;
GtkWidget *grid;
static DISCOVERED* d;
static GtkWidget *status;
void status_text(char *text) {
//fprintf(stderr,"splash_status: %s\n",text);
gtk_label_set_text(GTK_LABEL(status),text);
usleep(10000);
while (gtk_events_pending ())
gtk_main_iteration ();
}
static gint save_cb(gpointer data) {
radioSaveState();
return TRUE;
}
static pthread_t wisdom_thread_id;
static void* wisdom_thread(void *arg) {
status_text("Creating FFTW Wisdom file ...");
WDSPwisdom ((char *)arg);
sem_post(&wisdom_sem);
}
gboolean main_delete (GtkWidget *widget) {
#ifdef GPIO
gpio_close();
#endif
switch(protocol) {
case ORIGINAL_PROTOCOL:
old_protocol_stop();
break;
case NEW_PROTOCOL:
new_protocol_stop();
break;
#ifdef LIMESDR
case LIMESDR_PROTOCOL:
lime_protocol_stop();
break;
#endif
#ifdef RADIOBERRY
case RADIOBERRY_PROTOCOL:
radioberry_protocol_stop();
break;
#endif
}
radioSaveState();
_exit(0);
}
<<<<<<< HEAD
static gboolean start_cb (GtkWidget *widget, GdkEventButton *event, gpointer data) {
fprintf(stderr,"start_cb: %p\n",data);
radio=(DISCOVERED *)data;
gtk_widget_destroy(discovery_dialog);
start_radio();
return TRUE;
}
#ifdef GPIO
static gboolean gpio_cb (GtkWidget *widget, GdkEventButton *event, gpointer data) {
configure_gpio(discovery_dialog);
return TRUE;
}
#endif
static gboolean discover_cb (GtkWidget *widget, GdkEventButton *event, gpointer data) {
gtk_widget_destroy(discovery_dialog);
discover_devices();
return TRUE;
}
static gboolean exit_cb (GtkWidget *widget, GdkEventButton *event, gpointer data) {
gtk_widget_destroy(discovery_dialog);
_exit(0);
return TRUE;
}
static void discover_devices() {
gdk_window_set_cursor(splash_window,cursor_watch);
selected_device=0;
devices=0;
splash_status("Old Protocol ... Discovering Devices");
old_discovery();
splash_status("New Protocol ... Discovering Devices");
new_discovery();
#ifdef LIMESDR
splash_status("LimeSDR ... Discovering Devices");
lime_discovery();
#endif
#ifdef RADIOBERRY
splash_status("Radioberry SDR ... Discovering Device");
radioberry_discovery();
#endif
splash_status("Discovery");
if(devices==0) {
gdk_window_set_cursor(splash_window,cursor_arrow);
fprintf(stderr,"No devices found!\n");
GtkDialogFlags flags = GTK_DIALOG_DESTROY_WITH_PARENT;
/*
discovery_dialog = gtk_message_dialog_new (GTK_WINDOW(splash_screen),
flags,
GTK_MESSAGE_ERROR,
GTK_BUTTONS_OK_CANCEL,
"No devices found! Retry Discovery?");
*/
discovery_dialog = gtk_dialog_new();
gtk_window_set_transient_for(GTK_WINDOW(discovery_dialog),GTK_WINDOW(splash_screen));
gtk_window_set_decorated(GTK_WINDOW(discovery_dialog),FALSE);
gtk_widget_override_font(discovery_dialog, pango_font_description_from_string("FreeMono 16"));
GdkRGBA color;
color.red = 1.0;
color.green = 1.0;
color.blue = 1.0;
color.alpha = 1.0;
gtk_widget_override_background_color(discovery_dialog,GTK_STATE_FLAG_NORMAL,&color);
GtkWidget *content;
content=gtk_dialog_get_content_area(GTK_DIALOG(discovery_dialog));
GtkWidget *grid=gtk_grid_new();
gtk_grid_set_row_homogeneous(GTK_GRID(grid),TRUE);
gtk_grid_set_column_homogeneous(GTK_GRID(grid),TRUE);
gtk_grid_set_row_spacing (GTK_GRID(grid),10);
GtkWidget *label=gtk_label_new("No devices found!");
gtk_grid_attach(GTK_GRID(grid),label,0,0,2,1);
GtkWidget *exit_b=gtk_button_new_with_label("Exit");
g_signal_connect (exit_b, "button-press-event", G_CALLBACK(exit_cb), NULL);
gtk_grid_attach(GTK_GRID(grid),exit_b,0,1,1,1);
GtkWidget *discover_b=gtk_button_new_with_label("Retry Discovery");
g_signal_connect (discover_b, "button-press-event", G_CALLBACK(discover_cb), NULL);
gtk_grid_attach(GTK_GRID(grid),discover_b,1,1,1,1);
gtk_container_add (GTK_CONTAINER (content), grid);
gtk_widget_show_all(discovery_dialog);
} else {
//fprintf(stderr,"%s: found %d devices.\n", (char *)arg, devices);
gdk_window_set_cursor(splash_window,cursor_arrow);
/*
GtkDialogFlags flags=GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT;
discovery_dialog = gtk_dialog_new_with_buttons ("Discovered",
GTK_WINDOW(splash_window),
flags,
#ifdef GPIO
"Configure GPIO",
GTK_RESPONSE_YES,
#endif
"Discover",
GTK_RESPONSE_REJECT,
"Exit",
GTK_RESPONSE_CLOSE,
NULL);
*/
discovery_dialog = gtk_dialog_new();
gtk_window_set_transient_for(GTK_WINDOW(discovery_dialog),GTK_WINDOW(splash_screen));
gtk_window_set_decorated(GTK_WINDOW(discovery_dialog),FALSE);
gtk_widget_override_font(discovery_dialog, pango_font_description_from_string("FreeMono 16"));
GdkRGBA color;
color.red = 1.0;
color.green = 1.0;
color.blue = 1.0;
color.alpha = 1.0;
gtk_widget_override_background_color(discovery_dialog,GTK_STATE_FLAG_NORMAL,&color);
GtkWidget *content;
content=gtk_dialog_get_content_area(GTK_DIALOG(discovery_dialog));
GtkWidget *grid=gtk_grid_new();
gtk_grid_set_row_homogeneous(GTK_GRID(grid),TRUE);
gtk_grid_set_column_homogeneous(GTK_GRID(grid),TRUE);
gtk_grid_set_row_spacing (GTK_GRID(grid),10);
int i;
char version[16];
char text[128];
for(i=0;i<devices;i++) {
d=&discovered[i];
fprintf(stderr,"%p protocol=%d name=%s\n",d,d->protocol,d->name);
if(d->protocol==ORIGINAL_PROTOCOL) {
sprintf(version,"%d.%d",
d->software_version/10,
d->software_version%10);
} else {
sprintf(version,"%d.%d.%d",
d->software_version/100,
(d->software_version%100)/10,
d->software_version%10);
}
switch(d->protocol) {
case ORIGINAL_PROTOCOL:
case NEW_PROTOCOL:
sprintf(text,"%s (%s %s) %s (%02X:%02X:%02X:%02X:%02X:%02X) on %s\n",
d->name,
d->protocol==ORIGINAL_PROTOCOL?"old":"new",
version,
inet_ntoa(d->info.network.address.sin_addr),
d->info.network.mac_address[0],
d->info.network.mac_address[1],
d->info.network.mac_address[2],
d->info.network.mac_address[3],
d->info.network.mac_address[4],
d->info.network.mac_address[5],
d->info.network.interface_name);
break;
#ifdef LIMESDR
case LIMESDR_PROTOCOL:
/*
sprintf(text,"%s (%s %s)\n",
d->name,
"lime",
version);
*/
sprintf(text,"%s\n",
d->name);
break;
#endif
#ifdef RADIOBERRY
case RADIOBERRY_PROTOCOL:
sprintf(text,"%s\n",d->name);
break;
#endif
}
GtkWidget *label=gtk_label_new(text);
gtk_widget_override_font(label, pango_font_description_from_string("FreeMono 12"));
gtk_widget_show(label);
gtk_grid_attach(GTK_GRID(grid),label,0,i,3,1);
GtkWidget *start_button=gtk_button_new_with_label("Start");
gtk_widget_override_font(start_button, pango_font_description_from_string("FreeMono 18"));
gtk_widget_show(start_button);
gtk_grid_attach(GTK_GRID(grid),start_button,3,i,1,1);
g_signal_connect(start_button,"button_press_event",G_CALLBACK(start_cb),(gpointer)d);
// if not available then cannot start it
if(d->status!=STATE_AVAILABLE) {
gtk_button_set_label(GTK_BUTTON(start_button),"In Use");
gtk_widget_set_sensitive(start_button, FALSE);
}
// if not on the same subnet then cannot start it
if((d->info.network.interface_address.sin_addr.s_addr&d->info.network.interface_netmask.sin_addr.s_addr) != (d->info.network.address.sin_addr.s_addr&d->info.network.interface_netmask.sin_addr.s_addr)) {
gtk_button_set_label(GTK_BUTTON(start_button),"Subnet!");
gtk_widget_set_sensitive(start_button, FALSE);
}
}
#ifdef GPIO
GtkWidget *gpio_b=gtk_button_new_with_label("Config GPIO");
g_signal_connect (gpio_b, "button-press-event", G_CALLBACK(gpio_cb), NULL);
gtk_grid_attach(GTK_GRID(grid),gpio_b,0,i,1,1);
#endif
GtkWidget *discover_b=gtk_button_new_with_label("Discover");
g_signal_connect (discover_b, "button-press-event", G_CALLBACK(discover_cb), NULL);
gtk_grid_attach(GTK_GRID(grid),discover_b,1,i,1,1);
GtkWidget *exit_b=gtk_button_new_with_label("Exit");
g_signal_connect (exit_b, "button-press-event", G_CALLBACK(exit_cb), NULL);
gtk_grid_attach(GTK_GRID(grid),exit_b,2,i,1,1);
gtk_container_add (GTK_CONTAINER (content), grid);
gtk_widget_show_all(discovery_dialog);
}
}
static gboolean minimize_cb (GtkWidget *widget, GdkEventButton *event, gpointer data) {
gtk_window_iconify(GTK_WINDOW(window));
return TRUE;
}
static void start_radio() {
int y;
fprintf(stderr,"start: selected radio=%p device=%d\n",radio,radio->device);
gdk_window_set_cursor(splash_window,cursor_watch);
splash_status("Initializing wdsp ...");
protocol=radio->protocol;
device=radio->device;
switch(radio->protocol) {
case ORIGINAL_PROTOCOL:
case NEW_PROTOCOL:
sprintf(property_path,"%02X-%02X-%02X-%02X-%02X-%02X.props",
radio->info.network.mac_address[0],
radio->info.network.mac_address[1],
radio->info.network.mac_address[2],
radio->info.network.mac_address[3],
radio->info.network.mac_address[4],
radio->info.network.mac_address[5]);
break;
#ifdef LIMESDR
case LIMESDR_PROTOCOL:
sprintf(property_path,"limesdr.props");
break;
#endif
#ifdef RADIOBERRY
case RADIOBERRY_PROTOCOL:
sprintf(property_path,"radioberry.props");
break;
#endif
}
#ifdef GPIO
fprintf(stderr,"gpio_init\n");
splash_status("Initializing GPIO ...");
if(gpio_init()<0) {
}
#ifdef LOCALCW
// init local keyer if enabled
else if (cw_keyer_internal == 0)
keyer_update();
#endif
#endif
radioRestoreState();
fprintf(stderr,"malloc samples\n");
if(radio->protocol==NEW_PROTOCOL) {
samples=malloc(display_width*sizeof(float)*2*4); // 192 -> 48
} else {
samples=malloc(display_width*sizeof(float)*2);
}
//splash_status("Initializing wdsp ...");
fprintf(stderr,"wdsp_init\n");
wdsp_init(0,display_width,radio->protocol);
switch(radio->protocol) {
case ORIGINAL_PROTOCOL:
splash_status("Initializing old protocol ...");
fprintf(stderr,"old_protocol_init\n");
old_protocol_init(0,display_width);
break;
case NEW_PROTOCOL:
splash_status("Initializing new protocol ...");
fprintf(stderr,"new_protocol_init\n");
new_protocol_init(display_width);
break;
#ifdef LIMESDR
case LIMESDR_PROTOCOL:
splash_status("Initializing lime protocol ...");
lime_protocol_init(0,display_width);
break;
#endif
#ifdef RADIOBERRY
case RADIOBERRY_PROTOCOL:
splash_status("Initializing radioberry protocol ...");
radioberry_protocol_init(0,display_width);
break;
#endif
}
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_title (GTK_WINDOW (window), "pihpsdr");
gtk_window_set_position(GTK_WINDOW(window),GTK_WIN_POS_CENTER_ALWAYS);
gtk_window_set_resizable(GTK_WINDOW(window), FALSE);
g_signal_connect (window, "delete-event", G_CALLBACK (main_delete), NULL);
fixed=gtk_fixed_new();
gtk_container_add(GTK_CONTAINER(window), fixed);
y=0;
vfo = vfo_init(VFO_WIDTH,VFO_HEIGHT,window);
gtk_fixed_put(GTK_FIXED(fixed),vfo,0,0);
//rit_control = rit_init(RIT_WIDTH,MENU_HEIGHT,window);
//gtk_fixed_put(GTK_FIXED(fixed),rit_control,VFO_WIDTH,y);
GtkWidget *minimize_b=gtk_button_new_with_label("Hide");
gtk_widget_override_font(minimize_b, pango_font_description_from_string("FreeMono Bold 10"));
gtk_widget_set_size_request (minimize_b, MENU_WIDTH, MENU_HEIGHT/2);
g_signal_connect (minimize_b, "button-press-event", G_CALLBACK(minimize_cb), NULL);
gtk_widget_show(minimize_b);
gtk_fixed_put(GTK_FIXED(fixed),minimize_b,VFO_WIDTH,y);
//menu = menu_init(MENU_WIDTH,MENU_HEIGHT,window);
menu = new_menu_init(MENU_WIDTH,MENU_HEIGHT/2,window);
gtk_fixed_put(GTK_FIXED(fixed),menu,VFO_WIDTH,y+(MENU_HEIGHT/2));
meter = meter_init(METER_WIDTH,METER_HEIGHT,window);
gtk_fixed_put(GTK_FIXED(fixed),meter,VFO_WIDTH+MENU_WIDTH,y);
y+=VFO_HEIGHT;
if(display_panadapter) {
int height=PANADAPTER_HEIGHT;
if(!display_waterfall) {
height+=WATERFALL_HEIGHT;
if(!display_sliders) {
height+=SLIDERS_HEIGHT;
}
if(!display_toolbar) {
height+=TOOLBAR_HEIGHT;
}
} else {
if(!display_sliders) {
height+=SLIDERS_HEIGHT/2;
}
}
panadapter = panadapter_init(display_width,height);
gtk_fixed_put(GTK_FIXED(fixed),panadapter,0,VFO_HEIGHT);
y+=height;
}
if(display_waterfall) {
int height=WATERFALL_HEIGHT;
if(!display_panadapter) {
height+=PANADAPTER_HEIGHT;
}
if(!display_sliders) {
if(display_panadapter) {
height+=SLIDERS_HEIGHT/2;
} else {
height+=SLIDERS_HEIGHT;
}
}
if(!display_toolbar) {
height+=TOOLBAR_HEIGHT;
}
waterfall = waterfall_init(display_width,height);
gtk_fixed_put(GTK_FIXED(fixed),waterfall,0,y);
y+=height;
}
#ifdef PSK
int psk_height=PSK_WATERFALL_HEIGHT;
if(!display_sliders) {
psk_height+=SLIDERS_HEIGHT/2;
}
if(!display_toolbar) {
psk_height+=TOOLBAR_HEIGHT/2;
}
psk_waterfall = psk_waterfall_init(display_width,psk_height);
gtk_fixed_put(GTK_FIXED(fixed),psk_waterfall,0,VFO_HEIGHT);
psk = init_psk();
gtk_fixed_put(GTK_FIXED(fixed),psk,0,VFO_HEIGHT+psk_height);
#endif
if(display_sliders) {
sliders = sliders_init(display_width,SLIDERS_HEIGHT,window);
gtk_fixed_put(GTK_FIXED(fixed),sliders,0,y);
y+=SLIDERS_HEIGHT;
}
if(display_toolbar) {
toolbar = toolbar_init(display_width,TOOLBAR_HEIGHT,window);
gtk_fixed_put(GTK_FIXED(fixed),toolbar,0,y);
y+=TOOLBAR_HEIGHT;
}
splash_close();
gtk_widget_show_all (window);
linein_changed();
if(full_screen) {
gtk_window_fullscreen(GTK_WINDOW(window));
}
GdkWindow *gdk_window = gtk_widget_get_window(window);
gdk_window_set_cursor(gdk_window,cursor_arrow);
// start the receiver
SetChannelState(CHANNEL_RX0,1,1);
//update_timer_id=gdk_threads_add_timeout(1000/updates_per_second, update, NULL);
update_timer_id=gdk_threads_add_timeout_full(G_PRIORITY_HIGH_IDLE,1000/updates_per_second, update, NULL, NULL);
// save every 30 seconds
save_timer_id=gdk_threads_add_timeout(30000, save_cb, NULL);
if(protocol!=NEW_PROTOCOL) {
setFrequency(getFrequency());
}
#ifdef PSK
if(mode==modePSK) {
show_psk();
} else {
show_waterfall();
}
#endif
launch_rigctl();
g_idle_add(vfo_update,(gpointer)NULL);
}
#ifdef PSK
void show_psk() {
if(display_waterfall) {
gtk_widget_hide(waterfall);
}
if(display_panadapter) {
gtk_widget_hide(panadapter);
}
gtk_widget_show(psk);
gtk_widget_show(psk_waterfall);
}
void show_waterfall() {
gtk_widget_hide(psk_waterfall);
gtk_widget_hide(psk);
if(display_panadapter) {
gtk_widget_show(panadapter);
}
if(display_waterfall) {
gtk_widget_show(waterfall);
}
}
#endif
void reconfigure_display() {
int y=VFO_HEIGHT;
// configure panadapter
if(display_panadapter) {
int height=PANADAPTER_HEIGHT;
if(!display_waterfall) {
height+=WATERFALL_HEIGHT;
if(!display_sliders) {
height+=SLIDERS_HEIGHT;
}
if(!display_toolbar) {
height+=TOOLBAR_HEIGHT;
}
} else {
if(!display_sliders) {
height+=SLIDERS_HEIGHT/2;
}
if(!display_toolbar) {
height+=TOOLBAR_HEIGHT/2;
}
}
fprintf(stderr,"panadapter_height=%d\n",height);
if(panadapter==NULL) {
fprintf(stderr,"reconfigure_display: panadapter_init: width:%d height:%d\n",display_width,height);
panadapter = panadapter_init(display_width,height);
gtk_fixed_put(GTK_FIXED(fixed),panadapter,0,y);
} else {
// set the size
fprintf(stderr,"reconfigure_display: panadapter set_size_request: width:%d height:%d\n",display_width,height);
gtk_widget_set_size_request(panadapter, display_width, height);
// move the current one
gtk_fixed_move(GTK_FIXED(fixed),panadapter,0,y);
}
gtk_widget_show_all(panadapter);
y+=height;
} else {
gtk_widget_hide(panadapter);
}
// configure waterfall
if(display_waterfall) {
int height=WATERFALL_HEIGHT;
if(!display_panadapter) {
height+=PANADAPTER_HEIGHT;
if(!display_sliders) {
height+=SLIDERS_HEIGHT;
}
if(!display_toolbar) {
height+=TOOLBAR_HEIGHT;
}
} else {
if(!display_sliders) {
height+=SLIDERS_HEIGHT/2;
}
if(!display_toolbar) {
height+=TOOLBAR_HEIGHT/2;
}
}
fprintf(stderr,"waterfall_height=%d\n",height);
if(waterfall==NULL) {
fprintf(stderr,"reconfigure_display: waterfall_init: width:%d height:%d\n",display_width,height);
waterfall = waterfall_init(display_width,height);
gtk_fixed_put(GTK_FIXED(fixed),waterfall,0,y);
} else {
// set the size
fprintf(stderr,"reconfigure_display: waterfall set_size_request: width:%d height:%d\n",display_width,height);
gtk_widget_set_size_request (waterfall, display_width, height);
// move the current one
gtk_fixed_move(GTK_FIXED(fixed),waterfall,0,y);
}
gtk_widget_show_all(waterfall);
y+=height;
} else {
gtk_widget_hide(waterfall);
}
if(display_sliders) {
fprintf(stderr,"sliders_height=%d\n",SLIDERS_HEIGHT);
if(sliders==NULL) {
fprintf(stderr,"reconfigure_display: sliders_init: width:%d height:%d\n",display_width,SLIDERS_HEIGHT);
sliders = sliders_init(display_width,SLIDERS_HEIGHT,window);
gtk_fixed_put(GTK_FIXED(fixed),sliders,0,y);
} else {
gtk_fixed_move(GTK_FIXED(fixed),sliders,0,y);
gtk_widget_show(sliders);
}
gtk_widget_show_all(sliders);
linein_changed();
y+=SLIDERS_HEIGHT;
} else {
gtk_widget_hide(sliders);
}
if(display_toolbar) {
fprintf(stderr,"toolbar_height=%d\n",TOOLBAR_HEIGHT);
if(toolbar==NULL) {
fprintf(stderr,"reconfigure_display: toolbar_init: width:%d height:%d\n",display_width,TOOLBAR_HEIGHT);
toolbar = toolbar_init(display_width,TOOLBAR_HEIGHT,window);
gtk_fixed_put(GTK_FIXED(fixed),toolbar,0,y);
} else {
gtk_fixed_move(GTK_FIXED(fixed),toolbar,0,y);
gtk_widget_show(toolbar);
}
gtk_widget_show_all(toolbar);
y+=TOOLBAR_HEIGHT;
} else {
gtk_widget_hide(toolbar);
}
}
gint init(void* arg) {
=======
static int init(void *data) {
>>>>>>> upstream/master
char *res;
char wisdom_directory[1024];
char wisdom_file[1024];
fprintf(stderr,"init\n");
audio_get_cards();
cursor_arrow=gdk_cursor_new(GDK_ARROW);
cursor_watch=gdk_cursor_new(GDK_WATCH);
gdk_window_set_cursor(gtk_widget_get_window(top_window),cursor_watch);
// check if wisdom file exists
res=getcwd(wisdom_directory, sizeof(wisdom_directory));
strcpy(&wisdom_directory[strlen(wisdom_directory)],"/");
strcpy(wisdom_file,wisdom_directory);
strcpy(&wisdom_file[strlen(wisdom_file)],"wdspWisdom");
status_text("Checking FFTW Wisdom file ...");
if(access(wisdom_file,F_OK)<0) {
int rc=sem_init(&wisdom_sem, 0, 0);
rc=pthread_create(&wisdom_thread_id, NULL, wisdom_thread, (void *)wisdom_directory);
while(sem_trywait(&wisdom_sem)<0) {
status_text(wisdom_get_status());
while (gtk_events_pending ())
gtk_main_iteration ();
usleep(100000); // 100ms
}
}
g_idle_add(discovery,NULL);
return 0;
}
static void activate_pihpsdr(GtkApplication *app, gpointer data) {
//gtk_init (&argc, &argv);
fprintf(stderr,"Build: %s %s\n",build_date,version);
uname(&unameData);
fprintf(stderr,"sysname: %s\n",unameData.sysname);
fprintf(stderr,"nodename: %s\n",unameData.nodename);
fprintf(stderr,"release: %s\n",unameData.release);
fprintf(stderr,"version: %s\n",unameData.version);
fprintf(stderr,"machine: %s\n",unameData.machine);
GdkScreen *screen=gdk_screen_get_default();
if(screen==NULL) {
fprintf(stderr,"no default screen!\n");
_exit(0);
}
display_width=gdk_screen_get_width(screen);
display_height=gdk_screen_get_height(screen);
fprintf(stderr,"width=%d height=%d\n", display_width, display_height);
if(display_width>800 || display_height>480) {
display_width=800;
display_height=480;
full_screen=0;
}
fprintf(stderr,"display_width=%d display_height=%d\n", display_width, display_height);
fprintf(stderr,"create top level window\n");
top_window = gtk_application_window_new (app);
if(full_screen) {
fprintf(stderr,"full screen\n");
gtk_window_fullscreen(GTK_WINDOW(top_window));
}
gtk_widget_set_size_request(top_window, display_width, display_height);
gtk_window_set_title (GTK_WINDOW (top_window), "pihpsdr");
gtk_window_set_position(GTK_WINDOW(top_window),GTK_WIN_POS_CENTER_ALWAYS);
gtk_window_set_resizable(GTK_WINDOW(top_window), FALSE);
g_signal_connect (top_window, "delete-event", G_CALLBACK (main_delete), NULL);
//g_signal_connect (top_window,"draw", G_CALLBACK (main_draw_cb), NULL);
//fprintf(stderr,"create fixed container\n");
//fixed=gtk_fixed_new();
//gtk_container_add(GTK_CONTAINER(top_window), fixed);
fprintf(stderr,"create grid\n");
grid = gtk_grid_new();
gtk_widget_set_size_request(grid, display_width, display_height);
gtk_grid_set_row_homogeneous(GTK_GRID(grid),FALSE);
gtk_grid_set_column_homogeneous(GTK_GRID(grid),FALSE);
fprintf(stderr,"add grid\n");
gtk_container_add (GTK_CONTAINER (top_window), grid);
fprintf(stderr,"create image\n");
GtkWidget *image=gtk_image_new_from_file("hpsdr.png");
fprintf(stderr,"add image to grid\n");
gtk_grid_attach(GTK_GRID(grid), image, 0, 0, 1, 4);
fprintf(stderr,"create pi label\n");
char build[64];
sprintf(build,"build: %s %s",build_date, version);
GtkWidget *pi_label=gtk_label_new("pihpsdr by John Melton g0orx/n6lyt");
gtk_label_set_justify(GTK_LABEL(pi_label),GTK_JUSTIFY_LEFT);
gtk_widget_show(pi_label);
fprintf(stderr,"add pi label to grid\n");
gtk_grid_attach(GTK_GRID(grid),pi_label,1,0,1,1);
fprintf(stderr,"create build label\n");
GtkWidget *build_date_label=gtk_label_new(build);
gtk_label_set_justify(GTK_LABEL(build_date_label),GTK_JUSTIFY_LEFT);
gtk_widget_show(build_date_label);
fprintf(stderr,"add build label to grid\n");
gtk_grid_attach(GTK_GRID(grid),build_date_label,1,1,1,1);
fprintf(stderr,"create status\n");
status=gtk_label_new("");
gtk_label_set_justify(GTK_LABEL(status),GTK_JUSTIFY_LEFT);
gtk_widget_override_font(status, pango_font_description_from_string("FreeMono 18"));
gtk_widget_show(status);
fprintf(stderr,"add status to grid\n");
gtk_grid_attach(GTK_GRID(grid), status, 1, 3, 1, 1);
/*
fprintf(stderr,"create exit button\n");
GtkWidget *button = gtk_button_new_with_label ("Exit");
//g_signal_connect (button, "clicked", G_CALLBACK (print_hello), NULL);
g_signal_connect_swapped (button, "clicked", G_CALLBACK (gtk_widget_destroy), top_window);
fprintf(stderr,"add exit button to grid\n");
gtk_grid_attach(GTK_GRID(grid), button, 1, 4, 1, 1);
*/
gtk_widget_show_all(top_window);
g_idle_add(init,NULL);
//g_idle_add(discovery,NULL);
}
int main(int argc,char **argv) {
GtkApplication *pihpsdr;
int status;
pihpsdr=gtk_application_new("org.g0orx.pihpsdr", G_APPLICATION_FLAGS_NONE);
g_signal_connect(pihpsdr, "activate", G_CALLBACK(activate_pihpsdr), NULL);
status=g_application_run(G_APPLICATION(pihpsdr), argc, argv);
fprintf(stderr,"exiting ...\n");
g_object_unref(pihpsdr);
return status;
}