From 6dc90e3dc292a356e70dfa28a47879b75496f41c Mon Sep 17 00:00:00 2001
From: DL1YCF <dl1ycf@darc.de>
Date: Mon, 5 Dec 2022 19:49:27 +0100
Subject: [PATCH] minor improvements (mostly comments)

---
 discovery.c | 15 ++++++++++++++-
 receiver.c  | 20 +++++++++++++++-----
 2 files changed, 29 insertions(+), 6 deletions(-)

diff --git a/discovery.c b/discovery.c
index 06926da..bf26a2e 100644
--- a/discovery.c
+++ b/discovery.c
@@ -540,7 +540,20 @@ fprintf(stderr,"%p Protocol=%d name=%s\n",d,d->protocol,d->name);
     gtk_widget_show_all(discovery_dialog);
 fprintf(stderr,"showing device dialog\n");
 
-    // autostart if one device and autostart enabled
+    //
+    // Autostart and RedPitaya radios:
+    //
+    // Autostart means that if there only one device detected, start the
+    // radio without the need to click the "Start" button.
+    //
+    // If this is the first round of a RedPitaya (STEMlab) discovery,
+    // there may be more than one SDR app on the RedPitya available
+    // from which one can choose one.
+    // With autostart, there is no choice in this case, the SDR app
+    // with highest priority is automatically chosen (and started),
+    // and then the discovery process is re-initiated for RedPitya
+    // devices only.
+    //
     g_print("%s: devices=%d autostart=%d\n",__FUNCTION__,devices,autostart);
 
     if(devices==1 && autostart) {
diff --git a/receiver.c b/receiver.c
index a50e724..8fa9175 100644
--- a/receiver.c
+++ b/receiver.c
@@ -1327,12 +1327,15 @@ void receiver_frequency_changed(RECEIVER *rx) {
 
   if(vfo[id].ctun) {
 
-    long long frequency=vfo[id].frequency;
-    long long half=(long long)rx->sample_rate/2LL;
-    long long rx_low=vfo[id].ctun_frequency+rx->filter_low;
-    long long rx_high=vfo[id].ctun_frequency+rx->filter_high;
-
     if(rx->zoom>1) {
+      //
+      // Adjust PAN if new filter width has moved out of
+      // current display range
+      //
+      long long frequency=vfo[id].frequency;
+      long long half=(long long)rx->sample_rate/2LL;
+      long long rx_low=vfo[id].ctun_frequency+rx->filter_low;
+      long long rx_high=vfo[id].ctun_frequency+rx->filter_high;
       long long min_display=frequency-half+(long long)((double)rx->pan*rx->hz_per_pixel);
       long long max_display=min_display+(long long)((double)rx->width*rx->hz_per_pixel);
       if(rx_low<=min_display) {
@@ -1346,6 +1349,10 @@ void receiver_frequency_changed(RECEIVER *rx) {
       }
     }
 
+    //
+    // The (HPSDR) frequency does not change in CTUN,
+    // so simply compute new offset and tell WDSP about it
+    //
     vfo[id].offset=vfo[id].ctun_frequency-vfo[id].frequency;
     if(vfo[id].rit_enabled) {
       vfo[id].offset+=vfo[id].rit;
@@ -1353,6 +1360,9 @@ void receiver_frequency_changed(RECEIVER *rx) {
     set_offset(rx,vfo[id].offset);
   } else {
     switch(protocol) {
+      case ORIGINAL_PROTOCOL:
+	// P1 does this automatically
+        break;
       case NEW_PROTOCOL:
         schedule_high_priority(); // send new frequency
         break;
-- 
2.45.2