From 7b7d21d3a72e840ee61681495156f309fe2c86ed Mon Sep 17 00:00:00 2001 From: Phil Taylor Date: Mon, 6 Feb 2023 15:02:48 +0000 Subject: [PATCH] Improve USB device enumeration and fix for MacOS --- usbcontroller.cpp | 104 +++++++++++++++++++++++++++++++++------------- usbcontroller.h | 12 +++++- wfmain.cpp | 4 +- wfmain.h | 1 + 4 files changed, 91 insertions(+), 30 deletions(-) diff --git a/usbcontroller.cpp b/usbcontroller.cpp index 93adf56..4cbcc71 100644 --- a/usbcontroller.cpp +++ b/usbcontroller.cpp @@ -18,8 +18,16 @@ usbController::usbController() usbController::~usbController() { qInfo(logUsbControl) << "Ending usbController()"; - ledControl(false, 3); - hid_close(handle); + + if (handle) { + + if (usbDevice == RC28) { + ledControl(false, 3); + } + + hid_close(handle); + } + hid_exit(); #if (QT_VERSION < QT_VERSION_CHECK(6,0,0)) if (gamepad != Q_NULLPTR) @@ -32,6 +40,29 @@ usbController::~usbController() void usbController::init() { + hidStatus = hid_init(); + if (hidStatus) { + qInfo(logUsbControl()) << "Failed to intialize HID Devices"; + } + else { + +#if defined(__APPLE__) && HID_API_VERSION >= HID_API_MAKE_VERSION(0, 12, 0) + hid_darwin_set_open_exclusive(0); +#endif + + qInfo(logUsbControl()) << "Found available HID devices (not all will be suitable for use):"; + struct hid_device_info* devs; + devs = hid_enumerate(0x0, 0x0); + while (devs) { + qInfo(logUsbControl()) << QString("Manufacturer: %0 Product: %1 Release: %2") + .arg(devs->manufacturer_string) + .arg(devs->product_string) + .arg(devs->release_number); + devs = devs->next; + } + hid_free_enumeration(devs); + + } } void usbController::receiveCommands(QVector* cmds) @@ -49,9 +80,8 @@ void usbController::receiveButtons(QVector