From ec24f931007d75e061d26d6f9705790913f72fa0 Mon Sep 17 00:00:00 2001 From: Ludovic Rousseau Date: Tue, 22 May 2012 16:02:09 +0200 Subject: [PATCH] all: make hid_enumerate() able to match any vendor or any product Passing product_id=0 will match any product of a given vendor. This patch makes it also possible to use vendor_id=0 to match any vendor for a given product id. Windows code added to Ludovic's patch by Alan Ott. --- hidapi/hidapi.h | 2 ++ libusb/hid.c | 4 ++-- linux/hid.c | 4 ++-- mac/hid.c | 4 ++-- windows/hid.c | 4 ++-- 5 files changed, 10 insertions(+), 8 deletions(-) diff --git a/hidapi/hidapi.h b/hidapi/hidapi.h index 2c26d50..e58e8a4 100644 --- a/hidapi/hidapi.h +++ b/hidapi/hidapi.h @@ -112,6 +112,8 @@ extern "C" { This function returns a linked list of all the HID devices attached to the system which match vendor_id and product_id. + If @p vendor_id is set to 0 then any vendor matches. + If @p product_id is set to 0 then any product matches. If @p vendor_id and @p product_id are both set to 0, then all HID devices will be returned. diff --git a/libusb/hid.c b/libusb/hid.c index 9b8ab28..10ba742 100644 --- a/libusb/hid.c +++ b/libusb/hid.c @@ -474,8 +474,8 @@ struct hid_device_info HID_API_EXPORT *hid_enumerate(unsigned short vendor_id, interface_num = intf_desc->bInterfaceNumber; /* Check the VID/PID against the arguments */ - if ((vendor_id == 0x0 && product_id == 0x0) || - (vendor_id == dev_vid && product_id == dev_pid)) { + if ((vendor_id == 0x0 || vendor_id == dev_vid) && + (product_id == 0x0 || product_id == dev_pid)) { struct hid_device_info *tmp; /* VID/PID match. Create the record. */ diff --git a/linux/hid.c b/linux/hid.c index 3cc5671..98382d4 100644 --- a/linux/hid.c +++ b/linux/hid.c @@ -431,8 +431,8 @@ struct hid_device_info HID_API_EXPORT *hid_enumerate(unsigned short vendor_id, } /* Check the VID/PID against the arguments */ - if ((vendor_id == 0x0 && product_id == 0x0) || - (vendor_id == dev_vid && product_id == dev_pid)) { + if ((vendor_id == 0x0 || vendor_id == dev_vid) && + (product_id == 0x0 || product_id == dev_pid)) { struct hid_device_info *tmp; /* VID/PID match. Create the record. */ diff --git a/mac/hid.c b/mac/hid.c index c89a3a5..9e88ecd 100644 --- a/mac/hid.c +++ b/mac/hid.c @@ -444,8 +444,8 @@ struct hid_device_info HID_API_EXPORT *hid_enumerate(unsigned short vendor_id, dev_pid = get_product_id(dev); /* Check the VID/PID against the arguments */ - if ((vendor_id == 0x0 && product_id == 0x0) || - (vendor_id == dev_vid && product_id == dev_pid)) { + if ((vendor_id == 0x0 || vendor_id == dev_vid) && + (product_id == 0x0 || product_id == dev_pid)) { struct hid_device_info *tmp; size_t len; diff --git a/windows/hid.c b/windows/hid.c index 9785433..17a1a2d 100755 --- a/windows/hid.c +++ b/windows/hid.c @@ -371,8 +371,8 @@ struct hid_device_info HID_API_EXPORT * HID_API_CALL hid_enumerate(unsigned shor /* Check the VID/PID to see if we should add this device to the enumeration list. */ - if ((vendor_id == 0x0 && product_id == 0x0) || - (attrib.VendorID == vendor_id && attrib.ProductID == product_id)) { + if ((vendor_id == 0x0 || attrib.VendorID == vendor_id) && + (product_id == 0x0 || attrib.ProductID == product_id)) { #define WSTR_LEN 512 const char *str;