MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / enumerateDevices

Method enumerateDevices

app/src/IO/Drivers/HID.cpp:293–332  ·  view source on GitHub ↗

* @brief Re-enumerates all connected HID devices. */

Source from the content-addressed store, hash-verified

291 * @brief Re-enumerates all connected HID devices.
292 */
293void IO::Drivers::HID::enumerateDevices()
294{
295 hid_free_enumeration(m_deviceInfoList);
296 m_deviceInfoList = hid_enumerate(0x0000, 0x0000);
297
298 QList<DeviceEntry> entries = collectHidDeviceEntries();
299 std::sort(entries.begin(), entries.end(), [](const DeviceEntry& a, const DeviceEntry& b) {
300 return a.label < b.label;
301 });
302
303 QStringList newLabels;
304 QStringList newPaths;
305 QList<uint16_t> newUsagePages;
306 QList<uint16_t> newUsages;
307 composeHidDeviceLists(entries, newLabels, newPaths, newUsagePages, newUsages);
308
309 if (newLabels == m_deviceLabels)
310 return;
311
312 const QString prevPath = (m_deviceIndex > 0 && m_deviceIndex < m_devicePaths.size())
313 ? m_devicePaths.at(m_deviceIndex)
314 : QString();
315
316 m_deviceLabels = newLabels;
317 m_devicePaths = newPaths;
318 m_deviceUsagePages = newUsagePages;
319 m_deviceUsages = newUsages;
320
321 const int newIndex = restoreHidSelectionIndex(prevPath);
322 if (newIndex != m_deviceIndex) {
323 m_deviceIndex = newIndex;
324 Q_EMIT deviceIndexChanged();
325 }
326
327 updateHidUsageCache();
328
329 Q_EMIT deviceListChanged();
330 Q_EMIT deviceInfoChanged();
331 Q_EMIT configurationChanged();
332}
333
334/**
335 * @brief Walks the hidapi device-info linked list and merges duplicates by VID:PID:serial.

Callers

nothing calls this directly

Calls 5

sortFunction · 0.85
beginMethod · 0.80
hid_free_enumerationFunction · 0.50
hid_enumerateFunction · 0.50
sizeMethod · 0.45

Tested by

no test coverage detected