From f034482228449e8223db5abec9c7e22311334d28 Mon Sep 17 00:00:00 2001 From: Swiftb0y <12380386+Swiftb0y@users.noreply.github.com> Date: Mon, 9 Sep 2024 14:21:28 +0200 Subject: [PATCH] refactor: restructure `bulk_supported` to emphasize kv structure --- src/controllers/bulk/bulkcontroller.cpp | 10 +++++----- src/controllers/bulk/bulkenumerator.cpp | 6 ++---- src/controllers/bulk/bulksupported.h | 24 ++++++++++++++++-------- 3 files changed, 23 insertions(+), 17 deletions(-) diff --git a/src/controllers/bulk/bulkcontroller.cpp b/src/controllers/bulk/bulkcontroller.cpp index 6260c3d6b43..24c9e1ee7b0 100644 --- a/src/controllers/bulk/bulkcontroller.cpp +++ b/src/controllers/bulk/bulkcontroller.cpp @@ -151,18 +151,18 @@ int BulkController::open() { /* Look up endpoint addresses in supported database */ - const bulk_supported_t* pDevice = std::find_if( + const bulk_support_lookup* pDevice = std::find_if( std::cbegin(bulk_supported), std::cend(bulk_supported), [this](const auto& dev) { - return dev.vendor_id == m_vendorId && dev.product_id == m_productId; + return dev.key.vendor_id == m_vendorId && dev.key.product_id == m_productId; }); if (pDevice == std::cend(bulk_supported)) { qCWarning(m_logBase) << "USB Bulk device" << getName() << "unsupported"; return -1; } - m_inEndpointAddr = pDevice->in_epaddr; - m_outEndpointAddr = pDevice->out_epaddr; + m_inEndpointAddr = pDevice->endpoints.in_epaddr; + m_outEndpointAddr = pDevice->endpoints.out_epaddr; #if defined(__WINDOWS__) || defined(__APPLE__) - m_interfaceNumber = pDevice->interface_number; + m_interfaceNumber = pDevice->endpoints.interface_number; #endif // XXX: we should enumerate devices and match vendor, product, and serial diff --git a/src/controllers/bulk/bulkenumerator.cpp b/src/controllers/bulk/bulkenumerator.cpp index 71792b413b7..4435037ff11 100644 --- a/src/controllers/bulk/bulkenumerator.cpp +++ b/src/controllers/bulk/bulkenumerator.cpp @@ -22,12 +22,10 @@ BulkEnumerator::~BulkEnumerator() { } static bool is_interesting(const libusb_device_descriptor& desc) { - auto vendorId = desc.idVendor; - auto productId = desc.idProduct; return std::any_of(std::cbegin(bulk_supported), std::cend(bulk_supported), - [=](const auto& dev) { - return dev.vendor_id == vendorId && dev.product_id == productId; + [&](const auto& dev) { + return dev.key.vendor_id == desc.idVendor && dev.key.product_id == desc.idProduct; }); } diff --git a/src/controllers/bulk/bulksupported.h b/src/controllers/bulk/bulksupported.h index 4a86f0ec84f..49d3f05a636 100644 --- a/src/controllers/bulk/bulksupported.h +++ b/src/controllers/bulk/bulksupported.h @@ -2,19 +2,27 @@ #include -// A list of supported USB bulk devices - -struct bulk_supported_t { +struct bulk_device_id { std::uint16_t vendor_id; std::uint16_t product_id; +}; + +// A list of supported USB bulk devices + +struct bulk_device_endpoints { std::uint8_t in_epaddr; std::uint8_t out_epaddr; std::uint8_t interface_number; }; -constexpr static bulk_supported_t 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 +struct bulk_support_lookup { + bulk_device_id key; + bulk_device_endpoints endpoints; +}; + +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 };