Fixed Xbox 360 Controller support using libusb on Linux
authorSam Lantinga <slouken@libsdl.org>
Thu, 12 Dec 2019 14:26:34 -0800
changeset 133381caca966b0c6
parent 13337 9cbbe45952a4
child 13339 28292d16d893
Fixed Xbox 360 Controller support using libusb on Linux
src/hidapi/libusb/hid.c
     1.1 --- a/src/hidapi/libusb/hid.c	Thu Dec 12 14:25:02 2019 -0800
     1.2 +++ b/src/hidapi/libusb/hid.c	Thu Dec 12 14:26:34 2019 -0800
     1.3 @@ -554,13 +554,7 @@
     1.4  
     1.5  	/* Also enumerate Xbox 360 controllers */
     1.6  	if (is_xbox360(vendor_id, intf_desc))
     1.7 -	{
     1.8 -		/* hid_write() to Xbox 360 controllers doesn't seem to work on Linux:
     1.9 -		   - xpad 1-2:1.0: xpad_try_sending_next_out_packet - usb_submit_urb failed with result -2
    1.10 -		   Xbox 360 controller support is good on Linux anyway, so we'll ignore this for now.
    1.11  		return 1;
    1.12 -		*/
    1.13 -	}
    1.14  
    1.15  	/* Also enumerate Xbox One controllers */
    1.16  	if (is_xboxone(vendor_id, intf_desc))
    1.17 @@ -1057,17 +1051,17 @@
    1.18  int HID_API_EXPORT hid_write(hid_device *dev, const unsigned char *data, size_t length)
    1.19  {
    1.20  	int res;
    1.21 -	int report_number = data[0];
    1.22 -	int skipped_report_id = 0;
    1.23 -
    1.24 -	if (report_number == 0x0) {
    1.25 -		data++;
    1.26 -		length--;
    1.27 -		skipped_report_id = 1;
    1.28 -	}
    1.29 -
    1.30  
    1.31  	if (dev->output_endpoint <= 0) {
    1.32 +		int report_number = data[0];
    1.33 +		int skipped_report_id = 0;
    1.34 +
    1.35 +		if (report_number == 0x0) {
    1.36 +			data++;
    1.37 +			length--;
    1.38 +			skipped_report_id = 1;
    1.39 +		}
    1.40 +
    1.41  		/* No interrupt out endpoint. Use the Control Endpoint */
    1.42  		res = libusb_control_transfer(dev->device_handle,
    1.43  			LIBUSB_REQUEST_TYPE_CLASS|LIBUSB_RECIPIENT_INTERFACE|LIBUSB_ENDPOINT_OUT,
    1.44 @@ -1097,9 +1091,6 @@
    1.45  		if (res < 0)
    1.46  			return -1;
    1.47  
    1.48 -		if (skipped_report_id)
    1.49 -			actual_length++;
    1.50 -
    1.51  		return actual_length;
    1.52  	}
    1.53  }