-
Notifications
You must be signed in to change notification settings - Fork 2
/
subrx.c
485 lines (426 loc) · 15.2 KB
/
subrx.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
/**
* @file subrx.c
* @brief Receiver 2 files for GHPSDR
* @author John Melton, G0ORX/N6LYT, Doxygen Comments Dave Larsen, KV0S
* @version 0.1
* @date 2009-04-11
*/
/* Copyright (C)
* 2009 - John Melton, G0ORX/N6LYT, Doxygen Comments Dave Larsen, KV0S
* 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 <math.h>
#include <stdio.h>
#include <stdlib.h>
#include "screensize.h"
#include "bandstack.h"
#include "command.h"
#include "subrx.h"
#include "main.h"
#include "property.h"
#include "ozy.h"
#include "vfo.h"
#include "channel.h"
GtkWidget* subrxFrame;
GtkWidget* subrxTable;
GtkWidget* subrxEnabled;
GtkWidget* subrxGainFrame;
GtkWidget* subrxGainScale;
GtkWidget* subrxPanFrame;
GtkWidget* subrxPanScale;
GtkWidget* subrxFrequencyDisplay;
GdkPixmap* subrxPixmap;
float subrxGain=10.0;
float subrxPan=50.0;
long long subrxFrequency;
long long subrxFrequencyLO;
long long subrxFrequencyDsp;
long long subrxFrequencyDds;
gboolean subrx=FALSE;
void setSubrxFrequency(long long f);
void subrxIncrementFrequency(long increment,gboolean round);
/* --------------------------------------------------------------------------*/
/**
* @brief Callback when subrxFrequencyDisplay is created
*
* @param widget
* @param event
*
* @return
*/
gboolean subrxFrequencyDisplayConfigure(GtkWidget* widget,GdkEventConfigure* event) {
GdkGC* gc;
PangoContext *context;
PangoLayout *layout;
char temp[128];
if(subrxPixmap) g_object_unref(subrxPixmap);
subrxPixmap=gdk_pixmap_new(widget->window,widget->allocation.width,widget->allocation.height,-1);
gc=gdk_gc_new(widget->window);
gdk_gc_set_rgb_fg_color(gc,&background);
gdk_draw_rectangle(subrxPixmap,
gc,
TRUE,
0,0,
widget->allocation.width,
widget->allocation.height);
context = gdk_pango_context_get_for_screen(gdk_screen_get_default ());
layout = pango_layout_new(context);
pango_layout_set_width(layout,widget->allocation.width*PANGO_SCALE);
pango_layout_set_alignment(layout,PANGO_ALIGN_RIGHT);
#ifdef NETBOOK
sprintf(temp,"<span foreground='%s' background='#2C2C2C' font_desc='Sans Bold 12'>% 7lld.%03lld.%03lld </span>",subrx?"#00FF00":"#C0C0C0",subrxFrequency/1000000LL,(subrxFrequency%1000000LL)/1000LL,subrxFrequency%1000LL);
#else
sprintf(temp,"<span foreground='%s' background='#2C2C2C' font_desc='Sans Bold 24'>% 7lld.%03lld.%03lld </span>",subrx?"#00FF00":"#C0C0C0",subrxFrequency/1000000LL,(subrxFrequency%1000000LL)/1000LL,subrxFrequency%1000LL);
#endif
pango_layout_set_markup(layout,temp,-1);
gdk_draw_layout(GDK_DRAWABLE(subrxPixmap),gc,0,0,layout);
gdk_gc_set_rgb_fg_color(gc,&grey);
gdk_draw_rectangle(subrxPixmap,
gc,
FALSE,
0,0,
widget->allocation.width-1,
widget->allocation.height-1);
g_object_unref(context);
g_object_unref(layout);
g_object_unref(gc);
return TRUE;
}
/* --------------------------------------------------------------------------*/
/**
* @brief Callback when subrx is exposed - need to paint it from the pixmap
*
* @param widget
* @param event
*
* @return
*/
gboolean subrxFrequencyDisplayExpose(GtkWidget* widget,GdkEventExpose* event) {
gdk_draw_drawable(widget->window,
widget->style->fg_gc[GTK_WIDGET_STATE (widget)],
subrxPixmap,
event->area.x, event->area.y,
event->area.x, event->area.y,
event->area.width, event->area.height);
return FALSE;
}
/* --------------------------------------------------------------------------*/
/**
* @brief update vfo a display
*
* @param widget
* @param event
*
* @return
*/
void updateSubrxDisplay() {
GdkGC* gc;
PangoContext *context;
PangoLayout *layout;
char temp[128];
if(subrxFrequencyDisplay->window) {
gc=gdk_gc_new(subrxFrequencyDisplay->window);
gdk_gc_set_rgb_fg_color(gc,&background);
gdk_draw_rectangle(subrxPixmap,
gc,
TRUE,
0,0,
subrxFrequencyDisplay->allocation.width,
subrxFrequencyDisplay->allocation.height);
context = gdk_pango_context_get_for_screen (gdk_screen_get_default ());
layout = pango_layout_new (context);
pango_layout_set_width(layout,subrxFrequencyDisplay->allocation.width*PANGO_SCALE);
pango_layout_set_alignment(layout,PANGO_ALIGN_RIGHT);
#ifdef NETBOOK
sprintf(temp,"<span foreground='%s' background='#2C2C2C' font_desc='Sans Bold 12'>% 7lld.%03lld.%03lld </span>",subrx?"#00FF00":"#C0C0C0",subrxFrequency/1000000LL,(subrxFrequency%1000000LL)/1000LL,subrxFrequency%1000LL);
#else
sprintf(temp,"<span foreground='%s' background='#2C2C2C' font_desc='Sans Bold 24'>% 7lld.%03lld.%03lld </span>",subrx?"#00FF00":"#C0C0C0",subrxFrequency/1000000LL,(subrxFrequency%1000000LL)/1000LL,subrxFrequency%1000LL);
#endif
pango_layout_set_markup(layout,temp,-1);
gdk_draw_layout(GDK_DRAWABLE(subrxPixmap),gc,0,0,layout);
gdk_gc_set_rgb_fg_color(gc,&grey);
gdk_draw_rectangle(subrxPixmap,
gc,
FALSE,
0,0,
subrxFrequencyDisplay->allocation.width-1,
subrxFrequencyDisplay->allocation.height-1);
g_object_unref(context);
g_object_unref(layout);
g_object_unref(gc);
gtk_widget_queue_draw(subrxFrequencyDisplay);
}
}
/* --------------------------------------------------------------------------*/
/**
* @brief Frequency scroll wheel
*
* @param widget
* @param event
*
* @return
*/
gboolean subrx_frequency_scroll_event(GtkWidget* widget,GdkEventScroll* event) {
long increment;
if(event->direction==GDK_SCROLL_UP) {
increment=frequencyIncrement;
} else {
increment=-frequencyIncrement;
}
subrxIncrementFrequency(increment,FALSE);
}
/* --------------------------------------------------------------------------*/
/**
* @brief Enabled button Callback
*
* @param widget -- pointer to the parent widget,
* @param data -- pointer to the data.
*/
void subrxEnabledButtonCallback(GtkWidget* widget,gpointer data) {
GtkWidget* label;
char c[80];
gboolean state;
if(subrx) {
state=0;
} else {
state=1;
}
label=gtk_bin_get_child((GtkBin*)widget);
if(state) {
gtk_widget_modify_fg(label, GTK_STATE_NORMAL, &buttonSelected);
gtk_widget_modify_fg(label, GTK_STATE_PRELIGHT, &buttonSelected);
} else {
gtk_widget_modify_fg(label, GTK_STATE_NORMAL, &white);
gtk_widget_modify_fg(label, GTK_STATE_PRELIGHT, &black);
}
subrx=state;
if(subrx) {
subrxFrequencyLO=frequencyALO;
long long diff=subrxFrequency-frequencyA;
if(diff<0) diff=-diff;
if(diff>sampleRate/2) {
setSubrxFrequency(frequencyA);
} else {
setSubrxFrequency(subrxFrequency);
}
if(running) {
SetRXAShiftRun(CHANNEL_SUBRX, 1);
SetChannelState(CHANNEL_SUBRX, 1, 0);
}
} else {
if(running) {
SetRXAShiftRun(CHANNEL_SUBRX, 0);
SetChannelState(CHANNEL_SUBRX, 0, 0);
}
}
updateSubrxDisplay();
}
/* --------------------------------------------------------------------------*/
/**
* @brief Callback when subrx gain values changes
*
* @param widget
* @param data
*/
void subrxGainChanged(GtkWidget* widget,gpointer data) {
char command[80];
subrxGain=gtk_range_get_value((GtkRange*)subrxGainScale);
#ifdef DTTSP
SetRXOutputGain(0,1,subrxGain/100.0);
#endif
}
/* --------------------------------------------------------------------------*/
/**
* @brief Callback when subrx pan values changes
*
* @param widget
* @param data
*/
void subrxPanChanged(GtkWidget* widget,gpointer data) {
char command[80];
subrxPan=gtk_range_get_value((GtkRange*)subrxPanScale);
if(running) {
SetRXAPanelPan(CHANNEL_SUBRX, 1.0-subrxPan);
}
}
/* --------------------------------------------------------------------------*/
/**
* @brief Build Transmit User Interface
*
* @return GtkWidget pointer
*/
GtkWidget* buildSubRxUI() {
GtkWidget* label;
subrxFrame=gtk_frame_new("Sub RX");
gtk_widget_modify_bg(subrxFrame,GTK_STATE_NORMAL,&background);
gtk_widget_modify_fg(gtk_frame_get_label_widget(GTK_FRAME(subrxFrame)),GTK_STATE_NORMAL,&white);
#ifdef NETBOOK
subrxTable=gtk_table_new(1,9,TRUE);
#else
subrxTable=gtk_table_new(2,8,TRUE);
#endif
// subrx settings
subrxFrequencyDisplay=gtk_drawing_area_new();
//gtk_widget_set_size_request(GTK_WIDGET(subrxFrequencyDisplay),250,35);
g_signal_connect(G_OBJECT (subrxFrequencyDisplay),"configure_event",G_CALLBACK(subrxFrequencyDisplayConfigure),NULL);
g_signal_connect(G_OBJECT (subrxFrequencyDisplay),"expose_event",G_CALLBACK(subrxFrequencyDisplayExpose),NULL);
g_signal_connect(G_OBJECT(subrxFrequencyDisplay),"scroll_event",G_CALLBACK(subrx_frequency_scroll_event),NULL);
gtk_widget_set_events(subrxFrequencyDisplay,GDK_EXPOSURE_MASK|GDK_SCROLL_MASK);
gtk_widget_show(subrxFrequencyDisplay);
#ifdef NETBOOK
gtk_table_attach_defaults(GTK_TABLE(subrxTable),subrxFrequencyDisplay,5,9,0,1);
#else
gtk_table_attach_defaults(GTK_TABLE(subrxTable),subrxFrequencyDisplay,1,8,0,1);
#endif
subrxEnabled = gtk_button_new_with_label ("SubRX");
gtk_widget_modify_bg(subrxEnabled, GTK_STATE_NORMAL, &buttonBackground);
label=gtk_bin_get_child((GtkBin*)subrxEnabled);
if(subrx) {
gtk_widget_modify_fg(label, GTK_STATE_NORMAL, &buttonSelected);
gtk_widget_modify_fg(label, GTK_STATE_PRELIGHT, &buttonSelected);
} else {
gtk_widget_modify_fg(label, GTK_STATE_NORMAL, &white);
gtk_widget_modify_fg(label, GTK_STATE_PRELIGHT, &black);
}
gtk_widget_set_size_request(GTK_WIDGET(subrxEnabled),BUTTON_WIDTH,BUTTON_HEIGHT);
g_signal_connect(G_OBJECT(subrxEnabled),"clicked",G_CALLBACK(subrxEnabledButtonCallback),NULL);
gtk_widget_show(subrxEnabled);
gtk_table_attach_defaults(GTK_TABLE(subrxTable),subrxEnabled,0,1,0,1);
// subrx gain
subrxGainFrame=gtk_frame_new("AF Gain");
gtk_widget_modify_bg(subrxGainFrame,GTK_STATE_NORMAL,&background);
gtk_widget_modify_fg(gtk_frame_get_label_widget(GTK_FRAME(subrxGainFrame)),GTK_STATE_NORMAL,&white);
subrxGainScale=gtk_hscale_new_with_range(0.0,100.0,10.0);
g_signal_connect(G_OBJECT(subrxGainScale),"value-changed",G_CALLBACK(subrxGainChanged),NULL);
gtk_range_set_value((GtkRange*)subrxGainScale,subrxGain);
#ifdef NETBOOK
gtk_widget_set_size_request(GTK_WIDGET(subrxGainScale),80,37);
#else
gtk_widget_set_size_request(GTK_WIDGET(subrxGainScale),150,30);
#endif
gtk_widget_show(subrxGainScale);
gtk_container_add(GTK_CONTAINER(subrxGainFrame),subrxGainScale);
gtk_widget_show(subrxGainFrame);
#ifdef NETBOOK
gtk_table_attach_defaults(GTK_TABLE(subrxTable),subrxGainFrame,1,3,0,1);
#else
gtk_table_attach_defaults(GTK_TABLE(subrxTable),subrxGainFrame,0,4,1,2);
#endif
// subrx pan
subrxPanFrame=gtk_frame_new("AF Pan");
gtk_widget_modify_bg(subrxPanFrame,GTK_STATE_NORMAL,&background);
gtk_widget_modify_fg(gtk_frame_get_label_widget(GTK_FRAME(subrxPanFrame)),GTK_STATE_NORMAL,&white);
subrxPanScale=gtk_hscale_new_with_range(0.0,1.0,0.1);
g_signal_connect(G_OBJECT(subrxPanScale),"value-changed",G_CALLBACK(subrxPanChanged),NULL);
gtk_range_set_value((GtkRange*)subrxPanScale,subrxPan);
#ifdef NETBOOK
gtk_widget_set_size_request(GTK_WIDGET(subrxPanScale),80,37);
#else
gtk_widget_set_size_request(GTK_WIDGET(subrxPanScale),150,30);
#endif
gtk_widget_show(subrxPanScale);
gtk_container_add(GTK_CONTAINER(subrxPanFrame),subrxPanScale);
gtk_widget_show(subrxPanFrame);
#ifdef NETBOOK
gtk_table_attach_defaults(GTK_TABLE(subrxTable),subrxPanFrame,3,5,0,1);
#else
gtk_table_attach_defaults(GTK_TABLE(subrxTable),subrxPanFrame,4,8,1,2);
#endif
if(running) {
SetRXAPanelPan(CHANNEL_SUBRX, 1.0-subrxPan);
}
gtk_container_add(GTK_CONTAINER(subrxFrame),subrxTable);
gtk_widget_show(subrxTable);
gtk_widget_show(subrxFrame);
return subrxFrame;
}
/* --------------------------------------------------------------------------*/
/**
* @brief Set the subrx frequency
*
* @param f
*/
void setSubrxFrequency(long long f) {
long long diff;
if(subrx) {
if((f>=(frequencyA-(sampleRate/2))) && (f<=(frequencyA+(sampleRate/2)))) {
subrxFrequency=f;
}
subrxFrequencyDsp=0;
subrxFrequencyDds=0;
subrxFrequency=f;
subrxFrequencyDds=f-subrxFrequencyLO;
updateSubrxDisplay();
diff=subrxFrequency-frequencyA;
if(running) {
SetRXAShiftFreq(CHANNEL_SUBRX,(double)diff);
}
}
}
/* --------------------------------------------------------------------------*/
/**
* @brief Increment the frequency
*
* @param increment
*/
void subrxIncrementFrequency(long increment,gboolean round) {
long long f=subrxFrequency+(long long)increment;
if(round) {
f=(f/(long long)frequencyIncrement)*(long long)frequencyIncrement;
}
if((f>=(frequencyA-(sampleRate/2)))&& (f<=(frequencyA+(sampleRate/2)))) {
setSubrxFrequency(f);
}
}
/* --------------------------------------------------------------------------*/
/**
* @brief Save the sub rx state
*/
void subrxSaveState() {
char string[128];
sprintf(string,"%d",subrx);
setProperty("subrx",string);
sprintf(string,"%f",subrxGain);
setProperty("subrxGain",string);
sprintf(string,"%f",subrxPan);
setProperty("subrxPan",string);
sprintf(string,"%lld",subrxFrequency);
setProperty("subrxFrequency",string);
}
/* --------------------------------------------------------------------------*/
/**
* @brief Restore the sub rx state
*/
void subrxRestoreState() {
char* value;
value=getProperty("subrxGain");
if(value) subrxGain=atof(value); else subrxGain=10.0f;
value=getProperty("subrxPan");
if(value) subrxPan=atof(value); else subrxPan=50.0f;
value=getProperty("subrx");
if(value) subrx=atoi(value); else subrx=0;
value=getProperty("subrxFrequency");
if(value) subrxFrequency=atol(value); else subrxFrequency=7051000;
if(running) {
SetRXAPanelPan(CHANNEL_SUBRX, 1.0-subrxPan);
}
}
void resetSubRx() {
if(subrx) {
subrxEnabledButtonCallback(subrxEnabled,NULL);
}
}