Added SDL_HINT_HIDAPI_IGNORE_DEVICES to specify devices that should be ignored in SDL_hid_enumerate()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227
diff --git a/include/SDL_hints.h b/include/SDL_hints.h
index 8bc4828..ce22254 100644
--- a/include/SDL_hints.h
+++ b/include/SDL_hints.h
@@ -540,6 +540,14 @@ extern "C" {
#define SDL_HINT_GRAB_KEYBOARD "SDL_GRAB_KEYBOARD"
/**
+ * \brief A variable containing a list of devices to ignore in SDL_hid_enumerate()
+ *
+ * For example, to ignore the Shanwan DS3 controller and any Valve controller, you might
+ * have the string "0x2563/0x0523,0x28de/0x0000"
+ */
+#define SDL_HINT_HIDAPI_IGNORE_DEVICES "SDL_HIDAPI_IGNORE_DEVICES"
+
+/**
* \brief A variable controlling whether the idle timer is disabled on iOS.
*
* When an iOS app does not receive touches for some time, the screen is
diff --git a/src/hidapi/android/hid.cpp b/src/hidapi/android/hid.cpp
index 2b2af72..34fda42 100644
--- a/src/hidapi/android/hid.cpp
+++ b/src/hidapi/android/hid.cpp
@@ -1085,10 +1085,23 @@ int hid_init(void)
struct hid_device_info HID_API_EXPORT * HID_API_CALL hid_enumerate(unsigned short vendor_id, unsigned short product_id)
{
struct hid_device_info *root = NULL;
+ const char *hint = SDL_GetHint(SDL_HINT_HIDAPI_IGNORE_DEVICES);
+
hid_mutex_guard l( &g_DevicesMutex );
for ( hid_device_ref<CHIDDevice> pDevice = g_Devices; pDevice; pDevice = pDevice->next )
{
const hid_device_info *info = pDevice->GetDeviceInfo();
+
+ /* See if there are any devices we should skip in enumeration */
+ if (hint) {
+ char vendor_match[16], product_match[16];
+ SDL_snprintf(vendor_match, sizeof(vendor_match), "0x%.4x/0x0000", info->vendor_id);
+ SDL_snprintf(product_match, sizeof(product_match), "0x%.4x/0x%.4x", info->vendor_id, info->product_id);
+ if (SDL_strcasestr(hint, vendor_match) || SDL_strcasestr(hint, product_match)) {
+ continue;
+ }
+ }
+
if ( ( vendor_id == 0x0 || info->vendor_id == vendor_id ) &&
( product_id == 0x0 || info->product_id == product_id ) )
{
diff --git a/src/hidapi/ios/hid.m b/src/hidapi/ios/hid.m
index 111b8f2..5584570 100644
--- a/src/hidapi/ios/hid.m
+++ b/src/hidapi/ios/hid.m
@@ -836,7 +836,18 @@ int HID_API_EXPORT hid_set_nonblocking(hid_device *dev, int nonblock)
struct hid_device_info HID_API_EXPORT *hid_enumerate(unsigned short vendor_id, unsigned short product_id)
{ @autoreleasepool {
struct hid_device_info *root = NULL;
-
+ const char *hint = SDL_GetHint(SDL_HINT_HIDAPI_IGNORE_DEVICES);
+
+ /* See if there are any devices we should skip in enumeration */
+ if (hint) {
+ char vendor_match[16], product_match[16];
+ SDL_snprintf(vendor_match, sizeof(vendor_match), "0x%.4x/0x0000", VALVE_USB_VID);
+ SDL_snprintf(product_match, sizeof(product_match), "0x%.4x/0x%.4x", VALVE_USB_VID, D0G_BLE2_PID);
+ if (SDL_strcasestr(hint, vendor_match) || SDL_strcasestr(hint, product_match)) {
+ return NULL;
+ }
+ }
+
if ( ( vendor_id == 0 && product_id == 0 ) ||
( vendor_id == VALVE_USB_VID && product_id == D0G_BLE2_PID ) )
{
diff --git a/src/hidapi/libusb/hid.c b/src/hidapi/libusb/hid.c
index e86aa51..1f08aed 100644
--- a/src/hidapi/libusb/hid.c
+++ b/src/hidapi/libusb/hid.c
@@ -29,6 +29,7 @@
#include "../../SDL_internal.h"
#include "../../thread/SDL_systhread.h"
+#include "SDL_hints.h"
#include "SDL_mutex.h"
#include "SDL_thread.h"
@@ -761,6 +762,7 @@ struct hid_device_info HID_API_EXPORT *hid_enumerate(unsigned short vendor_id,
struct hid_device_info *root = NULL; /* return object */
struct hid_device_info *cur_dev = NULL;
+ const char *hint = SDL_GetHint(SDL_HINT_HIDAPI_IGNORE_DEVICES);
if(hid_init() < 0)
return NULL;
@@ -778,10 +780,21 @@ struct hid_device_info HID_API_EXPORT *hid_enumerate(unsigned short vendor_id,
unsigned short dev_vid = desc.idVendor;
unsigned short dev_pid = desc.idProduct;
+ /* See if there are any devices we should skip in enumeration */
+ if (hint) {
+ char vendor_match[16], product_match[16];
+ SDL_snprintf(vendor_match, sizeof(vendor_match), "0x%.4x/0x0000", dev_vid);
+ SDL_snprintf(product_match, sizeof(product_match), "0x%.4x/0x%.4x", dev_vid, dev_pid);
+ if (SDL_strcasestr(hint, vendor_match) || SDL_strcasestr(hint, product_match)) {
+ continue;
+ }
+ }
+
res = libusb_get_active_config_descriptor(dev, &conf_desc);
if (res < 0)
libusb_get_config_descriptor(dev, 0, &conf_desc);
if (conf_desc) {
+
for (j = 0; j < conf_desc->bNumInterfaces; j++) {
const struct libusb_interface *intf = &conf_desc->interface[j];
for (k = 0; k < intf->num_altsetting; k++) {
diff --git a/src/hidapi/linux/hid.c b/src/hidapi/linux/hid.c
index 6507dde..fbd0101 100644
--- a/src/hidapi/linux/hid.c
+++ b/src/hidapi/linux/hid.c
@@ -22,6 +22,8 @@
********************************************************/
#include "../../SDL_internal.h"
+#include "SDL_hints.h"
+
#ifndef _GNU_SOURCE
#define _GNU_SOURCE /* needed for wcsdup() before glibc 2.10 */
#endif
@@ -481,6 +483,7 @@ struct hid_device_info HID_API_EXPORT *hid_enumerate(unsigned short vendor_id,
struct hid_device_info *root = NULL; /* return object */
struct hid_device_info *cur_dev = NULL;
struct hid_device_info *prev_dev = NULL; /* previous device */
+ const char *hint = SDL_GetHint(SDL_HINT_HIDAPI_IGNORE_DEVICES);
hid_init();
@@ -552,6 +555,16 @@ struct hid_device_info HID_API_EXPORT *hid_enumerate(unsigned short vendor_id,
goto next;
}
+ /* See if there are any devices we should skip in enumeration */
+ if (hint) {
+ char vendor_match[16], product_match[16];
+ SDL_snprintf(vendor_match, sizeof(vendor_match), "0x%.4x/0x0000", dev_vid);
+ SDL_snprintf(product_match, sizeof(product_match), "0x%.4x/0x%.4x", dev_vid, dev_pid);
+ if (SDL_strcasestr(hint, vendor_match) || SDL_strcasestr(hint, product_match)) {
+ continue;
+ }
+ }
+
/* Check the VID/PID against the arguments */
if ((vendor_id == 0x0 || vendor_id == dev_vid) &&
(product_id == 0x0 || product_id == dev_pid)) {
diff --git a/src/hidapi/mac/hid.c b/src/hidapi/mac/hid.c
index d52b94f..d5dfbc2 100644
--- a/src/hidapi/mac/hid.c
+++ b/src/hidapi/mac/hid.c
@@ -21,6 +21,8 @@
********************************************************/
#include "../../SDL_internal.h"
+#include "SDL_hints.h"
+
/* See Apple Technical Note TN2187 for details on IOHidManager. */
#include <IOKit/hid/IOHIDManager.h>
@@ -517,6 +519,7 @@ struct hid_device_info HID_API_EXPORT *hid_enumerate(unsigned short vendor_id,
CFSetRef device_set;
IOHIDDeviceRef *device_array;
int i;
+ const char *hint = SDL_GetHint(SDL_HINT_HIDAPI_IGNORE_DEVICES);
/* Set up the HID Manager if it hasn't been done */
if (hid_init() < 0)
@@ -567,6 +570,16 @@ struct hid_device_info HID_API_EXPORT *hid_enumerate(unsigned short vendor_id,
dev_vid = get_vendor_id(dev);
dev_pid = get_product_id(dev);
+ /* See if there are any devices we should skip in enumeration */
+ if (hint) {
+ char vendor_match[16], product_match[16];
+ SDL_snprintf(vendor_match, sizeof(vendor_match), "0x%.4x/0x0000", dev_vid);
+ SDL_snprintf(product_match, sizeof(product_match), "0x%.4x/0x%.4x", dev_vid, dev_pid);
+ if (SDL_strcasestr(hint, vendor_match) || SDL_strcasestr(hint, product_match)) {
+ continue;
+ }
+ }
+
/* Check the VID/PID against the arguments */
if ((vendor_id == 0x0 || dev_vid == vendor_id) &&
(product_id == 0x0 || dev_pid == product_id)) {
diff --git a/src/hidapi/windows/hid.c b/src/hidapi/windows/hid.c
index 8dfd11d..27c09e5 100644
--- a/src/hidapi/windows/hid.c
+++ b/src/hidapi/windows/hid.c
@@ -21,6 +21,8 @@
********************************************************/
#include "../../SDL_internal.h"
+#include "SDL_hints.h"
+
#include <windows.h>
#ifndef _WIN32_WINNT_WIN8
@@ -371,6 +373,7 @@ struct hid_device_info HID_API_EXPORT * HID_API_CALL hid_enumerate(unsigned shor
SP_DEVICE_INTERFACE_DETAIL_DATA_A *device_interface_detail_data = NULL;
HDEVINFO device_info_set = INVALID_HANDLE_VALUE;
int device_index = 0;
+ const char *hint = SDL_GetHint(SDL_HINT_HIDAPI_IGNORE_DEVICES);
if (hid_init() < 0)
return NULL;
@@ -488,6 +491,16 @@ struct hid_device_info HID_API_EXPORT * HID_API_CALL hid_enumerate(unsigned shor
HidD_GetAttributes(write_handle, &attrib);
//wprintf(L"Product/Vendor: %x %x\n", attrib.ProductID, attrib.VendorID);
+ /* See if there are any devices we should skip in enumeration */
+ if (hint) {
+ char vendor_match[16], product_match[16];
+ SDL_snprintf(vendor_match, sizeof(vendor_match), "0x%.4x/0x0000", attrib.VendorID);
+ SDL_snprintf(product_match, sizeof(product_match), "0x%.4x/0x%.4x", attrib.VendorID, attrib.ProductID);
+ if (SDL_strcasestr(hint, vendor_match) || SDL_strcasestr(hint, product_match)) {
+ continue;
+ }
+ }
+
/* Check the VID/PID to see if we should add this
device to the enumeration list. */
if ((vendor_id == 0x0 || attrib.VendorID == vendor_id) &&