Skip to content

Commit

Permalink
refactor: restructure bulk_supported to emphasize kv structure
Browse files Browse the repository at this point in the history
  • Loading branch information
Swiftb0y committed Oct 10, 2024
1 parent bbbbb1a commit f034482
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 17 deletions.
10 changes: 5 additions & 5 deletions src/controllers/bulk/bulkcontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 2 additions & 4 deletions src/controllers/bulk/bulkenumerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
}

Expand Down
24 changes: 16 additions & 8 deletions src/controllers/bulk/bulksupported.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,27 @@

#include <cstdint>

// 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
};

0 comments on commit f034482

Please sign in to comment.