diff options
| author | mathieui <mathieui@mathieui.net> | 2015-04-26 23:53:36 +0200 |
|---|---|---|
| committer | mathieui <mathieui@mathieui.net> | 2015-04-30 11:35:16 +0200 |
| commit | 57f458fe9bc380db1cf811cc8289490b9afaa93f (patch) | |
| tree | 73204c46014fae69ff1c0157f43b3b36f0e708f2 /Source/Core/DolphinWX/ControllerConfigDiag.cpp | |
| parent | 989c0f427fe70dfedcac8a8cadcc8c677f7c2044 (diff) | |
GCAdapter: Add a background thread to detect the adapter
This scanning thread either polls libusb or checks every 500ms for a
change depending on host capabilities. The GC Adapter can now be plugged
and unplugged at any time when dolphin is open, it will be used if the
direct connect option is set.
Diffstat (limited to 'Source/Core/DolphinWX/ControllerConfigDiag.cpp')
| -rw-r--r-- | Source/Core/DolphinWX/ControllerConfigDiag.cpp | 49 |
1 files changed, 38 insertions, 11 deletions
diff --git a/Source/Core/DolphinWX/ControllerConfigDiag.cpp b/Source/Core/DolphinWX/ControllerConfigDiag.cpp index 6f3ae906f5..b78d8a526e 100644 --- a/Source/Core/DolphinWX/ControllerConfigDiag.cpp +++ b/Source/Core/DolphinWX/ControllerConfigDiag.cpp @@ -52,6 +52,8 @@ const std::array<wxString, 8> ControllerConfigDiag::m_gc_pad_type_strs = {{ _("AM-Baseboard") }}; +wxDEFINE_EVENT(wxEVT_ADAPTER_UPDATE, wxCommandEvent); + ControllerConfigDiag::ControllerConfigDiag(wxWindow* const parent) : wxDialog(parent, wxID_ANY, _("Dolphin Controller Configuration")) { @@ -71,6 +73,7 @@ ControllerConfigDiag::ControllerConfigDiag(wxWindow* const parent) SetLayoutAdaptationMode(wxDIALOG_ADAPTATION_MODE_ENABLED); SetSizerAndFit(main_sizer); Center(); + Bind(wxEVT_ADAPTER_UPDATE, &ControllerConfigDiag::UpdateAdapter, this); } wxStaticBoxSizer* ControllerConfigDiag::CreateGamecubeSizer() @@ -147,39 +150,58 @@ wxStaticBoxSizer* ControllerConfigDiag::CreateGamecubeSizer() gamecube_static_sizer->Add(gamecube_flex_sizer, 1, wxEXPAND, 5); gamecube_static_sizer->AddSpacer(5); - wxStaticBoxSizer* const gamecube_adapter_group = new wxStaticBoxSizer(wxHORIZONTAL, this, _("GameCube Adapter")); + wxStaticBoxSizer* const gamecube_adapter_group = new wxStaticBoxSizer(wxVERTICAL, this, _("GameCube Adapter")); wxBoxSizer* const gamecube_adapter_sizer = new wxBoxSizer(wxHORIZONTAL); wxCheckBox* const gamecube_adapter = new wxCheckBox(this, wxID_ANY, _("Direct Connect")); gamecube_adapter->Bind(wxEVT_CHECKBOX, &ControllerConfigDiag::OnGameCubeAdapter, this); + m_adapter_status = new wxStaticText(this, wxID_ANY, _("Adapter Not Detected")); + gamecube_adapter_sizer->Add(m_adapter_status, 0, wxEXPAND); gamecube_adapter_sizer->Add(gamecube_adapter, 0, wxEXPAND); gamecube_adapter_group->Add(gamecube_adapter_sizer, 0, wxEXPAND); gamecube_static_sizer->Add(gamecube_adapter_group, 0, wxEXPAND); #if defined(__LIBUSB__) || defined (_WIN32) + gamecube_adapter->SetValue(SConfig::GetInstance().m_GameCubeAdapter); if (!SI_GCAdapter::IsDetected()) { if (!SI_GCAdapter::IsDriverDetected()) - gamecube_adapter->SetLabelText(_("Driver Not Detected")); - else - gamecube_adapter->SetLabelText(_("Adapter Not Detected")); - gamecube_adapter->SetValue(false); - gamecube_adapter->Disable(); - } - else - { - gamecube_adapter->SetValue(SConfig::GetInstance().m_GameCubeAdapter); - if (Core::GetState() != Core::CORE_UNINITIALIZED) { + m_adapter_status->SetLabelText(_("Driver Not Detected")); gamecube_adapter->Disable(); + gamecube_adapter->SetValue(false); } } + else + { + m_adapter_status->SetLabelText(_("Adapter Detected")); + } + if (Core::GetState() != Core::CORE_UNINITIALIZED) + { + gamecube_adapter->Disable(); + } + SI_GCAdapter::SetAdapterCallback(std::bind(&ControllerConfigDiag::ScheduleAdapterUpdate, this)); #endif return gamecube_static_sizer; } +void ControllerConfigDiag::ScheduleAdapterUpdate() +{ + wxQueueEvent(this, new wxCommandEvent(wxEVT_ADAPTER_UPDATE)); +} + +void ControllerConfigDiag::UpdateAdapter(wxCommandEvent& ev) +{ + bool unpause = Core::PauseAndLock(true); + if (SI_GCAdapter::IsDetected()) + m_adapter_status->SetLabelText(_("Adapter Detected")); + else + m_adapter_status->SetLabelText(_("Adapter Not Detected")); + Core::PauseAndLock(false, unpause); +} + wxStaticBoxSizer* ControllerConfigDiag::CreateWiimoteConfigSizer() { wxStaticText* wiimote_label[4]; @@ -537,3 +559,8 @@ void ControllerConfigDiag::OnGameCubeConfigButton(wxCommandEvent& event) HotkeyManagerEmu::Enable(true); } + +ControllerConfigDiag::~ControllerConfigDiag() +{ + SI_GCAdapter::SetAdapterCallback(nullptr); +} |
