Add 'Refresh' button to SDR Devices dialog

This commit is contained in:
Charles J. Cliffe 2016-01-17 21:54:22 -05:00
parent cec4f7aed1
commit 448455a69f
10 changed files with 146 additions and 12 deletions

View File

@ -487,6 +487,26 @@ void CubicSDR::setSampleRate(long long rate_in) {
}
}
void CubicSDR::stopDevice() {
sdrThread->setDevice(nullptr);
if (!sdrThread->isTerminated()) {
sdrThread->terminate();
if (t_SDR) {
t_SDR->join();
delete t_SDR;
t_SDR = nullptr;
}
}
}
void CubicSDR::reEnumerateDevices() {
devicesReady.store(false);
devs = nullptr;
SDREnumerator::reset();
t_SDREnum = new std::thread(&SDREnumerator::threadMain, sdrEnum);
}
void CubicSDR::setDevice(SDRDeviceInfo *dev) {
if (!sdrThread->isTerminated()) {
sdrThread->terminate();
@ -512,14 +532,6 @@ void CubicSDR::setDevice(SDRDeviceInfo *dev) {
freqHigh = chan->getRFRange().getHigh();
freqLow = chan->getRFRange().getLow();
// upconverter settings don't like this, need to handle elsewhere..
// if (frequency > freqHigh) {
// frequency = freqHigh;
// }
// else if (frequency < freqLow) {
// frequency = freqLow;
// }
// Try for a reasonable default sample rate.
if (!sampleRateInitialized.load()) {
sampleRate = chan->getSampleRateNear(DEFAULT_SAMPLE_RATE);

View File

@ -97,6 +97,7 @@ public:
std::vector<SDRDeviceInfo *> *getDevices();
void setDevice(SDRDeviceInfo *dev);
void stopDevice();
SDRDeviceInfo * getDevice();
ScopeVisualProcessor *getScopeProcessor();
@ -136,7 +137,8 @@ public:
void removeRemote(std::string remoteAddr);
void setDeviceSelectorClosed();
bool isDeviceSelectorOpen();
void reEnumerateDevices();
bool isDeviceSelectorOpen();
void closeDeviceSelector();
void setAGCMode(bool mode);

View File

@ -8,11 +8,11 @@
SDRDevicesDialog::SDRDevicesDialog( wxWindow* parent ): devFrame( parent ) {
refresh = true;
failed = false;
m_refreshButton->Disable();
m_addRemoteButton->Disable();
m_useSelectedButton->Disable();
m_deviceTimer.Start(250);
}
}
void SDRDevicesDialog::OnClose( wxCloseEvent& event ) {
wxGetApp().setDeviceSelectorClosed();
@ -284,6 +284,7 @@ void SDRDevicesDialog::OnDeviceTimer( wxTimerEvent& event ) {
}
}
m_refreshButton->Enable();
m_addRemoteButton->Enable();
m_useSelectedButton->Enable();
devTree->Enable();
@ -293,4 +294,15 @@ void SDRDevicesDialog::OnDeviceTimer( wxTimerEvent& event ) {
refresh = false;
}
}
void SDRDevicesDialog::OnRefreshDevices( wxMouseEvent& event ) {
wxGetApp().stopDevice();
devTree->DeleteAllItems();
devTree->Disable();
m_refreshButton->Disable();
m_addRemoteButton->Disable();
m_useSelectedButton->Disable();
wxGetApp().reEnumerateDevices();
refresh = true;
}

View File

@ -490,6 +490,94 @@
<property name="name">bSizer5</property>
<property name="orient">wxHORIZONTAL</property>
<property name="permission">none</property>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxALL</property>
<property name="proportion">0</property>
<object class="wxButton" expanded="1">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
<property name="RightDockable">1</property>
<property name="TopDockable">1</property>
<property name="aui_layer"></property>
<property name="aui_name"></property>
<property name="aui_position"></property>
<property name="aui_row"></property>
<property name="best_size"></property>
<property name="bg"></property>
<property name="caption"></property>
<property name="caption_visible">1</property>
<property name="center_pane">0</property>
<property name="close_button">1</property>
<property name="context_help"></property>
<property name="context_menu">1</property>
<property name="default">0</property>
<property name="default_pane">0</property>
<property name="dock">Dock</property>
<property name="dock_fixed">0</property>
<property name="docking">Left</property>
<property name="enabled">1</property>
<property name="fg"></property>
<property name="floatable">1</property>
<property name="font"></property>
<property name="gripper">0</property>
<property name="hidden">0</property>
<property name="id">wxID_ANY</property>
<property name="label">Refresh</property>
<property name="max_size"></property>
<property name="maximize_button">0</property>
<property name="maximum_size"></property>
<property name="min_size"></property>
<property name="minimize_button">0</property>
<property name="minimum_size"></property>
<property name="moveable">1</property>
<property name="name">m_refreshButton</property>
<property name="pane_border">1</property>
<property name="pane_position"></property>
<property name="pane_size"></property>
<property name="permission">protected</property>
<property name="pin_button">1</property>
<property name="pos"></property>
<property name="resize">Resizable</property>
<property name="show">1</property>
<property name="size"></property>
<property name="style"></property>
<property name="subclass"></property>
<property name="toolbar_pane">0</property>
<property name="tooltip"></property>
<property name="validator_data_type"></property>
<property name="validator_style">wxFILTER_NONE</property>
<property name="validator_type">wxDefaultValidator</property>
<property name="validator_variable"></property>
<property name="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style"></property>
<event name="OnButtonClick"></event>
<event name="OnChar"></event>
<event name="OnEnterWindow"></event>
<event name="OnEraseBackground"></event>
<event name="OnKeyDown"></event>
<event name="OnKeyUp"></event>
<event name="OnKillFocus"></event>
<event name="OnLeaveWindow"></event>
<event name="OnLeftDClick"></event>
<event name="OnLeftDown"></event>
<event name="OnLeftUp">OnRefreshDevices</event>
<event name="OnMiddleDClick"></event>
<event name="OnMiddleDown"></event>
<event name="OnMiddleUp"></event>
<event name="OnMotion"></event>
<event name="OnMouseEvents"></event>
<event name="OnMouseWheel"></event>
<event name="OnPaint"></event>
<event name="OnRightDClick"></event>
<event name="OnRightDown"></event>
<event name="OnRightUp"></event>
<event name="OnSetFocus"></event>
<event name="OnSize"></event>
<event name="OnUpdateUI"></event>
</object>
</object>
<object class="sizeritem" expanded="0">
<property name="border">5</property>
<property name="flag">wxALL</property>

View File

@ -18,6 +18,7 @@ public:
void OnUseSelected( wxMouseEvent& event );
void OnTreeDoubleClick( wxMouseEvent& event );
void OnDeviceTimer( wxTimerEvent& event );
void OnRefreshDevices( wxMouseEvent& event );
private:
SDRDeviceInfo *getSelectedDevice(wxTreeItemId selId);

View File

@ -34,6 +34,9 @@ devFrame::devFrame( wxWindow* parent, wxWindowID id, const wxString& title, cons
wxBoxSizer* bSizer5;
bSizer5 = new wxBoxSizer( wxHORIZONTAL );
m_refreshButton = new wxButton( m_panel4, wxID_ANY, wxT("Refresh"), wxDefaultPosition, wxDefaultSize, 0 );
bSizer5->Add( m_refreshButton, 0, wxALL, 5 );
m_addRemoteButton = new wxButton( m_panel4, wxID_ANY, wxT("Add Remote"), wxDefaultPosition, wxDefaultSize, 0 );
bSizer5->Add( m_addRemoteButton, 1, wxALL, 5 );
@ -87,6 +90,7 @@ devFrame::devFrame( wxWindow* parent, wxWindowID id, const wxString& title, cons
devTree->Connect( wxEVT_LEFT_DCLICK, wxMouseEventHandler( devFrame::OnTreeDoubleClick ), NULL, this );
devTree->Connect( wxEVT_COMMAND_TREE_DELETE_ITEM, wxTreeEventHandler( devFrame::OnDeleteItem ), NULL, this );
devTree->Connect( wxEVT_COMMAND_TREE_SEL_CHANGED, wxTreeEventHandler( devFrame::OnSelectionChanged ), NULL, this );
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 );
this->Connect( wxID_ANY, wxEVT_TIMER, wxTimerEventHandler( devFrame::OnDeviceTimer ) );
@ -99,6 +103,7 @@ devFrame::~devFrame()
devTree->Disconnect( wxEVT_LEFT_DCLICK, wxMouseEventHandler( devFrame::OnTreeDoubleClick ), NULL, this );
devTree->Disconnect( wxEVT_COMMAND_TREE_DELETE_ITEM, wxTreeEventHandler( devFrame::OnDeleteItem ), NULL, this );
devTree->Disconnect( wxEVT_COMMAND_TREE_SEL_CHANGED, wxTreeEventHandler( devFrame::OnSelectionChanged ), NULL, this );
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 );
this->Disconnect( wxID_ANY, wxEVT_TIMER, wxTimerEventHandler( devFrame::OnDeviceTimer ) );

View File

@ -45,6 +45,7 @@ class devFrame : public wxFrame
wxPanel* m_panel6;
wxTreeCtrl* devTree;
wxPanel* m_panel4;
wxButton* m_refreshButton;
wxButton* m_addRemoteButton;
wxButton* m_useSelectedButton;
wxPanel* m_panel61;
@ -57,6 +58,7 @@ class devFrame : public wxFrame
virtual void OnTreeDoubleClick( wxMouseEvent& event ) { event.Skip(); }
virtual void OnDeleteItem( wxTreeEvent& event ) { event.Skip(); }
virtual void OnSelectionChanged( wxTreeEvent& event ) { event.Skip(); }
virtual void OnRefreshDevices( wxMouseEvent& event ) { event.Skip(); }
virtual void OnAddRemote( wxMouseEvent& event ) { event.Skip(); }
virtual void OnUseSelected( wxMouseEvent& event ) { event.Skip(); }
virtual void OnDeviceTimer( wxTimerEvent& event ) { event.Skip(); }

View File

@ -326,3 +326,10 @@ std::vector<std::string> &SDREnumerator::getRemotes() {
bool SDREnumerator::hasRemoteModule() {
return SDREnumerator::has_remote;
}
void SDREnumerator::reset() {
soapy_initialized = false;
factories.erase(factories.begin(), factories.end());
modules.erase(modules.begin(), modules.end());
devs.erase(devs.begin(), devs.end());
}

View File

@ -29,6 +29,7 @@ public:
static void removeRemote(std::string remoteAddr);
static std::vector<std::string> &getRemotes();
static bool hasRemoteModule();
static void reset();
protected:
static bool soapy_initialized, has_remote;

View File

@ -337,7 +337,11 @@ SDRDeviceInfo *SDRThread::getDevice() {
void SDRThread::setDevice(SDRDeviceInfo *dev) {
deviceInfo.store(dev);
deviceConfig.store(wxGetApp().getConfig()->getDevice(dev->getDeviceId()));
if (dev) {
deviceConfig.store(wxGetApp().getConfig()->getDevice(dev->getDeviceId()));
} else {
deviceConfig.store(nullptr);
}
}
int SDRThread::getOptimalElementCount(long long sampleRate, int fps) {