From 95986b9685a5e0ac7d49f3b39e3a5d30254ac0ab Mon Sep 17 00:00:00 2001 From: Michael Black Date: Sun, 23 Feb 2020 08:28:19 -0600 Subject: [PATCH] Add detection of VFO twiddling In the case of gpredict there are times when one has to adjust the VFO to dial in a frequency while gpredict is tracking. We now detect this situation and have a 3-second delay every time VFO twiddling is detected. set_freq and set_vfo calls will be ignored during this delay. May make this a settable value if needed. --- include/hamlib/rig.h | 5 +++-- src/rig.c | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/include/hamlib/rig.h b/include/hamlib/rig.h index a67de4930..a3c321bad 100644 --- a/include/hamlib/rig.h +++ b/include/hamlib/rig.h @@ -27,6 +27,7 @@ #include #include #include +#include /* Rig list is in a separate file so as not to mess up w/ this one */ #include @@ -1784,8 +1785,8 @@ struct rig_state { int transmit; /*!< rig should be transmitting i.e. hard wired PTT asserted - used by rigs that don't do CAT while in Tx */ - freq_t lo_freq; /*!< Local oscillator frequency of any - transverter */ + freq_t lo_freq; /*!< Local oscillator frequency of any transverter */ + time_t twiddling; /*!< time when vfo twiddling was detected */ }; diff --git a/src/rig.c b/src/rig.c index b7683f94d..e20cacbc3 100644 --- a/src/rig.c +++ b/src/rig.c @@ -1042,6 +1042,34 @@ int HAMLIB_API rig_cleanup(RIG *rig) } +// detect if somebody is twiddling the VFO +// indicator is last set freq doesn't match current freq +// so we have to query freq every time we set freq or vfo to handle this +static int twiddling(RIG *rig) +{ + const struct rig_caps *caps; + + caps = rig->caps; + + if ( caps->get_freq) { // gotta have get_freq of course + freq_t curr_freq = 0; + int retval2; + int elapsed; + + retval2 = caps->get_freq(rig, RIG_VFO_CURR, &curr_freq); + if (retval2 == RIG_OK && rig->state.current_freq != curr_freq) { + rig_debug(RIG_DEBUG_TRACE,"%s: Somebody twiddling the VFO? last_freq=%.0f, curr_freq=%.0f\n", __func__, rig->state.current_freq, curr_freq); + rig->state.twiddling = time(NULL); // update last twiddle time + } + elapsed = time(NULL) - rig->state.twiddling; + if (elapsed < 3) { + rig_debug(RIG_DEBUG_TRACE,"%s: Twiddle elapsed < 3, elapsed=%d\n", __func__, elapsed); + return 1; // would be better as error but other software won't handle it + } + } + return 0; // +} + /** * \brief set the frequency of the target VFO * \param rig The rig handle @@ -1108,6 +1136,11 @@ int HAMLIB_API rig_set_freq(RIG *rig, vfo_t vfo, freq_t freq) return retcode; } + if (twiddling(rig)) { + rig_debug(RIG_DEBUG_TRACE,"%s: Ignoring set_freq due to VFO twiddling\n", __func__); + return RIG_OK; // would be better as error but other software won't handle errors + } + retcode = caps->set_freq(rig, vfo, freq); /* try and revert even if we had an error above */ rc2 = caps->set_vfo(rig, curr_vfo); @@ -1571,6 +1604,11 @@ int HAMLIB_API rig_set_vfo(RIG *rig, vfo_t vfo) return -RIG_ENAVAIL; } + if (twiddling(rig)) { + rig_debug(RIG_DEBUG_TRACE,"%s: Ignoring set_vfo due to VFO twiddling\n", __func__); + return RIG_OK; // would be better as error but other software won't handle errors + } + retcode = caps->set_vfo(rig, vfo); if (retcode == RIG_OK)