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:
parent
dc08b73db1
commit
8d5810a103
|
@ -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;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
buf[len-1] = '\0';
|
||||
|
|
Loading…
Reference in New Issue