src/joystick/hidapi/SDL_hidapijoystick.c


Log

Author Commit Date CI Message
Pierre Wendling d0bbfdbf 2022-12-01T16:07:03 Clang-Tidy fixes (#6725) (cherry picked from commit 3c501b963dd8f0605a6ce7978882df39ba76f9cd)
Sam Lantinga b8d85c69 2022-11-30T12:51:59 Update for SDL3 coding style (#6717) I updated .clang-format and ran clang-format 14 over the src and test directories to standardize the code base. In general I let clang-format have it's way, and added markup to prevent formatting of code that would break or be completely unreadable if formatted. The script I ran for the src directory is added as build-scripts/clang-format-src.sh This fixes: #6592 #6593 #6594 (cherry picked from commit 5750bcb174300011b91d1de20edb288fcca70f8c)
Sam Lantinga a937b5c4 2022-11-28T13:47:30 Add 8BitDo to the list of Xbox 360 third party vendors Allows detection of the 8BitDo Ultimate Wired Controller
Sylvain Becker fb0ce375 2022-11-27T17:38:43 Cleanup add brace (#6545) * Add braces after if conditions * More add braces after if conditions * Add braces after while() conditions * Fix compilation because of macro being modified * Add braces to for loop * Add braces after if/goto * Move comments up * Remove extra () in the 'return ...;' statements * More remove extra () in the 'return ...;' statements * More remove extra () in the 'return ...;' statements after merge * Fix inconsistent patterns are xxx == NULL vs !xxx * More "{}" for "if() break;" and "if() continue;" * More "{}" after if() short statement * More "{}" after "if () return;" statement * More fix inconsistent patterns are xxx == NULL vs !xxx * Revert some modificaion on SDL_RLEaccel.c * SDL_RLEaccel: no short statement * Cleanup 'if' where the bracket is in a new line * Cleanup 'while' where the bracket is in a new line * Cleanup 'for' where the bracket is in a new line * Cleanup 'else' where the bracket is in a new line (cherry picked from commit 6a2200823c66e53bd3cda4a25f0206b834392652 to reduce conflicts merging between SDL2 and SDL3)
Sam Lantinga c70e6759 2022-11-03T12:37:54 Wait a bit for devices to initialize before trying to enumerate and open them. This works around udev event nodes arriving before hidraw nodes and the controller being opened twice - once using the Linux driver and once by the HIDAPI driver. This also fixes a kernel panic on Steam Link hardware due to trying to open the hidraw device node too early. A delay of 10 ms seems to be a good value, tested on Steam Link hardware.
Sam Lantinga b75d3187 2022-10-31T13:33:53 Sometimes the HID open doesn't succeed immediately after being notified about the device Tested on Steam Link hardware with the Nintendo Switch Pro controller, which will occasionally take 2 attempts to open.
Sam Lantinga 72f6e216 2022-10-25T12:25:57 Disabled debug logging
Sam Lantinga da478d1f 2022-10-25T10:30:56 Fixed build
Sam Lantinga a6018ae5 2022-10-25T10:23:51 Added support for the NVIDIA SHIELD controller v1.03 to the HIDAPI driver
Sam Lantinga 333935ff 2022-10-17T11:10:53 Make sure we completely unlock joysticks when opening HIDAPI devices Also lock the joysticks when adding and removing Android joysticks
Sam Lantinga 33050fea 2022-10-07T11:29:49 Only open HID devices that might have a HIDAPI driver available This prevents an OS prompt for every connected device when running on Android
Sam Lantinga fc720321 2022-10-06T18:23:07 Fix rare deadlock when opening a HID controller on Android Fixes https://github.com/libsdl-org/SDL/issues/6347
Sam Lantinga 0672dc8d 2022-10-02T08:48:38 Fixed combined Joy-Cons after https://github.com/libsdl-org/SDL/commit/aa2e2f4843567cfe4e6f2f4ffa3f0b74dd98f1ba (thanks @happyharryh!)
Sam Lantinga 18046b9a 2022-09-26T20:53:50 Fixed crash with a NULL serial number
Sam Lantinga b7fddb4c 2022-09-26T14:39:51 Minor tweaks
Sam Lantinga 39adcc0a 2022-09-26T14:20:34 Prefer USB input over Bluetooth for PS5/PS5/Switch controllers Nintendo Switch controllers will automatically turn off Bluetooth when connected over USB, but this takes care of that a little more quickly. PS4 and PS5 controllers will happily send reports over both Bluetooth and USB, so we'll prefer USB if connected and switch back to Bluetooth if USB is disconnected.
Sam Lantinga 51fefd1c 2022-09-23T02:39:35 Added support for third party PS3 controllers to the HIDAPI driver
Sam Lantinga b7940c29 2022-09-23T00:15:40 Allow HIDAPI controllers to override the default joystick type
Sam Lantinga fa2063fb 2022-09-22T23:42:25 Improved detection of third party PS4 and PS5 controllers
Sam Lantinga aa2e2f48 2022-09-22T18:22:17 Make sure HID devices can be opened before making them available to the application This prevents a number of issues where devices are enumerated but not actually able to be opened, like https://github.com/libsdl-org/SDL/issues/5781. We currently leave the devices open, allowing us to more easily do controller feature detection, protocol negotiation, detect dropped Bluetooth connections, etc. with the expectation that the application is likely to open the controllers shortly.
Sam Lantinga 7df571ff 2022-09-02T11:37:16 HIDAPI_DumpPacket() takes a const memory pointer
Sam Lantinga 8381e008 2022-09-01T21:13:16 Handle hotplugging of Wii controller extensions
Sam Lantinga c72e14e8 2022-09-01T15:29:01 Added initial support for Wii controllers (thanks @tellowkrinkle!)
Sam Lantinga cdaafcec 2022-08-30T14:56:11 The Kinvoca Joy-Cons are handled by the Joy-Con driver, not the Switch Pro driver.
Sam Lantinga b2c3237b 2022-08-30T14:14:38 Added support for the Kinvoca Joy-Cons These report their VID/PID as a Nintendo Switch Pro controller, but they are actually left/right Joy-Cons. We'll fix up the joystick GUID so applications can handle them appropriately.
Ludovico de Nittis e8cb4da7 2022-08-26T12:28:33 Add utility function to detect if SDL is inside a sandbox Refactor the previous sandbox check in a standalone function that also includes Snap support. Signed-off-by: Ludovico de Nittis <ludovico.denittis@collabora.com>
Sam Lantinga b6f96b69 2022-08-23T22:45:37 Initial HIDAPI driver support for the PS3 controller
Sam Lantinga 277b033e 2022-08-22T19:28:21 Refactor joystick GUID creation
Sam Lantinga c1e08739 2022-08-22T16:46:55 Added the CRC of the joystick name to the GUID This will make it possible to have mappings for different controllers that have the same VID/PID. This happens frequently with some generic controller boards that have been reused in many products. Fixes https://github.com/libsdl-org/SDL/issues/6004
Sam Lantinga 52b6899a 2022-08-19T11:11:23 Added hints for more fine grained control over HIDAPI Xbox controller support
Sam Lantinga 9670d2bb 2022-08-15T17:27:33 Make sure we hold the joystick lock when disconnecting a HIDAPI joystick This prevents crashes when calling SDL joystick API functions from a different thread while disconnection is happening. See https://github.com/libsdl-org/SDL/issues/6063 for a more thorough review of joystick locking.
Sam Lantinga 9ff498e7 2022-08-10T06:00:30 Make HIDAPI_JoystickOpen() more robust against internal logic errors Fixes https://github.com/libsdl-org/SDL/issues/6030
Sam Lantinga 1db7d33d 2022-08-09T17:04:26 Recover from Bluetooth devices temporarily out of range
Sam Lantinga 6d012b2a 2022-08-09T16:54:11 Better fix for rescanning devices after read failure
Sam Lantinga 5d63a3d4 2022-08-09T14:06:49 Re-enumerate devices if a read fails This allows combined Joy-Con devices to immediately separate if one of them is disconnected
Sam Lantinga 87825972 2022-08-08T08:22:20 Added SDL_GameControllerType enumeration for Nintendo Switch Joy-Con controllers
Sam Lantinga 29cdb2c9 2022-08-03T18:01:10 Added support for the Nintendo Switch Joy-Con Charging Grip
Sam Lantinga 8ab9dc8b 2022-08-03T13:18:00 Fixed crash if Joy-Cons are disabled while a combined Joy-Cons controller is open
Sam Lantinga bcdef4aa 2022-08-03T13:07:47 Added separate hints for Nintendo Online classic controllers and Joy-Cons This allows them to be enabled/disabled separately from Switch Pro HIDAPI support
Mathieu Eyraud 42b23207 2022-08-02T14:42:25 Fix memory leak of children for combined JoyCon
Sam Lantinga aee179e4 2022-07-28T21:50:20 Removed debug output
Sam Lantinga dfed862a 2022-07-28T19:35:46 Fixed variable shadow warning
Sam Lantinga 2fa2f9ff 2022-07-28T19:22:27 Greatly improved Nintendo Joy-Con support using the HIDAPI driver * Added support for mini-gamepad mode for Joy-Con controllers, matching the mapping for hid-nintendo on Linux and iOS 16 * Added the ability to merge left and right Joy-Con controllers into a single Pro-style controller * Added the hint SDL_HINT_JOYSTICK_HIDAPI_SWITCH_COMBINE_JOY_CONS to control this merging functionality * Removed the hint SDL_HINT_JOYSTICK_HIDAPI_JOY_CONS
Sam Lantinga be3a945a 2022-07-20T11:05:55 Added support for the 8BitDo Ultimate Wired Controller for Xbox
Cameron Gutman 6e712d24 2022-07-09T22:55:36 joystick: Add HIDAPI driver for NVIDIA SHIELD 2017 controller Basic input already works using the OS HID driver, but this enables force feedback and battery state reporting.
Cameron Gutman 3e114872 2022-06-30T20:36:45 joystick: Fix redetection of HIDAPI joysticks after reinitializing The HIDAPI joystick driver doesn't properly reset the change counter it uses to track if re-enumeration is needed when the joystick subsystem is quit and then reinitialized. The first SDL_Init(SDL_INIT_JOYSTICK) will result in the expected HIDAPI joysticks appearing, but subsequent calls will result in no joysticks being enumerated until another HIDAPI joystick is added or removed from the system.
chalonverse 3b191580 2022-06-27T17:19:39 Windows GDK Support (#5830) * Added GDK * Simplfied checks in SDL_config_wingdk.h * Added testgdk sample * Added GDK readme * Fixed error in merge of SDL_windows.h * Additional GDK fixes * OpenWatcom should not export _SDL_GDKGetTaskQueue * Formatting fixes * Moved initialization code into SDL_GDKRunApp
Sam Lantinga 16f55fbd 2022-06-15T20:44:43 Separate the controller protocol from the controller style This allows us to handle controllers that use the Xbox protocol but look like Nintendo Switch or Playstation controllers, like the Qanba Dragon Arcade Stick in PC mode
Sam Lantinga 68544be4 2022-06-10T11:31:59 Added support for the Nintendo Online controllers
Sam Lantinga b1cf3229 2022-05-19T16:49:47 Fixed HIDAPI PS4 controller being picked up when running under Steam Input with PS4 configuration enabled
Sam Lantinga e551384a 2022-04-26T14:54:14 Added functions to get the platform dependent name for a joystick or game controller
Ryan C. Gordon 4fe7b2cb 2022-03-24T11:00:43 static analysis: Fixed several complaints from codechecker. There are still some pending Objective-C specific issues. Reference issue #4600.
pionere 60deadba 2022-01-17T17:22:30 re-use return value of SDL_SetError/WIN_SetErrorFromHRESULT/SDL_OutOfMemory
Sam Lantinga 120c76c8 2022-01-03T09:40:00 Updated copyright for 2022
Ozkan Sezer a948ff84 2021-11-13T11:50:02 SDL_hidapijoystick.c: worked around a bogus 'unreachable code' warning.
Cameron Gutman 1ccfbf96 2021-11-11T11:13:08 joystick: Convert HasLED() into a generic GetCapabilities() function
Sam Lantinga b9b0df40 2021-11-11T12:52:31 Fixed Linux build
Sam Lantinga c9ada1c1 2021-11-11T12:45:38 Made HIDAPI device change notifications available via SDL_hid_device_change_count()
Sam Lantinga 2a6feb50 2021-11-08T07:10:38 Removed accidental debugging commit (thanks @DomGries!)
Sam Lantinga 5b646cd1 2021-11-07T22:58:44 Build hidapi code into SDL as a new public API This prevents conflicts with hidapi linked with applications, as well as allowing applications to make use of HIDAPI on Android and other platforms that might not normally have an implementation available.
Sam Lantinga 345c161f 2021-09-22T09:06:45 Fixed some accidental uses of external C runtime functions
Sam Lantinga cec5a129 2021-08-12T15:49:33 Fixed libudev hotplug notifications in the HIDAPI driver
Ryan C. Gordon dd683073 2021-08-06T15:13:14 hidapi: Patched to compile on QNX. Fixes #4591.
Sam Lantinga 2a53f831 2021-07-26T23:29:20 Fixed controllers showing up under both MFI and HIDAPI drivers The Game Controller Kit doesn't show the controllers at startup, so the HIDAPI driver sees them first and therefore gets preference when a controller is supported by both drivers. This fixes bug https://github.com/libsdl-org/SDL/issues/4209
Sam Lantinga d135c076 2021-07-08T13:22:41 Added SDL_GameControllerSendEffect() and SDL_JoystickSendEffect() to allow applications to send custom effects to the PS4 and PS5 controllers See testgamecontroller.c for an example of a custom PS5 trigger effect
Dimitriy Ryazantcev 17ed8d80 2021-07-07T16:05:35 Added HIDAPI backend for Amazon Luna Controller Model T28B69 connected via Bluetooth LE (VID:0171, PID:0419). To enter Bluetooth pairing mode hold B and Action (button with circle) buttons for 3 seconds. It works via usual HIDAPI if special filter driver is not installed: https://www.amazon.com/gp/help/customer/display.html?nodeId=GZCT4CTFHXLHEB9T With that driver installed it mimics Xbox One controller and works via XInput under Windows. Under DInput this controller is not usable at all.
Dimitriy Ryazantcev b81969d4 2021-05-17T14:50:33 Be more explicit about Xbox 360/One device ids. When Xbox One/Series Controllers are connected via USB on Windows they all are using `XBOXGIP` driver and produce a special ProductID `0x02FF` (GIP software PID) for any connected controller. On the other hand `Xbox 360 Wireless Controller Reciever` (PID 0x0719) is using `XUSB` driver and produces special ProductID `0x02A1` (XUSB software PID) for each connected Xbox 360 Wireless Controller. Also fixed Xbox One Series X Controller comment.
Steven Noonan 4535d654 2021-04-22T14:35:59 HIDAPI_UpdateDiscovery: only treat "add" and "remove" events as relevant I have a buggy system which reports a udev "change" event for an empty USB-C port every 0.14 seconds, which causes annoying frame hitches because SDL decides that means it needs to do a libusb hid_enumerate, which is slow (~25ms!) because of the get_usb_string() calls in there. We only need to re-enumerate if we've seen a device added or removed, so let's filter out the change event first. Signed-off-by: Steven Noonan <steven@valvesoftware.com> Signed-off-by: Sam Lantinga <slouken@libsdl.org>
Mathieu Eyraud 7a2b6f33 2021-02-22T13:32:42 Guard Inotify stuff with macro This fix implicit declaration of close and unused variable warning.
David Gow db58166e 2021-02-21T17:28:08 joystick: hidapi: Properly include <unistd.h> when inotify not available In the extremely unlikely event that inotify is not available (and, therefore, HAVE_INOTIFY is not #defined), SDL will no-longer build. This is because <unistd.h> is only included when HAVE_INOTIFY is defined, and PR #4098 adds a call to access(…, F_OK), which requires <unistd.h>. (Note that the F_OK symbol is the only one which actually prevented SDL from compiling, but both access() and close() fell back to implicit definitions, which is a bit concerning.) Fixes: 8d43f45a7b ("Don't use udev for joystick enumeration if running in a container")
Ludovico de Nittis 8d43f45a 2021-02-16T14:13:30 Don't use udev for joystick enumeration if running in a container If we are running in a container, like Flatpak[1] or pressure-vessel[2], it's likely that we are using user namespaces, therefore udev event notification via netlink won't work reliably. Use their filesystem API to detect them and automatically fallback to the inotify-based enumeration. [1] <https://flatpak.org/> [2] <https://gitlab.steamos.cloud/steamrt/steam-runtime-tools/-/tree/master/pressure-vessel> Signed-off-by: Ludovico de Nittis <ludovico.denittis@collabora.com>
Ludovico de Nittis 2c326915 2021-02-16T12:39:48 Use inotify for HIDAPI joystick enumeration if not using udev This improves SDL's ability to detect HIDAPI joystick hotplug in a container environment because we cannot reliably receive events from udev in a container. For a more detailed explanation of why this issue happens with containers, please check the previous commit "joystick: Use inotify to detect joystick unplug if not using udev" (b0eba1c5). Signed-off-by: Ludovico de Nittis <ludovico.denittis@collabora.com>
Ludovico de Nittis b17242bf 2021-02-16T11:50:20 Allow libudev for HIDAPI joystick to be disabled at runtime As already explained in the previous commit "joystick: Allow libudev to be disabled at runtime" (13e7d1a9), libudev can fail in a container. To make it easier to experiment with, we add a new environment variable "SDL_HIDAPI_JOYSTICK_DISABLE_UDEV" that disables udev and let it fallback to the device enumeration using polling. Signed-off-by: Ludovico de Nittis <ludovico.denittis@collabora.com>
Sam Lantinga 42607909 2021-02-20T22:51:57 Remove devices from the list after they've been disconnected due to read errors. This fixes problems with controllers not being re-detected when a computer goes to sleep and a controller is removed and plugged back in while it's asleep.
Sam Lantinga 7f710e93 2021-01-28T14:54:01 Make sure we don't create a game controller mapping for HID devices that aren't supported by HIDAPI
Sam Lantinga c857b5e0 2021-01-23T11:21:01 Minor cleanup
Sam Lantinga 1981d23f 2021-01-23T11:06:35 Fixed bug 5466 - Add haptic support for Stadia Controller Dimitriy Ryazantcev Consider adding support for Stadia Controller haptics. Here is example code how to deal with it: https://github.com/chromium/chromium/blob/99314be8152e688bafbbf9a615536bdbb289ea87/device/gamepad/hid_haptic_gamepad.cc#L45
Sam Lantinga e2f46ed8 2021-01-14T23:49:20 Always lock the HIDAPI device when closing, in case rumble is pending
Sam Lantinga 907b8eeb 2021-01-14T23:49:16 Make sure the HIDAPI device is locked when closing it, in case there is rumble pending that didn't complete
Sam Lantinga 9130f7c3 2021-01-02T10:25:38 Updated copyright for 2021
Sam Lantinga 80e5c689 2020-12-13T01:20:38 Fixed the PS5 controller not disconnecting when powered off
Sam Lantinga cb361896 2020-12-09T07:16:22 Fixed bug 5235 - All internal sources should include SDL_assert.h Ryan C. Gordon We should really stick this in SDL_internal.h or something so it's always available.
Sam Lantinga c9723c40 2020-12-07T09:38:21 Fixed potential hang in joystick close if the rumble thread is blocked for some reason It's still possible to hang when shutting down, if the rumble thread is still hung, but it won't block indefinitely at runtime.
Sam Lantinga 1031231b 2020-12-03T18:17:03 Fixed duplicating a device between XInput and HIDAPI
Sam Lantinga a0c5bfa3 2020-11-27T13:08:40 Moved raw input event processing from the main thread to the joystick thread This allows fast joystick event delivery regardless of what the main thread is doing.
Sam Lantinga ce77966d 2020-11-27T10:44:49 Fixed RAWINPUT_IsDevicePresent() not returning TRUE for Xbox One controllers
Sam Lantinga 9fc4a4c9 2020-11-24T22:25:26 Revamped Xbox One HIDAPI init sequence Added support for querying the controller serial number on newer firmware
Sam Lantinga 5b3616c3 2020-11-23T18:24:05 Generalized the raw input controller driver and moved XInput/WGI detection into it for XInput devices This fixes bad report parsing for various newer Xbox controllers, and this driver is now preferred over XInput, since it handles more than 4 controllers.
Sam Lantinga fcb21aa8 2020-11-17T10:30:20 Added API for sensors on game controllers Added support for the PS4 controller gyro and accelerometer on iOS and HIDAPI drivers Also fixed an issue with the accelerometer on iOS having inverted axes
Sam Lantinga d140d887 2020-11-16T17:36:47 Added SDL_JoystickGetSerial() and SDL_GameControllerGetSerial()
Sam Lantinga 71e32f5e 2020-11-16T15:00:15 Added SDL_crc32()
Sam Lantinga c6c116e8 2020-11-16T10:51:13 Implemented setting the LED color on the PS5 controller
Sam Lantinga 78422fa3 2020-11-13T13:17:07 Added more detail on the PS5 controller state packet and enable full reports over Bluetooth
Sam Lantinga 1e2caac5 2020-11-11T18:57:37 Added SDL_JoystickRumbleTriggers() and SDL_GameControllerRumbleTriggers()
Sam Lantinga 3a3aaac2 2020-11-06T11:30:52 Added 4 auxiliary buttons to the game controller API Xbox Elite controllers use AUX1-AUX4 to represent the paddle buttons when using the HIDAPI driver PS4 and PS5 controllers use AUX1 to represent the touchpad button Nintendo Switch Pro controllers use AUX1 to represent the capture button
Sam Lantinga a22beef4 2020-11-05T17:03:28 Moved the PS5 controller driver to a separate file, as the advanced feature protocol is very different from that of the PS4
Sam Lantinga e555d453 2020-11-05T11:07:54 Added SDL_JoystickHasLED Currently, this is only supported by the PS4 HIDAPI driver.
Sam Lantinga d000c1cd 2020-05-29T21:22:11 Fixed bug 5155 - HIDAPI_JoystickDisconnected incorrect array shift Anthony Pesch I was looking into my own input bug and noticed an issue in the HIDAPI code while looking over it. I don't have a controller that goes down this path to test and try to provoke the issue, but it looks pretty straight forward. The memmove to shift the joystick id array on disconnect isn't scaling the size by sizeof(SDL_JoystickID), likely corrupting the ids on disconnect.
Sam Lantinga 345b4d7e 2020-05-29T13:37:21 Fixed bug 5161 - Autodetect controller mappings based on the Linux Gamepad Specification Jan Bujak I wrote a new driver for my gamepad on Linux. I'd like SDL to support it out-of-box, as currently it just treats it as a generic joystick instead of a gamepad. From what I can see the only way to do that is to either 1) pick one of the already supported controllers' PID, VID and button layouts and have my driver send that (effectively lying that it's something else), or 2) submit a preconfigured, hardcoded mapping to SDL. Both of those, in my opinion, are silly when we already have the Linux Gamepad Specification which standarizes this: https://www.kernel.org/doc/html/v4.15/input/gamepad.html Unfortunately SDL doesn't make use of it currently. So I've took it upon myself to add it; patch is in the attachments. Basically what the patch does is that if SDL finds no built-it controller mappings for a given joystick it then asks the joystick backend to autodetect it, and that uses the relevant evdev bits to figure out which button/axis is which. (See the specs for more details.) With this patch applied my own driver for my controller works out-of-box with SDL with no extra configuration and is correctly recognized as a gamepad; this is also going to be the case for any other driver which follows the Linux Gamepad Specification.
Ethan Lee 83cddd2e 2020-04-30T11:57:29 Add SDL_JoystickSetLED. Currently, this is only supported by the PS4 HIDAPI driver.