summaryrefslogtreecommitdiffstats
path: root/src/input_common
diff options
context:
space:
mode:
Diffstat (limited to 'src/input_common')
-rw-r--r--src/input_common/gcadapter/gc_adapter.cpp39
-rw-r--r--src/input_common/gcadapter/gc_adapter.h1
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() {
LOG_INFO(Input, "GC Adapter Initialization started");
current_status = NO_ADAPTER_DETECTED;
- libusb_init(&libusb_ctx);
get_origin.fill(true);
- StartScanThread();
+ const int init_res = libusb_init(&libusb_ctx);
+ if (init_res == LIBUSB_SUCCESS) {
+ StartScanThread();
+ } else {
+ LOG_ERROR(Input, "libusb could not be initialized. failed with error = {}", init_res);
+ }
}
GCPadStatus Adapter::GetPadStatus(int port, const std::array<u8, 37>& adapter_payload) {
@@ -218,17 +222,26 @@ void Adapter::Setup() {
adapter_controllers_status.fill(ControllerTypes::None);
// pointer to list of connected usb devices
- libusb_device** devices;
+ libusb_device** devices{};
// populate the list of devices, get the count
- const std::size_t device_count = libusb_get_device_list(libusb_ctx, &devices);
+ const ssize_t device_count = libusb_get_device_list(libusb_ctx, &devices);
+ if (device_count < 0) {
+ LOG_ERROR(Input, "libusb_get_device_list failed with error: {}", device_count);
+ detect_thread_running = false; // Stop the loop constantly checking for gc adapter
+ // TODO: For hotplug+gc adapter checkbox implementation, revert this.
+ return;
+ }
- for (std::size_t index = 0; index < device_count; ++index) {
- if (CheckDeviceAccess(devices[index])) {
- // GC Adapter found and accessible, registering it
- GetGCEndpoint(devices[index]);
- break;
+ if (devices != nullptr) {
+ for (std::size_t index = 0; index < device_count; ++index) {
+ if (CheckDeviceAccess(devices[index])) {
+ // GC Adapter found and accessible, registering it
+ GetGCEndpoint(devices[index]);
+ break;
+ }
}
+ libusb_free_device_list(devices, 1);
}
}
@@ -286,7 +299,13 @@ bool Adapter::CheckDeviceAccess(libusb_device* device) {
void Adapter::GetGCEndpoint(libusb_device* device) {
libusb_config_descriptor* config = nullptr;
- libusb_get_config_descriptor(device, 0, &config);
+ const int config_descriptor_return = libusb_get_config_descriptor(device, 0, &config);
+ if (config_descriptor_return != LIBUSB_SUCCESS) {
+ LOG_ERROR(Input, "libusb_get_config_descriptor failed with error = {}",
+ config_descriptor_return);
+ return;
+ }
+
for (u8 ic = 0; ic < config->bNumInterfaces; ic++) {
const libusb_interface* interfaceContainer = &config->interface[ic];
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 @@
#include <functional>
#include <mutex>
#include <thread>
+#include <unordered_map>
#include <libusb.h>
#include "common/common_types.h"
#include "common/threadsafe_queue.h"