diff options
Diffstat (limited to 'src/input_common')
| -rw-r--r-- | src/input_common/gcadapter/gc_adapter.cpp | 39 | ||||
| -rw-r--r-- | src/input_common/gcadapter/gc_adapter.h | 1 |
2 files changed, 30 insertions, 10 deletions
diff --git a/src/input_common/gcadapter/gc_adapter.cpp b/src/input_common/gcadapter/gc_adapter.cpp index f1c280e2e..38cf02f7e 100644 --- a/src/input_common/gcadapter/gc_adapter.cpp +++ b/src/input_common/gcadapter/gc_adapter.cpp | |||
| @@ -24,10 +24,14 @@ Adapter::Adapter() { | |||
| 24 | LOG_INFO(Input, "GC Adapter Initialization started"); | 24 | LOG_INFO(Input, "GC Adapter Initialization started"); |
| 25 | 25 | ||
| 26 | current_status = NO_ADAPTER_DETECTED; | 26 | current_status = NO_ADAPTER_DETECTED; |
| 27 | libusb_init(&libusb_ctx); | ||
| 28 | get_origin.fill(true); | 27 | get_origin.fill(true); |
| 29 | 28 | ||
| 30 | StartScanThread(); | 29 | const int init_res = libusb_init(&libusb_ctx); |
| 30 | if (init_res == LIBUSB_SUCCESS) { | ||
| 31 | StartScanThread(); | ||
| 32 | } else { | ||
| 33 | LOG_ERROR(Input, "libusb could not be initialized. failed with error = {}", init_res); | ||
| 34 | } | ||
| 31 | } | 35 | } |
| 32 | 36 | ||
| 33 | GCPadStatus Adapter::GetPadStatus(int port, const std::array<u8, 37>& adapter_payload) { | 37 | GCPadStatus Adapter::GetPadStatus(int port, const std::array<u8, 37>& adapter_payload) { |
| @@ -218,17 +222,26 @@ void Adapter::Setup() { | |||
| 218 | adapter_controllers_status.fill(ControllerTypes::None); | 222 | adapter_controllers_status.fill(ControllerTypes::None); |
| 219 | 223 | ||
| 220 | // pointer to list of connected usb devices | 224 | // pointer to list of connected usb devices |
| 221 | libusb_device** devices; | 225 | libusb_device** devices{}; |
| 222 | 226 | ||
| 223 | // populate the list of devices, get the count | 227 | // populate the list of devices, get the count |
| 224 | const std::size_t device_count = libusb_get_device_list(libusb_ctx, &devices); | 228 | const ssize_t device_count = libusb_get_device_list(libusb_ctx, &devices); |
| 229 | if (device_count < 0) { | ||
| 230 | LOG_ERROR(Input, "libusb_get_device_list failed with error: {}", device_count); | ||
| 231 | detect_thread_running = false; // Stop the loop constantly checking for gc adapter | ||
| 232 | // TODO: For hotplug+gc adapter checkbox implementation, revert this. | ||
| 233 | return; | ||
| 234 | } | ||
| 225 | 235 | ||
| 226 | for (std::size_t index = 0; index < device_count; ++index) { | 236 | if (devices != nullptr) { |
| 227 | if (CheckDeviceAccess(devices[index])) { | 237 | for (std::size_t index = 0; index < device_count; ++index) { |
| 228 | // GC Adapter found and accessible, registering it | 238 | if (CheckDeviceAccess(devices[index])) { |
| 229 | GetGCEndpoint(devices[index]); | 239 | // GC Adapter found and accessible, registering it |
| 230 | break; | 240 | GetGCEndpoint(devices[index]); |
| 241 | break; | ||
| 242 | } | ||
| 231 | } | 243 | } |
| 244 | libusb_free_device_list(devices, 1); | ||
| 232 | } | 245 | } |
| 233 | } | 246 | } |
| 234 | 247 | ||
| @@ -286,7 +299,13 @@ bool Adapter::CheckDeviceAccess(libusb_device* device) { | |||
| 286 | 299 | ||
| 287 | void Adapter::GetGCEndpoint(libusb_device* device) { | 300 | void Adapter::GetGCEndpoint(libusb_device* device) { |
| 288 | libusb_config_descriptor* config = nullptr; | 301 | libusb_config_descriptor* config = nullptr; |
| 289 | libusb_get_config_descriptor(device, 0, &config); | 302 | const int config_descriptor_return = libusb_get_config_descriptor(device, 0, &config); |
| 303 | if (config_descriptor_return != LIBUSB_SUCCESS) { | ||
| 304 | LOG_ERROR(Input, "libusb_get_config_descriptor failed with error = {}", | ||
| 305 | config_descriptor_return); | ||
| 306 | return; | ||
| 307 | } | ||
| 308 | |||
| 290 | for (u8 ic = 0; ic < config->bNumInterfaces; ic++) { | 309 | for (u8 ic = 0; ic < config->bNumInterfaces; ic++) { |
| 291 | const libusb_interface* interfaceContainer = &config->interface[ic]; | 310 | const libusb_interface* interfaceContainer = &config->interface[ic]; |
| 292 | for (int i = 0; i < interfaceContainer->num_altsetting; i++) { | 311 | for (int i = 0; i < interfaceContainer->num_altsetting; i++) { |
diff --git a/src/input_common/gcadapter/gc_adapter.h b/src/input_common/gcadapter/gc_adapter.h index cb9d73a8e..a67485586 100644 --- a/src/input_common/gcadapter/gc_adapter.h +++ b/src/input_common/gcadapter/gc_adapter.h | |||
| @@ -7,6 +7,7 @@ | |||
| 7 | #include <functional> | 7 | #include <functional> |
| 8 | #include <mutex> | 8 | #include <mutex> |
| 9 | #include <thread> | 9 | #include <thread> |
| 10 | #include <unordered_map> | ||
| 10 | #include <libusb.h> | 11 | #include <libusb.h> |
| 11 | #include "common/common_types.h" | 12 | #include "common/common_types.h" |
| 12 | #include "common/threadsafe_queue.h" | 13 | #include "common/threadsafe_queue.h" |