Skip to content

Commit

Permalink
fix: add HID error message upon failed open
Browse files Browse the repository at this point in the history
  • Loading branch information
acolombier committed Feb 5, 2025
1 parent 7e3aa94 commit 83d154a
Showing 1 changed file with 45 additions and 7 deletions.
52 changes: 45 additions & 7 deletions src/controllers/hid/hidcontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@

#include "controllers/defs_controllers.h"
#include "moc_hidcontroller.cpp"
#include "util/string.h"

class LegacyControllerMapping;

namespace {
constexpr size_t kMaxHidErrorMessageSize = 512;
} // namespace

HidController::HidController(
mixxx::hid::DeviceInfo&& deviceInfo)
: Controller(deviceInfo.formatName()),
Expand Down Expand Up @@ -67,9 +72,20 @@ int HidController::open() {

// If that fails, try to open device with vendor/product/serial #
if (!pHidDevice) {
qCWarning(m_logBase) << "Failed. Trying to open with make, model & serial no:"
<< m_deviceInfo.getVendorId() << m_deviceInfo.getProductId()
<< m_deviceInfo.getSerialNumber();
qCWarning(m_logBase) << QStringLiteral(
"Unable to open specific HID device %1 using its path %2: %3")
.arg(getName(),
m_deviceInfo.pathRaw(),
mixxx::convertWCStringToQString(
hid_error(nullptr),
kMaxHidErrorMessageSize));
qCInfo(m_logBase) << QStringLiteral(
"Trying to open HID device %1 using its vendor, product and "
"serial no (0x%2, 0x%3 and %4)")
.arg(getName(),
QString::number(m_deviceInfo.getVendorId(), 16),
QString::number(m_deviceInfo.getProductId(), 16),
m_deviceInfo.getSerialNumber());
pHidDevice = hid_open(
m_deviceInfo.getVendorId(),
m_deviceInfo.getProductId(),
Expand All @@ -79,17 +95,39 @@ int HidController::open() {
// If it does fail, try without serial number WARNING: This will only open
// one of multiple identical devices
if (!pHidDevice) {
qCWarning(m_logBase) << "Unable to open specific HID device" << getName()
<< "Trying now with just make and model."
<< "(This may only open the first of multiple identical devices.)";
qCWarning(m_logBase) << QStringLiteral(
"Unable to open specific HID device %1 using its vendor, "
"product and serial no (0x%2, 0x%3 and %4): %5")
.arg(getName(),
QString::number(m_deviceInfo.getVendorId(), 16),
QString::number(m_deviceInfo.getProductId(), 16),
m_deviceInfo.getSerialNumber(),
mixxx::convertWCStringToQString(
hid_error(nullptr),
kMaxHidErrorMessageSize));
qCInfo(m_logBase) << QStringLiteral(
"Trying to open HID device %1 using its vendor and product "
"only (0x%2 and 0x%3). This may only open the first of multiple "
"identical devices.")
.arg(getName(),
QString::number(m_deviceInfo.getVendorId(), 16),
QString::number(m_deviceInfo.getProductId(), 16));
pHidDevice = hid_open(m_deviceInfo.getVendorId(),
m_deviceInfo.getProductId(),
nullptr);
}

// If that fails, we give up!
if (!pHidDevice) {
qCWarning(m_logBase) << "Unable to open HID device" << getName();
qCWarning(m_logBase) << QStringLiteral(
"Unable to open specific HID device %1 using its vendor and "
"product only (0x%2 and 0x%3): %4")
.arg(getName(),
QString::number(m_deviceInfo.getVendorId(), 16),
QString::number(m_deviceInfo.getProductId(), 16),
mixxx::convertWCStringToQString(
hid_error(nullptr),
kMaxHidErrorMessageSize));
return -1;
}

Expand Down

0 comments on commit 83d154a

Please sign in to comment.