Merge pull request #840 from cjcliffe/feature/zeroing_and_universal_offset

Update to standard SoapySDR frequency correction, allow zero-to-right by SHIFT+Right Click freq. digits
This commit is contained in:
Charles J. Cliffe 2020-08-24 22:47:42 -04:00 committed by GitHub
commit 4f1db5544d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 75 additions and 23 deletions

View File

@ -158,6 +158,9 @@ void FrequencyDialog::OnChar(wxKeyEvent& event) {
if (lastDemodType == "USB" || lastDemodType == "LSB") { if (lastDemodType == "USB" || lastDemodType == "LSB") {
freq *= 2; freq *= 2;
} }
if (freq > CHANNELIZER_RATE_MAX) {
freq = CHANNELIZER_RATE_MAX;
}
if (activeDemod) { if (activeDemod) {
activeDemod->setBandwidth(freq); activeDemod->setBandwidth(freq);
} else { } else {

View File

@ -327,9 +327,9 @@ void DemodulatorPreThread::setBandwidth(int bandwidth) {
} }
int DemodulatorPreThread::getBandwidth() { int DemodulatorPreThread::getBandwidth() {
if (bandwidthChanged.load()) { // if (bandwidthChanged.load()) {
return newBandwidth; // return newBandwidth;
} // }
return currentBandwidth; return currentBandwidth;
} }

View File

@ -168,6 +168,12 @@ SoapySDR::Device *SDRDeviceInfo::getSoapyDevice() {
return soapyDevice; return soapyDevice;
} }
/**
* @deprecated
* @param direction
* @param channel
* @return
*/
bool SDRDeviceInfo::hasCORR(int direction, size_t channel) { bool SDRDeviceInfo::hasCORR(int direction, size_t channel) {
SoapySDR::Device *dev = getSoapyDevice(); SoapySDR::Device *dev = getSoapyDevice();

View File

@ -111,12 +111,16 @@ bool SDRThread::init() {
//4. Apply other settings: Frequency, PPM correction, Gains, Device-specific settings: //4. Apply other settings: Frequency, PPM correction, Gains, Device-specific settings:
device->setFrequency(SOAPY_SDR_RX,0,"RF",frequency - offset.load()); 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); hasPPM.store(true);
device->setFrequency(SOAPY_SDR_RX,0,"CORR",ppm.load()); device->setFrequency(SOAPY_SDR_RX,0,"CORR",ppm.load());
} else { } else {
hasPPM.store(false); hasPPM.store(false);
} }
if (device->hasDCOffsetMode(SOAPY_SDR_RX, 0)) { if (device->hasDCOffsetMode(SOAPY_SDR_RX, 0)) {
hasHardwareDC.store(true); hasHardwareDC.store(true);
// wxGetApp().sdrEnumThreadNotify(SDREnumerator::SDR_ENUM_MESSAGE, std::string("Found hardware DC offset correction support, internal disabled.")); // 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()) { 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); ppm_changed.store(false);
} }

View File

@ -163,9 +163,18 @@ void TuningCanvas::OnPaint(wxPaintEvent& WXUNUSED(event)) {
SwapBuffers(); SwapBuffers();
} }
void TuningCanvas::StepTuner(ActiveState state, int exponent, bool up) { /***
double exp = pow(10, exponent); * Perform tuner step
long long amount = up?exp:-exp; *
* @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) { if (halfBand && state == TUNING_HOVER_BW) {
amount *= 2; amount *= 2;
@ -176,7 +185,11 @@ void TuningCanvas::StepTuner(ActiveState state, int exponent, bool up) {
long long freq = activeDemod->getFrequency(); long long freq = activeDemod->getFrequency();
long long diff = abs(wxGetApp().getFrequency() - freq); 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); bool carried = (long long)((freq) / (exp * 10)) != (long long)((freq + amount) / (exp * 10)) || (bottom && freq < exp);
freq += carried?(9*-amount):amount; freq += carried?(9*-amount):amount;
} else { } else {
@ -199,7 +212,11 @@ void TuningCanvas::StepTuner(ActiveState state, int exponent, bool up) {
if (state == TUNING_HOVER_BW) { if (state == TUNING_HOVER_BW) {
long bw = wxGetApp().getDemodMgr().getLastBandwidth(); 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); bool carried = (long)((bw) / (exp * 10)) != (long)((bw + amount) / (exp * 10)) || (bottom && bw < exp);
bw += carried?(9*-amount):amount; bw += carried?(9*-amount):amount;
} else { } else {
@ -219,7 +236,11 @@ void TuningCanvas::StepTuner(ActiveState state, int exponent, bool up) {
if (state == TUNING_HOVER_CENTER) { if (state == TUNING_HOVER_CENTER) {
long long ctr = wxGetApp().getFrequency(); 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); bool carried = (long long)((ctr) / (exp * 10)) != (long long)((ctr + amount) / (exp * 10)) || (bottom && ctr < exp);
ctr += carried?(9*-amount):amount; ctr += carried?(9*-amount):amount;
} else { } else {
@ -230,7 +251,7 @@ void TuningCanvas::StepTuner(ActiveState state, int exponent, bool up) {
} }
if (state == TUNING_HOVER_PPM) { 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); bool carried = (long long)((currentPPM) / (exp * 10)) != (long long)((currentPPM + amount) / (exp * 10)) || (bottom && currentPPM < exp);
currentPPM += carried?(9*-amount):amount; currentPPM += carried?(9*-amount):amount;
} else { } else {
@ -255,12 +276,12 @@ void TuningCanvas::OnIdle(wxIdleEvent & /* event */) {
if (downState != TUNING_HOVER_NONE) { if (downState != TUNING_HOVER_NONE) {
dragAccum += 5.0*mouseTracker.getOriginDeltaMouseX(); dragAccum += 5.0*mouseTracker.getOriginDeltaMouseX();
while (dragAccum > 1.0) { while (dragAccum > 1.0) {
StepTuner(downState, downIndex-1, true); StepTuner(downState, TUNING_DIRECTION_UP, downIndex - 1, shiftDown, false);
dragAccum -= 1.0; dragAccum -= 1.0;
dragging = true; dragging = true;
} }
while (dragAccum < -1.0) { while (dragAccum < -1.0) {
StepTuner(downState, downIndex-1, false); StepTuner(downState, TUNING_DIRECTION_DOWN, downIndex - 1, shiftDown, false);
dragAccum += 1.0; dragAccum += 1.0;
dragging = true; dragging = true;
} }
@ -310,16 +331,16 @@ void TuningCanvas::OnMouseMoved(wxMouseEvent& event) {
} else { } else {
switch (hoverState) { switch (hoverState) {
case TUNING_HOVER_FREQ: 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; break;
case TUNING_HOVER_BW: 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; break;
case TUNING_HOVER_CENTER: 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; break;
case TUNING_HOVER_PPM: 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; break;
case TUNING_HOVER_NONE: case TUNING_HOVER_NONE:
setStatusText(""); setStatusText("");
@ -352,9 +373,9 @@ void TuningCanvas::OnMouseWheelMoved(wxMouseEvent& event) {
if (hoverState != TUNING_HOVER_NONE && !mouseTracker.mouseDown() && hoverIndex) { if (hoverState != TUNING_HOVER_NONE && !mouseTracker.mouseDown() && hoverIndex) {
if (event.m_wheelAxis == wxMOUSE_WHEEL_VERTICAL) { 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 { } 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);
} }
} }
} }
@ -365,7 +386,7 @@ void TuningCanvas::OnMouseReleased(wxMouseEvent& event) {
int hExponent = hoverIndex - 1; int hExponent = hoverIndex - 1;
if (hoverState != TUNING_HOVER_NONE && !dragging && (downState == hoverState) && (downIndex == hoverIndex)) { 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); mouseTracker.setVertDragLock(false);
@ -376,12 +397,23 @@ void TuningCanvas::OnMouseReleased(wxMouseEvent& event) {
void TuningCanvas::OnMouseRightDown(wxMouseEvent& event) { void TuningCanvas::OnMouseRightDown(wxMouseEvent& event) {
InteractiveCanvas::OnMouseRightDown(event); InteractiveCanvas::OnMouseRightDown(event);
uxDown = 2.0 * (mouseTracker.getMouseX() - 0.5);
downIndex = hoverIndex;
downState = hoverState;
} }
void TuningCanvas::OnMouseRightReleased(wxMouseEvent& event) { void TuningCanvas::OnMouseRightReleased(wxMouseEvent& event) {
InteractiveCanvas::OnMouseRightReleased(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) { if (hoverIndex == 1) {
wxGetApp().setFrequencySnap(1); wxGetApp().setFrequencySnap(1);
} else if (hoverIndex > 1 && hoverIndex < 8) { } else if (hoverIndex > 1 && hoverIndex < 8) {

View File

@ -20,6 +20,9 @@ public:
enum ActiveState { enum ActiveState {
TUNING_HOVER_NONE, TUNING_HOVER_FREQ, TUNING_HOVER_BW, TUNING_HOVER_PPM, TUNING_HOVER_CENTER 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(wxWindow *parent, const wxGLAttributes& dispAttrs);
~TuningCanvas(); ~TuningCanvas();
@ -45,7 +48,7 @@ private:
void OnMouseRightDown(wxMouseEvent& event); void OnMouseRightDown(wxMouseEvent& event);
void OnMouseRightReleased(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; TuningContext *glContext;