]> git.rkrishnan.org Git - pihpsdr.git/commitdiff
Some more corrections involved in CTUN toggling
authorc vw <dl1ycf@darc.de>
Thu, 8 Dec 2022 18:21:52 +0000 (19:21 +0100)
committerc vw <dl1ycf@darc.de>
Thu, 8 Dec 2022 18:21:52 +0000 (19:21 +0100)
actions.c
radio.c
store.c

index 8dfe0136baddcc6bc10fe71926905f0eaf2b7fed..322a49454bc9e794c576748787e81ea038d6b5e9 100644 (file)
--- a/actions.c
+++ b/actions.c
@@ -566,9 +566,14 @@ int process_action(void *data) {
       if(a->mode==PRESSED) {
         vfo[active_receiver->id].ctun=!vfo[active_receiver->id].ctun;
         if(!vfo[active_receiver->id].ctun) {
-          vfo[active_receiver->id].offset=0;
+          // when deactivating CTUN,  keep frequency
+          setFrequency(vfo[active_receiver->id].ctun_frequency);
+        } else {
+          // when activating CTUN, continue with current frequency
+          vfo[active_receiver->id].ctun_frequency=vfo[active_receiver->id].frequency;
         }
-        vfo[active_receiver->id].ctun_frequency=vfo[active_receiver->id].frequency;
+        // in either case, start with zero offset after toggling CTUN
+        vfo[active_receiver->id].offset=0;
         set_offset(receiver[active_receiver->id],vfo[active_receiver->id].offset);
         g_idle_add(ext_vfo_update, NULL);
       }
diff --git a/radio.c b/radio.c
index 3708262564f1707834daae7d5ae8281046bf9474..6c9193a5b792772e705bcc32a9446b9c35007fbb 100644 (file)
--- a/radio.c
+++ b/radio.c
@@ -1849,26 +1849,26 @@ void setFrequency(long long f) {
   int v=active_receiver->id;
   vfo[v].band=get_band_from_frequency(f);
 
-  switch(protocol) {
-    case NEW_PROTOCOL:
-    case ORIGINAL_PROTOCOL:
-#ifdef SOAPYSDR
-    case SOAPYSDR_PROTOCOL:
-#endif
-      if(vfo[v].ctun) {
-        long long minf=vfo[v].frequency-(long long)(active_receiver->sample_rate/2);
-        long long maxf=vfo[v].frequency+(long long)(active_receiver->sample_rate/2);
-        if(f<minf) f=minf;
-        if(f>maxf) f=maxf;
-        vfo[v].ctun_frequency=f;
-        vfo[v].offset=f-vfo[v].frequency;
-        set_offset(active_receiver,vfo[v].offset);
-        return;
-      } else {
-        vfo[v].frequency=f;
-      }
-      break;
+  if(vfo[v].ctun) {
+    //
+    // If new frequency is within "window", change the CTUN frequency and
+    // update the offset. If it is outside, deactivate CTUN and fall
+    // through
+    //
+    long long minf=vfo[v].frequency-(long long)(active_receiver->sample_rate/2);
+    long long maxf=vfo[v].frequency+(long long)(active_receiver->sample_rate/2);
+    if(f > minf && f < maxf) {
+      vfo[v].ctun_frequency=f;
+      vfo[v].offset=f-vfo[v].frequency;
+      set_offset(active_receiver,vfo[v].offset);
+      return;
+    }
+    vfo[v].ctun=0;
+    vfo[v].ctun_frequency=0;
+    vfo[v].offset=0;
+    set_offset(active_receiver,vfo[v].offset);
   }
+  vfo[v].frequency=f;
 
   switch(protocol) {
     case NEW_PROTOCOL:
diff --git a/store.c b/store.c
index 0c7be6faed354dffc104e0c6acbf8ca7e4ac5618..2aaae2c267a02785b151aa0eec5f8fe4222cb823 100644 (file)
--- a/store.c
+++ b/store.c
@@ -129,7 +129,11 @@ void store_memory_slot(int index) {
    //
    // Store current frequency, mode, and filter in slot #index
    //
-   mem[index].frequency = vfo[id].frequency;
+   if (vfo[id].ctun) {
+     mem[index].frequency = vfo[id].ctun_frequency;
+   } else {
+     mem[index].frequency = vfo[id].frequency;
+   }
    mem[index].mode = vfo[id].mode;
    mem[index].filter=vfo[id].filter;