Skip to content

Commit

Permalink
fixup! refactor: remove OS-specific hidapi code
Browse files Browse the repository at this point in the history
  • Loading branch information
Swiftb0y committed Sep 18, 2024
1 parent 4df2508 commit 18c8ce4
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 14 deletions.
22 changes: 14 additions & 8 deletions src/controllers/bulk/bulkcontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion src/controllers/bulk/bulkcontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <QAtomicInt>
#include <QThread>
#include <optional>

#include "controllers/controller.h"
#include "controllers/hid/legacyhidcontrollermapping.h"
Expand Down Expand Up @@ -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<std::uint8_t> m_interfaceNumber;

QString m_manufacturer;
QString m_product;
Expand Down
12 changes: 7 additions & 5 deletions src/controllers/bulk/bulksupported.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <cstdint>
#include <optional>

struct bulk_device_id {
std::uint16_t vendor_id;
Expand All @@ -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<std::uint8_t> interface_number = std::nullopt;
};

struct bulk_support_lookup {
Expand All @@ -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
};

0 comments on commit 18c8ce4

Please sign in to comment.