From 3137e98e945a7b03a580946747a99d7eddce7a45 Mon Sep 17 00:00:00 2001 From: Steven Noreyko <1909661+okyeron@users.noreply.github.com> Date: Thu, 16 Jul 2026 14:05:46 -0500 Subject: [PATCH] Fix serial detection on pico/composite USB devices Composite USB devices show up as multiple nodes on Windows, but the grid serial number only exists on the parent node rather than the COM port node. Thus the serial number is not found and the device is not seen as a grid. This change walks up the USB device tree to try and find a valid serial. Co-Authored-By: IntaUnta <293010097+intaunta@users.noreply.github.com> --- src/platform/windows.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) mode change 100644 => 100755 src/platform/windows.c diff --git a/src/platform/windows.c b/src/platform/windows.c old mode 100644 new mode 100755 index 3b08243..434d30e --- a/src/platform/windows.c +++ b/src/platform/windows.c @@ -304,26 +304,24 @@ char *monome_platform_get_dev_serial(const char *path) { } devinfo.cbSize = sizeof(SP_DEVINFO_DATA); - di = 0; - while (SetupDiEnumDeviceInfo(hdevinfo, di, &devinfo)) { - if (!m_get_device_port_name(port_name, sizeof(port_name), hdevinfo, &devinfo)) { + for (di = 0; SetupDiEnumDeviceInfo(hdevinfo, di, &devinfo); di++) { + if (!m_get_device_port_name(port_name, sizeof(port_name), hdevinfo, &devinfo)) continue; - } if (strcmp(port_name, path) == 0) { - if (!SetupDiGetDeviceInstanceId(hdevinfo, &devinfo, instance_id, sizeof(instance_id), NULL)) { - fprintf(stderr, "libmonome: SetupDiGetDeviceInstanceId() failed.\n"); - continue; - }; + do { + if (CM_Get_Device_ID(devinfo.DevInst, instance_id, sizeof(instance_id), 0) == CR_SUCCESS) { + if ((serial = m_get_serial_from_instance_id(instance_id))) + goto done; + } + } while (CM_Get_Parent(&devinfo.DevInst, devinfo.DevInst, 0) == CR_SUCCESS); - serial = m_get_serial_from_instance_id(instance_id); break; } - - di++; } +done: SetupDiDestroyDeviceInfoList(hdevinfo); return serial; }