From 9e7d4d2abbe62e2d4d6578e883effff18fed44c4 Mon Sep 17 00:00:00 2001 From: Vincent Duvert Date: Wed, 25 Jul 2018 21:44:57 +0200 Subject: [PATCH] GCAdapter: Handle dynamic status updates for non-hotplug libusb Detect when the setup function found no adapter, or found one but could not connect to it, and report the new status in that case. --- Source/Core/InputCommon/GCAdapter.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Source/Core/InputCommon/GCAdapter.cpp b/Source/Core/InputCommon/GCAdapter.cpp index a4a4cee5cf..2d990a213c 100644 --- a/Source/Core/InputCommon/GCAdapter.cpp +++ b/Source/Core/InputCommon/GCAdapter.cpp @@ -177,8 +177,6 @@ static void ScanThreadFunc() { std::lock_guard lk(s_init_mutex); Setup(); - if (s_status == ADAPTER_DETECTED && s_detect_callback != nullptr) - s_detect_callback(); } Common::SleepCurrentThread(500); } @@ -229,6 +227,12 @@ void StopScanThread() static void Setup() { + int prev_status = s_status; + + // Reset the error status in case the adapter gets unplugged + if (s_status < 0) + s_status = NO_ADAPTER_DETECTED; + for (int i = 0; i < SerialInterface::MAX_SI_CHANNELS; i++) { s_controller_type[i] = ControllerTypes::CONTROLLER_NONE; @@ -244,6 +248,9 @@ static void Setup() } return true; }); + + if (s_status != ADAPTER_DETECTED && prev_status != s_status && s_detect_callback != nullptr) + s_detect_callback(); } static bool CheckDeviceAccess(libusb_device* device)