macOS: Use unique IDs for HID paths

If available, use the system-generated unique ID for HID device paths instead of a transport/vid/pid/location tuple.
The Mayflash Dolphinbar registers four HID devices (regardless of the number of connected Wiimotes) which had the same path with the previous path building method, causing a bit of confusion when detecting and connecting to Wiimotes.
The unique IDs do not change if the computer is suspended and resumed, but do change if the HID device is unplugged/replugged.
This commit is contained in:
Vincent Duvert 2018-01-07 11:00:01 +01:00
parent dc08b73db1
commit 8d5810a103
1 changed files with 16 additions and 5 deletions

View File

@ -217,6 +217,11 @@ static int32_t get_location_id(IOHIDDeviceRef device)
return get_int_property(device, CFSTR(kIOHIDLocationIDKey));
}
static int32_t get_unique_id(IOHIDDeviceRef device)
{
return get_int_property(device, CFSTR(kIOHIDUniqueIDKey));
}
static int32_t get_max_report_length(IOHIDDeviceRef device)
{
return get_int_property(device, CFSTR(kIOHIDMaxInputReportSizeKey));
@ -337,6 +342,7 @@ static int make_path(IOHIDDeviceRef device, char *buf, size_t len)
unsigned short vid, pid;
char transport[32];
int32_t location;
int32_t unique_id;
buf[0] = '\0';
@ -347,12 +353,17 @@ static int make_path(IOHIDDeviceRef device, char *buf, size_t len)
if (!res)
return -1;
location = get_location_id(device);
vid = get_vendor_id(device);
pid = get_product_id(device);
unique_id = get_unique_id(device);
if (unique_id != 0) {
res = snprintf(buf, len, "id_%x", unique_id);
} else {
location = get_location_id(device);
vid = get_vendor_id(device);
pid = get_product_id(device);
res = snprintf(buf, len, "%s_%04hx_%04hx_%x",
transport, vid, pid, location);
res = snprintf(buf, len, "%s_%04hx_%04hx_%x",
transport, vid, pid, location);
}
buf[len-1] = '\0';