Updated with upstream suggestions in https://github.com/libusb/hidapi/pull/572
parent
0cff44dbd4
commit
20182eed7c
|
@ -947,10 +947,10 @@ static uint16_t get_report_descriptor_size_from_interface_descriptors(const stru
|
|||
|
||||
static int is_xbox360(unsigned short vendor_id, const struct libusb_interface_descriptor *intf_desc)
|
||||
{
|
||||
static const int XB360_IFACE_SUBCLASS = 93;
|
||||
static const int XB360_IFACE_PROTOCOL = 1; /* Wired */
|
||||
static const int XB360W_IFACE_PROTOCOL = 129; /* Wireless */
|
||||
static const int SUPPORTED_VENDORS[] = {
|
||||
static const int xb360_iface_subclass = 93;
|
||||
static const int xb360_iface_protocol = 1; /* Wired */
|
||||
static const int xb360w_iface_protocol = 129; /* Wireless */
|
||||
static const int supported_vendors[] = {
|
||||
0x0079, /* GPD Win 2 */
|
||||
0x044f, /* Thrustmaster */
|
||||
0x045e, /* Microsoft */
|
||||
|
@ -980,12 +980,12 @@ static int is_xbox360(unsigned short vendor_id, const struct libusb_interface_de
|
|||
};
|
||||
|
||||
if (intf_desc->bInterfaceClass == LIBUSB_CLASS_VENDOR_SPEC &&
|
||||
intf_desc->bInterfaceSubClass == XB360_IFACE_SUBCLASS &&
|
||||
(intf_desc->bInterfaceProtocol == XB360_IFACE_PROTOCOL ||
|
||||
intf_desc->bInterfaceProtocol == XB360W_IFACE_PROTOCOL)) {
|
||||
intf_desc->bInterfaceSubClass == xb360_iface_subclass &&
|
||||
(intf_desc->bInterfaceProtocol == xb360_iface_protocol ||
|
||||
intf_desc->bInterfaceProtocol == xb360w_iface_protocol)) {
|
||||
size_t i;
|
||||
for (i = 0; i < sizeof(SUPPORTED_VENDORS)/sizeof(SUPPORTED_VENDORS[0]); ++i) {
|
||||
if (vendor_id == SUPPORTED_VENDORS[i]) {
|
||||
for (i = 0; i < sizeof(supported_vendors)/sizeof(supported_vendors[0]); ++i) {
|
||||
if (vendor_id == supported_vendors[i]) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
@ -995,9 +995,9 @@ static int is_xbox360(unsigned short vendor_id, const struct libusb_interface_de
|
|||
|
||||
static int is_xboxone(unsigned short vendor_id, const struct libusb_interface_descriptor *intf_desc)
|
||||
{
|
||||
static const int XB1_IFACE_SUBCLASS = 71;
|
||||
static const int XB1_IFACE_PROTOCOL = 208;
|
||||
static const int SUPPORTED_VENDORS[] = {
|
||||
static const int xb1_iface_subclass = 71;
|
||||
static const int xb1_iface_protocol = 208;
|
||||
static const int supported_vendors[] = {
|
||||
0x044f, /* Thrustmaster */
|
||||
0x045e, /* Microsoft */
|
||||
0x0738, /* Mad Catz */
|
||||
|
@ -1014,11 +1014,11 @@ static int is_xboxone(unsigned short vendor_id, const struct libusb_interface_de
|
|||
|
||||
if (intf_desc->bInterfaceNumber == 0 &&
|
||||
intf_desc->bInterfaceClass == LIBUSB_CLASS_VENDOR_SPEC &&
|
||||
intf_desc->bInterfaceSubClass == XB1_IFACE_SUBCLASS &&
|
||||
intf_desc->bInterfaceProtocol == XB1_IFACE_PROTOCOL) {
|
||||
intf_desc->bInterfaceSubClass == xb1_iface_subclass &&
|
||||
intf_desc->bInterfaceProtocol == xb1_iface_protocol) {
|
||||
size_t i;
|
||||
for (i = 0; i < sizeof(SUPPORTED_VENDORS)/sizeof(SUPPORTED_VENDORS[0]); ++i) {
|
||||
if (vendor_id == SUPPORTED_VENDORS[i]) {
|
||||
for (i = 0; i < sizeof(supported_vendors)/sizeof(supported_vendors[0]); ++i) {
|
||||
if (vendor_id == supported_vendors[i]) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
@ -1028,7 +1028,9 @@ static int is_xboxone(unsigned short vendor_id, const struct libusb_interface_de
|
|||
|
||||
static int should_enumerate_interface(unsigned short vendor_id, const struct libusb_interface_descriptor *intf_desc)
|
||||
{
|
||||
//printf("Checking interface 0x%x %d/%d/%d/%d\n", vendor_id, intf_desc->bInterfaceNumber, intf_desc->bInterfaceClass, intf_desc->bInterfaceSubClass, intf_desc->bInterfaceProtocol);
|
||||
#if 0
|
||||
printf("Checking interface 0x%x %d/%d/%d/%d\n", vendor_id, intf_desc->bInterfaceNumber, intf_desc->bInterfaceClass, intf_desc->bInterfaceSubClass, intf_desc->bInterfaceProtocol);
|
||||
#endif
|
||||
|
||||
if (intf_desc->bInterfaceClass == LIBUSB_CLASS_HID)
|
||||
return 1;
|
||||
|
@ -1370,15 +1372,16 @@ static void init_xbox360(libusb_device_handle *device_handle, unsigned short idV
|
|||
This VID/PID is also shared with other HORI controllers, but they all seem
|
||||
to be fine with this as well.
|
||||
*/
|
||||
memset(data, 0, sizeof(data));
|
||||
libusb_control_transfer(device_handle, 0xC1, 0x01, 0x100, 0x0, data, sizeof(data), 100);
|
||||
}
|
||||
}
|
||||
|
||||
static void init_xboxone(libusb_device_handle *device_handle, unsigned short idVendor, unsigned short idProduct, const struct libusb_config_descriptor *conf_desc)
|
||||
{
|
||||
static const int VENDOR_MICROSOFT = 0x045e;
|
||||
static const int XB1_IFACE_SUBCLASS = 71;
|
||||
static const int XB1_IFACE_PROTOCOL = 208;
|
||||
static const int vendor_microsoft = 0x045e;
|
||||
static const int xb1_iface_subclass = 71;
|
||||
static const int xb1_iface_protocol = 208;
|
||||
int j, k, res;
|
||||
|
||||
(void)idProduct;
|
||||
|
@ -1388,12 +1391,12 @@ static void init_xboxone(libusb_device_handle *device_handle, unsigned short idV
|
|||
for (k = 0; k < intf->num_altsetting; k++) {
|
||||
const struct libusb_interface_descriptor *intf_desc = &intf->altsetting[k];
|
||||
if (intf_desc->bInterfaceClass == LIBUSB_CLASS_VENDOR_SPEC &&
|
||||
intf_desc->bInterfaceSubClass == XB1_IFACE_SUBCLASS &&
|
||||
intf_desc->bInterfaceProtocol == XB1_IFACE_PROTOCOL) {
|
||||
intf_desc->bInterfaceSubClass == xb1_iface_subclass &&
|
||||
intf_desc->bInterfaceProtocol == xb1_iface_protocol) {
|
||||
int bSetAlternateSetting = 0;
|
||||
|
||||
/* Newer Microsoft Xbox One controllers have a high speed alternate setting */
|
||||
if (idVendor == VENDOR_MICROSOFT &&
|
||||
if (idVendor == vendor_microsoft &&
|
||||
intf_desc->bInterfaceNumber == 0 && intf_desc->bAlternateSetting == 1) {
|
||||
bSetAlternateSetting = 1;
|
||||
} else if (intf_desc->bInterfaceNumber != 0 && intf_desc->bAlternateSetting == 0) {
|
||||
|
@ -1434,7 +1437,7 @@ static void calculate_device_quirks(hid_device *dev, unsigned short idVendor, un
|
|||
}
|
||||
}
|
||||
|
||||
static int hidapi_initialize_device(hid_device *dev, int config_number, const struct libusb_interface_descriptor *intf_desc, const struct libusb_config_descriptor *conf_desc)
|
||||
static int hidapi_initialize_device(hid_device *dev, const struct libusb_interface_descriptor *intf_desc, const struct libusb_config_descriptor *conf_desc)
|
||||
{
|
||||
int i =0;
|
||||
int res = 0;
|
||||
|
@ -1487,7 +1490,7 @@ static int hidapi_initialize_device(hid_device *dev, int config_number, const st
|
|||
dev->serial_index = desc.iSerialNumber;
|
||||
|
||||
/* Store off the USB information */
|
||||
dev->config_number = config_number;
|
||||
dev->config_number = conf_desc->bConfigurationValue;
|
||||
dev->interface = intf_desc->bInterfaceNumber;
|
||||
dev->interface_class = intf_desc->bInterfaceClass;
|
||||
dev->interface_subclass = intf_desc->bInterfaceSubClass;
|
||||
|
@ -1588,7 +1591,7 @@ HID_API_EXPORT hid_device *hid_open_path(const char *path)
|
|||
LOG("can't open device\n");
|
||||
break;
|
||||
}
|
||||
good_open = hidapi_initialize_device(dev, conf_desc->bConfigurationValue, intf_desc, conf_desc);
|
||||
good_open = hidapi_initialize_device(dev, intf_desc, conf_desc);
|
||||
if (!good_open)
|
||||
libusb_close(dev->device_handle);
|
||||
}
|
||||
|
@ -1666,7 +1669,7 @@ HID_API_EXPORT hid_device * HID_API_CALL hid_libusb_wrap_sys_device(intptr_t sys
|
|||
goto err;
|
||||
}
|
||||
|
||||
if (!hidapi_initialize_device(dev, conf_desc->bConfigurationValue, selected_intf_desc, conf_desc))
|
||||
if (!hidapi_initialize_device(dev, selected_intf_desc, conf_desc))
|
||||
goto err;
|
||||
|
||||
return dev;
|
||||
|
|
Loading…
Reference in New Issue