From cd515bd1b9b1726502d94e7830f862db2b4bd92e Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Thu, 12 Dec 2019 14:26:34 -0800 Subject: [PATCH] Fixed Xbox 360 Controller support using libusb on Linux --- src/hidapi/libusb/hid.c | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/src/hidapi/libusb/hid.c b/src/hidapi/libusb/hid.c index b44e886bf0002..e346cd20e8aa2 100644 --- a/src/hidapi/libusb/hid.c +++ b/src/hidapi/libusb/hid.c @@ -554,13 +554,7 @@ static int should_enumerate_interface(unsigned short vendor_id, const struct lib /* Also enumerate Xbox 360 controllers */ if (is_xbox360(vendor_id, intf_desc)) - { - /* hid_write() to Xbox 360 controllers doesn't seem to work on Linux: - - xpad 1-2:1.0: xpad_try_sending_next_out_packet - usb_submit_urb failed with result -2 - Xbox 360 controller support is good on Linux anyway, so we'll ignore this for now. return 1; - */ - } /* Also enumerate Xbox One controllers */ if (is_xboxone(vendor_id, intf_desc)) @@ -1057,17 +1051,17 @@ hid_device * HID_API_EXPORT hid_open_path(const char *path, int bExclusive) int HID_API_EXPORT hid_write(hid_device *dev, const unsigned char *data, size_t length) { int res; - int report_number = data[0]; - int skipped_report_id = 0; - if (report_number == 0x0) { - data++; - length--; - skipped_report_id = 1; - } + if (dev->output_endpoint <= 0) { + int report_number = data[0]; + int skipped_report_id = 0; + if (report_number == 0x0) { + data++; + length--; + skipped_report_id = 1; + } - if (dev->output_endpoint <= 0) { /* No interrupt out endpoint. Use the Control Endpoint */ res = libusb_control_transfer(dev->device_handle, LIBUSB_REQUEST_TYPE_CLASS|LIBUSB_RECIPIENT_INTERFACE|LIBUSB_ENDPOINT_OUT, @@ -1097,9 +1091,6 @@ int HID_API_EXPORT hid_write(hid_device *dev, const unsigned char *data, size_t if (res < 0) return -1; - if (skipped_report_id) - actual_length++; - return actual_length; } }