Commit graph

69 commits

Author SHA1 Message Date
Sam Lantinga 05b03032f1 Updated copyright for 2023 2023-01-09 09:52:59 -08:00
SDL Wiki Bot 393acf6362 Sync SDL wiki -> header 2022-10-25 18:07:13 +00:00
SDL Wiki Bot 4ca86dae2f Sync SDL wiki -> header 2022-10-05 23:26:14 +00:00
Sam Lantinga 6c2c01e0d1 Fixed documentation to match function parameter 2022-08-31 15:04:12 -07:00
Sam Lantinga 0e4baf1c4e Don't crash if SDL functions are passed a closed joystick or gamecontroller 2022-08-30 12:39:23 -07:00
SDL Wiki Bot 3fe6768caf Sync SDL wiki -> header 2022-08-30 18:47:15 +00:00
Sam Lantinga 40bd4feedc Revamped joystick locking
This makes the joystick locking more robust by holding the lock while updating joysticks.

The lock should be held when calling any SDL joystick function on a different thread than the one calling SDL_PumpEvents() and SDL_JoystickUpdate().

It is now possible to hold the lock while reinitializing the joystick subsystem, however any open joysticks will become invalid and potentially cause crashes if used afterwards.

Fixes https://github.com/libsdl-org/SDL/issues/6063
2022-08-30 11:42:13 -07:00
SDL Wiki Bot 644a4e5b31 Sync SDL wiki -> header 2022-08-28 02:01:12 +00:00
Sam Lantinga 3cbfd75d0f Re-added the CRC to the joystick guid
This is now used as a crc field in the mapping rather than directly in mapping guids, for better mapping compatibility between versions of SDL.

Added SDL_GetJoystickGUIDInfo() to get device information encoded in a joystick GUID, so that mapping programs can clear the CRC from the GUID when generating mappings.

sort_controllers.py has been updated to extract the CRC from mappings created by older mapping programs and convert it into the new crc field. It will also take the CRC into account when checking for duplicate mappings.

Also regenerated the GUIDs for the PS2/PSP/Vita controller mappings, fixing https://github.com/libsdl-org/SDL/issues/6151
2022-08-27 19:00:31 -07:00
SDL Wiki Bot 111626f4cf Sync SDL wiki -> header 2022-08-25 17:17:12 +00:00
Sam Lantinga e4b85091fd Document the range of trigger axes for virtual joysticks
Fixes https://github.com/libsdl-org/SDL/issues/6130
2022-08-25 10:15:45 -07:00
SDL Wiki Bot 523bedac1a Sync SDL wiki -> header 2022-08-09 15:48:12 +00:00
Sam Lantinga aad2df7f0d Document passing -1 to clear the player index for a controller 2022-08-09 08:47:49 -07:00
Christoph Reichenbach 3a20274ddf Refactoring: move GUID operations out of Joystick
- SDL_JoystickGUID -> SDL_GUID (though we retain a type alias)
- Operations for GUID <-> String ops are now in
  src/SDL_guid.c and include/SDL_guid.h
- The corresponding Joystick operations delegate to SDL_guid.c
- Added test/testguid.c
2022-06-04 17:22:13 -07:00
SDL Wiki Bot 3604ae1d1b Sync wiki -> header 2022-06-04 01:52:04 +00:00
Sam Lantinga 423141bfca Added a function to get the controller firmware version 2022-06-03 18:50:00 -07:00
Cameron Cawley 0cca71a846 Use SDLCALL for callbacks in public APIs 2022-05-18 15:01:27 -07:00
Sam Lantinga f0bc5c9cbf Added effects support for virtual controllers 2022-05-16 07:21:28 -07:00
SDL Wiki Bot 5953422c09 Sync wiki -> header 2022-05-16 03:52:04 +00:00
Sam Lantinga bfac54b59c Added the ability to specify which buttons and axes are present for virtual controllers 2022-05-15 20:34:44 -07:00
SDL Wiki Bot 49ca8bf520 Sync wiki -> header 2022-05-16 03:03:04 +00:00
Sam Lantinga 94eeb587c1 First pass at extending virtual controller functionality
Added the ability to specify a name and the product VID/PID for a virtual controller

Also added a test case to testgamecontroller, if you pass --virtual as a parameter
2022-05-15 20:01:12 -07:00
Sam Lantinga e551384a99 Added functions to get the platform dependent name for a joystick or game controller 2022-04-26 14:54:14 -07:00
Sam Lantinga ae73ea9c07 Clarified documentation for the trigger rumble API
Fixes https://github.com/libsdl-org/SDL/issues/5372
2022-03-04 09:27:46 -08:00
Sam Lantinga 120c76c84b Updated copyright for 2022 2022-01-03 09:40:21 -08:00
Cameron Gutman fe09a4930a joystick: Add APIs to query rumble support 2021-11-11 15:10:08 -08:00
SDL Wiki Bot c7dafb1556 Sync wiki -> header 2021-10-27 01:36:05 +00:00
Ryan C. Gordon 1b49f09243
include: manually ran wikiheaders.pl and cleaned up the obvious issues. 2021-10-08 20:50:30 -04:00
SDL Wiki Bot 192538357b Sync wiki -> header 2021-09-17 19:14:05 +00:00
Ryan C. Gordon c88eb7a896
Sync wiki -> header. 2021-07-14 17:07:04 -04:00
Sam Lantinga d135c0762f 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
2021-07-08 13:22:41 -07:00
Sam Lantinga 40b0509ef6 Fixed header documentation errors 2021-03-26 14:34:58 -07:00
Ryan C. Gordon c486959e71
headers: Fix up bullet lists, now that wikiheaders.pl can handle them. 2021-03-24 10:48:45 -04:00
Ryan C. Gordon 3f40396d33
First shot at merging the wiki documentation into the headers. 2021-03-21 14:19:53 -04:00
Sam Lantinga 9130f7c377 Updated copyright for 2021 2021-01-02 10:25:38 -08:00
Sam Lantinga c63bbb06e9 Including SDL_config_iphoneos.h enables MFI controller code 2020-11-24 06:55:33 -08:00
Sam Lantinga d140d88744 Added SDL_JoystickGetSerial() and SDL_GameControllerGetSerial() 2020-11-16 17:36:47 -08:00
Sam Lantinga 1e2caac58b Added SDL_JoystickRumbleTriggers() and SDL_GameControllerRumbleTriggers() 2020-11-11 18:57:37 -08:00
Sam Lantinga e555d45331 Added SDL_JoystickHasLED
Currently, this is only supported by the PS4 HIDAPI driver.
2020-11-05 11:07:54 -08:00
Ethan Lee 83cddd2ebc Add SDL_JoystickSetLED.
Currently, this is only supported by the PS4 HIDAPI driver.
2020-04-30 11:57:29 -04:00
David Ludwig d64761558c virtual joysticks: improved docs for SDL_JoystickSetVirtual* functions 2020-03-15 13:35:03 -04:00
David Ludwig cc90875647 virtual joysticks: removed ball support (Bug 5028) 2020-03-15 13:25:49 -04:00
Sam Lantinga 2be75c6a61 Fixed bug 5028 - Virtual Joysticks (new joystick backend)
David Ludwig

I have created a new driver for SDL's Joystick and Game-Controller subsystem: a Virtual driver.  This driver allows one to create a software-based joystick, which to SDL applications will look and react like a real joystick, but whose state can be set programmatically.  A primary use case for this is to help enable developers to add touch-screen joysticks to their apps.

The driver comes with a set of new, public APIs, with functions to attach and detach joysticks, set virtual-joystick state, and to determine if a joystick is a virtual-one.

Use of virtual joysticks goes as such:

1. Attach one or more virtual joysticks by calling SDL_JoystickAttachVirtual.  If successful, this returns the virtual-device's joystick-index.
2. Open the virtual joysticks (using indicies returned by SDL_JoystickAttachVirtual).
3. Call any of the SDL_JoystickSetVirtual* functions when joystick-state changes.  Please note that virtual-joystick state will only get applied on the next call to SDL_JoystickUpdate, or when pumping or polling for SDL events (via SDL_PumpEvents or SDL_PollEvent).


Here is a listing of the new, public APIs, at present and subject to change:

------------------------------------------------------------

/**
 * Attaches a new virtual joystick.
 * Returns the joystick's device index, or -1 if an error occurred.
 */
extern DECLSPEC int SDLCALL SDL_JoystickAttachVirtual(SDL_JoystickType type, int naxes, int nballs, int nbuttons, int nhats);

/**
 * Detaches a virtual joystick
 * Returns 0 on success, or -1 if an error occurred.
 */
extern DECLSPEC int SDLCALL SDL_JoystickDetachVirtual(int device_index);

/**
 * Indicates whether or not a virtual-joystick is at a given device index.
 */
extern DECLSPEC SDL_bool SDLCALL SDL_JoystickIsVirtual(int device_index);

/**
 * Set values on an opened, virtual-joystick's controls.
 * Returns 0 on success, -1 on error.
 */
extern DECLSPEC int SDLCALL SDL_JoystickSetVirtualAxis(SDL_Joystick * joystick, int axis, Sint16 value);
extern DECLSPEC int SDLCALL SDL_JoystickSetVirtualBall(SDL_Joystick * joystick, int ball, Sint16 xrel, Sint16 yrel);
extern DECLSPEC int SDLCALL SDL_JoystickSetVirtualButton(SDL_Joystick * joystick, int button, Uint8 value);
extern DECLSPEC int SDLCALL SDL_JoystickSetVirtualHat(SDL_Joystick * joystick, int hat, Uint8 value);

------------------------------------------------------------

Miscellaneous notes on the initial patch, which are also subject to change:

1. no test code is present in SDL, yet.  This should, perhaps, change.  Initial development was done with an ImGui-based app, which potentially is too thick for use in SDL-official.  If tests are to be added, what kind of tests?  Automated?  Graphical?

2. virtual game controllers can be created by calling SDL_JoystickAttachVirtual with a joystick-type of SDL_JOYSTICK_TYPE_GAME_CONTROLLER, with naxes (num axes) set to SDL_CONTROLLER_AXIS_MAX, and with nbuttons (num buttons) set to SDL_CONTROLLER_BUTTON_MAX.  When updating their state, values of type SDL_GameControllerAxis or SDL_GameControllerButton can be casted to an int and used for the control-index (in calls to SDL_JoystickSetVirtual* functions).

3. virtual joysticks' guids are mostly all-zeros with the exception of the last two bytes, the first of which is a 'v', to indicate that the guid is a virtual one, and the second of which is a SDL_JoystickType that has been converted into a Uint8.

4. virtual joysticks are ONLY turned into virtual game-controllers if and when their joystick-type is set to SDL_JOYSTICK_TYPE_GAMECONTROLLER.  This is controlled by having SDL's default list of game-controllers have a single entry for a virtual game controller (of guid, "00000000000000000000000000007601", which is subject to the guid-encoding described above).

5. regarding having to call SDL_JoystickUpdate, either directly or indirectly via SDL_PumpEvents or SDL_PollEvents, before new virtual-joystick state becomes active (as specified via SDL_JoystickSetVirtual* function-calls), this was done to match behavior found in SDL's other joystick drivers, almost all of which will only update SDL-state during SDL_JoystickUpdate.

6. the initial patch is based off of SDL 2.0.12

7. the virtual joystick subsystem is disabled by default.  It should be possible to enable it by building with SDL_JOYSTICK_VIRTUAL=1



Questions, comments, suggestions, or bug reports very welcome!
2020-03-13 19:08:45 -07:00
Sam Lantinga a8780c6a28 Updated copyright date for 2020 2020-01-16 20:49:25 -08:00
Sam Lantinga 46e1377d49 Automatically assign player indexes to game controllers, and allow changing the player index for game controllers and joysticks.
Added the functions SDL_JoystickFromPlayerIndex(), SDL_JoystickSetPlayerIndex(), SDL_GameControllerFromPlayerIndex(), and SDL_GameControllerSetPlayerIndex()
2019-12-20 20:12:03 -08:00
Sam Lantinga 5e13087b0f Updated copyright for 2019 2019-01-04 22:01:14 -08:00
Sam Lantinga 14329256cb Generalized the XInput user index into a player index 2018-10-25 16:53:14 -07:00
Sam Lantinga 9987ca69f3 Added SDL_JoystickGetXInputUserIndex() 2018-10-25 12:54:42 -07:00
Sam Lantinga d2042e1ed4 Added HIDAPI joystick drivers for more consistent support for Xbox, PS4 and Nintendo Switch Pro controller support across platforms.
Added SDL_GameControllerRumble() and SDL_JoystickRumble() for simple force feedback outside of the SDL haptics API
2018-08-09 16:00:17 -07:00
Sam Lantinga e3cc5b2c6b Updated copyright for 2018 2018-01-03 10:03:25 -08:00