]> git.rkrishnan.org Git - pihpsdr.git/commitdiff
restrict ctune to visible limits
authorRamakrishnan Muthukrishnan <ram@rkrishnan.org>
Sun, 31 Dec 2023 10:50:40 +0000 (16:20 +0530)
committerRamakrishnan Muthukrishnan <ram@rkrishnan.org>
Sun, 31 Dec 2023 10:50:40 +0000 (16:20 +0530)
Once the filter limits go beyond visible band, move the background of
the band, than the ctune frequency.

radio.c
rigctl.c
vfo.c

diff --git a/radio.c b/radio.c
index 5eceae4ac0c0bb0708af09174e5e5ef65e980df6..29c61a51b36ea790f8fdfd7ca63db1ffb51f4651 100644 (file)
--- a/radio.c
+++ b/radio.c
@@ -1566,22 +1566,24 @@ void setFrequency(long long f) {
     case NEW_PROTOCOL:
     case ORIGINAL_PROTOCOL:
         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;
+           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;
+           // XXX: handle ctune going beyond the band limits.
+           // See XXX notes in vfo.c
+           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;
     }
 
     switch (protocol) {
index e36303e74ea194be5dc47059b33bee0455bb87ce..03e6692e5f7f3580004119366336afaf70350ec2 100644 (file)
--- a/rigctl.c
+++ b/rigctl.c
@@ -1053,6 +1053,7 @@ gboolean parse_extended_cmd(char *command, CLIENT *client) {
                     hz = (long long)steps[step_index];
                 }
                 if (hz != 0LL) {
+                   log_info("rigctl: move vfo down");
                     vfo_id_move(VFO_A, -hz, FALSE);
                 }
             } else {
diff --git a/vfo.c b/vfo.c
index 59b4401eafe006639257cedc027aebd778b29d47..1dc7870ef86ec5b2959be914c846c4a8cfcbefc6 100644 (file)
--- a/vfo.c
+++ b/vfo.c
@@ -597,24 +597,29 @@ void vfo_a_swap_b() {
     g_idle_add(ext_vfo_update, NULL);
 }
 
+/* static int steps_to_freq(int steps) { */
+/*     return step * steps; */
+/* } */
+
 void vfo_step(int steps) {
-    int id = active_receiver->id;
+    return vfo_id_step(active_receiver->id, steps);
+}
+
+void vfo_id_step(int id, int steps) {
     long long delta;
     int sid;
     RECEIVER *other_receiver;
 
-#ifdef CLIENT_SERVER
-    if (radio_is_remote) {
-        update_vfo_step(id, steps);
-        return;
-    }
-#endif
-
     if (!locked) {
-
         if (vfo[id].ctun) {
             // don't let ctun go beyond end of passband
             long long frequency = vfo[id].frequency;
+            /* long long rx_low = */
+            /*     vfo[id].ctun_frequency + hz + active_receiver->filter_low; */
+           // convert frequency in terms of steps, then add the given
+           // number of steps in the argument and then convert it
+           // back to frequency.
+
             long long rx_low =
                 ((vfo[id].ctun_frequency / step + steps) * step) +
                 active_receiver->filter_low;
@@ -625,9 +630,25 @@ void vfo_step(int steps) {
             long long min_freq = frequency - half;
             long long max_freq = frequency + half;
 
+           log_info("rx_low = %ld, rx_high = %ld", rx_low, rx_high);
+           log_info("min_freq = %ld, max_freq = %ld", min_freq, max_freq);
             if (rx_low <= min_freq) {
+               // XXX handle ctune beyond the screen limits
+               long long delta_move = min_freq - rx_low;
+               vfo[id].frequency = ((vfo[id].frequency / step + steps) * step) - delta_move;
+               //vfo[id].ctun_frequency = ((vfo[id].ctun_frequency / step + steps) * step);
+               receiver_frequency_changed(receiver[id]);
+               log_info("vfo_f = %lld, ctun_f = %lld", vfo[id].frequency, vfo[id].ctun_frequency);
+               g_idle_add(ext_vfo_update, NULL);
                 return;
             } else if (rx_high >= max_freq) {
+               // XXX: move the background
+               long long delta_move = rx_high - max_freq;
+               vfo[id].frequency = ((vfo[id].frequency / step + steps) * step) - delta_move;
+               //vfo[id].ctun_frequency = (vfo[id].ctun_frequency / step + steps) * step;
+               log_info("vfo_f = %lld, ctun_f = %lld", vfo[id].frequency, vfo[id].ctun_frequency);
+               receiver_frequency_changed(receiver[id]);
+               g_idle_add(ext_vfo_update, NULL);
                 return;
             }
 
@@ -670,65 +691,14 @@ void vfo_step(int steps) {
             }
             break;
         }
+
         receiver_frequency_changed(active_receiver);
         g_idle_add(ext_vfo_update, NULL);
     }
 }
-//
-// DL1YCF: essentially a duplicate of vfo_step but
-//         changing a specific VFO freq instead of
-//         changing the VFO of the active receiver
-//
-void vfo_id_step(int id, int steps) {
-    long long delta;
-    int sid;
-    RECEIVER *other_receiver;
-
-    if (!locked) {
-        if (vfo[id].ctun) {
-            delta = vfo[id].ctun_frequency;
-            vfo[id].ctun_frequency =
-                (vfo[id].ctun_frequency / step + steps) * step;
-            delta = vfo[id].ctun_frequency - delta;
-        } else {
-            delta = vfo[id].frequency;
-            vfo[id].frequency = (vfo[id].frequency / step + steps) * step;
-            delta = vfo[id].frequency - delta;
-        }
-
-        sid = id == 0 ? 1 : 0;
-        other_receiver = receiver[sid];
-
-        switch (sat_mode) {
-        case SAT_NONE:
-            break;
-        case SAT_MODE:
-            // A and B increment and decrement together
-            if (vfo[sid].ctun) {
-                vfo[sid].ctun_frequency += delta;
-            } else {
-                vfo[sid].frequency += delta;
-            }
-            if (receivers == 2) {
-                receiver_frequency_changed(other_receiver);
-            }
-            break;
-        case RSAT_MODE:
-            // A increments and B decrements or A decrments and B increments
-            if (vfo[sid].ctun) {
-                vfo[sid].ctun_frequency -= delta;
-            } else {
-                vfo[sid].frequency -= delta;
-            }
-            if (receivers == 2) {
-                receiver_frequency_changed(other_receiver);
-            }
-            break;
-        }
 
-        receiver_frequency_changed(active_receiver);
-        g_idle_add(ext_vfo_update, NULL);
-    }
+void vfo_move(long long hz, int round) {
+    return vfo_id_move(active_receiver->id, hz, round);
 }
 
 void vfo_id_move(int id, long long hz, int round) {
@@ -746,6 +716,7 @@ void vfo_id_move(int id, long long hz, int round) {
 
     if (!locked) {
         if (vfo[id].ctun) {
+           log_trace("vfo_id_move: ctune, vfo changed");
             // don't let ctun go beyond end of passband
             long long frequency = vfo[id].frequency;
             long long rx_low =
@@ -767,6 +738,7 @@ void vfo_id_move(int id, long long hz, int round) {
                // required offset and let ctun_freq remain as it is.
                long long delta_move = min_freq - rx_low;
                vfo[id].frequency = vfo[id].frequency + hz - delta_move;
+               vfo[id].ctun_frequency = vfo[id].ctun_frequency + hz;
                receiver_frequency_changed(receiver[id]);
                g_idle_add(ext_vfo_update, NULL);
                 return;
@@ -774,6 +746,7 @@ void vfo_id_move(int id, long long hz, int round) {
                // XXX: move the background
                long long delta_move = rx_high - max_freq;
                vfo[id].frequency = vfo[id].frequency + hz - delta_move;
+               vfo[id].ctun_frequency = vfo[id].ctun_frequency + hz;
                receiver_frequency_changed(receiver[id]);
                g_idle_add(ext_vfo_update, NULL);
                 return;
@@ -828,10 +801,6 @@ void vfo_id_move(int id, long long hz, int round) {
     }
 }
 
-void vfo_move(long long hz, int round) {
-    vfo_id_move(active_receiver->id, hz, round);
-}
-
 void vfo_move_to(long long hz) {
     // hz is the offset from the min displayed frequency
     int id = active_receiver->id;
@@ -857,6 +826,7 @@ void vfo_move_to(long long hz) {
 
     if (!locked) {
         if (vfo[id].ctun) {
+           log_trace("vfo_move_to: ctune, vfo changed");
             delta = vfo[id].ctun_frequency;
             vfo[id].ctun_frequency = f;
             if (vfo[id].mode == modeCWL) {