diff --git a/src/AppFrame.cpp b/src/AppFrame.cpp index 6532d0a..23628b1 100644 --- a/src/AppFrame.cpp +++ b/src/AppFrame.cpp @@ -121,23 +121,37 @@ AppFrame::AppFrame() : this->SetSizer(vbox); -// waterfallCanvas->SetFocusFromKbd(); + // waterfallCanvas->SetFocusFromKbd(); waterfallCanvas->SetFocus(); -// SetIcon(wxICON(sample)); + // SetIcon(wxICON(sample)); -// Make a menubar + // Make a menubar wxMenuBar *menuBar = new wxMenuBar; wxMenu *menu = new wxMenu; -// menu->Append(wxID_NEW); + menu->Append(wxID_SET_FREQ_OFFSET, "Set Frequency Offset"); menu->Append(wxID_SET_PPM, "Set Device PPM"); + + wxMenu *dsMenu = new wxMenu; + + dsMenu->AppendRadioItem(wxID_SET_DS_OFF, "Off"); + dsMenu->AppendRadioItem(wxID_SET_DS_I, "I-ADC"); + dsMenu->AppendRadioItem(wxID_SET_DS_Q, "Q-ADC"); + + menu->AppendSubMenu(dsMenu, "Direct Sampling"); + + wxMenu *sessionMenu = new wxMenu; + sessionMenu->Append(wxID_OPEN, "&Open Session"); + sessionMenu->Append(wxID_SAVE, "&Save Session"); + sessionMenu->Append(wxID_SAVEAS, "Save Session &As.."); + sessionMenu->AppendSeparator(); + sessionMenu->Append(wxID_RESET, "&Reset Session"); + + menu->AppendSubMenu(sessionMenu, "Session"); + menu->AppendSeparator(); - menu->Append(wxID_OPEN, "&Open Session"); - menu->Append(wxID_SAVE, "&Save Session"); - menu->Append(wxID_SAVEAS, "Save Session &As.."); - menu->AppendSeparator(); - menu->Append(wxID_RESET, "&Reset Session"); + menu->Append(wxID_CLOSE); menuBar->Append(menu, wxT("&File")); @@ -320,6 +334,12 @@ void AppFrame::OnMenu(wxCommandEvent& event) { if (ofs != -1) { wxGetApp().setOffset(ofs); } + } else if (event.GetId() == wxID_SET_DS_OFF) { + wxGetApp().setDirectSampling(0); + } else if (event.GetId() == wxID_SET_DS_I) { + wxGetApp().setDirectSampling(1); + } else if (event.GetId() == wxID_SET_DS_Q) { + wxGetApp().setDirectSampling(2); } else if (event.GetId() == wxID_SET_PPM) { long ofs = wxGetNumberFromUser("Frequency correction for device in PPM.\ni.e. -51 for -51 PPM\n\nNote: you can adjust PPM interactively\nby holding ALT over the frequency tuning bar.\n", "Parts per million (PPM)", "Frequency Correction", wxGetApp().getPPM(), -1000, 1000, this); diff --git a/src/AppFrame.h b/src/AppFrame.h index d5bb09a..8066701 100644 --- a/src/AppFrame.h +++ b/src/AppFrame.h @@ -16,6 +16,9 @@ #define wxID_SET_FREQ_OFFSET 2001 #define wxID_RESET 2002 #define wxID_SET_PPM 2003 +#define wxID_SET_DS_OFF 2004 +#define wxID_SET_DS_I 2005 +#define wxID_SET_DS_Q 2006 #define wxID_THEME_DEFAULT 2100 #define wxID_THEME_SHARP 2101 diff --git a/src/CubicSDR.cpp b/src/CubicSDR.cpp index fce7a96..35430cf 100644 --- a/src/CubicSDR.cpp +++ b/src/CubicSDR.cpp @@ -45,6 +45,7 @@ bool CubicSDR::OnInit() { frequency = DEFAULT_FREQ; offset = 0; ppm = 0; + directSamplingMode = 0; audioVisualQueue = new DemodulatorThreadOutputQueue(); audioVisualQueue->set_max_num_items(1); @@ -170,6 +171,17 @@ void CubicSDR::setOffset(long long ofs) { threadCmdQueueSDR->push(command); } +void CubicSDR::setDirectSampling(int mode) { + directSamplingMode = mode; + SDRThreadCommand command(SDRThreadCommand::SDR_THREAD_CMD_SET_DIRECT_SAMPLING); + command.llong_value = mode; + threadCmdQueueSDR->push(command); +} + +int CubicSDR::getDirectSampling() { + return directSamplingMode; +} + long long CubicSDR::getFrequency() { return frequency; } diff --git a/src/CubicSDR.h b/src/CubicSDR.h index 2d84af1..2536c0c 100644 --- a/src/CubicSDR.h +++ b/src/CubicSDR.h @@ -37,6 +37,9 @@ public: void setOffset(long long ofs); long long getOffset(); + void setDirectSampling(int mode); + int getDirectSampling(); + void setSampleRate(long long rate_in); long long getSampleRate(); @@ -74,6 +77,7 @@ private: long long offset; int ppm, snap; long long sampleRate; + int directSamplingMode; SDRThread *sdrThread; SDRPostThread *sdrPostThread; diff --git a/src/sdr/SDRThread.cpp b/src/sdr/SDRThread.cpp index 872525a..033bd24 100644 --- a/src/sdr/SDRThread.cpp +++ b/src/sdr/SDRThread.cpp @@ -140,6 +140,7 @@ void SDRThread::threadMain() { long long frequency = DEFAULT_FREQ; int ppm = wxGetApp().getConfig()->getDevice(devs[deviceId]->getDeviceId())->getPPM(); + int direct_sampling_mode = 0; rtlsdr_open(&dev, deviceId); rtlsdr_set_sample_rate(dev, sampleRate); @@ -170,6 +171,7 @@ void SDRThread::threadMain() { bool rate_changed = false; bool device_changed = false; bool ppm_changed = false; + bool direct_sampling_changed = false; long long new_freq = frequency; long long new_offset = offset; long long new_rate = sampleRate; @@ -209,6 +211,10 @@ void SDRThread::threadMain() { new_ppm = (int) command.llong_value; //std::cout << "Set PPM: " << new_ppm << std::endl; break; + case SDRThreadCommand::SDR_THREAD_CMD_SET_DIRECT_SAMPLING: + direct_sampling_mode = (int)command.llong_value; + direct_sampling_changed = true; + break; default: break; } @@ -222,6 +228,7 @@ void SDRThread::threadMain() { rtlsdr_set_freq_correction(dev, ppm); rtlsdr_set_agc_mode(dev, 1); rtlsdr_set_offset_tuning(dev, 0); + rtlsdr_set_direct_sampling(dev, direct_sampling_mode); rtlsdr_reset_buffer(dev); } if (offset_changed && !freq_changed) { @@ -241,6 +248,9 @@ void SDRThread::threadMain() { ppm = new_ppm; rtlsdr_set_freq_correction(dev, ppm); } + if (direct_sampling_changed) { + rtlsdr_set_direct_sampling(dev, direct_sampling_mode); + } } rtlsdr_read_sync(dev, buf, BUF_SIZE, &n_read); diff --git a/src/sdr/SDRThread.h b/src/sdr/SDRThread.h index 57e8523..135fb90 100644 --- a/src/sdr/SDRThread.h +++ b/src/sdr/SDRThread.h @@ -81,7 +81,7 @@ private: class SDRThreadCommand { public: enum SDRThreadCommandEnum { - SDR_THREAD_CMD_NULL, SDR_THREAD_CMD_TUNE, SDR_THREAD_CMD_SET_OFFSET, SDR_THREAD_CMD_SET_SAMPLERATE, SDR_THREAD_CMD_SET_PPM, SDR_THREAD_CMD_SET_DEVICE + SDR_THREAD_CMD_NULL, SDR_THREAD_CMD_TUNE, SDR_THREAD_CMD_SET_OFFSET, SDR_THREAD_CMD_SET_SAMPLERATE, SDR_THREAD_CMD_SET_PPM, SDR_THREAD_CMD_SET_DEVICE, SDR_THREAD_CMD_SET_DIRECT_SAMPLING }; SDRThreadCommand() :