39 #define USB_MON_QXTLOG_DEBUG(...) qDebug() << __VA_ARGS__
40 #else // USB_MON_DEBUG
41 #define USB_MON_QXTLOG_DEBUG(...)
42 #endif // USB_MON_DEBUG
44 #define printf USB_MON_QXTLOG_DEBUG
56 qRegisterMetaType<USBPortInfo>();
60 connect(&periodicTimer, &QTimer::timeout,
this, &USBMonitor::periodic);
61 periodicTimer.setSingleShot(
true);
62 periodicTimer.start(150);
70 hid_free_enumeration(prevDevList);
73 void USBMonitor::periodic()
83 struct hid_device_info *hidDevList = hid_enumerate(0, 0, prevDevList);
88 bool didAnything =
false;
90 for (
struct hid_device_info *hidDev = hidDevList; hidDev != NULL; hidDev = hidDev->next) {
96 info.
serialNumber = QString::fromWCharArray(hidDev->serial_number);
97 info.
product = QString::fromWCharArray(hidDev->product_string);
98 info.
manufacturer = QString::fromWCharArray(hidDev->manufacturer_string);
99 info.
path = QString::fromLatin1(hidDev->path);
101 if (!unseenDevices.removeOne(info)) {
102 newDevices.append(info);
106 prevDevList = hidDevList;
116 knowndevices.removeOne(item);
122 if (!knowndevices.contains(item)) {
128 knowndevices.append(item);
135 qDebug() <<
"usbmonitor detection cycle complete.";
139 periodicTimer.start(150);
168 && ((port.
bcdDevice >> 8) == bcdDeviceMSB || bcdDeviceMSB == -1)
169 && ((port.
bcdDevice & 0x00ff) == bcdDeviceLSB || bcdDeviceLSB == -1))
170 thePortsWeWant.append(port);
173 return thePortsWeWant;
QList< USBPortInfo > availableDevices()
void deviceDiscovered(const USBPortInfo &info)
USBMonitor(QObject *parent=nullptr)
static USBMonitor * instance()
void deviceRemoved(const USBPortInfo &info)
QString path
Opaque OS-specific path.