#if defined(USB_CONTROLLER) #include "usbcontroller.h" #ifdef Q_OS_WIN #pragma comment (lib, "Setupapi.lib") #endif #include #include "logcategories.h" usbController::usbController() { qInfo(logUsbControl()) << "Starting usbController()"; } usbController::~usbController() { qInfo(logUsbControl) << "Ending usbController()"; 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) { delete gamepad; gamepad = Q_NULLPTR; } #endif } void usbController::init(int sens) { sensitivity = sens; emit sendSensitivity(sensitivity); #ifdef HID_API_VERSION_MAJOR if (HID_API_VERSION == HID_API_MAKE_VERSION(hid_version()->major, hid_version()->minor, hid_version()->patch)) { qInfo(logUsbControl) << QString("Compile-time version matches runtime version of hidapi: %0.%1.%2") .arg(hid_version()->major) .arg(hid_version()->minor) .arg(hid_version()->patch); } else { qInfo(logUsbControl) << QString("Compile-time and runtime versions of hidapi do not match (%0.%1.%2 vs %0.%1.%2)") .arg(HID_API_VERSION_MAJOR) .arg(HID_API_VERSION_MINOR) .arg(HID_API_VERSION_PATCH) .arg(hid_version()->major) .arg(hid_version()->minor) .arg(hid_version()->patch); } #endif 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 Path: %2") .arg(QString::fromWCharArray(devs->manufacturer_string)) .arg(QString::fromWCharArray(devs->product_string)) .arg(QString::fromLocal8Bit(devs->path)); devs = devs->next; } hid_free_enumeration(devs); } } void usbController::receiveCommands(QVector* cmds) { qDebug(logUsbControl()) << "Receiving commands"; commands = cmds; } void usbController::receiveButtons(QVector