2015-05-04 19:44:03 -04:00
|
|
|
#include "FrequencyDialog.h"
|
|
|
|
|
2015-05-09 23:13:35 -04:00
|
|
|
#include "wx/clipbrd.h"
|
2015-05-10 01:07:48 -04:00
|
|
|
#include <sstream>
|
|
|
|
#include "CubicSDR.h"
|
2015-05-09 23:13:35 -04:00
|
|
|
|
2015-06-07 21:42:23 -04:00
|
|
|
wxBEGIN_EVENT_TABLE(FrequencyDialog, wxDialog)
|
|
|
|
EVT_CHAR_HOOK(FrequencyDialog::OnChar)
|
2015-05-09 23:13:35 -04:00
|
|
|
wxEND_EVENT_TABLE()
|
2015-05-04 19:44:03 -04:00
|
|
|
|
2015-05-10 20:00:48 -04:00
|
|
|
FrequencyDialog::FrequencyDialog(wxWindow * parent, wxWindowID id, const wxString & title, DemodulatorInstance *demod, const wxPoint & position,
|
2016-02-07 19:32:05 -05:00
|
|
|
const wxSize & size, long style, FrequencyDialogTarget targetMode, wxString initString) :
|
2015-05-10 20:00:48 -04:00
|
|
|
wxDialog(parent, id, title, position, size, style) {
|
2015-05-10 01:39:10 -04:00
|
|
|
wxString freqStr;
|
|
|
|
activeDemod = demod;
|
2015-08-14 20:19:37 -04:00
|
|
|
this->targetMode = targetMode;
|
2015-05-10 01:39:10 -04:00
|
|
|
|
2015-08-14 20:19:37 -04:00
|
|
|
if (targetMode == FDIALOG_TARGET_DEFAULT) {
|
|
|
|
if (activeDemod) {
|
|
|
|
freqStr = frequencyToStr(activeDemod->getFrequency());
|
|
|
|
} else {
|
|
|
|
freqStr = frequencyToStr(wxGetApp().getFrequency());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (targetMode == FDIALOG_TARGET_BANDWIDTH) {
|
2015-12-31 22:31:14 -05:00
|
|
|
std::string lastDemodType = activeDemod?activeDemod->getDemodulatorType():wxGetApp().getDemodMgr().getLastDemodulatorType();
|
|
|
|
if (lastDemodType == "USB" || lastDemodType == "LSB") {
|
|
|
|
freqStr = frequencyToStr(wxGetApp().getDemodMgr().getLastBandwidth()/2);
|
|
|
|
} else {
|
|
|
|
freqStr = frequencyToStr(wxGetApp().getDemodMgr().getLastBandwidth());
|
|
|
|
}
|
2015-05-10 01:39:10 -04:00
|
|
|
}
|
2016-02-07 21:05:49 -05:00
|
|
|
|
|
|
|
if (targetMode == FDIALOG_TARGET_WATERFALL_LPS) {
|
|
|
|
freqStr = std::to_string(wxGetApp().getAppFrame()->getWaterfallDataThread()->getLinesPerSecond());
|
|
|
|
}
|
2015-05-04 19:44:03 -04:00
|
|
|
|
2016-02-07 21:05:49 -05:00
|
|
|
if (targetMode == FDIALOG_TARGET_SPECTRUM_AVG) {
|
|
|
|
freqStr = std::to_string(wxGetApp().getSpectrumProcessor()->getFFTAverageRate());
|
|
|
|
}
|
2016-02-07 22:19:05 -05:00
|
|
|
|
|
|
|
if (targetMode == FDIALOG_TARGET_GAIN) {
|
|
|
|
if (wxGetApp().getActiveGainEntry() != "") {
|
|
|
|
freqStr = std::to_string((int)wxGetApp().getGain(wxGetApp().getActiveGainEntry()));
|
|
|
|
}
|
|
|
|
}
|
2016-02-07 21:05:49 -05:00
|
|
|
|
2015-05-10 20:00:48 -04:00
|
|
|
dialogText = new wxTextCtrl(this, wxID_FREQ_INPUT, freqStr, wxPoint(6, 1), wxSize(size.GetWidth() - 20, size.GetHeight() - 70),
|
|
|
|
wxTE_PROCESS_ENTER);
|
2015-05-04 19:44:03 -04:00
|
|
|
dialogText->SetFont(wxFont(20, wxFONTFAMILY_TELETYPE, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD));
|
|
|
|
|
|
|
|
Centre();
|
2015-05-04 23:03:55 -04:00
|
|
|
|
2016-02-07 21:05:49 -05:00
|
|
|
if (initString != "" && initString.length() == 1) {
|
2016-02-07 19:32:05 -05:00
|
|
|
dialogText->SetValue(initString);
|
|
|
|
dialogText->SetSelection(initString.length(), initString.length());
|
|
|
|
dialogText->SetFocus();
|
|
|
|
} else {
|
2016-02-07 21:05:49 -05:00
|
|
|
if (initString != "") {
|
|
|
|
dialogText->SetValue(initString);
|
|
|
|
}
|
2016-02-07 19:32:05 -05:00
|
|
|
dialogText->SetSelection(-1, -1);
|
|
|
|
}
|
2015-05-04 19:44:03 -04:00
|
|
|
}
|
|
|
|
|
2015-05-10 01:07:48 -04:00
|
|
|
|
2015-05-09 23:13:35 -04:00
|
|
|
void FrequencyDialog::OnChar(wxKeyEvent& event) {
|
2015-06-07 21:42:23 -04:00
|
|
|
int c = event.GetKeyCode();
|
2015-05-10 01:07:48 -04:00
|
|
|
long long freq;
|
2016-02-07 21:05:49 -05:00
|
|
|
double dblval;
|
2015-12-31 22:31:14 -05:00
|
|
|
std::string lastDemodType = activeDemod?activeDemod->getDemodulatorType():wxGetApp().getDemodMgr().getLastDemodulatorType();
|
2016-02-07 21:05:49 -05:00
|
|
|
std::string strValue = dialogText->GetValue().ToStdString();
|
|
|
|
|
2015-05-09 23:13:35 -04:00
|
|
|
switch (c) {
|
|
|
|
case WXK_RETURN:
|
|
|
|
case WXK_NUMPAD_ENTER:
|
|
|
|
// Do Stuff
|
2015-12-31 22:31:14 -05:00
|
|
|
|
|
|
|
if (targetMode == FDIALOG_TARGET_DEFAULT) {
|
2016-02-07 21:05:49 -05:00
|
|
|
freq = strToFrequency(strValue);
|
2015-12-31 22:31:14 -05:00
|
|
|
if (activeDemod) {
|
|
|
|
activeDemod->setTracking(true);
|
|
|
|
activeDemod->setFollow(true);
|
|
|
|
activeDemod->setFrequency(freq);
|
|
|
|
activeDemod->updateLabel(freq);
|
|
|
|
} else {
|
|
|
|
wxGetApp().setFrequency(freq);
|
2015-08-14 20:19:37 -04:00
|
|
|
}
|
2015-12-31 22:31:14 -05:00
|
|
|
}
|
|
|
|
if (targetMode == FDIALOG_TARGET_BANDWIDTH) {
|
2016-02-07 21:05:49 -05:00
|
|
|
freq = strToFrequency(strValue);
|
2016-01-03 10:59:24 -05:00
|
|
|
if (lastDemodType == "USB" || lastDemodType == "LSB") {
|
|
|
|
freq *= 2;
|
|
|
|
}
|
2015-12-31 22:31:14 -05:00
|
|
|
if (activeDemod) {
|
|
|
|
activeDemod->setBandwidth(freq);
|
|
|
|
} else {
|
|
|
|
wxGetApp().getDemodMgr().setLastBandwidth(freq);
|
2015-08-14 20:19:37 -04:00
|
|
|
}
|
2016-02-07 21:05:49 -05:00
|
|
|
}
|
|
|
|
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);
|
2015-12-31 22:31:14 -05:00
|
|
|
}
|
2016-02-07 22:19:05 -05:00
|
|
|
|
|
|
|
if (targetMode == FDIALOG_TARGET_GAIN) {
|
|
|
|
try {
|
|
|
|
freq = std::stoi(strValue);
|
|
|
|
} catch (exception e) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
SDRDeviceInfo *devInfo = wxGetApp().getDevice();
|
|
|
|
std::string gainName = wxGetApp().getActiveGainEntry();
|
|
|
|
if (gainName == "") {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
SDRRangeMap gains = devInfo->getGains(SOAPY_SDR_RX, 0);
|
|
|
|
if (freq > gains[gainName].maximum()) {
|
|
|
|
freq = gains[gainName].maximum();
|
|
|
|
}
|
|
|
|
if (freq < gains[gainName].minimum()) {
|
|
|
|
freq = gains[gainName].minimum();
|
|
|
|
}
|
|
|
|
wxGetApp().setGain(gainName, freq);
|
|
|
|
wxGetApp().getAppFrame()->refreshGainUI();
|
|
|
|
}
|
|
|
|
|
2015-05-09 23:13:35 -04:00
|
|
|
Close();
|
|
|
|
break;
|
|
|
|
case WXK_ESCAPE:
|
|
|
|
Close();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string allowed("0123456789.MKGHZmkghz");
|
|
|
|
|
2015-05-10 20:00:48 -04:00
|
|
|
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)) {
|
2015-06-07 21:42:23 -04:00
|
|
|
#ifdef __linux__
|
|
|
|
dialogText->OnChar(event);
|
|
|
|
event.Skip();
|
|
|
|
#else
|
2015-05-09 23:13:35 -04:00
|
|
|
event.DoAllowNextEvent();
|
2015-06-07 21:42:23 -04:00
|
|
|
#endif
|
2015-05-09 23:13:35 -04:00
|
|
|
} else if (event.ControlDown() && c == 'V') {
|
|
|
|
// Alter clipboard contents to remove unwanted chars
|
|
|
|
wxTheClipboard->Open();
|
|
|
|
wxTextDataObject data;
|
|
|
|
wxTheClipboard->GetData(data);
|
|
|
|
std::string clipText = data.GetText().ToStdString();
|
2015-05-10 01:07:48 -04:00
|
|
|
std::string pasteText = filterChars(clipText, std::string(allowed));
|
2015-05-09 23:13:35 -04:00
|
|
|
wxTheClipboard->SetData(new wxTextDataObject(pasteText));
|
|
|
|
wxTheClipboard->Close();
|
|
|
|
event.Skip();
|
|
|
|
} else if (c == WXK_RIGHT || c == WXK_LEFT || event.ControlDown()) {
|
|
|
|
event.Skip();
|
|
|
|
}
|
2015-05-04 19:44:03 -04:00
|
|
|
}
|