]> git.rkrishnan.org Git - pihpsdr.git/commitdiff
VFO step size stored "by mode", better treatment of VFO step sizes, polished
authorc vw <dl1ycf@darc.de>
Mon, 13 Sep 2021 15:29:51 +0000 (17:29 +0200)
committerc vw <dl1ycf@darc.de>
Mon, 13 Sep 2021 15:29:51 +0000 (17:29 +0200)
applying mode_settings.

actions.c
ext.c
rigctl.c
step_menu.c
vfo.c
vfo.h
vfo_menu.c

index c48ebb2034951d145c7b54bc975f26ea27744078..53f6c12d362cada9ed1a248cfc1ddcb2794b5faf 100644 (file)
--- a/actions.c
+++ b/actions.c
@@ -1159,25 +1159,19 @@ int process_action(void *data) {
       break;
     case VFO_STEP_MINUS:
       if(a->mode==PRESSED) {
-        for(i=0;i<STEPS;i++) {
-          if(steps[i]==step) break;
-        }
-        if(i>=STEPS) i=0;
+        i=vfo_get_stepindex();
         i--;
         if(i<0) i=STEPS-1;
-        step=steps[i];
+        vfo_set_stepsize(steps[i]);
         g_idle_add(ext_vfo_update, NULL);
       }
       break;
     case VFO_STEP_PLUS:
       if(a->mode==PRESSED) {
-        for(i=0;i<STEPS;i++) {
-          if(steps[i]==step) break;
-        }
-        if(i>=STEPS) i=0;
+        i=vfo_get_stepindex();
         i++;
         if(i>=STEPS) i=0;
-        step=steps[i];
+        vfo_set_stepsize(steps[i]);
         g_idle_add(ext_vfo_update, NULL);
       }
       break;
diff --git a/ext.c b/ext.c
index 3370fa8d990ab7432127bbce38703c9a72e80593..7cfa1de22212732f9fb981adf3adf33c705e17d9 100644 (file)
--- a/ext.c
+++ b/ext.c
@@ -190,26 +190,14 @@ void num_pad(int val) {
 }
 
 void update_vfo_step(int direction) {
-  int i;
-  for (i=0; i<STEPS; i++) {
-    if (steps[i] == step) break;
-  }
-  //
-  // This should not happen (step size not found). If it happens,
-  // take the seond-smallest one such that the step size remains
-  // small after changing it.
-  //
-  if (i >= STEPS) i=1;
+  int i = vfo_get_stepindex();;
 
   if (direction > 0) {
     i++;
   } else {
     i--;
   }
-  if (i >= STEPS) i=STEPS-1;
-  if (i < 0     ) i=0;
-  step=steps[i];
-
+  vfo_set_step_from_index(i);
   vfo_update();
 }
 
index f35a8c07ce64366bbc2051b525a8a988e1f83bca..227c9ce2ad12bf3d18e54f1791ca56e3a8b5e748 100644 (file)
--- a/rigctl.c
+++ b/rigctl.c
@@ -798,22 +798,12 @@ gboolean parse_extended_cmd (char *command,CLIENT *client) {
           // sets or reads the Step Size
           if(command[4]==';') {
             // read the step size
-            int i=0;
-            for(i=0;i<STEPS;i++) {
-              if(steps[i]==step) break;
-            }
-            if(i<STEPS) {
-              // send reply back
-              sprintf(reply,"ZZAC%02d;",i);
-              send_resp(client->fd,reply) ;
-            }
+            sprintf(reply,"ZZAC%02d;",vfo_get_stepindex());
+            send_resp(client->fd,reply) ;
           } else if(command[6]==';') {
             // set the step size
             int i=atoi(&command[4]) ;
-            if(i>=0 && i<STEPS) {
-              step=steps[i];
-              vfo_update();
-            }
+            vfo_set_step_from_index(i);
           } else {
           }
           break;
@@ -821,12 +811,8 @@ gboolean parse_extended_cmd (char *command,CLIENT *client) {
           // move VFO A down by selected step
           if(command[6]==';') {
             int step_index=atoi(&command[4]);
-            long long hz=0;
             if(step_index>=0 && step_index<STEPS) {
-              hz=(long long)steps[step_index];
-            }
-            if(hz!=0LL) {
-              vfo_id_move(VFO_A,-hz,FALSE);
+              vfo_id_move(VFO_A,-steps[step_index],FALSE);
             }
           } else {
           }
@@ -894,12 +880,8 @@ gboolean parse_extended_cmd (char *command,CLIENT *client) {
           // move VFO A up by selected step
           if(command[6]==';') {
             int step_index=atoi(&command[4]);
-            long long hz=0;
             if(step_index>=0 && step_index<STEPS) {
-              hz=(long long)steps[step_index];
-            }
-            if(hz!=0LL) {
-              vfo_id_move(VFO_A,hz,FALSE);
+              vfo_id_move(VFO_A,steps[step_index],FALSE);
             }
           } else {
           }
@@ -958,12 +940,8 @@ gboolean parse_extended_cmd (char *command,CLIENT *client) {
           // move VFO B down by selected step
           if(command[6]==';') {
             int step_index=atoi(&command[4]);
-            long long hz=0;
             if(step_index>=0 && step_index<STEPS) {
-              hz=(long long)steps[step_index];
-            }
-            if(hz!=0LL) {
-              vfo_id_move(VFO_B,-hz,FALSE);
+              vfo_id_move(VFO_B,-steps[step_index],FALSE);
             }
           } else {
           }
@@ -973,12 +951,8 @@ gboolean parse_extended_cmd (char *command,CLIENT *client) {
           // move VFO B up by selected step
           if(command[6]==';') {
             int step_index=atoi(&command[4]);
-            long long hz=0;
             if(step_index>=0 && step_index<STEPS) {
-              hz=(long long)steps[step_index];
-            }
-            if(hz!=0LL) {
-              vfo_id_move(VFO_B,hz,FALSE);
+              vfo_id_move(VFO_B,steps[step_index],FALSE);
             }
           } else {
           }
index 10380fb0212c2784f8f169914a9b1d49696700fe..578452b2c1f4837a03c896cb304c17383f3ba648 100644 (file)
@@ -52,8 +52,8 @@ static gboolean delete_event(GtkWidget *widget, GdkEvent *event, gpointer user_d
 
 static void step_select_cb (GtkToggleButton *widget, gpointer        data) {
   int val=GPOINTER_TO_INT(data);
-  if(gtk_toggle_button_get_active(widget) && val >= 0 && val<STEPS) {
-    step=steps[GPOINTER_TO_INT(data)];
+  if(gtk_toggle_button_get_active(widget)) {
+    vfo_set_step_from_index(val);
     g_idle_add(ext_vfo_update,NULL);
   }
 }
diff --git a/vfo.c b/vfo.c
index 8a5e6b6d556952fc5327f2feea791b3aa9961013..99fff9c2a10f9f4b4420a2f6b43c04990472b258 100644 (file)
--- a/vfo.c
+++ b/vfo.c
@@ -138,6 +138,9 @@ void modesettings_save_state() {
     sprintf(name,"modeset.%d.rxeq.3", i);
     sprintf(value,"%d", mode_settings[i].rxeq[3]);
     setProperty(name,value);
+    sprintf(name,"modeset.%d.step", i);
+    sprintf(value,"%lld", mode_settings[i].step);
+    setProperty(name,value);
   }
 }
 
@@ -146,7 +149,7 @@ void modesettings_restore_state() {
   char name[80];
   char *value;
 
-  // set some reasonable defaults for the filters
+  // set some reasonable defaults
 
   for (i=0; i<MODES; i++) {
     mode_settings[i].filter=filterF6;
@@ -166,6 +169,7 @@ void modesettings_restore_state() {
     mode_settings[i].rxeq[1]=0;
     mode_settings[i].rxeq[2]=0;
     mode_settings[i].rxeq[3]=0;
+    mode_settings[i].step=100;
 
     sprintf(name,"modeset.%d.filter",i);
     value=getProperty(name);
@@ -218,6 +222,9 @@ void modesettings_restore_state() {
     sprintf(name,"modeset.%d.rxeq.3",i);
     value=getProperty(name);
     if(value) mode_settings[i].rxeq[3]=atoi(value);
+    sprintf(name,"modeset.%d.step",i);
+    value=getProperty(name);
+    if(value) mode_settings[i].step=atoll(value);
   }
 }
 
@@ -338,9 +345,38 @@ void vfo_xvtr_changed() {
   }
 }
 
+void vfo_apply_mode_settings(int id) {
+  int m; 
+
+  m=vfo[id].mode;
+
+  vfo[id].filter      =mode_settings[m].filter;
+  active_receiver->nr =mode_settings[m].nr;
+  active_receiver->nr2=mode_settings[m].nr2;
+  active_receiver->nb =mode_settings[m].nb;
+  active_receiver->nb2=mode_settings[m].nb2;
+  active_receiver->anf=mode_settings[m].anf;
+  active_receiver->snb=mode_settings[m].snb;
+  enable_rx_equalizer =mode_settings[m].en_rxeq;
+  rx_equalizer[0]     =mode_settings[m].rxeq[0];
+  rx_equalizer[1]     =mode_settings[m].rxeq[1];
+  rx_equalizer[2]     =mode_settings[m].rxeq[2];
+  rx_equalizer[3]     =mode_settings[m].rxeq[3];
+  enable_tx_equalizer =mode_settings[m].en_txeq;
+  tx_equalizer[0]     =mode_settings[m].txeq[0];
+  tx_equalizer[1]     =mode_settings[m].txeq[1];
+  tx_equalizer[2]     =mode_settings[m].txeq[2];
+  tx_equalizer[3]     =mode_settings[m].txeq[3];
+  step                =mode_settings[m].step;
+
+  // make changes effective
+  g_idle_add(ext_update_noise, NULL);
+  g_idle_add(ext_update_eq   , NULL);
+
+}
+
 void vfo_band_changed(int id,int b) {
   BANDSTACK *bandstack;
-  int m; 
 
 #ifdef CLIENT_SERVER
   if(radio_is_remote) {
@@ -372,32 +408,7 @@ void vfo_band_changed(int id,int b) {
   vfo[id].mode=entry->mode;
   vfo[id].lo=band->frequencyLO+band->errorLO;
 
-//
-// Apply the filter/NR combination stored for this mode
-//
-  m=vfo[id].mode;
-
-  vfo[id].filter      =mode_settings[m].filter;
-  active_receiver->nr =mode_settings[m].nr;
-  active_receiver->nr2=mode_settings[m].nr2;
-  active_receiver->nb =mode_settings[m].nb;
-  active_receiver->nb2=mode_settings[m].nb2;
-  active_receiver->anf=mode_settings[m].anf;
-  active_receiver->snb=mode_settings[m].snb;
-  enable_rx_equalizer =mode_settings[m].en_rxeq;
-  rx_equalizer[0]     =mode_settings[m].rxeq[0];
-  rx_equalizer[1]     =mode_settings[m].rxeq[1];
-  rx_equalizer[2]     =mode_settings[m].rxeq[2];
-  rx_equalizer[3]     =mode_settings[m].rxeq[3];
-  enable_tx_equalizer =mode_settings[m].en_txeq;
-  tx_equalizer[0]     =mode_settings[m].txeq[0];
-  tx_equalizer[1]     =mode_settings[m].txeq[1];
-  tx_equalizer[2]     =mode_settings[m].txeq[2];
-  tx_equalizer[3]     =mode_settings[m].txeq[3];
-
-  // make changes effective
-  g_idle_add(ext_update_noise, NULL);
-  g_idle_add(ext_update_eq   , NULL);
+  vfo_apply_mode_settings(id);
 
   // turn off ctun
   vfo[id].ctun=0;
@@ -497,30 +508,8 @@ void vfo_mode_changed(int m) {
 #endif
 
   vfo[id].mode=m;
-//
-// Change to the filter/NR combination stored for this mode
-//
-  vfo[id].filter      =mode_settings[m].filter;
-  active_receiver->nr =mode_settings[m].nr;
-  active_receiver->nr2=mode_settings[m].nr2;
-  active_receiver->nb =mode_settings[m].nb;
-  active_receiver->nb2=mode_settings[m].nb2;
-  active_receiver->anf=mode_settings[m].anf;
-  active_receiver->snb=mode_settings[m].snb;
-  enable_rx_equalizer =mode_settings[m].en_rxeq;
-  rx_equalizer[0]     =mode_settings[m].rxeq[0];
-  rx_equalizer[1]     =mode_settings[m].rxeq[1];
-  rx_equalizer[2]     =mode_settings[m].rxeq[2];
-  rx_equalizer[3]     =mode_settings[m].rxeq[3];
-  enable_tx_equalizer =mode_settings[m].en_txeq;
-  tx_equalizer[0]     =mode_settings[m].txeq[0];
-  tx_equalizer[1]     =mode_settings[m].txeq[1];
-  tx_equalizer[2]     =mode_settings[m].txeq[2];
-  tx_equalizer[3]     =mode_settings[m].txeq[3];
+  vfo_apply_mode_settings(id);
 
-  // make changes effective
-  g_idle_add(ext_update_noise, NULL);
-  g_idle_add(ext_update_eq   , NULL);
   switch(id) {
     case 0:
       receiver_mode_changed(receiver[0]);
@@ -684,6 +673,50 @@ void vfo_a_swap_b() {
   g_idle_add(ext_vfo_update,NULL);
 }
 
+//
+// here we collect various functions to
+// get/set the VFO step size
+//
+
+int vfo_get_stepindex() {
+  //
+  // return index of current step size in steps[] array,
+  // or 1 if not found
+  //
+  int i;
+  for(i=0;i<STEPS;i++) {
+    if(steps[i]==step) break;
+  }
+  //
+  // If step size is not found (usually cannot happen)
+  // report second-smallest step size so that we can
+  // safely increment and decrement in the caller
+  //
+  if (i >= STEPS) i=1;
+  return i;
+}
+
+void vfo_set_step_from_index(int index) {
+  //
+  // Set VFO step size to steps[index], with range checking
+  //
+  if (index < 0)      index=0;
+  if (index >= STEPS) index = STEPS-1;
+  vfo_set_stepsize(steps[index]);
+}
+
+void vfo_set_stepsize(long long newstep) {
+  //
+  // Set current VFO step size.
+  // and store the value in mode_settings of the current mode
+  //
+  int id=active_receiver->id;
+  int m=vfo[id].mode;
+
+  step=newstep;
+  mode_settings[m].step=newstep;
+}
+
 void vfo_step(int steps) {
   int id=active_receiver->id;
   long long delta;
diff --git a/vfo.h b/vfo.h
index f380cce4089159fe42eba97915a8234a746a89dc..82b124a0030b6d76853edeff0bbd536646999eb6 100644 (file)
--- a/vfo.h
+++ b/vfo.h
@@ -67,6 +67,7 @@ struct _mode_settings {
   int en_rxeq;       // RX equalizer on/off
   int txeq[4];       // TX equalizer settings
   int rxeq[4];       // RX equalizer settings
+  long long step;    // VFO step size
 };
 
 extern struct _mode_settings mode_settings[];
@@ -81,6 +82,9 @@ extern int steps[];
 extern char *step_labels[];
 
 extern GtkWidget* vfo_init(int width,int height,GtkWidget *parent);
+extern int  vfo_get_stepindex();
+extern void vfo_set_step_from_index(int index);
+extern void vfo_set_stepsize(long long newstep);
 extern void vfo_step(int steps);
 extern void vfo_id_step(int id, int steps);
 extern void vfo_move(long long hz,int round);
index 49c4c394ece8e4fdfeb2340fd30c55161054567f..e47db55f958fa113942fe2104934935e00acfd4a 100644 (file)
@@ -187,8 +187,11 @@ static void rit_cb(GtkComboBox *widget,gpointer data) {
 }
 
 static void vfo_cb(GtkComboBox *widget,gpointer data) {
-  step=steps[gtk_combo_box_get_active(widget)];
-  g_idle_add(ext_vfo_update,NULL);
+  int i=gtk_combo_box_get_active(widget);
+  if (i >= 0 && i < STEPS) {
+    vfo_set_stepsize(steps[i]);
+    g_idle_add(ext_vfo_update,NULL);
+  }
 }
 
 #ifdef PURESIGNAL