From 18c8ce479f57a22eb01fe04bfd6c7a752c8a88bb Mon Sep 17 00:00:00 2001 From: Swiftb0y <12380386+Swiftb0y@users.noreply.github.com> Date: Wed, 18 Sep 2024 12:00:49 +0200 Subject: [PATCH] fixup! refactor: remove OS-specific hidapi code --- src/controllers/bulk/bulkcontroller.cpp | 22 ++++++++++++++-------- src/controllers/bulk/bulkcontroller.h | 3 ++- src/controllers/bulk/bulksupported.h | 12 +++++++----- 3 files changed, 23 insertions(+), 14 deletions(-) diff --git a/src/controllers/bulk/bulkcontroller.cpp b/src/controllers/bulk/bulkcontroller.cpp index 9f5b150c9ed8..caabb84907a5 100644 --- a/src/controllers/bulk/bulkcontroller.cpp +++ b/src/controllers/bulk/bulkcontroller.cpp @@ -175,11 +175,14 @@ int BulkController::open() { qCDebug(m_logBase) << "unable to automatically detach kernel driver for" << getName(); } - if (int ret = libusb_claim_interface(m_phandle, m_interfaceNumber); ret < 0) { - qCWarning(m_logBase) << "Cannot claim interface for" << getName() - << ":" << libusb_error_name(ret); - libusb_close(m_phandle); - return -1; + if (m_interfaceNumber.has_value()) { + int error = libusb_claim_interface(m_phandle, *m_interfaceNumber); + if (error < 0) { + qCWarning(m_logBase) << "Cannot claim interface for" << getName() + << ":" << libusb_error_name(error); + libusb_close(m_phandle); + return -1; + } } else { qCDebug(m_logBase) << "Claimed interface for" << getName(); } @@ -237,9 +240,12 @@ int BulkController::close() { stopEngine(); // Close device - if (int ret = libusb_release_interface(m_phandle, m_interfaceNumber); ret < 0) { - qCWarning(m_logBase) << "Cannot release interface for" << getName() - << ":" << libusb_error_name(ret); + if (m_interfaceNumber.has_value()) { + int error = libusb_release_interface(m_phandle, *m_interfaceNumber); + if (error < 0) { + qCWarning(m_logBase) << "Cannot release interface for" << getName() + << ":" << libusb_error_name(error); + } } qCInfo(m_logBase) << " Closing device"; libusb_close(m_phandle); diff --git a/src/controllers/bulk/bulkcontroller.h b/src/controllers/bulk/bulkcontroller.h index 5e2b8dc17735..f2f1b0e9416a 100644 --- a/src/controllers/bulk/bulkcontroller.h +++ b/src/controllers/bulk/bulkcontroller.h @@ -2,6 +2,7 @@ #include #include +#include #include "controllers/controller.h" #include "controllers/hid/legacyhidcontrollermapping.h" @@ -76,7 +77,7 @@ class BulkController : public Controller { std::uint16_t m_productId; std::uint8_t m_inEndpointAddr; std::uint8_t m_outEndpointAddr; - std::uint8_t m_interfaceNumber; + std::optional m_interfaceNumber; QString m_manufacturer; QString m_product; diff --git a/src/controllers/bulk/bulksupported.h b/src/controllers/bulk/bulksupported.h index 49d3f05a636d..14566d8b86fa 100644 --- a/src/controllers/bulk/bulksupported.h +++ b/src/controllers/bulk/bulksupported.h @@ -1,6 +1,7 @@ #pragma once #include +#include struct bulk_device_id { std::uint16_t vendor_id; @@ -12,7 +13,8 @@ struct bulk_device_id { struct bulk_device_endpoints { std::uint8_t in_epaddr; std::uint8_t out_epaddr; - std::uint8_t interface_number; + // we may not know the interface, in which case we should not try to claim it. + std::optional interface_number = std::nullopt; }; struct bulk_support_lookup { @@ -21,8 +23,8 @@ struct bulk_support_lookup { }; constexpr static bulk_support_lookup bulk_supported[] = { - {{0x06f8, 0xb105}, {0x82, 0x03, 0}}, // Hercules MP3e2 - {{0x06f8, 0xb107}, {0x83, 0x03, 0}}, // Hercules Mk4 - {{0x06f8, 0xb100}, {0x86, 0x06, 0}}, // Hercules Mk2 - {{0x06f8, 0xb120}, {0x82, 0x03, 0}}, // Hercules MP3 LE / Glow + {{0x06f8, 0xb105}, {0x82, 0x03}}, // Hercules MP3e2 + {{0x06f8, 0xb107}, {0x83, 0x03}}, // Hercules Mk4 + {{0x06f8, 0xb100}, {0x86, 0x06}}, // Hercules Mk2 + {{0x06f8, 0xb120}, {0x82, 0x03}}, // Hercules MP3 LE / Glow };