MCPcopy Create free account
hub / github.com/Hamlib/Hamlib / twiddling

Function twiddling

src/rig.c:2036–2084  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

2034// indicator is last set freq doesn't match current freq
2035// so we have to query freq every time we set freq or vfo to handle this
2036static int twiddling(RIG *rig)
2037{
2038 const struct rig_caps *caps;
2039 struct rig_state *rs = STATE(rig);
2040
2041 if (rs->twiddle_timeout == 0) { return 0; } // don't detect twiddling
2042
2043 ENTERFUNC2;
2044 caps = rig->caps;
2045
2046 if (caps->get_freq) // gotta have get_freq of course
2047 {
2048 freq_t curr_freq = 0;
2049 int retval2;
2050 int elapsed;
2051
2052 HAMLIB_TRACE;
2053 retval2 = caps->get_freq(rig, RIG_VFO_CURR, &curr_freq);
2054
2055 if (retval2 == RIG_OK && rs->current_freq != curr_freq)
2056 {
2057 rig_debug(RIG_DEBUG_TRACE,
2058 "%s: Somebody twiddling the VFO? last_freq=%.0f, curr_freq=%.0f\n", __func__,
2059 rs->current_freq, curr_freq);
2060
2061 if (rs->current_freq == 0)
2062 {
2063 rs->current_freq = curr_freq;
2064 RETURNFUNC2(0); // not twiddling as first time freq is being set
2065 }
2066
2067 rs->twiddle_time = time(NULL); // update last twiddle time
2068 rs->current_freq = curr_freq; // we have a new freq to remember
2069 rig_set_cache_freq(rig, RIG_VFO_CURR, curr_freq);
2070 }
2071
2072 elapsed = time(NULL) - rs->twiddle_time;
2073
2074 if (elapsed < rs->twiddle_timeout)
2075 {
2076 rig_debug(RIG_DEBUG_TRACE, "%s: Twiddle elapsed < %d, elapsed=%d\n", __func__,
2077 rs->twiddle_timeout, elapsed);
2078 rs->twiddle_state = TWIDDLE_ON; // gets turned off in rig_set_freq;
2079 RETURNFUNC2(1); // would be better as error but other software won't handle it
2080 }
2081 }
2082
2083 RETURNFUNC2(0);
2084}
2085
2086#include "band_changed.c"
2087

Callers 2

rig_set_freqFunction · 0.85
rig_set_vfoFunction · 0.85

Calls 2

rig_debugFunction · 0.85
rig_set_cache_freqFunction · 0.85

Tested by

no test coverage detected