diff --git a/src/AppConfig.cpp b/src/AppConfig.cpp index a88353a..446aaac 100644 --- a/src/AppConfig.cpp +++ b/src/AppConfig.cpp @@ -10,54 +10,65 @@ DeviceConfig::DeviceConfig(std::string deviceId) : ppm(0) { } void DeviceConfig::setPPM(int ppm) { - this->ppm = ppm; + this->ppm.store(ppm); } int DeviceConfig::getPPM() { - return ppm; + return ppm.load(); } void DeviceConfig::setDirectSampling(int mode) { - directSampling = mode; + directSampling.store(mode); } int DeviceConfig::getDirectSampling() { - return directSampling; + return directSampling.load(); } void DeviceConfig::setOffset(long long offset) { - this->offset = offset; + this->offset.store(offset); } long long DeviceConfig::getOffset() { - return offset; + return offset.load(); } void DeviceConfig::setIQSwap(bool iqSwap) { - this->iqSwap = iqSwap; + this->iqSwap.store(iqSwap); } bool DeviceConfig::getIQSwap() { - return iqSwap; + return iqSwap.load(); } void DeviceConfig::setDeviceId(std::string deviceId) { + busy_lock.lock(); this->deviceId = deviceId; + busy_lock.unlock(); } std::string DeviceConfig::getDeviceId() { - return deviceId; + std::string tmp; + + busy_lock.lock(); + tmp = deviceId; + busy_lock.unlock(); + + return tmp; } void DeviceConfig::save(DataNode *node) { + busy_lock.lock(); *node->newChild("id") = deviceId; *node->newChild("ppm") = (int)ppm; *node->newChild("iq_swap") = iqSwap; *node->newChild("direct_sampling") = directSampling; *node->newChild("offset") = offset; + busy_lock.unlock(); } void DeviceConfig::load(DataNode *node) { + busy_lock.lock(); if (node->hasAnother("ppm")) { DataNode *ppm_node = node->getNext("ppm"); int ppmValue = 0; @@ -96,8 +107,9 @@ void DeviceConfig::load(DataNode *node) { long long offsetValue = 0; offset_node->element()->get(offsetValue); setOffset(offsetValue); - std::cout << "Loaded offset for device '" << deviceId << "' at " << offsetValue << "ppm" << std::endl; + std::cout << "Loaded offset for device '" << deviceId << "' at " << offsetValue << "Hz" << std::endl; } + busy_lock.unlock(); } diff --git a/src/AppConfig.h b/src/AppConfig.h index 8e55fd3..baebdff 100644 --- a/src/AppConfig.h +++ b/src/AppConfig.h @@ -3,10 +3,11 @@ #include #include #include +#include +#include #include "DataTree.h" - class DeviceConfig { public: DeviceConfig(); @@ -32,9 +33,11 @@ public: private: std::string deviceId; - int ppm, directSampling; - bool iqSwap; - long long offset; + std::mutex busy_lock; + + std::atomic ppm, directSampling; + std::atomic iqSwap; + std::atomic offset; }; class AppConfig { diff --git a/src/AppFrame.cpp b/src/AppFrame.cpp index 92bc87f..64365d1 100644 --- a/src/AppFrame.cpp +++ b/src/AppFrame.cpp @@ -319,8 +319,18 @@ AppFrame::AppFrame() : wxAcceleratorTable accel(3, entries); SetAcceleratorTable(accel); - SDRDeviceInfo *dev = (*wxGetApp().getDevices())[wxGetApp().getDevice()]; - DeviceConfig *devConfig = wxGetApp().getConfig()->getDevice(dev->getDeviceId()); +// static const int attribs[] = { WX_GL_RGBA, WX_GL_DOUBLEBUFFER, 0 }; +// wxLogStatus("Double-buffered display %s supported", wxGLCanvas::IsDisplaySupported(attribs) ? "is" : "not"); +// ShowFullScreen(true); +} + +AppFrame::~AppFrame() { + +} + + +void AppFrame::initDeviceParams(std::string deviceId) { + DeviceConfig *devConfig = wxGetApp().getConfig()->getDevice(deviceId); int dsMode = devConfig->getDirectSampling(); @@ -331,16 +341,8 @@ AppFrame::AppFrame() : if (devConfig->getIQSwap()) { iqSwapMenuItem->Check(); } - - -// static const int attribs[] = { WX_GL_RGBA, WX_GL_DOUBLEBUFFER, 0 }; -// wxLogStatus("Double-buffered display %s supported", wxGLCanvas::IsDisplaySupported(attribs) ? "is" : "not"); -// ShowFullScreen(true); } -AppFrame::~AppFrame() { - -} void AppFrame::OnMenu(wxCommandEvent& event) { if (event.GetId() >= wxID_RT_AUDIO_DEVICE && event.GetId() < wxID_RT_AUDIO_DEVICE + devices.size()) { diff --git a/src/AppFrame.h b/src/AppFrame.h index 751da2a..ebae67e 100644 --- a/src/AppFrame.h +++ b/src/AppFrame.h @@ -58,6 +58,7 @@ public: ~AppFrame(); void OnThread(wxCommandEvent& event); void OnEventInput(wxThreadEvent& event); + void initDeviceParams(std::string deviceId); void saveSession(std::string fileName); bool loadSession(std::string fileName); diff --git a/src/CubicSDR.cpp b/src/CubicSDR.cpp index 874d713..659e3e5 100644 --- a/src/CubicSDR.cpp +++ b/src/CubicSDR.cpp @@ -67,6 +67,7 @@ bool CubicSDR::OnInit() { std::vector::iterator devs_i; SDRThread::enumerate_rtl(&devs); + SDRDeviceInfo *dev = NULL; if (devs.size() > 1) { wxArrayString choices; @@ -78,6 +79,9 @@ bool CubicSDR::OnInit() { devName.append(" ["); devName.append((*devs_i)->getSerial()); devName.append("]"); + if (!dev) { + dev = (*devs_i); + } } else { devName.append(" (In Use?)"); } @@ -85,15 +89,24 @@ bool CubicSDR::OnInit() { } int devId = wxGetSingleChoiceIndex(wxT("Devices"), wxT("Choose Input Device"), choices); + dev = devs[devId]; - std::cout << "Chosen: " << devId << std::endl; sdrThread->setDeviceId(devId); + } else if (devs.size() == 1) { + dev = devs[0]; } t_PostSDR = new std::thread(&SDRPostThread::threadMain, sdrPostThread); t_SDR = new std::thread(&SDRThread::threadMain, sdrThread); appframe = new AppFrame(); + if (dev != NULL) { + appframe->initDeviceParams(dev->getDeviceId()); + DeviceConfig *devConfig = wxGetApp().getConfig()->getDevice(dev->getDeviceId()); + ppm = devConfig->getPPM(); + offset = devConfig->getOffset(); + directSamplingMode = devConfig->getDirectSampling(); + } #ifdef __APPLE__ int main_policy;