From 96d22ee8f77de31a248f4fa9bbd2947c5029e1cc Mon Sep 17 00:00:00 2001 From: "Charles J. Cliffe" Date: Sun, 7 Feb 2016 21:05:49 -0500 Subject: [PATCH] Set waterfall lps or spectrum avg by space/typing --- src/AppFrame.cpp | 39 +++++++++++++++++++++++++++-- src/AppFrame.h | 6 +++++ src/CubicSDR.cpp | 20 +++++++++++++-- src/CubicSDR.h | 2 ++ src/FrequencyDialog.cpp | 50 ++++++++++++++++++++++++++++++++++--- src/FrequencyDialog.h | 9 ++++++- src/visual/MeterCanvas.cpp | 5 ++++ src/visual/MeterCanvas.h | 1 + src/visual/TuningCanvas.cpp | 4 +++ src/visual/TuningCanvas.h | 2 ++ 10 files changed, 130 insertions(+), 8 deletions(-) diff --git a/src/AppFrame.cpp b/src/AppFrame.cpp index afecb5d..24556c1 100644 --- a/src/AppFrame.cpp +++ b/src/AppFrame.cpp @@ -1543,6 +1543,32 @@ void AppFrame::setMainWaterfallFFTSize(int fftSize) { waterfallCanvas->setFFTSize(fftSize); } +FrequencyDialog::FrequencyDialogTarget AppFrame::getFrequencyDialogTarget() { + FrequencyDialog::FrequencyDialogTarget target = FrequencyDialog::FrequencyDialogTarget::FDIALOG_TARGET_DEFAULT; + + if (waterfallSpeedMeter->getMouseTracker()->mouseInView()) { + target = FrequencyDialog::FrequencyDialogTarget::FDIALOG_TARGET_WATERFALL_LPS; + } + else if (spectrumAvgMeter->getMouseTracker()->mouseInView()) { + target = FrequencyDialog::FrequencyDialogTarget::FDIALOG_TARGET_SPECTRUM_AVG; + } else if (demodTuner->getMouseTracker()->mouseInView()) { + switch (demodTuner->getHoverState()) { + case TuningCanvas::ActiveState::TUNING_HOVER_BW: + target = FrequencyDialog::FrequencyDialogTarget::FDIALOG_TARGET_BANDWIDTH; + break; + case TuningCanvas::ActiveState::TUNING_HOVER_FREQ: + target = FrequencyDialog::FrequencyDialogTarget::FDIALOG_TARGET_FREQ; + break; + case TuningCanvas::ActiveState::TUNING_HOVER_CENTER: + default: + target = FrequencyDialog::FrequencyDialogTarget::FDIALOG_TARGET_DEFAULT; + break; + + } + } + return target; +} + int AppFrame::OnGlobalKeyDown(wxKeyEvent &event) { if (!this->IsActive()) { return -1; @@ -1574,7 +1600,7 @@ int AppFrame::OnGlobalKeyDown(wxKeyEvent &event) { case '7': case '8': case '9': - wxGetApp().showFrequencyInput(FrequencyDialog::FDIALOG_TARGET_DEFAULT, std::to_string(event.GetKeyCode() - '0')); + wxGetApp().showFrequencyInput(getFrequencyDialogTarget(), std::to_string(event.GetKeyCode() - '0')); return 0; break; default: @@ -1600,7 +1626,7 @@ int AppFrame::OnGlobalKeyUp(wxKeyEvent &event) { switch (event.GetKeyCode()) { case WXK_SPACE: if (!demodTuner->getMouseTracker()->mouseInView()) { - wxGetApp().showFrequencyInput(); + wxGetApp().showFrequencyInput(getFrequencyDialogTarget()); return 0; } break; @@ -1648,3 +1674,12 @@ int AppFrame::OnGlobalKeyUp(wxKeyEvent &event) { return 0; } + +void AppFrame::setWaterfallLinesPerSecond(int lps) { + waterfallSpeedMeter->setUserInputValue(sqrt(lps)); +} + +void AppFrame::setSpectrumAvgSpeed(double avg) { + spectrumAvgMeter->setUserInputValue(avg); +} + diff --git a/src/AppFrame.h b/src/AppFrame.h index 84d32ba..afd1f0e 100644 --- a/src/AppFrame.h +++ b/src/AppFrame.h @@ -18,6 +18,7 @@ #include "SDRDeviceInfo.h" #include "ModemProperties.h" //#include "UITestCanvas.h" +#include "FrequencyDialog.h" #include @@ -78,6 +79,11 @@ public: int OnGlobalKeyDown(wxKeyEvent &event); int OnGlobalKeyUp(wxKeyEvent &event); + void setWaterfallLinesPerSecond(int lps); + void setSpectrumAvgSpeed(double avg); + + FrequencyDialog::FrequencyDialogTarget getFrequencyDialogTarget(); + private: void OnMenu(wxCommandEvent& event); void OnClose(wxCloseEvent& event); diff --git a/src/CubicSDR.cpp b/src/CubicSDR.cpp index 1db3ac9..5320cfe 100644 --- a/src/CubicSDR.cpp +++ b/src/CubicSDR.cpp @@ -134,6 +134,7 @@ CubicSDR::CubicSDR() : appframe(NULL), m_glContext(NULL), frequency(0), offset(0 sdrThread(NULL), sdrPostThread(NULL), spectrumVisualThread(NULL), demodVisualThread(NULL), pipeSDRIQData(NULL), pipeIQVisualData(NULL), pipeAudioVisualData(NULL), t_SDR(NULL), t_PostSDR(NULL) { sampleRateInitialized.store(false); agcMode.store(true); + fdlgTarget = FrequencyDialog::FDIALOG_TARGET_DEFAULT; } bool CubicSDR::OnInit() { @@ -649,14 +650,23 @@ int CubicSDR::getPPM() { return ppm; } +void CubicSDR::setFrequencyInputTarget(FrequencyDialog::FrequencyDialogTarget targetMode) { + fdlgTarget = targetMode; +} void CubicSDR::showFrequencyInput(FrequencyDialog::FrequencyDialogTarget targetMode, wxString initString) { const wxString demodTitle("Set Demodulator Frequency"); const wxString freqTitle("Set Center Frequency"); - const wxString bwTitle("Set Demodulator Bandwidth"); + const wxString bwTitle("Modem Bandwidth (150Hz - 500KHz)"); + const wxString lpsTitle("Lines-Per-Second (1-1024)"); + const wxString avgTitle("Average Rate (0.1 - 0.99)"); wxString title; +// if (targetMode == FrequencyDialog::FDIALOG_TARGET_DEFAULT && fdlgTarget != FrequencyDialog::FDIALOG_TARGET_DEFAULT) { +// targetMode = fdlgTarget; +// } + switch (targetMode) { case FrequencyDialog::FDIALOG_TARGET_DEFAULT: title = demodMgr.getActiveDemodulator()?demodTitle:freqTitle; @@ -664,11 +674,17 @@ void CubicSDR::showFrequencyInput(FrequencyDialog::FrequencyDialogTarget targetM case FrequencyDialog::FDIALOG_TARGET_BANDWIDTH: title = bwTitle; break; + case FrequencyDialog::FDIALOG_TARGET_WATERFALL_LPS: + title = lpsTitle; + break; + case FrequencyDialog::FDIALOG_TARGET_SPECTRUM_AVG: + title = avgTitle; + break; default: break; } - FrequencyDialog fdialog(appframe, -1, title, demodMgr.getActiveDemodulator(), wxPoint(-100,-100), wxSize(320, 75 ), wxDEFAULT_DIALOG_STYLE, targetMode, initString); + FrequencyDialog fdialog(appframe, -1, title, demodMgr.getActiveDemodulator(), wxPoint(-100,-100), wxSize(350, 75), wxDEFAULT_DIALOG_STYLE, targetMode, initString); fdialog.ShowModal(); } diff --git a/src/CubicSDR.h b/src/CubicSDR.h index d15adbc..c96f18a 100644 --- a/src/CubicSDR.h +++ b/src/CubicSDR.h @@ -125,6 +125,7 @@ public: void setPPM(int ppm_in); int getPPM(); + void setFrequencyInputTarget(FrequencyDialog::FrequencyDialogTarget targetMode); void showFrequencyInput(FrequencyDialog::FrequencyDialogTarget targetMode = FrequencyDialog::FDIALOG_TARGET_DEFAULT, wxString initString = ""); AppFrame *getAppFrame(); @@ -207,6 +208,7 @@ private: std::mutex notify_busy; std::atomic_bool frequency_locked; std::atomic_llong lock_freq; + FrequencyDialog::FrequencyDialogTarget fdlgTarget; #ifdef USE_HAMLIB RigThread *rigThread; std::thread *t_Rig; diff --git a/src/FrequencyDialog.cpp b/src/FrequencyDialog.cpp index eda526e..09b0f19 100644 --- a/src/FrequencyDialog.cpp +++ b/src/FrequencyDialog.cpp @@ -31,18 +31,29 @@ FrequencyDialog::FrequencyDialog(wxWindow * parent, wxWindowID id, const wxStrin freqStr = frequencyToStr(wxGetApp().getDemodMgr().getLastBandwidth()); } } + + if (targetMode == FDIALOG_TARGET_WATERFALL_LPS) { + freqStr = std::to_string(wxGetApp().getAppFrame()->getWaterfallDataThread()->getLinesPerSecond()); + } + if (targetMode == FDIALOG_TARGET_SPECTRUM_AVG) { + freqStr = std::to_string(wxGetApp().getSpectrumProcessor()->getFFTAverageRate()); + } + dialogText = new wxTextCtrl(this, wxID_FREQ_INPUT, freqStr, wxPoint(6, 1), wxSize(size.GetWidth() - 20, size.GetHeight() - 70), wxTE_PROCESS_ENTER); dialogText->SetFont(wxFont(20, wxFONTFAMILY_TELETYPE, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD)); Centre(); - if (initString != "") { + if (initString != "" && initString.length() == 1) { dialogText->SetValue(initString); dialogText->SetSelection(initString.length(), initString.length()); dialogText->SetFocus(); } else { + if (initString != "") { + dialogText->SetValue(initString); + } dialogText->SetSelection(-1, -1); } } @@ -51,15 +62,17 @@ FrequencyDialog::FrequencyDialog(wxWindow * parent, wxWindowID id, const wxStrin void FrequencyDialog::OnChar(wxKeyEvent& event) { int c = event.GetKeyCode(); long long freq; + double dblval; std::string lastDemodType = activeDemod?activeDemod->getDemodulatorType():wxGetApp().getDemodMgr().getLastDemodulatorType(); - + std::string strValue = dialogText->GetValue().ToStdString(); + switch (c) { case WXK_RETURN: case WXK_NUMPAD_ENTER: // Do Stuff - freq = strToFrequency(dialogText->GetValue().ToStdString()); if (targetMode == FDIALOG_TARGET_DEFAULT) { + freq = strToFrequency(strValue); if (activeDemod) { activeDemod->setTracking(true); activeDemod->setFollow(true); @@ -70,6 +83,7 @@ void FrequencyDialog::OnChar(wxKeyEvent& event) { } } if (targetMode == FDIALOG_TARGET_BANDWIDTH) { + freq = strToFrequency(strValue); if (lastDemodType == "USB" || lastDemodType == "LSB") { freq *= 2; } @@ -79,6 +93,36 @@ void FrequencyDialog::OnChar(wxKeyEvent& event) { wxGetApp().getDemodMgr().setLastBandwidth(freq); } } + if (targetMode == FDIALOG_TARGET_WATERFALL_LPS) { + try { + freq = std::stoi(strValue); + } catch (exception e) { + Close(); + break; + } + if (freq > 1024) { + freq = 1024; + } + if (freq < 1) { + freq = 1; + } + wxGetApp().getAppFrame()->setWaterfallLinesPerSecond(freq); + } + if (targetMode == FDIALOG_TARGET_SPECTRUM_AVG) { + try { + dblval = std::stod(strValue); + } catch (exception e) { + Close(); + break; + } + if (dblval > 0.99) { + dblval = 0.99; + } + if (dblval < 0.1) { + dblval = 0.1; + } + wxGetApp().getAppFrame()->setSpectrumAvgSpeed(dblval); + } Close(); break; case WXK_ESCAPE: diff --git a/src/FrequencyDialog.h b/src/FrequencyDialog.h index 03859b8..768401a 100644 --- a/src/FrequencyDialog.h +++ b/src/FrequencyDialog.h @@ -11,7 +11,14 @@ class FrequencyDialog: public wxDialog { public: - typedef enum FrequencyDialogTarget { FDIALOG_TARGET_DEFAULT, FDIALOG_TARGET_CENTERFREQ, FDIALOG_TARGET_FREQ, FDIALOG_TARGET_BANDWIDTH } FrequencyDialogTarget; + typedef enum FrequencyDialogTarget { + FDIALOG_TARGET_DEFAULT, + FDIALOG_TARGET_CENTERFREQ, + FDIALOG_TARGET_FREQ, + FDIALOG_TARGET_BANDWIDTH, + FDIALOG_TARGET_WATERFALL_LPS, + FDIALOG_TARGET_SPECTRUM_AVG + } FrequencyDialogTarget; FrequencyDialog ( wxWindow * parent, wxWindowID id, const wxString & title, DemodulatorInstance *demod = NULL, const wxPoint & pos = wxDefaultPosition, diff --git a/src/visual/MeterCanvas.cpp b/src/visual/MeterCanvas.cpp index e696421..d5b6037 100644 --- a/src/visual/MeterCanvas.cpp +++ b/src/visual/MeterCanvas.cpp @@ -52,6 +52,11 @@ void MeterCanvas::setMin(float min_in) { Refresh(); } +void MeterCanvas::setUserInputValue(float slider_in) { + userInputValue = slider_in; + Refresh(); +} + void MeterCanvas::setInputValue(float slider_in) { userInputValue = inputValue = slider_in; Refresh(); diff --git a/src/visual/MeterCanvas.h b/src/visual/MeterCanvas.h index 12577b2..7da390e 100644 --- a/src/visual/MeterCanvas.h +++ b/src/visual/MeterCanvas.h @@ -24,6 +24,7 @@ public: void setMax(float max_in); void setMin(float max_in); + void setUserInputValue(float slider_in); void setInputValue(float slider_in); bool inputChanged(); float getInputValue(); diff --git a/src/visual/TuningCanvas.cpp b/src/visual/TuningCanvas.cpp index bd21503..d5e0160 100644 --- a/src/visual/TuningCanvas.cpp +++ b/src/visual/TuningCanvas.cpp @@ -428,3 +428,7 @@ void TuningCanvas::OnKeyDown(wxKeyEvent& event) { void TuningCanvas::OnKeyUp(wxKeyEvent& event) { InteractiveCanvas::OnKeyUp(event); } + +TuningCanvas::ActiveState TuningCanvas::getHoverState() { + return hoverState; +} diff --git a/src/visual/TuningCanvas.h b/src/visual/TuningCanvas.h index 3482163..403181f 100644 --- a/src/visual/TuningCanvas.h +++ b/src/visual/TuningCanvas.h @@ -28,6 +28,8 @@ public: void OnKeyDown(wxKeyEvent& event); void OnKeyUp(wxKeyEvent& event); + ActiveState getHoverState(); + private: void OnPaint(wxPaintEvent& event); void OnIdle(wxIdleEvent &event);