From 19bf41596b6b7eccb76fab0bc910ed9f45d894c4 Mon Sep 17 00:00:00 2001 From: "Charles J. Cliffe" Date: Mon, 18 Jan 2016 20:46:56 -0500 Subject: [PATCH] Device name/offset edit in SDR Devices dialog --- src/AppConfig.cpp | 20 +++++++ src/AppConfig.h | 4 ++ src/forms/SDRDevices/SDRDevices.cpp | 73 +++++++++++++++++++------ src/forms/SDRDevices/SDRDevices.h | 3 + src/forms/SDRDevices/SDRDevicesForm.cpp | 2 + src/forms/SDRDevices/SDRDevicesForm.h | 1 + 6 files changed, 86 insertions(+), 17 deletions(-) diff --git a/src/AppConfig.cpp b/src/AppConfig.cpp index ae110d1..91ecde9 100644 --- a/src/AppConfig.cpp +++ b/src/AppConfig.cpp @@ -42,9 +42,26 @@ std::string DeviceConfig::getDeviceId() { return tmp; } +void DeviceConfig::setDeviceName(std::string deviceName) { + busy_lock.lock(); + this->deviceName = deviceName; + busy_lock.unlock(); +} + +std::string DeviceConfig::getDeviceName() { + std::string tmp; + + busy_lock.lock(); + tmp = (deviceName=="")?deviceId:deviceName; + busy_lock.unlock(); + + return tmp; +} + void DeviceConfig::save(DataNode *node) { busy_lock.lock(); *node->newChild("id") = deviceId; + *node->newChild("name") = deviceName; *node->newChild("ppm") = (int)ppm; *node->newChild("offset") = offset; DataNode *streamOptsNode = node->newChild("streamOpts"); @@ -66,6 +83,9 @@ void DeviceConfig::save(DataNode *node) { void DeviceConfig::load(DataNode *node) { busy_lock.lock(); + if (node->hasAnother("name")) { + deviceName = node->getNext("name")->element()->toString(); + } if (node->hasAnother("ppm")) { DataNode *ppm_node = node->getNext("ppm"); int ppmValue = 0; diff --git a/src/AppConfig.h b/src/AppConfig.h index b7e7f7c..fc35f81 100644 --- a/src/AppConfig.h +++ b/src/AppConfig.h @@ -25,6 +25,9 @@ public: void setDeviceId(std::string deviceId); std::string getDeviceId(); + void setDeviceName(std::string deviceName); + std::string getDeviceName(); + void setStreamOpts(ConfigSettings opts); ConfigSettings getStreamOpts(); void setStreamOpt(std::string key, std::string value); @@ -43,6 +46,7 @@ public: private: std::string deviceId; + std::string deviceName; std::mutex busy_lock; std::atomic_int ppm; diff --git a/src/forms/SDRDevices/SDRDevices.cpp b/src/forms/SDRDevices/SDRDevices.cpp index b32371c..24c11dd 100644 --- a/src/forms/SDRDevices/SDRDevices.cpp +++ b/src/forms/SDRDevices/SDRDevices.cpp @@ -12,6 +12,7 @@ SDRDevicesDialog::SDRDevicesDialog( wxWindow* parent ): devFrame( parent ) { m_addRemoteButton->Disable(); m_useSelectedButton->Disable(); m_deviceTimer.Start(250); + selId = 0; } void SDRDevicesDialog::OnClose( wxCloseEvent& event ) { @@ -91,21 +92,31 @@ wxPGProperty *SDRDevicesDialog::addArgInfoProperty(wxPropertyGrid *pg, SoapySDR: } void SDRDevicesDialog::OnSelectionChanged( wxTreeEvent& event ) { - wxTreeItemId selId = devTree->GetSelection(); - dev = getSelectedDevice(selId); - props.erase(props.begin(), props.end()); - if (dev) { + SDRDeviceInfo *selDev = getSelectedDevice(devTree->GetSelection()); + if (selDev) { + dev = selDev; + selId = devTree->GetSelection(); + DeviceConfig *devConfig = wxGetApp().getConfig()->getDevice(dev->getName()); m_propertyGrid->Clear(); - m_propertyGrid->Append(new wxPropertyCategory("Run-time Settings")); - - SoapySDR::ArgInfoList::const_iterator args_i; SoapySDR::ArgInfoList args = dev->getSettingsArgInfo(); + SoapySDR::ArgInfoList::const_iterator args_i; + + m_propertyGrid->Append(new wxPropertyCategory("General Settings")); - for (args_i = args.begin(); args_i != args.end(); args_i++) { - SoapySDR::ArgInfo arg = (*args_i); - props.push_back(addArgInfoProperty(m_propertyGrid, arg)); + devSettings.erase(devSettings.begin(),devSettings.end()); + devSettings["name"] = m_propertyGrid->Append( new wxStringProperty("Name", wxPG_LABEL, devConfig->getDeviceName()) ); + devSettings["offset"] = m_propertyGrid->Append( new wxIntProperty("Offset (Hz)", wxPG_LABEL, devConfig->getOffset()) ); + + if (args.size()) { + m_propertyGrid->Append(new wxPropertyCategory("Run-time Settings")); + + + for (args_i = args.begin(); args_i != args.end(); args_i++) { + SoapySDR::ArgInfo arg = (*args_i); + props.push_back(addArgInfoProperty(m_propertyGrid, arg)); + } } if (dev->getRxChannel()) { @@ -165,9 +176,6 @@ SDRDeviceInfo *SDRDevicesDialog::getSelectedDevice(wxTreeItemId selId) { } void SDRDevicesDialog::OnUseSelected( wxMouseEvent& event ) { - wxTreeItemId selId = devTree->GetSelection(); - - dev = getSelectedDevice(selId); if (dev != NULL) { int i = 0; @@ -259,10 +267,11 @@ void SDRDevicesDialog::OnDeviceTimer( wxTimerEvent& event ) { devs[""] = SDREnumerator::enumerate_devices("",true); if (devs[""] != NULL) { for (devs_i = devs[""]->begin(); devs_i != devs[""]->end(); devs_i++) { + DeviceConfig *devConfig = wxGetApp().getConfig()->getDevice((*devs_i)->getDeviceId()); if ((*devs_i)->isRemote()) { - devItems[devTree->AppendItem(dsBranch, (*devs_i)->getName())] = (*devs_i); + devItems[devTree->AppendItem(dsBranch, devConfig->getDeviceName())] = (*devs_i); } else { - devItems[devTree->AppendItem(localBranch, (*devs_i)->getName())] = (*devs_i); + devItems[devTree->AppendItem(localBranch, devConfig->getDeviceName())] = (*devs_i); } } } @@ -274,7 +283,9 @@ void SDRDevicesDialog::OnDeviceTimer( wxTimerEvent& event ) { if (remotes.size()) { for (remotes_i = remotes.begin(); remotes_i != remotes.end(); remotes_i++) { devs[*remotes_i] = SDREnumerator::enumerate_devices(*remotes_i, true); - wxTreeItemId remoteNode = devTree->AppendItem(remoteBranch, *remotes_i); + DeviceConfig *devConfig = wxGetApp().getConfig()->getDevice(*remotes_i); + + wxTreeItemId remoteNode = devTree->AppendItem(remoteBranch, devConfig->getDeviceName()); if (devs[*remotes_i] != NULL) { for (remoteDevs_i = devs[*remotes_i]->begin(); remoteDevs_i != devs[*remotes_i]->end(); remoteDevs_i++) { @@ -300,9 +311,37 @@ void SDRDevicesDialog::OnRefreshDevices( wxMouseEvent& event ) { wxGetApp().stopDevice(); devTree->DeleteAllItems(); devTree->Disable(); + m_propertyGrid->Clear(); + props.erase(props.begin(),props.end()); + devSettings.erase(devSettings.begin(), devSettings.end()); m_refreshButton->Disable(); m_addRemoteButton->Disable(); m_useSelectedButton->Disable(); wxGetApp().reEnumerateDevices(); + selId = 0; + dev = nullptr; refresh = true; -} \ No newline at end of file +} + +void SDRDevicesDialog::OnPropGridChanged( wxPropertyGridEvent& event ) { + if (dev && event.GetProperty() == devSettings["name"]) { + DeviceConfig *devConfig = wxGetApp().getConfig()->getDevice(dev->getDeviceId()); + + wxString devName = event.GetPropertyValue().GetString(); + + devConfig->setDeviceName(devName.ToStdString()); + if (selId) { + devTree->SetItemText(selId, devConfig->getDeviceName()); + } + if (devName == "") { + event.GetProperty()->SetValueFromString(devConfig->getDeviceName()); + } + } + if (dev && event.GetProperty() == devSettings["offset"]) { + DeviceConfig *devConfig = wxGetApp().getConfig()->getDevice(dev->getDeviceId()); + + long offset = event.GetPropertyValue().GetInteger(); + + devConfig->setOffset(offset); + } +} diff --git a/src/forms/SDRDevices/SDRDevices.h b/src/forms/SDRDevices/SDRDevices.h index c3b99ad..02f68f9 100644 --- a/src/forms/SDRDevices/SDRDevices.h +++ b/src/forms/SDRDevices/SDRDevices.h @@ -19,6 +19,7 @@ public: void OnTreeDoubleClick( wxMouseEvent& event ); void OnDeviceTimer( wxTimerEvent& event ); void OnRefreshDevices( wxMouseEvent& event ); + void OnPropGridChanged( wxPropertyGridEvent& event ); private: SDRDeviceInfo *getSelectedDevice(wxTreeItemId selId); @@ -31,4 +32,6 @@ private: std::map::iterator devItems_i; SDRDeviceInfo *dev = NULL; std::vector props; + std::map devSettings; + wxTreeItemId selId; }; \ No newline at end of file diff --git a/src/forms/SDRDevices/SDRDevicesForm.cpp b/src/forms/SDRDevices/SDRDevicesForm.cpp index 1a82b2a..061cee1 100644 --- a/src/forms/SDRDevices/SDRDevicesForm.cpp +++ b/src/forms/SDRDevices/SDRDevicesForm.cpp @@ -93,6 +93,7 @@ devFrame::devFrame( wxWindow* parent, wxWindowID id, const wxString& title, cons m_refreshButton->Connect( wxEVT_LEFT_UP, wxMouseEventHandler( devFrame::OnRefreshDevices ), NULL, this ); m_addRemoteButton->Connect( wxEVT_LEFT_UP, wxMouseEventHandler( devFrame::OnAddRemote ), NULL, this ); m_useSelectedButton->Connect( wxEVT_LEFT_UP, wxMouseEventHandler( devFrame::OnUseSelected ), NULL, this ); + m_propertyGrid->Connect( wxEVT_PG_CHANGED, wxPropertyGridEventHandler( devFrame::OnPropGridChanged ), NULL, this ); this->Connect( wxID_ANY, wxEVT_TIMER, wxTimerEventHandler( devFrame::OnDeviceTimer ) ); } @@ -106,6 +107,7 @@ devFrame::~devFrame() m_refreshButton->Disconnect( wxEVT_LEFT_UP, wxMouseEventHandler( devFrame::OnRefreshDevices ), NULL, this ); m_addRemoteButton->Disconnect( wxEVT_LEFT_UP, wxMouseEventHandler( devFrame::OnAddRemote ), NULL, this ); m_useSelectedButton->Disconnect( wxEVT_LEFT_UP, wxMouseEventHandler( devFrame::OnUseSelected ), NULL, this ); + m_propertyGrid->Disconnect( wxEVT_PG_CHANGED, wxPropertyGridEventHandler( devFrame::OnPropGridChanged ), NULL, this ); this->Disconnect( wxID_ANY, wxEVT_TIMER, wxTimerEventHandler( devFrame::OnDeviceTimer ) ); } diff --git a/src/forms/SDRDevices/SDRDevicesForm.h b/src/forms/SDRDevices/SDRDevicesForm.h index cb9f9a1..885677e 100644 --- a/src/forms/SDRDevices/SDRDevicesForm.h +++ b/src/forms/SDRDevices/SDRDevicesForm.h @@ -61,6 +61,7 @@ class devFrame : public wxFrame virtual void OnRefreshDevices( wxMouseEvent& event ) { event.Skip(); } virtual void OnAddRemote( wxMouseEvent& event ) { event.Skip(); } virtual void OnUseSelected( wxMouseEvent& event ) { event.Skip(); } + virtual void OnPropGridChanged( wxPropertyGridEvent& event ) { event.Skip(); } virtual void OnDeviceTimer( wxTimerEvent& event ) { event.Skip(); }