]> git.rkrishnan.org Git - pihpsdr.git/commitdiff
Added VOX legend to VFO. Added green/red indicator to vox_menu to show when vox would...
authorJohn Melton - G0ORX/N6LYT <john.d.melton@googlemail.com>
Thu, 16 Feb 2017 13:19:27 +0000 (13:19 +0000)
committerJohn Melton - G0ORX/N6LYT <john.d.melton@googlemail.com>
Thu, 16 Feb 2017 13:19:27 +0000 (13:19 +0000)
Makefile
led.c [new file with mode: 0644]
led.h [new file with mode: 0644]
lime_protocol.c
radio.c
toolbar.c
vfo.c
vox.c
vox_menu.c

index de84be5e3aa8d4a77c6510ba96ba1a45821fd5df..736b0a435bb5a3d2a67049f12c8c03fbf80f27ba 100644 (file)
--- 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 (file)
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 <gtk/gtk.h>
+
+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 (file)
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);
index c0c34e1532974cbdcd5fff1bbe8a8c439faa1502..07ae695326d84f771c50fcd9854d95847355252a 100644 (file)
@@ -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 e4a55d560e14e16749ed89ad4cdeb2dcb29797b0..851ddc7c83da9d5f075d9b1daec77351aaa663ad 100644 (file)
--- 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;i<MAX_VFOS;i++) {
-  fprintf(stderr,"start_radio: vfo %d band=%d bandstack=%d frequency=%lld mode=%d filter=%d rit=%lld lo=%%ld offset=%lld\n",
+  fprintf(stderr,"start_radio: vfo %d band=%d bandstack=%d frequency=%lld mode=%d filter=%d rit=%lld lo=%lld offset=%lld\n",
     i,
     vfo[i].band,
     vfo[i].bandstack,
@@ -550,6 +550,7 @@ void radio_change_sample_rate(int rate) {
       break;
 #ifdef LIMESDR
     case LIMESDR_PROTOCOL:
+      lime_protocol_change_sample_rate(rate);
       break;
 #endif
   }
index 27019901b36f4b59cd9e922ccbc62596794a36c7..69fab0ec6b9646dc84bf5edbae4ab5e92613dae4 100644 (file)
--- a/toolbar.c
+++ b/toolbar.c
@@ -227,7 +227,7 @@ static void mem_cb(GtkWidget *widget, gpointer data) {
 }
 
 static void vox_cb(GtkWidget *widget, gpointer data) {
-  vox=vox==1?0:1;
+  vox_enabled=vox_enabled==1?0:1;
   vfo_update(NULL);
 }
 
diff --git a/vfo.c b/vfo.c
index 512c30807afc1a99fcd498da83714cb97b1d3bba..b5752d834426c22979e49efb925617951636742e 100644 (file)
--- a/vfo.c
+++ b/vfo.c
@@ -634,7 +634,15 @@ int vfo_update(void *data) {
         cairo_set_font_size(cr, 12);
         cairo_show_text(cr, temp_text);
 
-        cairo_move_to(cr, 210, 15);  
+        cairo_move_to(cr, 190, 15);  
+        if(vox_enabled) {
+          cairo_set_source_rgb(cr, 1, 0, 0);
+        } else {
+          cairo_set_source_rgb(cr, 0.7, 0.7, 0.7);
+        }
+        cairo_show_text(cr, "VOX");
+        
+        cairo_move_to(cr, 220, 15);  
         if(locked) {
           cairo_set_source_rgb(cr, 1, 0, 0);
         } else {
diff --git a/vox.c b/vox.c
index 287b1cde01304bdd3284764e48d90d5a9b90bf4e..cfeb6b7ed6bbee0200dfc89c2c0e01078a33b322 100644 (file)
--- a/vox.c
+++ b/vox.c
@@ -29,6 +29,7 @@ static guint vox_timeout;
 static double peak=0.0;
 
 static int vox_timeout_cb(gpointer data) {
+fprintf(stderr,"vox timeout\n");
   setVox(0);
   g_idle_add(vfo_update,NULL);
   return FALSE;
@@ -56,14 +57,10 @@ void update_vox(TRANSMITTER *tx) {
     }
   }
 
-//fprintf(stderr,"update_vox: id=%d peak=%f\n",tx->id,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 {
index 1d2d51676bb3301822e1ca080989e77b7b707c78..8c1a54c487b218c293ed58e83a057c90537a2975 100644 (file)
@@ -23,6 +23,7 @@
 #include <string.h>
 #include <pthread.h>
 
+#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);