mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-23 06:09:50 -06:00
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.
This commit is contained in:
@ -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();
|
||||
{
|
||||
m_adapter_status->SetLabelText(_("Driver Not Detected"));
|
||||
gamecube_adapter->Disable();
|
||||
gamecube_adapter->SetValue(false);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
gamecube_adapter->SetValue(SConfig::GetInstance().m_GameCubeAdapter);
|
||||
if (Core::GetState() != Core::CORE_UNINITIALIZED)
|
||||
{
|
||||
gamecube_adapter->Disable();
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user