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.
This commit is contained in:
Vincent Duvert 2018-07-25 21:44:57 +02:00
parent 2ac1ca133f
commit 9e7d4d2abb
1 changed files with 9 additions and 2 deletions

View File

@ -177,8 +177,6 @@ static void ScanThreadFunc()
{
std::lock_guard<std::mutex> 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)