src/joystick/hidapi/SDL_hidapi_switch.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)
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 e8fdb861 2022-10-15T10:02:39 Removed redundant masking when loading the IMU calibration
happyharryh a6573f94 2022-10-16T00:23:25 Fix bugs in IMU calibration loading for Nintendo Controllers
happyharryh 6f224e4d 2022-10-11T10:44:20 Made timestamp_us of sensor events increase monotonically for Nintendo controllers
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 bd6afc23 2022-10-02T10:15:39 Fixed sensor axes in vertical mode
Sam Lantinga b4c25f57 2022-10-02T09:51:05 Remapped the side button and trigger as paddles for the mini-gamepad mode of the Joy-Cons This is the only case where the mapping differs between right and left Joy-Cons in mini-gamepad mode. The left Joy-Con will have the left paddles and the right Joy-Con will have the right paddles. This facilitates co-op gameplay with individual actions while still using the normal mini-gamepad mode. The paddles are used for this because conceptually they are more awkward to hit than the normal controls and they are in roughly the correct hand position.
Sam Lantinga 37dfa262 2022-10-02T09:36:50 Added paddle mapping for combined Joy-Cons
Happy Harry 6c8bf3af 2022-10-03T00:19:34 Add vertical mode for Nintendo Joy-Con (#6303) * Added support for vertical mode for Joy-Con controllers * Added the hint SDL_HINT_JOYSTICK_HIDAPI_VERTICAL_JOY_CONS for switching to this mode * Added support for SL/SR buttons in combined/vertical mode and L/ZL/R/ZR buttons in mini-gamepad mode
Sam Lantinga 18eb319a 2022-09-27T12:34:03 Added sensor timestamp for Nintendo Switch controllers
Sam Lantinga 2c518747 2022-09-27T09:56:02 Added microsecond timestamp to sensor values for PS4 and PS5 controllers using the HIDAPI driver
Sam Lantinga 1e1be0b9 2022-09-26T23:00:58 Updated logic to match between PS4/PS5/Switch controllers
Sam Lantinga 67fa6a93 2022-09-26T20:49:26 Don't wait a long time for zombie Bluetooth controllers If a Nintendo Switch Pro controller is turned off, it will leave the controller connected in Windows, but not responding to reports. Don't wait a really long time trying to get information from a controller in this state.
Sam Lantinga 67db8a91 2022-09-26T20:41:51 Wait for input before reconnecting a Bluetooth device On Windows, the Bluetooth device can remain in a connected state if the controller just shut down. It won't return any errors, but it also won't generate any input reports in this state, so wait until we know for sure that the Bluetooth controller is sending data before letting the application know it's available.
Sam Lantinga 2cc91761 2022-09-26T18:52:26 Removed debug logging
Sam Lantinga 2c98c8af 2022-09-26T18:39:18 Use better default values for Switch controller calibration
Sam Lantinga a205c5e2 2022-09-26T18:18:16 Use separate extents for simple and advanced reports
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 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 4018f35e 2022-09-07T00:00:27 Added left and right sensors for Nintendo Joy-Con and Wii controllers
Sam Lantinga 396411c0 2022-09-01T20:27:34 Added mapping for the Wii Nunchuk extension
Sam Lantinga 7861f924 2022-08-31T13:34:43 Removed debug print statements
Sam Lantinga 62f2379e 2022-08-31T13:24:23 Try up to 20 times to read the controller type It takes a while for Joy-Cons to initialize when plugged in via the Nintendo Joy-Con Charging Grip.
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.
Sam Lantinga f1aa8434 2022-08-25T21:51:20 Don't report rumble capability for Nintendo Online controllers
Sam Lantinga 52b6899a 2022-08-19T11:11:23 Added hints for more fine grained control over HIDAPI Xbox controller support
Sam Lantinga 8e782876 2022-08-09T21:30:11 Fixed spamming the controller with reset IMU commands when they are failing
Sam Lantinga eab27b90 2022-08-09T17:58:42 Make sure Switch controller initialization is synchronous and start the input timeout then
Sam Lantinga 483a010f 2022-08-09T15:39:39 Fixed accidentally deadlocking the rumble thread with combined Joy-Cons Also added more accurate check for sensor data. At least one axis will always have acceleration because of gravity.
Sam Lantinga da50f1bd 2022-08-09T14:05:43 Bluetooth devices can recover from over a second of dropped reports
Sam Lantinga 824f2d46 2022-08-09T13:41:58 Added a second hint SDL_HINT_JOYSTICK_HIDAPI_JOYCON_HOME_LED to control the Home button LED on Nintendo Joy-Con controllers separately from Nintendo Switch Pro controllers
Sam Lantinga 8aa6922f 2022-08-09T13:25:52 Fixed detecting Bluetooth disconnection on Nintendo Switch controllers
Sam Lantinga df537a7c 2022-08-09T00:18:19 SDL_GameControllerSetPlayerIndex(gamecontroller, -1) means turn off the player LED if possible
Sam Lantinga 6204ae50 2022-08-08T20:09:49 Restart the IMU if the controller stops sending gyro/accel data
Sam Lantinga d58bec72 2022-08-08T17:19:12 Fixed Joy-Con gyro axes in mini-gamepad mode
Sam Lantinga 87825972 2022-08-08T08:22:20 Added SDL_GameControllerType enumeration for Nintendo Switch Joy-Con controllers
Sam Lantinga 52bf5b1d 2022-08-06T10:34:19 Added the hint SDL_HINT_JOYSTICK_HIDAPI_SWITCH_PLAYER_LED to control whether the player LED is set on Nintendo Switch controllers
Sam Lantinga 4a9ceb7b 2022-08-04T11:33:36 The HORIPAD S uses the Xbox 360 protocol on all platforms and shows up as multiple styles of controller, depending on what model you have.
Sam Lantinga 28c01955 2022-08-04T10:46:37 Fixed button mapping for the HORIPAD S This controller actually comes in at least two flavors: a GameCube controller and an arcade pad, neither of which should have the face buttons remapped.
Sam Lantinga 43b90484 2022-08-04T00:40:38 Retry a little longer when writing to the Nintendo Joy-Con Charging Grip
Sam Lantinga dfd2c574 2022-08-03T22:27:43 Removed unused variable
Sam Lantinga c84dea09 2022-08-03T22:12:21 Fixed detecting the controller type of controllers over USB
Sam Lantinga ba297f12 2022-08-03T21:46:01 Use the Nintendo controller type to determine whether to always use button labels
Sam Lantinga 946f4777 2022-08-03T21:33:38 Don't set Bluetooth controllers to wired power level
Sam Lantinga 57c3b2c9 2022-08-03T21:31:12 Don't rely on the device VID/PID to get the Nintendo controller type The Nintendo Online Sega Genesis controller reports the SNES VID/PID over Bluetooth. This is a more robust way of handling future controllers as well, so let's go with this instead. Also use full reports over Bluetooth, and don't report gyro for Nintendo Online classic controllers.
Sam Lantinga b6aadb16 2022-08-03T20:38:33 Added k_eSwitchDeviceInfoControllerType_N64 to ESwitchDeviceInfoControllerType
Sam Lantinga bdfb32de 2022-08-03T20:30:58 Added some additional Nintendo controller types to ESwitchDeviceInfoControllerType
Sam Lantinga 5d50fa52 2022-08-03T19:39:36 Fixed timeout opening the Nintendo Joy-Con Charging Grip Sometimes opening the right Joy-Con takes a little longer for some reason
Sam Lantinga 29cdb2c9 2022-08-03T18:01:10 Added support for the Nintendo Switch Joy-Con Charging Grip
Sam Lantinga a8120104 2022-08-03T13:53:49 The Nintendo Online classic controllers and Joy-Cons shouldn't show up as Switch Pro controllers
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 59a104b8 2022-08-02T15:00:55 Do not pass NULL to memcpy ReadJoyConControllerType calls WriteSubcommandSync with pbuf=NULL
Sam Lantinga 875b737c 2022-07-28T21:39:32 Added support for the Nintendo Online NES Controllers to the HIDAPI driver
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 def60ce6 2022-07-27T19:20:42 Fixed the name of the HIDAPI Joy-Con controller for consistency with other drivers
Sam Lantinga a169259f 2022-07-27T09:05:02 Actually we don't need to unlock to send k_eSwitchProprietaryCommandIDs_ForceUSB since we don't wait for reply
Sam Lantinga c51464d9 2022-07-27T09:00:39 Put the Nintendo Switch Pro controller back into enhanced mode as needed Fixes https://github.com/libsdl-org/SDL/issues/3450
Sam Lantinga a423848e 2022-07-25T11:26:18 Allow floating point values for SDL_HINT_JOYSTICK_HIDAPI_SWITCH_HOME_LED This allows setting the brightness of the home LED on Nintendo Switch Pro controllers, in the range 0.0 - 1.0. This can be updated at runtime by setting the hint dynamically. Fixes https://github.com/libsdl-org/SDL/issues/3787
Sam Lantinga 68544be4 2022-06-10T11:31:59 Added support for the Nintendo Online controllers
Jibb Smart d7c07d6b 2022-04-27T00:57:17 Read motion sensor scale from Switch controllers (#5555) * Read IMU scale data from Switch controllers. Up until now, SDL has used hard-coded scaling which isn't correct with some supported controllers. * Moved declarations to beginning of code blocks to better fit with SDL style requirements
meyraud705 0964c84d 2022-02-02T11:21:32 Always use SDL_PrivateJoystickBatteryLevel to update battery level But do not use it for initialisation.
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
Sam Lantinga 66058bbb 2021-11-15T16:52:56 Fixed exception accessing Bluetooth devices on Android 12 Since accessing Bluetooth prompts the user for permission on both Android and iOS, and we only need it for Steam Controller support, we'll leave it off by default. You can enable it by setting the hint SDL_HINT_JOYSTICK_HIDAPI_STEAM to "1" before calling SDL_Init() Fixes https://github.com/libsdl-org/SDL/issues/4952
Ozkan Sezer a2c27d39 2021-11-13T17:56:28 SDL_hidapi_switch.c (ConstructSubcommand): lose use of '&' on rumbleData SwitchCommonOutputPacket_t->rumbleData is an array.
Cameron Gutman afccabb8 2021-11-11T12:12:05 joystick: Add capability flags for rumble and trigger rumble When API limitations force us to guess, we favor a false positive (reporting support when it doesn't exist) compared to a false negative.
Cameron Gutman 1ccfbf96 2021-11-11T11:13:08 joystick: Convert HasLED() into a generic GetCapabilities() function
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 fe2fe290 2021-11-07T11:48:16 Backed out accidentally committed PR https://github.com/libsdl-org/SDL/pull/4849
Sam Lantinga 86bc65a7 2021-11-07T11:35:12 Fixed non-Apple builds
Sam Lantinga 345c161f 2021-09-22T09:06:45 Fixed some accidental uses of external C runtime functions
Sam Lantinga 503ea8e8 2021-08-25T14:41:58 Don't modify the Nintendo Switch home LED state by default
Sam Lantinga 9fdb0645 2021-08-04T11:33:28 Added support for the Joy-Con Charging Grip when SDL_HINT_JOYSTICK_HIDAPI_JOY_CONS is enabled
Sam Lantinga b3a0174b 2021-07-29T14:23:15 Scale the values correctly based on the sensor type (thanks @meyraud705)
Sam Lantinga a186a503 2021-07-29T06:43:39 Added SDL_GameControllerGetSensorDataRate() to get the sensor update rate for a controller.
Sam Lantinga 8d527def 2021-07-26T10:18:18 Revert "hidapi_switch: Implement HD rumble effect (#4538)" This reverts commit 19082b115b8ba3fff93e1c317c380718086a509c, which broke rumble on the Nintendo Switch Pro controller
Narr the Reg 19082b11 2021-07-26T12:00:53 hidapi_switch: Implement HD rumble effect (#4538)
Sam Lantinga 3c9559f7 2021-07-24T19:43:56 Don't try to rumble third-party Nintendo Switch Pro controllers Sending rumble to the PowerA Spectra Nintendo Switch controller hangs input reports for a couple of seconds.
german77 e6e8fe6d 2021-07-23T10:45:03 hidapi_switch: Implement analog rumble
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
Sam Lantinga 3fcaf5b4 2021-05-25T10:33:30 Fixed incorrect axis scaling for Nintendo Switch controllers
JibbSmart c287087f 2021-02-23T09:26:03 Only change joystick->nbuttons for Joy-Cons, since they're the only ones that have these "paddles"
JibbSmart ee52624f 2021-02-22T17:23:13 Switch Joy-Con SL and SR buttons are now mapped to matching paddle positions so that all buttons can be accessed when using SDL_HINT_JOYSTICK_HIDAPI_JOY_CONS
Sam Lantinga ac72a2ba 2021-01-25T20:38:50 Fixed bug 5493 - Hint to let the user opt out of having Switch controllers' Home button lit when opened jibb New hint to let the user opt out of having Switch controllers' Home button lit when opened. This is more consistent with the Switch itself (which doesn't light the button normally) and may be preferred by users who may disconnect their controller without letting the application close it. I think this warrants a Switch-specific hint because the default behaviour is unusual (inconsistent with using a Switch controller on a Switch itself or with some other programs on PC), and because of that it's distinct from other lights (the player number on Switch controllers and the player colour on PlayStation controllers).
Sam Lantinga c857b5e0 2021-01-23T11:21:01 Minor cleanup
JibbSmart 0f57864c 2021-01-18T19:57:29 Hint SDL_HINT_JOYSTICK_HIDAPI_JOY_CONS added so we can recognise a Joy-Con as half a Pro Controller, so we can read its analog input and read its sensors just like we do a Pro Controller.
Ozkan Sezer bdb3e6b8 2021-01-15T12:40:00 SDL_hidapi_switch.c: fix build with older compilers
Sam Lantinga e3dbae50 2021-01-14T23:49:41 Get the serial number for the Nintendo Switch Pro controller
Sam Lantinga 5fc743c4 2021-01-14T23:49:37 Phantom Nintendo Switch Pro Controller initialization problem
Sam Lantinga 92742306 2021-01-14T23:49:33 Fixed rumble reset failing for Switch Pro controllers in USB mode
Sam Lantinga e2f46ed8 2021-01-14T23:49:20 Always lock the HIDAPI device when closing, in case rumble is pending
JibbSmart e9887045 2021-01-11T15:36:40 Gyro and Accel sensor support for Switch Pro Controller. Note that axes are changed to match the axes we're using with PlayStation controllers, since users will appreciate consistent behaviour across devices.
Sam Lantinga 9130f7c3 2021-01-02T10:25:38 Updated copyright for 2021
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