MCPcopy Create free account
hub / github.com/cjcliffe/CubicSDR / StepTuner

Method StepTuner

src/visual/TuningCanvas.cpp:173–270  ·  view source on GitHub ↗

* Perform tuner step * * @param state Current hover state * @param digit Digit position * @param tuningDir Tuning direction, true for up * @param preventCarry Prevent carry operation on digit overflow * @param zeroOut Zero out 'digit' and lower digits */

Source from the content-addressed store, hash-verified

171 * @param zeroOut Zero out 'digit' and lower digits
172 */
173void TuningCanvas::StepTuner(ActiveState state, TuningDirection tuningDir, int digit, bool preventCarry, bool zeroOut) {
174 double exp = pow(10, digit);
175 long long amount = tuningDir ? exp : -exp;
176
177 if (halfBand && state == TUNING_HOVER_BW) {
178 amount *= 2;
179 }
180
181 auto activeDemod = wxGetApp().getDemodMgr().getCurrentModem();
182 if (state == TUNING_HOVER_FREQ && activeDemod) {
183 long long demod_freq = activeDemod->getFrequency();
184 long long diff = abs(wxGetApp().getFrequency() - demod_freq);
185
186 if (zeroOut) { // Zero digits to right
187 double intpart;
188 modf(demod_freq / (exp * 10), &intpart);
189 demod_freq = intpart * exp * 10;
190 } else if (preventCarry) { // Prevent digit from carrying
191 bool carried = (long long)((demod_freq) / (exp * 10)) != (long long)((demod_freq + amount) / (exp * 10)) || (bottom && demod_freq < exp);
192 demod_freq += carried ? (9 * -amount) : amount;
193 } else {
194 demod_freq += amount;
195 }
196
197 if (wxGetApp().getSampleRate() / 2 < diff) {
198 wxGetApp().setFrequency(demod_freq);
199 }
200
201 activeDemod->setTracking(true);
202 activeDemod->setFollow(true);
203 activeDemod->setFrequency(demod_freq);
204 if (activeDemod->isDeltaLock()) {
205 activeDemod->setDeltaLockOfs(activeDemod->getFrequency() - wxGetApp().getFrequency());
206 }
207 activeDemod->updateLabel(demod_freq);
208 }
209
210 if (state == TUNING_HOVER_BW) {
211 long nbw = wxGetApp().getDemodMgr().getLastBandwidth();
212
213 if (zeroOut) { // Zero digits to right
214 double intpart;
215 modf(nbw / (exp * 10), &intpart);
216 nbw = intpart * exp * 10;
217 } else if (preventCarry) { // Prevent digit from carrying
218 bool carried = (long)((nbw) / (exp * 10)) != (long)((nbw + amount) / (exp * 10)) || (bottom && nbw < exp);
219 nbw += carried ? (9 * -amount) : amount;
220 } else {
221 nbw += amount;
222 }
223
224 if (nbw > CHANNELIZER_RATE_MAX) {
225 nbw = CHANNELIZER_RATE_MAX;
226 }
227
228 wxGetApp().getDemodMgr().setLastBandwidth(nbw);
229
230 if (activeDemod) {

Callers

nothing calls this directly

Calls 14

getCurrentModemMethod · 0.80
setTrackingMethod · 0.80
setFollowMethod · 0.80
isDeltaLockMethod · 0.80
setDeltaLockOfsMethod · 0.80
updateLabelMethod · 0.80
getLastBandwidthMethod · 0.80
setLastBandwidthMethod · 0.80
getFrequencyMethod · 0.45
getSampleRateMethod · 0.45
setFrequencyMethod · 0.45

Tested by

no test coverage detected