Added support for detecting previously unknown Xbox 360 and Xbox One controllers using the HIDAPI driver with libusb and Android

This commit is contained in:
Sam Lantinga
2020-01-18 11:21:14 -08:00
parent 27035425e0
commit 43aa1fa9e7
18 changed files with 244 additions and 141 deletions

View File

@@ -419,6 +419,9 @@ LIBUSB_CopyHIDDeviceInfo(struct LIBUSB_hid_device_info *pSrc,
pDst->usage_page = pSrc->usage_page;
pDst->usage = pSrc->usage;
pDst->interface_number = pSrc->interface_number;
pDst->interface_class = pSrc->interface_class;
pDst->interface_subclass = pSrc->interface_subclass;
pDst->interface_protocol = pSrc->interface_protocol;
pDst->next = NULL;
}
#endif /* SDL_LIBUSB_DYNAMIC */
@@ -438,6 +441,9 @@ PLATFORM_CopyHIDDeviceInfo(struct PLATFORM_hid_device_info *pSrc,
pDst->usage_page = pSrc->usage_page;
pDst->usage = pSrc->usage;
pDst->interface_number = pSrc->interface_number;
pDst->interface_class = pSrc->interface_class;
pDst->interface_subclass = pSrc->interface_subclass;
pDst->interface_protocol = pSrc->interface_protocol;
pDst->next = NULL;
}
#endif /* HAVE_PLATFORM_BACKEND */

View File

@@ -739,7 +739,7 @@ extern "C"
JNIEXPORT void JNICALL HID_DEVICE_MANAGER_JAVA_INTERFACE(HIDDeviceReleaseCallback)(JNIEnv *env, jobject thiz);
extern "C"
JNIEXPORT void JNICALL HID_DEVICE_MANAGER_JAVA_INTERFACE(HIDDeviceConnected)(JNIEnv *env, jobject thiz, int nDeviceID, jstring sIdentifier, int nVendorId, int nProductId, jstring sSerialNumber, int nReleaseNumber, jstring sManufacturer, jstring sProduct, int nInterface );
JNIEXPORT void JNICALL HID_DEVICE_MANAGER_JAVA_INTERFACE(HIDDeviceConnected)(JNIEnv *env, jobject thiz, int nDeviceID, jstring sIdentifier, int nVendorId, int nProductId, jstring sSerialNumber, int nReleaseNumber, jstring sManufacturer, jstring sProduct, int nInterface, int nInterfaceClass, int nInterfaceSubclass, int nInterfaceProtocol );
extern "C"
JNIEXPORT void JNICALL HID_DEVICE_MANAGER_JAVA_INTERFACE(HIDDeviceOpenPending)(JNIEnv *env, jobject thiz, int nDeviceID);
@@ -828,7 +828,7 @@ JNIEXPORT void JNICALL HID_DEVICE_MANAGER_JAVA_INTERFACE(HIDDeviceReleaseCallbac
}
extern "C"
JNIEXPORT void JNICALL HID_DEVICE_MANAGER_JAVA_INTERFACE(HIDDeviceConnected)(JNIEnv *env, jobject thiz, int nDeviceID, jstring sIdentifier, int nVendorId, int nProductId, jstring sSerialNumber, int nReleaseNumber, jstring sManufacturer, jstring sProduct, int nInterface )
JNIEXPORT void JNICALL HID_DEVICE_MANAGER_JAVA_INTERFACE(HIDDeviceConnected)(JNIEnv *env, jobject thiz, int nDeviceID, jstring sIdentifier, int nVendorId, int nProductId, jstring sSerialNumber, int nReleaseNumber, jstring sManufacturer, jstring sProduct, int nInterface, int nInterfaceClass, int nInterfaceSubclass, int nInterfaceProtocol )
{
LOGV( "HIDDeviceConnected() id=%d VID/PID = %.4x/%.4x, interface %d\n", nDeviceID, nVendorId, nProductId, nInterface );
@@ -842,6 +842,9 @@ JNIEXPORT void JNICALL HID_DEVICE_MANAGER_JAVA_INTERFACE(HIDDeviceConnected)(JNI
pInfo->manufacturer_string = CreateWStringFromJString( env, sManufacturer );
pInfo->product_string = CreateWStringFromJString( env, sProduct );
pInfo->interface_number = nInterface;
pInfo->interface_class = nInterfaceClass;
pInfo->interface_subclass = nInterfaceSubclass;
pInfo->interface_protocol = nInterfaceProtocol;
hid_device_ref<CHIDDevice> pDevice( new CHIDDevice( nDeviceID, pInfo ) );

View File

@@ -78,6 +78,12 @@ namespace NAMESPACE {
only if the device contains more than one interface. */
int interface_number;
/** Additional information about the USB interface.
Valid on libusb and Android implementations. */
int interface_class;
int interface_subclass;
int interface_protocol;
/** Pointer to the next device */
struct hid_device_info *next;
};

View File

@@ -714,6 +714,9 @@ struct hid_device_info HID_API_EXPORT *hid_enumerate(unsigned short vendor_id,
/* Interface Number */
cur_dev->interface_number = interface_num;
cur_dev->interface_class = intf_desc->bInterfaceClass;
cur_dev->interface_subclass = intf_desc->bInterfaceSubClass;
cur_dev->interface_protocol = intf_desc->bInterfaceProtocol;
}
}
} /* altsettings */

View File

@@ -41,10 +41,10 @@
StackOverflow. It is used with his permission. */
typedef int pthread_barrierattr_t;
typedef struct pthread_barrier {
pthread_mutex_t mutex;
pthread_cond_t cond;
int count;
int trip_count;
pthread_mutex_t mutex;
pthread_cond_t cond;
int count;
int trip_count;
} pthread_barrier_t;
static int pthread_barrier_init(pthread_barrier_t *barrier, const pthread_barrierattr_t *attr, unsigned int count)
@@ -178,22 +178,22 @@ static void free_hid_device(hid_device *dev)
free(dev->input_report_buf);
if (device_list) {
if (device_list->dev == dev) {
device_list = device_list->next;
}
else {
struct hid_device_list_node *node = device_list;
while (node) {
if (node->next && node->next->dev == dev) {
struct hid_device_list_node *new_next = node->next->next;
free(node->next);
node->next = new_next;
break;
}
if (device_list->dev == dev) {
device_list = device_list->next;
}
else {
struct hid_device_list_node *node = device_list;
while (node) {
if (node->next && node->next->dev == dev) {
struct hid_device_list_node *new_next = node->next->next;
free(node->next);
node->next = new_next;
break;
}
node = node->next;
}
}
node = node->next;
}
}
}
/* Clean up the thread objects */
@@ -478,9 +478,10 @@ struct hid_device_info HID_API_EXPORT *hid_enumerate(unsigned short vendor_id,
IOHIDDeviceRef dev = device_array[i];
if (!dev) {
continue;
}
if (!dev) {
continue;
}
dev_vid = get_vendor_id(dev);
dev_pid = get_product_id(dev);