]> git.rkrishnan.org Git - pihpsdr.git/commitdiff
Took care of RigCtlEnable/SerialEnable interplay
authorc vw <dl1ycf@darc.de>
Tue, 26 May 2020 16:31:33 +0000 (18:31 +0200)
committerc vw <dl1ycf@darc.de>
Tue, 26 May 2020 16:31:33 +0000 (18:31 +0200)
radio.c
rigctl_menu.c

diff --git a/radio.c b/radio.c
index 09dcdb913ff061cac18f885699d0d3940991ffcd..2209b81c6edb2b197a65c0d14232198c63f5da79 100644 (file)
--- a/radio.c
+++ b/radio.c
@@ -1221,6 +1221,10 @@ void start_radio() {
     if (serial_enable) {
       launch_serial();
     }
+  } else {
+    // since we do not spawn the serial thread,
+    // disable serial
+    serial_enable=0;
   }
 
   if(can_transmit) {
index 5ccf950b3fb030f11b8d011f3f64d9f94b23193e..a35d12dcbe64be8cf7464cafb57fa27b97c4341c 100644 (file)
@@ -33,6 +33,7 @@
 #include "vfo.h"
 
 int  serial_enable;
+static GtkWidget *serial_enable_b;
 char ser_port[64]="/dev/ttyACM0";
 int serial_baud_rate = B9600;
 int serial_parity = 0; // 0=none, 1=even, 2=odd
@@ -80,16 +81,33 @@ static void rigctl_enable_cb(GtkWidget *widget, gpointer data) {
   if(rigctl_enable) {
      launch_rigctl();
   } else {
+     //
+     // If serial server is running, terminate it.
+     // Disable serial and clear check-box
+     //
+     if (serial_enable) {
+       disable_serial();
+     }
+     serial_enable=0;
+     gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON(serial_enable_b),0);
      disable_rigctl();
   }
 }
 
 static void serial_enable_cb(GtkWidget *widget, gpointer data) {
+  //
+  // If rigctl is not running, serial cannot be enabled
+  //
+  if (!rigctl_enable) {
+    serial_enable=0;
+    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget),0);
+    return;
+  }
   strcpy(ser_port,gtk_entry_get_text(GTK_ENTRY(serial_port_entry)));
   serial_enable=gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
   if(serial_enable) {
      if(launch_serial() == 0) {
-        gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON(widget),FALSE)      ;
+        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget),FALSE)       ;
      }       
   } else {
      disable_serial();
@@ -98,8 +116,12 @@ static void serial_enable_cb(GtkWidget *widget, gpointer data) {
 
 // Set Baud Rate
 static void baud_rate_cb(GtkWidget *widget, gpointer data) {
-   serial_baud_rate = GPOINTER_TO_INT(data);
-   fprintf(stderr,"RIGCTL_MENU: Baud rate changed: %d\n",serial_baud_rate);
+   int active=gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
+   fprintf(stderr,"ACTIVE=%d BAUD=%d\n", active, GPOINTER_TO_INT(data));
+   if (active) {
+     serial_baud_rate = GPOINTER_TO_INT(data);
+     fprintf(stderr,"RIGCTL_MENU: Baud rate changed: %d\n",serial_baud_rate);
+   }
 }
 
 // Set Parity 0=None, 1=Even, 2=0dd
@@ -163,7 +185,7 @@ void rigctl_menu(GtkWidget *parent) {
   g_signal_connect(rigctl_port_spinner,"value_changed",G_CALLBACK(rigctl_value_changed_cb),NULL);
 
   /* Put the Serial Port stuff here */
-  GtkWidget *serial_enable_b=gtk_check_button_new_with_label("Serial Port Enable");
+             serial_enable_b=gtk_check_button_new_with_label("Serial Port Enable");
   gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (serial_enable_b), serial_enable);
   gtk_widget_show(serial_enable_b);
   gtk_grid_attach(GTK_GRID(grid),serial_enable_b,0,3,1,1);