From 24b5922608e6ef0bb3699bc52215815852aba7ec Mon Sep 17 00:00:00 2001 From: John Melton - G0ORX/N6LYT Date: Thu, 16 Feb 2017 13:19:27 +0000 Subject: [PATCH] Added VOX legend to VFO. Added green/red indicator to vox_menu to show when vox would be enanled. --- Makefile | 13 ++++++----- led.c | 49 ++++++++++++++++++++++++++++++++++++++++++ led.h | 22 +++++++++++++++++++ lime_protocol.c | 9 ++++++-- radio.c | 3 ++- toolbar.c | 2 +- vfo.c | 10 ++++++++- vox.c | 9 +++----- vox_menu.c | 57 +++++++++++++++++++++++++++++++++++++------------ 9 files changed, 144 insertions(+), 30 deletions(-) create mode 100644 led.c create mode 100644 led.h diff --git a/Makefile b/Makefile index de84be5..736b0a4 100644 --- a/Makefile +++ b/Makefile @@ -25,11 +25,11 @@ USBOZY_INCLUDE=USBOZY #I2C_INCLUDE=I2C #uncomment the line below for the platform being compiled on -UNAME_N=raspberrypi +#UNAME_N=raspberrypi #UNAME_N=odroid #UNAME_N=up #UNAME_N=pine64 -#UNAME_N=x86 +UNAME_N=x86 CC=gcc LINK=gcc @@ -206,7 +206,8 @@ vox.c \ update.c \ store.c \ store_menu.c \ -memory.c +memory.c \ +led.c HEADERS= \ @@ -270,7 +271,8 @@ vox.h \ update.h \ store.h \ store_menu.h \ -memory.h +memory.h \ +led.h OBJS= \ @@ -332,7 +334,8 @@ vox.o \ update.o \ store.o \ store_menu.o \ -memory.o +memory.o \ +led.o all: prebuild $(PROGRAM) $(HEADERS) $(USBOZY_HEADERS) $(LIMESDR_HEADERS) $(FREEDV_HEADERS) $(LOCALCW_HEADERS) $(I2C_HEADERS) $(GPIO_HEADERS) $(PSK_HEADERS) $(SOURCES) $(USBOZY_SOURCES) $(LIMESDR_SOURCES) $(FREEDV_SOURCES) $(I2C_SOURCES) $(GPIO_SOURCES) $(PSK_SOURCES) diff --git a/led.c b/led.c new file mode 100644 index 0000000..00d6561 --- /dev/null +++ b/led.c @@ -0,0 +1,49 @@ +/* Copyright (C) +* 2017 - 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 + +static GtkWidget *led; + +static double red=0.0; +static double green=1.0; +static double blue=0.0; + + +static gboolean draw_cb (GtkWidget *widget, cairo_t *cr, gpointer data) { + cairo_set_source_rgb(cr, red, green, blue); + cairo_paint(cr); + return FALSE; +} + +void led_set_color(double r,double g,double b) { + red=r; + green=g; + blue=b; + gtk_widget_queue_draw (led); +} + +GtkWidget *create_led(int width,int height) { + led=gtk_drawing_area_new(); + gtk_widget_set_size_request(led,width,height); + + g_signal_connect (led, "draw", G_CALLBACK (draw_cb), NULL); + + return led; +} diff --git a/led.h b/led.h new file mode 100644 index 0000000..905ef22 --- /dev/null +++ b/led.h @@ -0,0 +1,22 @@ +/* Copyright (C) +* 2017 - 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. +* +*/ + + +extern GtkWidget *create_led(int width,int height); +extern void led_set_color(double r,double g,double b); diff --git a/lime_protocol.c b/lime_protocol.c index c0c34e1..07ae695 100644 --- a/lime_protocol.c +++ b/lime_protocol.c @@ -19,6 +19,7 @@ static double bandwidth=3000000.0; +static int lime_sample_rate= static size_t receiver; static SoapySDRDevice *lime_device; static SoapySDRStream *stream; @@ -52,14 +53,15 @@ static int rate_samples; static int running; -void lime_protocol_init(int rx,int pixels) { +void lime_protocol_init(int rx,int pixels,int sample_rate) { SoapySDRKwargs args; int rc; -fprintf(stderr,"lime_protocol_init: receiver=%d pixels=%d\n",rx,pixels); +fprintf(stderr,"lime_protocol_init: receiver=%d pixels=%d sample_rate=%d\n",rx,pixels,sample_rate); receiver=(size_t)rx; display_width=pixels; + lime_sample_rate=sample_rate; outputsamples=BUFFER_SIZE/(sample_rate/48000); /* @@ -114,6 +116,9 @@ if(sample_rate==768000 && actual_rate==767999) { fprintf(stderr,"lime_protocol: forced actual_rate\n"); } +void lime_protocol_change_sample_rate(int rate) { +} + fprintf(stderr,"lime_protocol: setting bandwidth =%f\n",bandwidth); rc=SoapySDRDevice_setBandwidth(lime_device,SOAPY_SDR_RX,receiver,bandwidth); if(rc!=0) { diff --git a/radio.c b/radio.c index e4a55d5..851ddc7 100644 --- a/radio.c +++ b/radio.c @@ -504,7 +504,7 @@ fprintf(stderr,"set cursor\n"); gdk_window_set_cursor(gtk_widget_get_window(top_window),gdk_cursor_new(GDK_ARROW)); for(i=0;iid,peak); if(vox_enabled) { - double threshold=vox_threshold; - -//fprintf(stderr,"update_vox: peak=%f threshold=%f\n",peak,threshold); - - if(peak>threshold) { +fprintf(stderr,"update_vox: id=%d peak=%f threshold=%f enabled=%d\n",tx->id,peak,vox_threshold,vox_enabled); + if(peak>vox_threshold) { if(previous_vox) { g_source_remove(vox_timeout); } else { diff --git a/vox_menu.c b/vox_menu.c index 1d2d516..8c1a54c 100644 --- a/vox_menu.c +++ b/vox_menu.c @@ -23,6 +23,7 @@ #include #include +#include "led.h" #include "new_menu.h" #include "radio.h" #include "transmitter.h" @@ -35,13 +36,43 @@ static GtkWidget *dialog=NULL; static GtkWidget *level; -GThread *level_thread_id; +static GtkWidget *led; + +static GdkRGBA white={1.0,1.0,1.0,1.0}; +static GdkRGBA red={1.0,0.0,0.0,1.0}; +static GdkRGBA green={0.0,1.0,0.1,1.0}; + +static GThread *level_thread_id; static int run_level=0; static double peak=0.0; +static gint vox_timeout; +static int hold=0; + +static int vox_timeout_cb(gpointer data) { + hold=0; + return FALSE; +} static int level_update(void *data) { -//fprintf(stderr,"vox peak=%f\n",peak); + char title[16]; +fprintf(stderr,"vox peak=%f threshold=%f\n",peak,vox_threshold); gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(level),peak); + + if(peak>vox_threshold) { + // red indicator + led_set_color(1.0,0.0,0.0); // red + if(hold==0) { + hold=1; + } else { + g_source_remove(vox_timeout); + } + vox_timeout=g_timeout_add((int)vox_hang,vox_timeout_cb,NULL); + } else { + // green indicator + if(hold==0) { + led_set_color(0.0,1.0,0.0); // green + } + } return 0; } @@ -99,12 +130,7 @@ void vox_menu(GtkWidget *parent) { gtk_window_set_transient_for(GTK_WINDOW(dialog),GTK_WINDOW(parent_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); + gtk_widget_override_background_color(dialog,GTK_STATE_FLAG_NORMAL,&white); GtkWidget *content=gtk_dialog_get_content_area(GTK_DIALOG(dialog)); @@ -112,21 +138,24 @@ void vox_menu(GtkWidget *parent) { 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); + gtk_grid_set_column_homogeneous(GTK_GRID(grid),TRUE); GtkWidget *close_b=gtk_button_new_with_label("Close VOX"); g_signal_connect (close_b, "pressed", G_CALLBACK(close_cb), NULL); gtk_grid_attach(GTK_GRID(grid),close_b,0,0,1,1); + led=create_led(10,10); + gtk_grid_attach(GTK_GRID(grid),led,2,0,1,1); + GtkWidget *level_label=gtk_label_new("Mic Level:"); gtk_misc_set_alignment (GTK_MISC(level_label), 0, 0); gtk_widget_show(level_label); gtk_grid_attach(GTK_GRID(grid),level_label,0,1,1,1); level=gtk_progress_bar_new(); - gtk_widget_set_size_request (level, 300, 25); +// gtk_widget_set_size_request (level, 300, 25); gtk_widget_show(level); - gtk_grid_attach(GTK_GRID(grid),level,1,1,1,1); + gtk_grid_attach(GTK_GRID(grid),level,1,1,3,1); GtkWidget *threshold_label=gtk_label_new("VOX Threshold:"); gtk_misc_set_alignment (GTK_MISC(threshold_label), 0, 0); @@ -134,10 +163,10 @@ void vox_menu(GtkWidget *parent) { gtk_grid_attach(GTK_GRID(grid),threshold_label,0,2,1,1); GtkWidget *vox_scale=gtk_scale_new_with_range(GTK_ORIENTATION_HORIZONTAL,0.0,1000.0,1.0); - gtk_widget_set_size_request (vox_scale, 300, 25); +// gtk_widget_set_size_request (vox_scale, 300, 25); gtk_range_set_value(GTK_RANGE(vox_scale),vox_threshold*1000.0); gtk_widget_show(vox_scale); - gtk_grid_attach(GTK_GRID(grid),vox_scale,1,2,1,1); + gtk_grid_attach(GTK_GRID(grid),vox_scale,1,2,3,1); g_signal_connect(G_OBJECT(vox_scale),"value_changed",G_CALLBACK(vox_value_changed_cb),NULL); GtkWidget *hang_label=gtk_label_new("VOX Hang (ms):"); @@ -148,7 +177,7 @@ void vox_menu(GtkWidget *parent) { GtkWidget *vox_hang_scale=gtk_scale_new_with_range(GTK_ORIENTATION_HORIZONTAL,0.0,1000.0,1.0); gtk_range_set_value(GTK_RANGE(vox_hang_scale),vox_hang); gtk_widget_show(vox_hang_scale); - gtk_grid_attach(GTK_GRID(grid),vox_hang_scale,1,4,1,1); + gtk_grid_attach(GTK_GRID(grid),vox_hang_scale,1,4,3,1); g_signal_connect(G_OBJECT(vox_hang_scale),"value_changed",G_CALLBACK(vox_hang_value_changed_cb),NULL); gtk_container_add(GTK_CONTAINER(content),grid); -- 2.45.2