Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to standard SoapySDR frequency correction, allow zero-to-right by SHIFT+Right Click freq. digits #840

Merged
merged 4 commits into from
Aug 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/FrequencyDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions src/demod/DemodulatorPreThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,9 +327,9 @@ void DemodulatorPreThread::setBandwidth(int bandwidth) {
}

int DemodulatorPreThread::getBandwidth() {
if (bandwidthChanged.load()) {
return newBandwidth;
}
// if (bandwidthChanged.load()) {
// return newBandwidth;
// }

return currentBandwidth;
}
Expand Down
6 changes: 6 additions & 0 deletions src/sdr/SDRDeviceInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
12 changes: 10 additions & 2 deletions src/sdr/SoapySDRThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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."));
Expand Down Expand Up @@ -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);
}

Expand Down
66 changes: 49 additions & 17 deletions src/visual/TuningCanvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -176,7 +185,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 (zeroOut) { // Zero digits to right
double intpart;
modf(freq / (exp * 10), &intpart);
freq = intpart * exp * 10;
} 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 {
Expand All @@ -199,7 +212,11 @@ void TuningCanvas::StepTuner(ActiveState state, int exponent, bool up) {
if (state == TUNING_HOVER_BW) {
long bw = wxGetApp().getDemodMgr().getLastBandwidth();

if (shiftDown) {
if (zeroOut) { // Zero digits to right
double intpart;
modf(bw / (exp * 10), &intpart);
bw = intpart * exp * 10;
} 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 {
Expand All @@ -219,7 +236,11 @@ void TuningCanvas::StepTuner(ActiveState state, int exponent, bool up) {

if (state == TUNING_HOVER_CENTER) {
long long ctr = wxGetApp().getFrequency();
if (shiftDown) {
if (zeroOut) { // Zero digits to right
double intpart;
modf(ctr / (exp * 10), &intpart);
ctr = intpart * exp * 10;
} 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 {
Expand All @@ -230,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 {
Expand All @@ -255,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;
}
Expand Down Expand Up @@ -310,16 +331,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. SHIFT-right click 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. SHIFT-right click 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. SHIFT-right click 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("");
Expand Down Expand Up @@ -352,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);
}
}
}
Expand All @@ -365,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);
Expand All @@ -376,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) {
Expand Down
5 changes: 4 additions & 1 deletion src/visual/TuningCanvas.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ class TuningCanvas: public InteractiveCanvas {
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();

Expand All @@ -45,7 +48,7 @@ class TuningCanvas: public InteractiveCanvas {
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;

Expand Down