From 94ca0bbe54bb06c0151ccc32fe8c20033d96d10f Mon Sep 17 00:00:00 2001 From: "Charles J. Cliffe" Date: Mon, 20 Jul 2020 01:01:28 -0400 Subject: [PATCH 1/4] Update to use SoapySDR frequency correction instead of RTL-SDR specific --- src/sdr/SDRDeviceInfo.cpp | 6 ++++++ src/sdr/SoapySDRThread.cpp | 12 ++++++++++-- src/visual/TuningCanvas.cpp | 26 +++++++++++++++++++------- 3 files changed, 35 insertions(+), 9 deletions(-) diff --git a/src/sdr/SDRDeviceInfo.cpp b/src/sdr/SDRDeviceInfo.cpp index 2dbaf03..677a8c9 100644 --- a/src/sdr/SDRDeviceInfo.cpp +++ b/src/sdr/SDRDeviceInfo.cpp @@ -168,6 +168,12 @@ SoapySDR::Device *SDRDeviceInfo::getSoapyDevice() { return soapyDevice; } +/** + * @deprecated + * @param direction + * @param channel + * @return + */ bool SDRDeviceInfo::hasCORR(int direction, size_t channel) { SoapySDR::Device *dev = getSoapyDevice(); diff --git a/src/sdr/SoapySDRThread.cpp b/src/sdr/SoapySDRThread.cpp index e8e476f..2143bf0 100644 --- a/src/sdr/SoapySDRThread.cpp +++ b/src/sdr/SoapySDRThread.cpp @@ -111,12 +111,16 @@ bool SDRThread::init() { //4. Apply other settings: Frequency, PPM correction, Gains, Device-specific settings: device->setFrequency(SOAPY_SDR_RX,0,"RF",frequency - offset.load()); - if (devInfo->hasCORR(SOAPY_SDR_RX, 0)) { + if (device->hasFrequencyCorrection(SOAPY_SDR_RX, 0)) { + hasPPM.store(true); + device->setFrequencyCorrection(SOAPY_SDR_RX, 0, ppm.load()); + } else if (devInfo->hasCORR(SOAPY_SDR_RX, 0)) { hasPPM.store(true); device->setFrequency(SOAPY_SDR_RX,0,"CORR",ppm.load()); } else { hasPPM.store(false); } + if (device->hasDCOffsetMode(SOAPY_SDR_RX, 0)) { hasHardwareDC.store(true); // wxGetApp().sdrEnumThreadNotify(SDREnumerator::SDR_ENUM_MESSAGE, std::string("Found hardware DC offset correction support, internal disabled.")); @@ -518,7 +522,11 @@ void SDRThread::updateSettings() { } if (ppm_changed.load() && hasPPM.load()) { - device->setFrequency(SOAPY_SDR_RX,0,"CORR",ppm.load()); + if (device->hasFrequencyCorrection(SOAPY_SDR_RX, 0)) { + device->setFrequencyCorrection(SOAPY_SDR_RX, 0, ppm.load()); + } else { + device->setFrequency(SOAPY_SDR_RX, 0, "CORR", ppm.load()); + } ppm_changed.store(false); } diff --git a/src/visual/TuningCanvas.cpp b/src/visual/TuningCanvas.cpp index 1fef0fc..eb370bf 100644 --- a/src/visual/TuningCanvas.cpp +++ b/src/visual/TuningCanvas.cpp @@ -176,7 +176,11 @@ void TuningCanvas::StepTuner(ActiveState state, int exponent, bool up) { long long freq = activeDemod->getFrequency(); long long diff = abs(wxGetApp().getFrequency() - freq); - if (shiftDown) { + if (ctrlDown) { // Zero digits to right + double intpart; + modf(freq / (exp * 10), &intpart); + freq = intpart * exp * 10; + } else if (shiftDown) { // Prevent digit from carrying bool carried = (long long)((freq) / (exp * 10)) != (long long)((freq + amount) / (exp * 10)) || (bottom && freq < exp); freq += carried?(9*-amount):amount; } else { @@ -199,7 +203,11 @@ void TuningCanvas::StepTuner(ActiveState state, int exponent, bool up) { if (state == TUNING_HOVER_BW) { long bw = wxGetApp().getDemodMgr().getLastBandwidth(); - if (shiftDown) { + if (ctrlDown) { // Zero digits to right + double intpart; + modf(bw / (exp * 10), &intpart); + bw = intpart * exp * 10; + } else if (shiftDown) { // Prevent digit from carrying bool carried = (long)((bw) / (exp * 10)) != (long)((bw + amount) / (exp * 10)) || (bottom && bw < exp); bw += carried?(9*-amount):amount; } else { @@ -219,7 +227,11 @@ void TuningCanvas::StepTuner(ActiveState state, int exponent, bool up) { if (state == TUNING_HOVER_CENTER) { long long ctr = wxGetApp().getFrequency(); - if (shiftDown) { + if (ctrlDown) { // Zero digits to right + double intpart; + modf(ctr / (exp * 10), &intpart); + ctr = intpart * exp * 10; + } else if (shiftDown) { // Prevent digit from carrying bool carried = (long long)((ctr) / (exp * 10)) != (long long)((ctr + amount) / (exp * 10)) || (bottom && ctr < exp); ctr += carried?(9*-amount):amount; } else { @@ -310,16 +322,16 @@ void TuningCanvas::OnMouseMoved(wxMouseEvent& event) { } else { switch (hoverState) { case TUNING_HOVER_FREQ: - setStatusText("Click, wheel or drag a digit to change frequency; SPACE or numeric key for direct input. Right click to set/clear snap. Hold ALT to change PPM. Hold SHIFT to disable carry."); + setStatusText("Click, wheel or drag(left/right) a digit to change frequency; SPACE or numeric key for direct input. Right click to set/clear snap. Hold ALT to change PPM. Hold SHIFT to disable carry. Hold CTRL to Zero Right."); break; case TUNING_HOVER_BW: - setStatusText("Click, wheel or drag a digit to change bandwidth; SPACE or numeric key for direct input. Hold SHIFT to disable carry."); + setStatusText("Click, wheel or drag(left/right) a digit to change bandwidth; SPACE or numeric key for direct input. Hold SHIFT to disable carry. Hold CTRL to Zero Right."); break; case TUNING_HOVER_CENTER: - setStatusText("Click, wheel or drag a digit to change center frequency; SPACE or numeric key for direct input. Hold SHIFT to disable carry."); + setStatusText("Click, wheel or drag(left/right) a digit to change center frequency; SPACE or numeric key for direct input. Hold SHIFT to disable carry. Hold CTRL to Zero Right."); break; case TUNING_HOVER_PPM: - setStatusText("Click, wheel or drag a digit to change device PPM offset. Hold SHIFT to disable carry."); + setStatusText("Click, wheel or drag(left/right) a digit to change device PPM offset. Hold SHIFT to disable carry."); break; case TUNING_HOVER_NONE: setStatusText(""); From 63631cd255cd227687c1afc7b29535e00157e24a Mon Sep 17 00:00:00 2001 From: "Charles J. Cliffe" Date: Tue, 28 Jul 2020 23:24:00 -0400 Subject: [PATCH 2/4] Use shift-right click for zero-right instead, additional cleanup --- src/visual/TuningCanvas.cpp | 58 +++++++++++++++++++++++++------------ src/visual/TuningCanvas.h | 5 +++- 2 files changed, 43 insertions(+), 20 deletions(-) diff --git a/src/visual/TuningCanvas.cpp b/src/visual/TuningCanvas.cpp index eb370bf..476f04f 100644 --- a/src/visual/TuningCanvas.cpp +++ b/src/visual/TuningCanvas.cpp @@ -163,9 +163,18 @@ void TuningCanvas::OnPaint(wxPaintEvent& WXUNUSED(event)) { SwapBuffers(); } -void TuningCanvas::StepTuner(ActiveState state, int exponent, bool up) { - double exp = pow(10, exponent); - long long amount = up?exp:-exp; +/*** + * 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 + */ +void TuningCanvas::StepTuner(ActiveState state, TuningDirection tuningDir, int digit, bool preventCarry, bool zeroOut) { + double exp = pow(10, digit); + long long amount = tuningDir ? exp : -exp; if (halfBand && state == TUNING_HOVER_BW) { amount *= 2; @@ -176,11 +185,11 @@ void TuningCanvas::StepTuner(ActiveState state, int exponent, bool up) { long long freq = activeDemod->getFrequency(); long long diff = abs(wxGetApp().getFrequency() - freq); - if (ctrlDown) { // Zero digits to right + if (zeroOut) { // Zero digits to right double intpart; modf(freq / (exp * 10), &intpart); freq = intpart * exp * 10; - } else if (shiftDown) { // Prevent digit from carrying + } else if (preventCarry) { // Prevent digit from carrying bool carried = (long long)((freq) / (exp * 10)) != (long long)((freq + amount) / (exp * 10)) || (bottom && freq < exp); freq += carried?(9*-amount):amount; } else { @@ -203,11 +212,11 @@ void TuningCanvas::StepTuner(ActiveState state, int exponent, bool up) { if (state == TUNING_HOVER_BW) { long bw = wxGetApp().getDemodMgr().getLastBandwidth(); - if (ctrlDown) { // Zero digits to right + if (zeroOut) { // Zero digits to right double intpart; modf(bw / (exp * 10), &intpart); bw = intpart * exp * 10; - } else if (shiftDown) { // Prevent digit from carrying + } else if (preventCarry) { // Prevent digit from carrying bool carried = (long)((bw) / (exp * 10)) != (long)((bw + amount) / (exp * 10)) || (bottom && bw < exp); bw += carried?(9*-amount):amount; } else { @@ -227,11 +236,11 @@ void TuningCanvas::StepTuner(ActiveState state, int exponent, bool up) { if (state == TUNING_HOVER_CENTER) { long long ctr = wxGetApp().getFrequency(); - if (ctrlDown) { // Zero digits to right + if (zeroOut) { // Zero digits to right double intpart; modf(ctr / (exp * 10), &intpart); ctr = intpart * exp * 10; - } else if (shiftDown) { // Prevent digit from carrying + } else if (preventCarry) { // Prevent digit from carrying bool carried = (long long)((ctr) / (exp * 10)) != (long long)((ctr + amount) / (exp * 10)) || (bottom && ctr < exp); ctr += carried?(9*-amount):amount; } else { @@ -242,7 +251,7 @@ void TuningCanvas::StepTuner(ActiveState state, int exponent, bool up) { } if (state == TUNING_HOVER_PPM) { - if (shiftDown) { + if (preventCarry) { bool carried = (long long)((currentPPM) / (exp * 10)) != (long long)((currentPPM + amount) / (exp * 10)) || (bottom && currentPPM < exp); currentPPM += carried?(9*-amount):amount; } else { @@ -267,12 +276,12 @@ void TuningCanvas::OnIdle(wxIdleEvent & /* event */) { if (downState != TUNING_HOVER_NONE) { dragAccum += 5.0*mouseTracker.getOriginDeltaMouseX(); while (dragAccum > 1.0) { - StepTuner(downState, downIndex-1, true); + StepTuner(downState, TUNING_DIRECTION_UP, downIndex - 1, shiftDown, false); dragAccum -= 1.0; dragging = true; } while (dragAccum < -1.0) { - StepTuner(downState, downIndex-1, false); + StepTuner(downState, TUNING_DIRECTION_DOWN, downIndex - 1, shiftDown, false); dragAccum += 1.0; dragging = true; } @@ -322,13 +331,13 @@ void TuningCanvas::OnMouseMoved(wxMouseEvent& event) { } else { switch (hoverState) { case TUNING_HOVER_FREQ: - setStatusText("Click, wheel or drag(left/right) a digit to change frequency; SPACE or numeric key for direct input. Right click to set/clear snap. Hold ALT to change PPM. Hold SHIFT to disable carry. Hold CTRL to Zero Right."); + setStatusText("Click, wheel or drag(left/right) a digit to change frequency; SPACE or numeric key for direct input. Right click to set/clear snap. Hold ALT to change PPM. Hold SHIFT to disable carry. SHIFT-right click to Zero Right."); break; case TUNING_HOVER_BW: - setStatusText("Click, wheel or drag(left/right) a digit to change bandwidth; SPACE or numeric key for direct input. Hold SHIFT to disable carry. Hold CTRL to Zero Right."); + setStatusText("Click, wheel or drag(left/right) a digit to change bandwidth; SPACE or numeric key for direct input. Hold SHIFT to disable carry. SHIFT-right click to Zero Right."); break; case TUNING_HOVER_CENTER: - setStatusText("Click, wheel or drag(left/right) a digit to change center frequency; SPACE or numeric key for direct input. Hold SHIFT to disable carry. Hold CTRL to Zero Right."); + setStatusText("Click, wheel or drag(left/right) a digit to change center frequency; SPACE or numeric key for direct input. Hold SHIFT to disable carry. SHIFT-right click to Zero Right."); break; case TUNING_HOVER_PPM: setStatusText("Click, wheel or drag(left/right) a digit to change device PPM offset. Hold SHIFT to disable carry."); @@ -364,9 +373,9 @@ void TuningCanvas::OnMouseWheelMoved(wxMouseEvent& event) { if (hoverState != TUNING_HOVER_NONE && !mouseTracker.mouseDown() && hoverIndex) { if (event.m_wheelAxis == wxMOUSE_WHEEL_VERTICAL) { - StepTuner(hoverState, hExponent, (event.m_wheelRotation > 0)?true:false); + StepTuner(hoverState, (event.m_wheelRotation > 0) ? TUNING_DIRECTION_UP : TUNING_DIRECTION_DOWN, hExponent, shiftDown, false); } else { - StepTuner(hoverState, hExponent, (event.m_wheelRotation < 0)?true:false); + StepTuner(hoverState, (event.m_wheelRotation < 0) ? TUNING_DIRECTION_UP : TUNING_DIRECTION_DOWN, hExponent, shiftDown, false); } } } @@ -377,7 +386,7 @@ void TuningCanvas::OnMouseReleased(wxMouseEvent& event) { int hExponent = hoverIndex - 1; if (hoverState != TUNING_HOVER_NONE && !dragging && (downState == hoverState) && (downIndex == hoverIndex)) { - StepTuner(hoverState, hExponent, top); + StepTuner(hoverState, top ? TUNING_DIRECTION_UP : TUNING_DIRECTION_DOWN, hExponent, shiftDown, false); } mouseTracker.setVertDragLock(false); @@ -388,12 +397,23 @@ void TuningCanvas::OnMouseReleased(wxMouseEvent& event) { void TuningCanvas::OnMouseRightDown(wxMouseEvent& event) { InteractiveCanvas::OnMouseRightDown(event); + + uxDown = 2.0 * (mouseTracker.getMouseX() - 0.5); + + downIndex = hoverIndex; + downState = hoverState; } void TuningCanvas::OnMouseRightReleased(wxMouseEvent& event) { InteractiveCanvas::OnMouseRightReleased(event); - if (hoverState == TUNING_HOVER_FREQ) { + if (shiftDown) { + int hExponent = hoverIndex - 1; + + if (hoverState != TUNING_HOVER_NONE && !dragging && (downState == hoverState) && (downIndex == hoverIndex)) { + StepTuner(hoverState, top ? TUNING_DIRECTION_UP : TUNING_DIRECTION_DOWN, hExponent, false, true); + } + } else if (hoverState == TUNING_HOVER_FREQ) { if (hoverIndex == 1) { wxGetApp().setFrequencySnap(1); } else if (hoverIndex > 1 && hoverIndex < 8) { diff --git a/src/visual/TuningCanvas.h b/src/visual/TuningCanvas.h index 5a947be..dad6665 100644 --- a/src/visual/TuningCanvas.h +++ b/src/visual/TuningCanvas.h @@ -20,6 +20,9 @@ public: enum ActiveState { TUNING_HOVER_NONE, TUNING_HOVER_FREQ, TUNING_HOVER_BW, TUNING_HOVER_PPM, TUNING_HOVER_CENTER }; + enum TuningDirection { + TUNING_DIRECTION_DOWN, TUNING_DIRECTION_UP + }; TuningCanvas(wxWindow *parent, const wxGLAttributes& dispAttrs); ~TuningCanvas(); @@ -45,7 +48,7 @@ private: void OnMouseRightDown(wxMouseEvent& event); void OnMouseRightReleased(wxMouseEvent& event); - void StepTuner(ActiveState state, int factor, bool up = true); + void StepTuner(ActiveState state, TuningDirection tuningDir, int digit, bool preventCarry = false, bool zeroOut = false); TuningContext *glContext; From 2f0bbef2349ac6d736a65bbe6ffc5a66594a7bfd Mon Sep 17 00:00:00 2001 From: "Charles J. Cliffe" Date: Mon, 10 Aug 2020 23:05:28 -0400 Subject: [PATCH 3/4] Frequency dialog bw limit check --- src/FrequencyDialog.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/FrequencyDialog.cpp b/src/FrequencyDialog.cpp index 0f83da1..ce17e99 100644 --- a/src/FrequencyDialog.cpp +++ b/src/FrequencyDialog.cpp @@ -158,6 +158,9 @@ void FrequencyDialog::OnChar(wxKeyEvent& event) { if (lastDemodType == "USB" || lastDemodType == "LSB") { freq *= 2; } + if (freq > CHANNELIZER_RATE_MAX) { + freq = CHANNELIZER_RATE_MAX; + } if (activeDemod) { activeDemod->setBandwidth(freq); } else { From 850e646c6db67dcc220c22bf813d43d6ece0241a Mon Sep 17 00:00:00 2001 From: "Charles J. Cliffe" Date: Mon, 10 Aug 2020 23:16:37 -0400 Subject: [PATCH 4/4] Fix source of bandwidth display visual glitch --- src/demod/DemodulatorPreThread.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/demod/DemodulatorPreThread.cpp b/src/demod/DemodulatorPreThread.cpp index 049014b..09d2801 100644 --- a/src/demod/DemodulatorPreThread.cpp +++ b/src/demod/DemodulatorPreThread.cpp @@ -327,9 +327,9 @@ void DemodulatorPreThread::setBandwidth(int bandwidth) { } int DemodulatorPreThread::getBandwidth() { - if (bandwidthChanged.load()) { - return newBandwidth; - } +// if (bandwidthChanged.load()) { +// return newBandwidth; +// } return currentBandwidth; }