mirror of
https://github.com/cjcliffe/CubicSDR.git
synced 2024-11-10 06:18:57 -05:00
Device name/offset edit in SDR Devices dialog
This commit is contained in:
parent
448455a69f
commit
19bf41596b
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
||||
for (args_i = args.begin(); args_i != args.end(); args_i++) {
|
||||
SoapySDR::ArgInfo arg = (*args_i);
|
||||
props.push_back(addArgInfoProperty(m_propertyGrid, arg));
|
||||
m_propertyGrid->Append(new wxPropertyCategory("General Settings"));
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -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<wxTreeItemId, SDRDeviceInfo *>::iterator devItems_i;
|
||||
SDRDeviceInfo *dev = NULL;
|
||||
std::vector<wxPGProperty *> props;
|
||||
std::map<std::string, wxPGProperty *> devSettings;
|
||||
wxTreeItemId selId;
|
||||
};
|
@ -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 ) );
|
||||
|
||||
}
|
||||
|
@ -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(); }
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user