Fix refresh, allow device dialog to update active device

This commit is contained in:
Charles J. Cliffe 2016-02-02 20:05:32 -05:00
parent 2518e22682
commit cc189cc274
4 changed files with 28 additions and 10 deletions

View File

@ -408,7 +408,11 @@ void SDRDevicesDialog::OnPropGridChanged( wxPropertyGridEvent& event ) {
for (std::map<std::string, wxPGProperty *>::iterator rtp = runtimeProps.begin(); rtp != runtimeProps.end(); rtp++) {
if (rtp->second == prop) {
SoapySDR::Device *soapyDev = dev->getSoapyDevice();
soapyDev->writeSetting(rtp->first, prop->GetValueAsString().ToStdString());
std::string settingValue = prop->GetValueAsString().ToStdString();
soapyDev->writeSetting(rtp->first, settingValue);
if (dev->isActive()) {
wxGetApp().getSDRThread()->writeSetting(rtp->first, settingValue);
}
refreshDeviceProperties();
return;
}
@ -422,6 +426,10 @@ void SDRDevicesDialog::OnPropGridFocus( wxFocusEvent& /* event */) {
void SDRDevicesDialog::doRefreshDevices() {
selId = nullptr;
editId = nullptr;
removeId = nullptr;
dev = nullptr;
wxGetApp().stopDevice();
devTree->DeleteAllItems();
devTree->Disable();
@ -433,10 +441,6 @@ void SDRDevicesDialog::doRefreshDevices() {
m_addRemoteButton->Disable();
m_useSelectedButton->Disable();
wxGetApp().reEnumerateDevices();
selId = nullptr;
editId = nullptr;
removeId = nullptr;
dev = nullptr;
refresh = true;
m_addRemoteButton->SetLabel("Add");
}

View File

@ -1,7 +1,7 @@
#include "SDRDeviceInfo.h"
#include <cstdlib>
SDRDeviceInfo::SDRDeviceInfo() : name(""), serial(""), available(false), remote(false), manual(false), soapyDevice(nullptr) {
SDRDeviceInfo::SDRDeviceInfo() : name(""), serial(""), available(false), remote(false), manual(false), active(false), soapyDevice(nullptr) {
}
@ -37,6 +37,14 @@ void SDRDeviceInfo::setAvailable(bool available) {
this->available = available;
}
bool SDRDeviceInfo::isActive() const {
return active.load();
}
void SDRDeviceInfo::setActive(bool active) {
this->active.store(active);
}
const std::string& SDRDeviceInfo::getName() const {
return name;
}

View File

@ -25,7 +25,10 @@ public:
bool isAvailable() const;
void setAvailable(bool available);
bool isActive() const;
void setActive(bool active);
const std::string& getName() const;
void setName(const std::string& name);
@ -86,6 +89,7 @@ private:
std::string name, serial, product, manufacturer, tuner;
std::string driver, hardware, manual_params;
bool timestamps, available, remote, manual;
std::atomic_bool active;
SoapySDR::Kwargs deviceArgs, streamArgs;
SoapySDR::Device *soapyDevice;

View File

@ -146,10 +146,8 @@ void SDRThread::init() {
}
void SDRThread::deinit() {
SDRDeviceInfo *devInfo = deviceInfo.load();
device->deactivateStream(stream);
device->closeStream(stream);
devInfo->setSoapyDevice(nullptr);
free(buffs[0]);
}
@ -353,11 +351,15 @@ void SDRThread::run() {
std::cout << "SDR thread starting." << std::endl;
terminated.store(false);
if (deviceInfo.load() != NULL) {
SDRDeviceInfo *activeDev = deviceInfo.load();
if (activeDev != NULL) {
std::cout << "device init()" << std::endl;
init();
std::cout << "starting readLoop()" << std::endl;
activeDev->setActive(true);
readLoop();
activeDev->setActive(false);
std::cout << "readLoop() ended." << std::endl;
deinit();
std::cout << "device deinit()" << std::endl;