Skip to content

Commit

Permalink
Fixed Xbox 360 Controller support using libusb on Linux
Browse files Browse the repository at this point in the history
  • Loading branch information
slouken committed Dec 12, 2019
1 parent 1ac7eab commit cd515bd
Showing 1 changed file with 8 additions and 17 deletions.
25 changes: 8 additions & 17 deletions src/hidapi/libusb/hid.c
Expand Up @@ -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))
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;
}
}
Expand Down

0 comments on commit cd515bd

Please sign in to comment.