Merge pull request #430 from cjcliffe/freq_range_input

Support ranged frequency input for center frequency
This commit is contained in:
Charles J. Cliffe 2016-08-16 00:02:12 -04:00 committed by GitHub
commit ad7779de53
4 changed files with 66 additions and 5 deletions

View File

@ -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}")

View File

@ -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();
}

View File

@ -98,6 +98,8 @@ public:
FrequencyDialog::FrequencyDialogTarget getFrequencyDialogTarget();
void refreshGainUI();
void setViewState(long long center_freq, int bandwidth);
void setViewState(long long center_freq);
#ifdef _WIN32
bool canFocus();

View File

@ -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) {
@ -163,6 +206,11 @@ void FrequencyDialog::OnChar(wxKeyEvent& event) {
std::string allowed("0123456789.MKGHZmkghz");
// Support '-' for range
if (targetMode == FDIALOG_TARGET_DEFAULT && !activeDemod && strValue.length() > 0) {
allowed.append("-");
}
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)) {
#ifdef __linux__