From 4be9fa0538a2443c9ab730d3ae0c3b9fe8fbf1e6 Mon Sep 17 00:00:00 2001 From: "Charles J. Cliffe" Date: Mon, 15 Aug 2016 23:53:27 -0400 Subject: [PATCH] Support ranged frequency input for center frequency --- CMakeLists.txt | 2 +- src/AppFrame.cpp | 11 +++++++++ src/AppFrame.h | 4 +++- src/FrequencyDialog.cpp | 51 +++++++++++++++++++++++++++++++++++++---- 4 files changed, 62 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8250013..7f8ac92 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,7 +7,7 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules/") SET(CUBICSDR_VERSION_MAJOR "0") SET(CUBICSDR_VERSION_MINOR "2") SET(CUBICSDR_VERSION_PATCH "0") -SET(CUBICSDR_VERSION_REL "beta-rc5") +SET(CUBICSDR_VERSION_REL "beta-rc6") SET(CUBICSDR_VERSION "${CUBICSDR_VERSION_MAJOR}.${CUBICSDR_VERSION_MINOR}.${CUBICSDR_VERSION_PATCH}-${CUBICSDR_VERSION_REL}") SET(CPACK_PACKAGE_VERSION "${CUBICSDR_VERSION_MAJOR}.${CUBICSDR_VERSION_MINOR}.${CUBICSDR_VERSION_PATCH}") diff --git a/src/AppFrame.cpp b/src/AppFrame.cpp index 3e39091..bf1ccca 100644 --- a/src/AppFrame.cpp +++ b/src/AppFrame.cpp @@ -2191,3 +2191,14 @@ void AppFrame::setSpectrumAvgSpeed(double avg) { spectrumAvgMeter->setUserInputValue(avg); } +void AppFrame::setViewState(long long center_freq, int bandwidth) { + spectrumCanvas->setView(center_freq, bandwidth); + waterfallCanvas->setView(center_freq, bandwidth); +} + +void AppFrame::setViewState(long long center_freq) { + spectrumCanvas->setCenterFrequency(wxGetApp().getFrequency()); + waterfallCanvas->setCenterFrequency(wxGetApp().getFrequency()); + spectrumCanvas->disableView(); + waterfallCanvas->disableView(); +} diff --git a/src/AppFrame.h b/src/AppFrame.h index aedc53c..fcd73f9 100644 --- a/src/AppFrame.h +++ b/src/AppFrame.h @@ -98,7 +98,9 @@ public: FrequencyDialog::FrequencyDialogTarget getFrequencyDialogTarget(); void refreshGainUI(); - + void setViewState(long long center_freq, int bandwidth); + void setViewState(long long center_freq); + #ifdef _WIN32 bool canFocus(); #endif diff --git a/src/FrequencyDialog.cpp b/src/FrequencyDialog.cpp index 1d6fb04..9b6adb5 100644 --- a/src/FrequencyDialog.cpp +++ b/src/FrequencyDialog.cpp @@ -69,25 +69,68 @@ FrequencyDialog::FrequencyDialog(wxWindow * parent, wxWindowID id, const wxStrin void FrequencyDialog::OnChar(wxKeyEvent& event) { int c = event.GetKeyCode(); - long long freq; + long long freq, freq2, freq_ctr, range_bw; double dblval; std::string lastDemodType = activeDemod?activeDemod->getDemodulatorType():wxGetApp().getDemodMgr().getLastDemodulatorType(); std::string strValue = dialogText->GetValue().ToStdString(); + bool ranged = false; + std::string strValue2; + size_t range_pos; + switch (c) { case WXK_RETURN: case WXK_NUMPAD_ENTER: // Do Stuff + ranged = false; + if ((range_pos = strValue.find_first_of("-")) > 0) { + strValue2 = strValue.substr(range_pos+1); + strValue = strValue.substr(0,range_pos); + + if (targetMode == FDIALOG_TARGET_DEFAULT && !activeDemod && strValue.length() && strValue2.length()) { + ranged = true; + } + } if (targetMode == FDIALOG_TARGET_DEFAULT) { - freq = strToFrequency(strValue); + if (ranged) { + freq = strToFrequency(strValue); + freq2 = strToFrequency(strValue2); + } else { + freq = strToFrequency(strValue); + } if (activeDemod) { activeDemod->setTracking(true); activeDemod->setFollow(true); activeDemod->setFrequency(freq); activeDemod->updateLabel(freq); } else { - wxGetApp().setFrequency(freq); + if (ranged && (freq || freq2)) { + if (freq > freq2) { + std::swap(freq,freq2); + } + range_bw = (freq2-freq); + freq_ctr = freq + (range_bw/2); + if (range_bw > wxGetApp().getSampleRate()) { + range_bw = wxGetApp().getSampleRate(); + } + if (range_bw < 30000) { + range_bw = 30000; + } + if (freq == freq2) { + wxGetApp().setFrequency(freq_ctr); + wxGetApp().getAppFrame()->setViewState(freq_ctr); + } else { + if (wxGetApp().getSampleRate()/4 > range_bw) { + wxGetApp().setFrequency(freq_ctr + wxGetApp().getSampleRate()/4); + } else { + wxGetApp().setFrequency(freq_ctr); + } + wxGetApp().getAppFrame()->setViewState(freq_ctr, range_bw); + } + } else { + wxGetApp().setFrequency(freq); + } } } if (targetMode == FDIALOG_TARGET_BANDWIDTH) { @@ -161,7 +204,7 @@ void FrequencyDialog::OnChar(wxKeyEvent& event) { break; } - std::string allowed("0123456789.MKGHZmkghz"); + std::string allowed("0123456789.MKGHZmkghz-"); if (allowed.find_first_of(c) != std::string::npos || c == WXK_DELETE || c == WXK_BACK || c == WXK_NUMPAD_DECIMAL || (c >= WXK_NUMPAD0 && c <= WXK_NUMPAD9)) {