From 711ed7711f5a7c1ffaea64cce89e2406062cd742 Mon Sep 17 00:00:00 2001
From: AlexandreRouma <alexandre.rouma@gmail.com>
Date: Thu, 19 Dec 2024 04:18:19 +0100
Subject: [PATCH] more work on the rigctl client update

---
 misc_modules/rigctl_client/src/main.cpp | 41 ++++++++++++++++---------
 1 file changed, 26 insertions(+), 15 deletions(-)

diff --git a/misc_modules/rigctl_client/src/main.cpp b/misc_modules/rigctl_client/src/main.cpp
index 2c58a93c..ddd1ac43 100644
--- a/misc_modules/rigctl_client/src/main.cpp
+++ b/misc_modules/rigctl_client/src/main.cpp
@@ -334,6 +334,10 @@ private:
 
             }
 
+            // Save frequencies
+            lastRigctlFreq = rigctlFreq;
+            lastCenterFreq = centerFreq;
+
             // Wait for the time interval
             std::this_thread::sleep_for(std::chrono::milliseconds(interval));
         }
@@ -341,11 +345,9 @@ private:
 
     void mirrorWorker() {
         int64_t lastRigctlFreq = -1;
-        int64_t lastCenterFreq = -1;
-        int64_t lastVFOFreq = -1;
+        int64_t lastFreq = -1;
         int64_t rigctlFreq;
-        int64_t centerFreq;
-        int64_t vfoFreq;
+        int64_t freq;
         int lastRigctlMode = -1;
         int lastVFOMode = -1;
         int rigctlMode;
@@ -357,19 +359,22 @@ private:
                 // Get the current rigctl frequency
                 rigctlFreq = (int64_t)client->getFreq();
 
-                // Get the current center frequency
-                centerFreq = (int64_t)gui::waterfall.getCenterFrequency();
-
-                // Get the current VFO frequency if there is a VFO
-                // TODO
-
                 // Get the rigctl and VFO modes
-                if (!selectedVFO.empty() && syncMode && vfoIsRadio) {
-                    // Get the current rigctl mode
-                    // rigctlMode = client->getMode();
+                if (selectedVFO.empty()) {
+                    // Get the VFO frequency
+                    // TODO
 
-                    // Get the current VFO mode
-                    core::modComManager.callInterface(selectedVFO, RADIO_IFACE_CMD_GET_MODE, NULL, &vfoMode);
+                    // Get the mode if needed
+                    if (syncMode && vfoIsRadio) {
+                        // Get the current rigctl mode
+                        // rigctlMode = client->getMode();
+
+                        // Get the current VFO mode
+                        core::modComManager.callInterface(selectedVFO, RADIO_IFACE_CMD_GET_MODE, NULL, &vfoMode);
+                    }
+                }
+                else {
+                    freq = (int64_t)gui::waterfall.getCenterFrequency();
                 }
             }
             catch (const std::exception& e) {
@@ -384,6 +389,12 @@ private:
 
             }
 
+            // Save modes and frequencies
+            lastRigctlFreq = rigctlFreq;
+            lastFreq = freq;
+            lastRigctlMode = rigctlMode;
+            lastVFOMode = vfoMode;
+
             // Wait for the time interval
             std::this_thread::sleep_for(std::chrono::milliseconds(interval));
         }