mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-09-12 14:28:14 +00:00
Fixed initializing the Nyko and EVORETRO GameCube adaptors
This requires root on most Linux distributions, as we have to directly send USB messages to the devices to enable input reports.
This commit is contained in:
@@ -955,6 +955,57 @@ HID_API_EXPORT const wchar_t* HID_API_CALL hid_error(hid_device *device)
|
||||
return wrapper->backend->hid_error(wrapper->device);
|
||||
}
|
||||
|
||||
/* This is needed to enable input for Nyko and EVORETRO GameCube adaptors */
|
||||
void SDL_EnableGameCubeAdaptors(void)
|
||||
{
|
||||
#ifdef SDL_LIBUSB_DYNAMIC
|
||||
libusb_context *usb_context = NULL;
|
||||
libusb_device **devs = NULL;
|
||||
libusb_device_handle *handle = NULL;
|
||||
struct libusb_device_descriptor desc;
|
||||
ssize_t i, num_devs;
|
||||
int kernel_detached = 0;
|
||||
|
||||
if (libusb_init(&usb_context) == 0) {
|
||||
num_devs = libusb_get_device_list(usb_context, &devs);
|
||||
for (i = 0; i < num_devs; ++i) {
|
||||
if (libusb_get_device_descriptor(devs[i], &desc) != 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (desc.idVendor != 0x057e || desc.idProduct != 0x0337) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (libusb_open(devs[i], &handle) != 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (libusb_kernel_driver_active(handle, 0)) {
|
||||
if (libusb_detach_kernel_driver(handle, 0) == 0) {
|
||||
kernel_detached = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (libusb_claim_interface(handle, 0) == 0) {
|
||||
libusb_control_transfer(handle, 0x21, 11, 0x0001, 0, NULL, 0, 1000);
|
||||
libusb_release_interface(handle, 0);
|
||||
}
|
||||
|
||||
if (kernel_detached) {
|
||||
libusb_attach_kernel_driver(handle, 0);
|
||||
}
|
||||
|
||||
libusb_close(handle);
|
||||
}
|
||||
|
||||
libusb_free_device_list(devs, 1);
|
||||
|
||||
libusb_exit(usb_context);
|
||||
}
|
||||
#endif /* SDL_LIBUSB_DYNAMIC */
|
||||
}
|
||||
|
||||
#endif /* SDL_JOYSTICK_HIDAPI */
|
||||
|
||||
/* vi: set sts=4 ts=4 sw=4 expandtab: */
|
||||
|
||||
Reference in New Issue
Block a user