| 1 | /* |
| 2 | Simple DirectMedia Layer |
| 3 | Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org> |
| 4 | |
| 5 | This software is provided 'as-is', without any express or implied |
| 6 | warranty. In no event will the authors be held liable for any damages |
| 7 | arising from the use of this software. |
| 8 | |
| 9 | Permission is granted to anyone to use this software for any purpose, |
| 10 | including commercial applications, and to alter it and redistribute it |
| 11 | freely, subject to the following restrictions: |
| 12 | |
| 13 | 1. The origin of this software must not be misrepresented; you must not |
| 14 | claim that you wrote the original software. If you use this software |
| 15 | in a product, an acknowledgment in the product documentation would be |
| 16 | appreciated but is not required. |
| 17 | 2. Altered source versions must be plainly marked as such, and must not be |
| 18 | misrepresented as being the original software. |
| 19 | 3. This notice may not be removed or altered from any source distribution. |
| 20 | */ |
| 21 | |
| 22 | /** |
| 23 | * # CategoryJoystick |
| 24 | * |
| 25 | * Include file for SDL joystick event handling |
| 26 | * |
| 27 | * The term "device_index" identifies currently plugged in joystick devices |
| 28 | * between 0 and SDL_NumJoysticks(), with the exact joystick behind a |
| 29 | * device_index changing as joysticks are plugged and unplugged. |
| 30 | * |
| 31 | * The term "instance_id" is the current instantiation of a joystick device in |
| 32 | * the system, if the joystick is removed and then re-inserted then it will |
| 33 | * get a new instance_id, instance_id's are monotonically increasing |
| 34 | * identifiers of a joystick plugged in. |
| 35 | * |
| 36 | * The term "player_index" is the number assigned to a player on a specific |
| 37 | * controller. For XInput controllers this returns the XInput user index. Many |
| 38 | * joysticks will not be able to supply this information. |
| 39 | * |
| 40 | * The term JoystickGUID is a stable 128-bit identifier for a joystick device |
| 41 | * that does not change over time, it identifies class of the device (a X360 |
| 42 | * wired controller for example). This identifier is platform dependent. |
| 43 | */ |
| 44 | |
| 45 | #ifndef SDL_joystick_h_ |
| 46 | #define SDL_joystick_h_ |
| 47 | |
| 48 | #include "SDL_stdinc.h" |
| 49 | #include "SDL_error.h" |
| 50 | #include "SDL_guid.h" |
| 51 | #include "SDL_mutex.h" |
| 52 | |
| 53 | #include "begin_code.h" |
| 54 | /* Set up for C function definitions, even when using C++ */ |
| 55 | #ifdef __cplusplus |
| 56 | extern "C" { |
| 57 | #endif |
| 58 | |
| 59 | /** |
| 60 | * \file SDL_joystick.h |
| 61 | * |
| 62 | * In order to use these functions, SDL_Init() must have been called |
| 63 | * with the SDL_INIT_JOYSTICK flag. This causes SDL to scan the system |
| 64 | * for joysticks, and load appropriate drivers. |
| 65 | * |
| 66 | * If you would like to receive joystick updates while the application |
| 67 | * is in the background, you should set the following hint before calling |
| 68 | * SDL_Init(): SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS |
| 69 | */ |
| 70 | |
| 71 | /** |
| 72 | * The joystick structure used to identify an SDL joystick |
| 73 | */ |
| 74 | #ifdef SDL_THREAD_SAFETY_ANALYSIS |
| 75 | extern SDL_mutex *SDL_joystick_lock; |
| 76 | #endif |
| 77 | struct _SDL_Joystick; |
| 78 | typedef struct _SDL_Joystick SDL_Joystick; |
| 79 | |
| 80 | /** |
| 81 | * A structure that encodes the stable unique id for a joystick device. |
| 82 | * |
| 83 | * This is just a standard SDL_GUID by a different name. |
| 84 | */ |
| 85 | typedef SDL_GUID SDL_JoystickGUID; |
| 86 | |
| 87 | /** |
| 88 | * This is a unique ID for a joystick for the time it is connected to the |
| 89 | * system, and is never reused for the lifetime of the application. |
| 90 | * |
| 91 | * If the joystick is disconnected and reconnected, it will get a new ID. |
| 92 | * |
| 93 | * The ID value starts at 0 and increments from there. The value -1 is an |
| 94 | * invalid ID. |
| 95 | */ |
| 96 | typedef Sint32 SDL_JoystickID; |
| 97 | |
| 98 | typedef enum |
| 99 | { |
| 100 | SDL_JOYSTICK_TYPE_UNKNOWN, |
| 101 | SDL_JOYSTICK_TYPE_GAMECONTROLLER, |
| 102 | SDL_JOYSTICK_TYPE_WHEEL, |
| 103 | SDL_JOYSTICK_TYPE_ARCADE_STICK, |
| 104 | SDL_JOYSTICK_TYPE_FLIGHT_STICK, |
| 105 | SDL_JOYSTICK_TYPE_DANCE_PAD, |
| 106 | SDL_JOYSTICK_TYPE_GUITAR, |
| 107 | SDL_JOYSTICK_TYPE_DRUM_KIT, |
| 108 | SDL_JOYSTICK_TYPE_ARCADE_PAD, |
| 109 | SDL_JOYSTICK_TYPE_THROTTLE |
| 110 | } SDL_JoystickType; |
| 111 | |
| 112 | typedef enum |
| 113 | { |
| 114 | SDL_JOYSTICK_POWER_UNKNOWN = -1, |
| 115 | SDL_JOYSTICK_POWER_EMPTY, /* <= 5% */ |
| 116 | SDL_JOYSTICK_POWER_LOW, /* <= 20% */ |
| 117 | SDL_JOYSTICK_POWER_MEDIUM, /* <= 70% */ |
| 118 | SDL_JOYSTICK_POWER_FULL, /* <= 100% */ |
| 119 | SDL_JOYSTICK_POWER_WIRED, |
| 120 | SDL_JOYSTICK_POWER_MAX |
| 121 | } SDL_JoystickPowerLevel; |
| 122 | |
| 123 | /* Set max recognized G-force from accelerometer |
| 124 | See src/joystick/uikit/SDL_sysjoystick.m for notes on why this is needed |
| 125 | */ |
| 126 | #define SDL_IPHONE_MAX_GFORCE 5.0 |
| 127 | |
| 128 | |
| 129 | /* Function prototypes */ |
| 130 | |
| 131 | /** |
| 132 | * Locking for multi-threaded access to the joystick API |
| 133 | * |
| 134 | * If you are using the joystick API or handling events from multiple threads |
| 135 | * you should use these locking functions to protect access to the joysticks. |
| 136 | * |
| 137 | * In particular, you are guaranteed that the joystick list won't change, so |
| 138 | * the API functions that take a joystick index will be valid, and joystick |
| 139 | * and game controller events will not be delivered. |
| 140 | * |
| 141 | * As of SDL 2.26.0, you can take the joystick lock around reinitializing the |
| 142 | * joystick subsystem, to prevent other threads from seeing joysticks in an |
| 143 | * uninitialized state. However, all open joysticks will be closed and SDL |
| 144 | * functions called with them will fail. |
| 145 | * |
| 146 | * \since This function is available since SDL 2.0.7. |
| 147 | */ |
| 148 | extern DECLSPEC void SDLCALL SDL_LockJoysticks(void) SDL_ACQUIRE(SDL_joystick_lock); |
| 149 | |
| 150 | |
| 151 | /** |
| 152 | * Unlocking for multi-threaded access to the joystick API |
| 153 | * |
| 154 | * If you are using the joystick API or handling events from multiple threads |
| 155 | * you should use these locking functions to protect access to the joysticks. |
| 156 | * |
| 157 | * In particular, you are guaranteed that the joystick list won't change, so |
| 158 | * the API functions that take a joystick index will be valid, and joystick |
| 159 | * and game controller events will not be delivered. |
| 160 | * |
| 161 | * \since This function is available since SDL 2.0.7. |
| 162 | */ |
| 163 | extern DECLSPEC void SDLCALL SDL_UnlockJoysticks(void) SDL_RELEASE(SDL_joystick_lock); |
| 164 | |
| 165 | /** |
| 166 | * Count the number of joysticks attached to the system. |
| 167 | * |
| 168 | * \returns the number of attached joysticks on success or a negative error |
| 169 | * code on failure; call SDL_GetError() for more information. |
| 170 | * |
| 171 | * \since This function is available since SDL 2.0.0. |
| 172 | * |
| 173 | * \sa SDL_JoystickName |
| 174 | * \sa SDL_JoystickPath |
| 175 | * \sa SDL_JoystickOpen |
| 176 | */ |
| 177 | extern DECLSPEC int SDLCALL SDL_NumJoysticks(void); |
| 178 | |
| 179 | /** |
| 180 | * Get the implementation dependent name of a joystick. |
| 181 | * |
| 182 | * This can be called before any joysticks are opened. |
| 183 | * |
| 184 | * \param device_index the index of the joystick to query (the N'th joystick |
| 185 | * on the system). |
| 186 | * \returns the name of the selected joystick. If no name can be found, this |
| 187 | * function returns NULL; call SDL_GetError() for more information. |
| 188 | * |
| 189 | * \since This function is available since SDL 2.0.0. |
| 190 | * |
| 191 | * \sa SDL_JoystickName |
| 192 | * \sa SDL_JoystickOpen |
| 193 | */ |
| 194 | extern DECLSPEC const char *SDLCALL SDL_JoystickNameForIndex(int device_index); |
| 195 | |
| 196 | /** |
| 197 | * Get the implementation dependent path of a joystick. |
| 198 | * |
| 199 | * This can be called before any joysticks are opened. |
| 200 | * |
| 201 | * \param device_index the index of the joystick to query (the N'th joystick |
| 202 | * on the system). |
| 203 | * \returns the path of the selected joystick. If no path can be found, this |
| 204 | * function returns NULL; call SDL_GetError() for more information. |
| 205 | * |
| 206 | * \since This function is available since SDL 2.24.0. |
| 207 | * |
| 208 | * \sa SDL_JoystickPath |
| 209 | * \sa SDL_JoystickOpen |
| 210 | */ |
| 211 | extern DECLSPEC const char *SDLCALL SDL_JoystickPathForIndex(int device_index); |
| 212 | |
| 213 | /** |
| 214 | * Get the player index of a joystick, or -1 if it's not available This can be |
| 215 | * called before any joysticks are opened. |
| 216 | * |
| 217 | * \param device_index device index. |
| 218 | * \returns player index, or -1 if not available. |
| 219 | * |
| 220 | * \since This function is available since SDL 2.0.9. |
| 221 | */ |
| 222 | extern DECLSPEC int SDLCALL SDL_JoystickGetDevicePlayerIndex(int device_index); |
| 223 | |
| 224 | /** |
| 225 | * Get the implementation-dependent GUID for the joystick at a given device |
| 226 | * index. |
| 227 | * |
| 228 | * This function can be called before any joysticks are opened. |
| 229 | * |
| 230 | * \param device_index the index of the joystick to query (the N'th joystick |
| 231 | * on the system. |
| 232 | * \returns the GUID of the selected joystick. If called on an invalid index, |
| 233 | * this function returns a zero GUID. |
| 234 | * |
| 235 | * \since This function is available since SDL 2.0.0. |
| 236 | * |
| 237 | * \sa SDL_JoystickGetGUID |
| 238 | * \sa SDL_JoystickGetGUIDString |
| 239 | */ |
| 240 | extern DECLSPEC SDL_JoystickGUID SDLCALL SDL_JoystickGetDeviceGUID(int device_index); |
| 241 | |
| 242 | /** |
| 243 | * Get the USB vendor ID of a joystick, if available. |
| 244 | * |
| 245 | * This can be called before any joysticks are opened. If the vendor ID isn't |
| 246 | * available this function returns 0. |
| 247 | * |
| 248 | * \param device_index the index of the joystick to query (the N'th joystick |
| 249 | * on the system. |
| 250 | * \returns the USB vendor ID of the selected joystick. If called on an |
| 251 | * invalid index, this function returns zero. |
| 252 | * |
| 253 | * \since This function is available since SDL 2.0.6. |
| 254 | */ |
| 255 | extern DECLSPEC Uint16 SDLCALL SDL_JoystickGetDeviceVendor(int device_index); |
| 256 | |
| 257 | /** |
| 258 | * Get the USB product ID of a joystick, if available. |
| 259 | * |
| 260 | * This can be called before any joysticks are opened. If the product ID isn't |
| 261 | * available this function returns 0. |
| 262 | * |
| 263 | * \param device_index the index of the joystick to query (the N'th joystick |
| 264 | * on the system. |
| 265 | * \returns the USB product ID of the selected joystick. If called on an |
| 266 | * invalid index, this function returns zero. |
| 267 | * |
| 268 | * \since This function is available since SDL 2.0.6. |
| 269 | */ |
| 270 | extern DECLSPEC Uint16 SDLCALL SDL_JoystickGetDeviceProduct(int device_index); |
| 271 | |
| 272 | /** |
| 273 | * Get the product version of a joystick, if available. |
| 274 | * |
| 275 | * This can be called before any joysticks are opened. If the product version |
| 276 | * isn't available this function returns 0. |
| 277 | * |
| 278 | * \param device_index the index of the joystick to query (the N'th joystick |
| 279 | * on the system. |
| 280 | * \returns the product version of the selected joystick. If called on an |
| 281 | * invalid index, this function returns zero. |
| 282 | * |
| 283 | * \since This function is available since SDL 2.0.6. |
| 284 | */ |
| 285 | extern DECLSPEC Uint16 SDLCALL SDL_JoystickGetDeviceProductVersion(int device_index); |
| 286 | |
| 287 | /** |
| 288 | * Get the type of a joystick, if available. |
| 289 | * |
| 290 | * This can be called before any joysticks are opened. |
| 291 | * |
| 292 | * \param device_index the index of the joystick to query (the N'th joystick |
| 293 | * on the system. |
| 294 | * \returns the SDL_JoystickType of the selected joystick. If called on an |
| 295 | * invalid index, this function returns `SDL_JOYSTICK_TYPE_UNKNOWN`. |
| 296 | * |
| 297 | * \since This function is available since SDL 2.0.6. |
| 298 | */ |
| 299 | extern DECLSPEC SDL_JoystickType SDLCALL SDL_JoystickGetDeviceType(int device_index); |
| 300 | |
| 301 | /** |
| 302 | * Get the instance ID of a joystick. |
| 303 | * |
| 304 | * This can be called before any joysticks are opened. |
| 305 | * |
| 306 | * \param device_index the index of the joystick to query (the N'th joystick |
| 307 | * on the system. |
| 308 | * \returns the instance id of the selected joystick. If called on an invalid |
| 309 | * index, this function returns -1. |
| 310 | * |
| 311 | * \since This function is available since SDL 2.0.6. |
| 312 | */ |
| 313 | extern DECLSPEC SDL_JoystickID SDLCALL SDL_JoystickGetDeviceInstanceID(int device_index); |
| 314 | |
| 315 | /** |
| 316 | * Open a joystick for use. |
| 317 | * |
| 318 | * The `device_index` argument refers to the N'th joystick presently |
| 319 | * recognized by SDL on the system. It is **NOT** the same as the instance ID |
| 320 | * used to identify the joystick in future events. See |
| 321 | * SDL_JoystickInstanceID() for more details about instance IDs. |
| 322 | * |
| 323 | * The joystick subsystem must be initialized before a joystick can be opened |
| 324 | * for use. |
| 325 | * |
| 326 | * \param device_index the index of the joystick to query. |
| 327 | * \returns a joystick identifier or NULL if an error occurred; call |
| 328 | * SDL_GetError() for more information. |
| 329 | * |
| 330 | * \since This function is available since SDL 2.0.0. |
| 331 | * |
| 332 | * \sa SDL_JoystickClose |
| 333 | * \sa SDL_JoystickInstanceID |
| 334 | */ |
| 335 | extern DECLSPEC SDL_Joystick *SDLCALL SDL_JoystickOpen(int device_index); |
| 336 | |
| 337 | /** |
| 338 | * Get the SDL_Joystick associated with an instance id. |
| 339 | * |
| 340 | * \param instance_id the instance id to get the SDL_Joystick for. |
| 341 | * \returns an SDL_Joystick on success or NULL on failure; call SDL_GetError() |
| 342 | * for more information. |
| 343 | * |
| 344 | * \since This function is available since SDL 2.0.4. |
| 345 | */ |
| 346 | extern DECLSPEC SDL_Joystick *SDLCALL SDL_JoystickFromInstanceID(SDL_JoystickID instance_id); |
| 347 | |
| 348 | /** |
| 349 | * Get the SDL_Joystick associated with a player index. |
| 350 | * |
| 351 | * \param player_index the player index to get the SDL_Joystick for. |
| 352 | * \returns an SDL_Joystick on success or NULL on failure; call SDL_GetError() |
| 353 | * for more information. |
| 354 | * |
| 355 | * \since This function is available since SDL 2.0.12. |
| 356 | */ |
| 357 | extern DECLSPEC SDL_Joystick *SDLCALL SDL_JoystickFromPlayerIndex(int player_index); |
| 358 | |
| 359 | /** |
| 360 | * Attach a new virtual joystick. |
| 361 | * |
| 362 | * \param type joystick type. |
| 363 | * \param naxes number of axes. |
| 364 | * \param nbuttons number of buttons. |
| 365 | * \param nhats number of hats. |
| 366 | * \returns the joystick's device index, or -1 if an error occurred. |
| 367 | * |
| 368 | * \since This function is available since SDL 2.0.14. |
| 369 | */ |
| 370 | extern DECLSPEC int SDLCALL SDL_JoystickAttachVirtual(SDL_JoystickType type, |
| 371 | int naxes, |
| 372 | int nbuttons, |
| 373 | int nhats); |
| 374 | |
| 375 | /** |
| 376 | * The structure that defines an extended virtual joystick description |
| 377 | * |
| 378 | * The caller must zero the structure and then initialize the version with |
| 379 | * `SDL_VIRTUAL_JOYSTICK_DESC_VERSION` before passing it to |
| 380 | * SDL_JoystickAttachVirtualEx() All other elements of this structure are |
| 381 | * optional and can be left 0. |
| 382 | * |
| 383 | * \sa SDL_JoystickAttachVirtualEx |
| 384 | */ |
| 385 | typedef struct SDL_VirtualJoystickDesc |
| 386 | { |
| 387 | Uint16 version; /**< `SDL_VIRTUAL_JOYSTICK_DESC_VERSION` */ |
| 388 | Uint16 type; /**< `SDL_JoystickType` */ |
| 389 | Uint16 naxes; /**< the number of axes on this joystick */ |
| 390 | Uint16 nbuttons; /**< the number of buttons on this joystick */ |
| 391 | Uint16 nhats; /**< the number of hats on this joystick */ |
| 392 | Uint16 vendor_id; /**< the USB vendor ID of this joystick */ |
| 393 | Uint16 product_id; /**< the USB product ID of this joystick */ |
| 394 | Uint16 padding; /**< unused */ |
| 395 | Uint32 button_mask; /**< A mask of which buttons are valid for this controller |
| 396 | e.g. (1 << SDL_CONTROLLER_BUTTON_A) */ |
| 397 | Uint32 axis_mask; /**< A mask of which axes are valid for this controller |
| 398 | e.g. (1 << SDL_CONTROLLER_AXIS_LEFTX) */ |
| 399 | const char *name; /**< the name of the joystick */ |
| 400 | |
| 401 | void *userdata; /**< User data pointer passed to callbacks */ |
| 402 | void (SDLCALL *Update)(void *userdata); /**< Called when the joystick state should be updated */ |
| 403 | void (SDLCALL *SetPlayerIndex)(void *userdata, int player_index); /**< Called when the player index is set */ |
| 404 | int (SDLCALL *Rumble)(void *userdata, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble); /**< Implements SDL_JoystickRumble() */ |
| 405 | int (SDLCALL *RumbleTriggers)(void *userdata, Uint16 left_rumble, Uint16 right_rumble); /**< Implements SDL_JoystickRumbleTriggers() */ |
| 406 | int (SDLCALL *SetLED)(void *userdata, Uint8 red, Uint8 green, Uint8 blue); /**< Implements SDL_JoystickSetLED() */ |
| 407 | int (SDLCALL *SendEffect)(void *userdata, const void *data, int size); /**< Implements SDL_JoystickSendEffect() */ |
| 408 | |
| 409 | } SDL_VirtualJoystickDesc; |
| 410 | |
| 411 | /** |
| 412 | * The current version of the SDL_VirtualJoystickDesc structure |
| 413 | */ |
| 414 | #define SDL_VIRTUAL_JOYSTICK_DESC_VERSION 1 |
| 415 | |
| 416 | /** |
| 417 | * Attach a new virtual joystick with extended properties. |
| 418 | * |
| 419 | * \param desc joystick description. |
| 420 | * \returns the joystick's device index, or -1 if an error occurred. |
| 421 | * |
| 422 | * \since This function is available since SDL 2.24.0. |
| 423 | */ |
| 424 | extern DECLSPEC int SDLCALL SDL_JoystickAttachVirtualEx(const SDL_VirtualJoystickDesc *desc); |
| 425 | |
| 426 | /** |
| 427 | * Detach a virtual joystick. |
| 428 | * |
| 429 | * \param device_index a value previously returned from |
| 430 | * SDL_JoystickAttachVirtual(). |
| 431 | * \returns 0 on success, or -1 if an error occurred. |
| 432 | * |
| 433 | * \since This function is available since SDL 2.0.14. |
| 434 | */ |
| 435 | extern DECLSPEC int SDLCALL SDL_JoystickDetachVirtual(int device_index); |
| 436 | |
| 437 | /** |
| 438 | * Query whether or not the joystick at a given device index is virtual. |
| 439 | * |
| 440 | * \param device_index a joystick device index. |
| 441 | * \returns SDL_TRUE if the joystick is virtual, SDL_FALSE otherwise. |
| 442 | * |
| 443 | * \since This function is available since SDL 2.0.14. |
| 444 | */ |
| 445 | extern DECLSPEC SDL_bool SDLCALL SDL_JoystickIsVirtual(int device_index); |
| 446 | |
| 447 | /** |
| 448 | * Set values on an opened, virtual-joystick's axis. |
| 449 | * |
| 450 | * Please note that values set here will not be applied until the next call to |
| 451 | * SDL_JoystickUpdate, which can either be called directly, or can be called |
| 452 | * indirectly through various other SDL APIs, including, but not limited to |
| 453 | * the following: SDL_PollEvent, SDL_PumpEvents, SDL_WaitEventTimeout, |
| 454 | * SDL_WaitEvent. |
| 455 | * |
| 456 | * Note that when sending trigger axes, you should scale the value to the full |
| 457 | * range of Sint16. For example, a trigger at rest would have the value of |
| 458 | * `SDL_JOYSTICK_AXIS_MIN`. |
| 459 | * |
| 460 | * \param joystick the virtual joystick on which to set state. |
| 461 | * \param axis the specific axis on the virtual joystick to set. |
| 462 | * \param value the new value for the specified axis. |
| 463 | * \returns 0 on success, -1 on error. |
| 464 | * |
| 465 | * \since This function is available since SDL 2.0.14. |
| 466 | */ |
| 467 | extern DECLSPEC int SDLCALL SDL_JoystickSetVirtualAxis(SDL_Joystick *joystick, int axis, Sint16 value); |
| 468 | |
| 469 | /** |
| 470 | * Set values on an opened, virtual-joystick's button. |
| 471 | * |
| 472 | * Please note that values set here will not be applied until the next call to |
| 473 | * SDL_JoystickUpdate, which can either be called directly, or can be called |
| 474 | * indirectly through various other SDL APIs, including, but not limited to |
| 475 | * the following: SDL_PollEvent, SDL_PumpEvents, SDL_WaitEventTimeout, |
| 476 | * SDL_WaitEvent. |
| 477 | * |
| 478 | * \param joystick the virtual joystick on which to set state. |
| 479 | * \param button the specific button on the virtual joystick to set. |
| 480 | * \param value the new value for the specified button. |
| 481 | * \returns 0 on success, -1 on error. |
| 482 | * |
| 483 | * \since This function is available since SDL 2.0.14. |
| 484 | */ |
| 485 | extern DECLSPEC int SDLCALL SDL_JoystickSetVirtualButton(SDL_Joystick *joystick, int button, Uint8 value); |
| 486 | |
| 487 | /** |
| 488 | * Set values on an opened, virtual-joystick's hat. |
| 489 | * |
| 490 | * Please note that values set here will not be applied until the next call to |
| 491 | * SDL_JoystickUpdate, which can either be called directly, or can be called |
| 492 | * indirectly through various other SDL APIs, including, but not limited to |
| 493 | * the following: SDL_PollEvent, SDL_PumpEvents, SDL_WaitEventTimeout, |
| 494 | * SDL_WaitEvent. |
| 495 | * |
| 496 | * \param joystick the virtual joystick on which to set state. |
| 497 | * \param hat the specific hat on the virtual joystick to set. |
| 498 | * \param value the new value for the specified hat. |
| 499 | * \returns 0 on success, -1 on error. |
| 500 | * |
| 501 | * \since This function is available since SDL 2.0.14. |
| 502 | */ |
| 503 | extern DECLSPEC int SDLCALL SDL_JoystickSetVirtualHat(SDL_Joystick *joystick, int hat, Uint8 value); |
| 504 | |
| 505 | /** |
| 506 | * Get the implementation dependent name of a joystick. |
| 507 | * |
| 508 | * \param joystick the SDL_Joystick obtained from SDL_JoystickOpen(). |
| 509 | * \returns the name of the selected joystick. If no name can be found, this |
| 510 | * function returns NULL; call SDL_GetError() for more information. |
| 511 | * |
| 512 | * \since This function is available since SDL 2.0.0. |
| 513 | * |
| 514 | * \sa SDL_JoystickNameForIndex |
| 515 | * \sa SDL_JoystickOpen |
| 516 | */ |
| 517 | extern DECLSPEC const char *SDLCALL SDL_JoystickName(SDL_Joystick *joystick); |
| 518 | |
| 519 | /** |
| 520 | * Get the implementation dependent path of a joystick. |
| 521 | * |
| 522 | * \param joystick the SDL_Joystick obtained from SDL_JoystickOpen(). |
| 523 | * \returns the path of the selected joystick. If no path can be found, this |
| 524 | * function returns NULL; call SDL_GetError() for more information. |
| 525 | * |
| 526 | * \since This function is available since SDL 2.24.0. |
| 527 | * |
| 528 | * \sa SDL_JoystickPathForIndex |
| 529 | */ |
| 530 | extern DECLSPEC const char *SDLCALL SDL_JoystickPath(SDL_Joystick *joystick); |
| 531 | |
| 532 | /** |
| 533 | * Get the player index of an opened joystick. |
| 534 | * |
| 535 | * For XInput controllers this returns the XInput user index. Many joysticks |
| 536 | * will not be able to supply this information. |
| 537 | * |
| 538 | * \param joystick the SDL_Joystick obtained from SDL_JoystickOpen(). |
| 539 | * \returns the player index, or -1 if it's not available. |
| 540 | * |
| 541 | * \since This function is available since SDL 2.0.9. |
| 542 | */ |
| 543 | extern DECLSPEC int SDLCALL SDL_JoystickGetPlayerIndex(SDL_Joystick *joystick); |
| 544 | |
| 545 | /** |
| 546 | * Set the player index of an opened joystick. |
| 547 | * |
| 548 | * \param joystick the SDL_Joystick obtained from SDL_JoystickOpen(). |
| 549 | * \param player_index Player index to assign to this joystick, or -1 to clear |
| 550 | * the player index and turn off player LEDs. |
| 551 | * |
| 552 | * \since This function is available since SDL 2.0.12. |
| 553 | */ |
| 554 | extern DECLSPEC void SDLCALL SDL_JoystickSetPlayerIndex(SDL_Joystick *joystick, int player_index); |
| 555 | |
| 556 | /** |
| 557 | * Get the implementation-dependent GUID for the joystick. |
| 558 | * |
| 559 | * This function requires an open joystick. |
| 560 | * |
| 561 | * \param joystick the SDL_Joystick obtained from SDL_JoystickOpen(). |
| 562 | * \returns the GUID of the given joystick. If called on an invalid index, |
| 563 | * this function returns a zero GUID; call SDL_GetError() for more |
| 564 | * information. |
| 565 | * |
| 566 | * \since This function is available since SDL 2.0.0. |
| 567 | * |
| 568 | * \sa SDL_JoystickGetDeviceGUID |
| 569 | * \sa SDL_JoystickGetGUIDString |
| 570 | */ |
| 571 | extern DECLSPEC SDL_JoystickGUID SDLCALL SDL_JoystickGetGUID(SDL_Joystick *joystick); |
| 572 | |
| 573 | /** |
| 574 | * Get the USB vendor ID of an opened joystick, if available. |
| 575 | * |
| 576 | * If the vendor ID isn't available this function returns 0. |
| 577 | * |
| 578 | * \param joystick the SDL_Joystick obtained from SDL_JoystickOpen(). |
| 579 | * \returns the USB vendor ID of the selected joystick, or 0 if unavailable. |
| 580 | * |
| 581 | * \since This function is available since SDL 2.0.6. |
| 582 | */ |
| 583 | extern DECLSPEC Uint16 SDLCALL SDL_JoystickGetVendor(SDL_Joystick *joystick); |
| 584 | |
| 585 | /** |
| 586 | * Get the USB product ID of an opened joystick, if available. |
| 587 | * |
| 588 | * If the product ID isn't available this function returns 0. |
| 589 | * |
| 590 | * \param joystick the SDL_Joystick obtained from SDL_JoystickOpen(). |
| 591 | * \returns the USB product ID of the selected joystick, or 0 if unavailable. |
| 592 | * |
| 593 | * \since This function is available since SDL 2.0.6. |
| 594 | */ |
| 595 | extern DECLSPEC Uint16 SDLCALL SDL_JoystickGetProduct(SDL_Joystick *joystick); |
| 596 | |
| 597 | /** |
| 598 | * Get the product version of an opened joystick, if available. |
| 599 | * |
| 600 | * If the product version isn't available this function returns 0. |
| 601 | * |
| 602 | * \param joystick the SDL_Joystick obtained from SDL_JoystickOpen(). |
| 603 | * \returns the product version of the selected joystick, or 0 if unavailable. |
| 604 | * |
| 605 | * \since This function is available since SDL 2.0.6. |
| 606 | */ |
| 607 | extern DECLSPEC Uint16 SDLCALL SDL_JoystickGetProductVersion(SDL_Joystick *joystick); |
| 608 | |
| 609 | /** |
| 610 | * Get the firmware version of an opened joystick, if available. |
| 611 | * |
| 612 | * If the firmware version isn't available this function returns 0. |
| 613 | * |
| 614 | * \param joystick the SDL_Joystick obtained from SDL_JoystickOpen(). |
| 615 | * \returns the firmware version of the selected joystick, or 0 if |
| 616 | * unavailable. |
| 617 | * |
| 618 | * \since This function is available since SDL 2.24.0. |
| 619 | */ |
| 620 | extern DECLSPEC Uint16 SDLCALL SDL_JoystickGetFirmwareVersion(SDL_Joystick *joystick); |
| 621 | |
| 622 | /** |
| 623 | * Get the serial number of an opened joystick, if available. |
| 624 | * |
| 625 | * Returns the serial number of the joystick, or NULL if it is not available. |
| 626 | * |
| 627 | * \param joystick the SDL_Joystick obtained from SDL_JoystickOpen(). |
| 628 | * \returns the serial number of the selected joystick, or NULL if |
| 629 | * unavailable. |
| 630 | * |
| 631 | * \since This function is available since SDL 2.0.14. |
| 632 | */ |
| 633 | extern DECLSPEC const char * SDLCALL SDL_JoystickGetSerial(SDL_Joystick *joystick); |
| 634 | |
| 635 | /** |
| 636 | * Get the type of an opened joystick. |
| 637 | * |
| 638 | * \param joystick the SDL_Joystick obtained from SDL_JoystickOpen(). |
| 639 | * \returns the SDL_JoystickType of the selected joystick. |
| 640 | * |
| 641 | * \since This function is available since SDL 2.0.6. |
| 642 | */ |
| 643 | extern DECLSPEC SDL_JoystickType SDLCALL SDL_JoystickGetType(SDL_Joystick *joystick); |
| 644 | |
| 645 | /** |
| 646 | * Get an ASCII string representation for a given SDL_JoystickGUID. |
| 647 | * |
| 648 | * You should supply at least 33 bytes for pszGUID. |
| 649 | * |
| 650 | * \param guid the SDL_JoystickGUID you wish to convert to string. |
| 651 | * \param pszGUID buffer in which to write the ASCII string. |
| 652 | * \param cbGUID the size of pszGUID. |
| 653 | * |
| 654 | * \since This function is available since SDL 2.0.0. |
| 655 | * |
| 656 | * \sa SDL_JoystickGetDeviceGUID |
| 657 | * \sa SDL_JoystickGetGUID |
| 658 | * \sa SDL_JoystickGetGUIDFromString |
| 659 | */ |
| 660 | extern DECLSPEC void SDLCALL SDL_JoystickGetGUIDString(SDL_JoystickGUID guid, char *pszGUID, int cbGUID); |
| 661 | |
| 662 | /** |
| 663 | * Convert a GUID string into a SDL_JoystickGUID structure. |
| 664 | * |
| 665 | * Performs no error checking. If this function is given a string containing |
| 666 | * an invalid GUID, the function will silently succeed, but the GUID generated |
| 667 | * will not be useful. |
| 668 | * |
| 669 | * \param pchGUID string containing an ASCII representation of a GUID. |
| 670 | * \returns a SDL_JoystickGUID structure. |
| 671 | * |
| 672 | * \since This function is available since SDL 2.0.0. |
| 673 | * |
| 674 | * \sa SDL_JoystickGetGUIDString |
| 675 | */ |
| 676 | extern DECLSPEC SDL_JoystickGUID SDLCALL SDL_JoystickGetGUIDFromString(const char *pchGUID); |
| 677 | |
| 678 | /** |
| 679 | * Get the device information encoded in a SDL_JoystickGUID structure |
| 680 | * |
| 681 | * \param guid the SDL_JoystickGUID you wish to get info about. |
| 682 | * \param vendor A pointer filled in with the device VID, or 0 if not |
| 683 | * available. |
| 684 | * \param product A pointer filled in with the device PID, or 0 if not |
| 685 | * available. |
| 686 | * \param version A pointer filled in with the device version, or 0 if not |
| 687 | * available. |
| 688 | * \param crc16 A pointer filled in with a CRC used to distinguish different |
| 689 | * products with the same VID/PID, or 0 if not available. |
| 690 | * |
| 691 | * \since This function is available since SDL 2.26.0. |
| 692 | * |
| 693 | * \sa SDL_JoystickGetDeviceGUID |
| 694 | */ |
| 695 | extern DECLSPEC void SDLCALL SDL_GetJoystickGUIDInfo(SDL_JoystickGUID guid, Uint16 *vendor, Uint16 *product, Uint16 *version, Uint16 *crc16); |
| 696 | |
| 697 | /** |
| 698 | * Get the status of a specified joystick. |
| 699 | * |
| 700 | * \param joystick the joystick to query. |
| 701 | * \returns SDL_TRUE if the joystick has been opened, SDL_FALSE if it has not; |
| 702 | * call SDL_GetError() for more information. |
| 703 | * |
| 704 | * \since This function is available since SDL 2.0.0. |
| 705 | * |
| 706 | * \sa SDL_JoystickClose |
| 707 | * \sa SDL_JoystickOpen |
| 708 | */ |
| 709 | extern DECLSPEC SDL_bool SDLCALL SDL_JoystickGetAttached(SDL_Joystick *joystick); |
| 710 | |
| 711 | /** |
| 712 | * Get the instance ID of an opened joystick. |
| 713 | * |
| 714 | * \param joystick an SDL_Joystick structure containing joystick information. |
| 715 | * \returns the instance ID of the specified joystick on success or a negative |
| 716 | * error code on failure; call SDL_GetError() for more information. |
| 717 | * |
| 718 | * \since This function is available since SDL 2.0.0. |
| 719 | * |
| 720 | * \sa SDL_JoystickOpen |
| 721 | */ |
| 722 | extern DECLSPEC SDL_JoystickID SDLCALL SDL_JoystickInstanceID(SDL_Joystick *joystick); |
| 723 | |
| 724 | /** |
| 725 | * Get the number of general axis controls on a joystick. |
| 726 | * |
| 727 | * Often, the directional pad on a game controller will either look like 4 |
| 728 | * separate buttons or a POV hat, and not axes, but all of this is up to the |
| 729 | * device and platform. |
| 730 | * |
| 731 | * \param joystick an SDL_Joystick structure containing joystick information. |
| 732 | * \returns the number of axis controls/number of axes on success or a |
| 733 | * negative error code on failure; call SDL_GetError() for more |
| 734 | * information. |
| 735 | * |
| 736 | * \since This function is available since SDL 2.0.0. |
| 737 | * |
| 738 | * \sa SDL_JoystickGetAxis |
| 739 | * \sa SDL_JoystickOpen |
| 740 | */ |
| 741 | extern DECLSPEC int SDLCALL SDL_JoystickNumAxes(SDL_Joystick *joystick); |
| 742 | |
| 743 | /** |
| 744 | * Get the number of trackballs on a joystick. |
| 745 | * |
| 746 | * Joystick trackballs have only relative motion events associated with them |
| 747 | * and their state cannot be polled. |
| 748 | * |
| 749 | * Most joysticks do not have trackballs. |
| 750 | * |
| 751 | * \param joystick an SDL_Joystick structure containing joystick information. |
| 752 | * \returns the number of trackballs on success or a negative error code on |
| 753 | * failure; call SDL_GetError() for more information. |
| 754 | * |
| 755 | * \since This function is available since SDL 2.0.0. |
| 756 | * |
| 757 | * \sa SDL_JoystickGetBall |
| 758 | */ |
| 759 | extern DECLSPEC int SDLCALL SDL_JoystickNumBalls(SDL_Joystick *joystick); |
| 760 | |
| 761 | /** |
| 762 | * Get the number of POV hats on a joystick. |
| 763 | * |
| 764 | * \param joystick an SDL_Joystick structure containing joystick information. |
| 765 | * \returns the number of POV hats on success or a negative error code on |
| 766 | * failure; call SDL_GetError() for more information. |
| 767 | * |
| 768 | * \since This function is available since SDL 2.0.0. |
| 769 | * |
| 770 | * \sa SDL_JoystickGetHat |
| 771 | * \sa SDL_JoystickOpen |
| 772 | */ |
| 773 | extern DECLSPEC int SDLCALL SDL_JoystickNumHats(SDL_Joystick *joystick); |
| 774 | |
| 775 | /** |
| 776 | * Get the number of buttons on a joystick. |
| 777 | * |
| 778 | * \param joystick an SDL_Joystick structure containing joystick information. |
| 779 | * \returns the number of buttons on success or a negative error code on |
| 780 | * failure; call SDL_GetError() for more information. |
| 781 | * |
| 782 | * \since This function is available since SDL 2.0.0. |
| 783 | * |
| 784 | * \sa SDL_JoystickGetButton |
| 785 | * \sa SDL_JoystickOpen |
| 786 | */ |
| 787 | extern DECLSPEC int SDLCALL SDL_JoystickNumButtons(SDL_Joystick *joystick); |
| 788 | |
| 789 | /** |
| 790 | * Update the current state of the open joysticks. |
| 791 | * |
| 792 | * This is called automatically by the event loop if any joystick events are |
| 793 | * enabled. |
| 794 | * |
| 795 | * \since This function is available since SDL 2.0.0. |
| 796 | * |
| 797 | * \sa SDL_JoystickEventState |
| 798 | */ |
| 799 | extern DECLSPEC void SDLCALL SDL_JoystickUpdate(void); |
| 800 | |
| 801 | /** |
| 802 | * Enable/disable joystick event polling. |
| 803 | * |
| 804 | * If joystick events are disabled, you must call SDL_JoystickUpdate() |
| 805 | * yourself and manually check the state of the joystick when you want |
| 806 | * joystick information. |
| 807 | * |
| 808 | * It is recommended that you leave joystick event handling enabled. |
| 809 | * |
| 810 | * **WARNING**: Calling this function may delete all events currently in SDL's |
| 811 | * event queue. |
| 812 | * |
| 813 | * While `param` is meant to be one of `SDL_QUERY`, `SDL_IGNORE`, or |
| 814 | * `SDL_ENABLE`, this function accepts any value, with any non-zero value that |
| 815 | * isn't `SDL_QUERY` being treated as `SDL_ENABLE`. |
| 816 | * |
| 817 | * If SDL was built with events disabled (extremely uncommon!), this will do |
| 818 | * nothing and always return `SDL_IGNORE`. |
| 819 | * |
| 820 | * \param state can be one of `SDL_QUERY`, `SDL_IGNORE`, or `SDL_ENABLE`. |
| 821 | * \returns If `state` is `SDL_QUERY` then the current state is returned, |
| 822 | * otherwise `state` is returned (even if it was not one of the |
| 823 | * allowed values). |
| 824 | * |
| 825 | * \since This function is available since SDL 2.0.0. |
| 826 | * |
| 827 | * \sa SDL_GameControllerEventState |
| 828 | */ |
| 829 | extern DECLSPEC int SDLCALL SDL_JoystickEventState(int state); |
| 830 | |
| 831 | /* Limits for joystick axes... */ |
| 832 | #define SDL_JOYSTICK_AXIS_MAX 32767 |
| 833 | #define SDL_JOYSTICK_AXIS_MIN -32768 |
| 834 | |
| 835 | /** |
| 836 | * Get the current state of an axis control on a joystick. |
| 837 | * |
| 838 | * SDL makes no promises about what part of the joystick any given axis refers |
| 839 | * to. Your game should have some sort of configuration UI to let users |
| 840 | * specify what each axis should be bound to. Alternately, SDL's higher-level |
| 841 | * Game Controller API makes a great effort to apply order to this lower-level |
| 842 | * interface, so you know that a specific axis is the "left thumb stick," etc. |
| 843 | * |
| 844 | * The value returned by SDL_JoystickGetAxis() is a signed integer (-32768 to |
| 845 | * 32767) representing the current position of the axis. It may be necessary |
| 846 | * to impose certain tolerances on these values to account for jitter. |
| 847 | * |
| 848 | * \param joystick an SDL_Joystick structure containing joystick information. |
| 849 | * \param axis the axis to query; the axis indices start at index 0. |
| 850 | * \returns a 16-bit signed integer representing the current position of the |
| 851 | * axis or 0 on failure; call SDL_GetError() for more information. |
| 852 | * |
| 853 | * \since This function is available since SDL 2.0.0. |
| 854 | * |
| 855 | * \sa SDL_JoystickNumAxes |
| 856 | */ |
| 857 | extern DECLSPEC Sint16 SDLCALL SDL_JoystickGetAxis(SDL_Joystick *joystick, |
| 858 | int axis); |
| 859 | |
| 860 | /** |
| 861 | * Get the initial state of an axis control on a joystick. |
| 862 | * |
| 863 | * The state is a value ranging from -32768 to 32767. |
| 864 | * |
| 865 | * The axis indices start at index 0. |
| 866 | * |
| 867 | * \param joystick an SDL_Joystick structure containing joystick information. |
| 868 | * \param axis the axis to query; the axis indices start at index 0. |
| 869 | * \param state Upon return, the initial value is supplied here. |
| 870 | * \return SDL_TRUE if this axis has any initial value, or SDL_FALSE if not. |
| 871 | * |
| 872 | * \since This function is available since SDL 2.0.6. |
| 873 | */ |
| 874 | extern DECLSPEC SDL_bool SDLCALL SDL_JoystickGetAxisInitialState(SDL_Joystick *joystick, |
| 875 | int axis, Sint16 *state); |
| 876 | |
| 877 | /** |
| 878 | * \name Hat positions |
| 879 | */ |
| 880 | /* @{ */ |
| 881 | #define SDL_HAT_CENTERED 0x00 |
| 882 | #define SDL_HAT_UP 0x01 |
| 883 | #define SDL_HAT_RIGHT 0x02 |
| 884 | #define SDL_HAT_DOWN 0x04 |
| 885 | #define SDL_HAT_LEFT 0x08 |
| 886 | #define SDL_HAT_RIGHTUP (SDL_HAT_RIGHT|SDL_HAT_UP) |
| 887 | #define SDL_HAT_RIGHTDOWN (SDL_HAT_RIGHT|SDL_HAT_DOWN) |
| 888 | #define SDL_HAT_LEFTUP (SDL_HAT_LEFT|SDL_HAT_UP) |
| 889 | #define SDL_HAT_LEFTDOWN (SDL_HAT_LEFT|SDL_HAT_DOWN) |
| 890 | /* @} */ |
| 891 | |
| 892 | /** |
| 893 | * Get the current state of a POV hat on a joystick. |
| 894 | * |
| 895 | * The returned value will be one of the following positions: |
| 896 | * |
| 897 | * - `SDL_HAT_CENTERED` |
| 898 | * - `SDL_HAT_UP` |
| 899 | * - `SDL_HAT_RIGHT` |
| 900 | * - `SDL_HAT_DOWN` |
| 901 | * - `SDL_HAT_LEFT` |
| 902 | * - `SDL_HAT_RIGHTUP` |
| 903 | * - `SDL_HAT_RIGHTDOWN` |
| 904 | * - `SDL_HAT_LEFTUP` |
| 905 | * - `SDL_HAT_LEFTDOWN` |
| 906 | * |
| 907 | * \param joystick an SDL_Joystick structure containing joystick information. |
| 908 | * \param hat the hat index to get the state from; indices start at index 0. |
| 909 | * \returns the current hat position. |
| 910 | * |
| 911 | * \since This function is available since SDL 2.0.0. |
| 912 | * |
| 913 | * \sa SDL_JoystickNumHats |
| 914 | */ |
| 915 | extern DECLSPEC Uint8 SDLCALL SDL_JoystickGetHat(SDL_Joystick *joystick, |
| 916 | int hat); |
| 917 | |
| 918 | /** |
| 919 | * Get the ball axis change since the last poll. |
| 920 | * |
| 921 | * Trackballs can only return relative motion since the last call to |
| 922 | * SDL_JoystickGetBall(), these motion deltas are placed into `dx` and `dy`. |
| 923 | * |
| 924 | * Most joysticks do not have trackballs. |
| 925 | * |
| 926 | * \param joystick the SDL_Joystick to query. |
| 927 | * \param ball the ball index to query; ball indices start at index 0. |
| 928 | * \param dx stores the difference in the x axis position since the last poll. |
| 929 | * \param dy stores the difference in the y axis position since the last poll. |
| 930 | * \returns 0 on success or a negative error code on failure; call |
| 931 | * SDL_GetError() for more information. |
| 932 | * |
| 933 | * \since This function is available since SDL 2.0.0. |
| 934 | * |
| 935 | * \sa SDL_JoystickNumBalls |
| 936 | */ |
| 937 | extern DECLSPEC int SDLCALL SDL_JoystickGetBall(SDL_Joystick *joystick, |
| 938 | int ball, int *dx, int *dy); |
| 939 | |
| 940 | /** |
| 941 | * Get the current state of a button on a joystick. |
| 942 | * |
| 943 | * \param joystick an SDL_Joystick structure containing joystick information. |
| 944 | * \param button the button index to get the state from; indices start at |
| 945 | * index 0. |
| 946 | * \returns 1 if the specified button is pressed, 0 otherwise. |
| 947 | * |
| 948 | * \since This function is available since SDL 2.0.0. |
| 949 | * |
| 950 | * \sa SDL_JoystickNumButtons |
| 951 | */ |
| 952 | extern DECLSPEC Uint8 SDLCALL SDL_JoystickGetButton(SDL_Joystick *joystick, |
| 953 | int button); |
| 954 | |
| 955 | /** |
| 956 | * Start a rumble effect. |
| 957 | * |
| 958 | * Each call to this function cancels any previous rumble effect, and calling |
| 959 | * it with 0 intensity stops any rumbling. |
| 960 | * |
| 961 | * \param joystick The joystick to vibrate. |
| 962 | * \param low_frequency_rumble The intensity of the low frequency (left) |
| 963 | * rumble motor, from 0 to 0xFFFF. |
| 964 | * \param high_frequency_rumble The intensity of the high frequency (right) |
| 965 | * rumble motor, from 0 to 0xFFFF. |
| 966 | * \param duration_ms The duration of the rumble effect, in milliseconds. |
| 967 | * \returns 0, or -1 if rumble isn't supported on this joystick. |
| 968 | * |
| 969 | * \since This function is available since SDL 2.0.9. |
| 970 | * |
| 971 | * \sa SDL_JoystickHasRumble |
| 972 | */ |
| 973 | extern DECLSPEC int SDLCALL SDL_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble, Uint32 duration_ms); |
| 974 | |
| 975 | /** |
| 976 | * Start a rumble effect in the joystick's triggers |
| 977 | * |
| 978 | * Each call to this function cancels any previous trigger rumble effect, and |
| 979 | * calling it with 0 intensity stops any rumbling. |
| 980 | * |
| 981 | * Note that this is rumbling of the _triggers_ and not the game controller as |
| 982 | * a whole. This is currently only supported on Xbox One controllers. If you |
| 983 | * want the (more common) whole-controller rumble, use SDL_JoystickRumble() |
| 984 | * instead. |
| 985 | * |
| 986 | * \param joystick The joystick to vibrate. |
| 987 | * \param left_rumble The intensity of the left trigger rumble motor, from 0 |
| 988 | * to 0xFFFF. |
| 989 | * \param right_rumble The intensity of the right trigger rumble motor, from 0 |
| 990 | * to 0xFFFF. |
| 991 | * \param duration_ms The duration of the rumble effect, in milliseconds. |
| 992 | * \returns 0, or -1 if trigger rumble isn't supported on this joystick. |
| 993 | * |
| 994 | * \since This function is available since SDL 2.0.14. |
| 995 | * |
| 996 | * \sa SDL_JoystickHasRumbleTriggers |
| 997 | */ |
| 998 | extern DECLSPEC int SDLCALL SDL_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble, Uint32 duration_ms); |
| 999 | |
| 1000 | /** |
| 1001 | * Query whether a joystick has an LED. |
| 1002 | * |
| 1003 | * An example of a joystick LED is the light on the back of a PlayStation 4's |
| 1004 | * DualShock 4 controller. |
| 1005 | * |
| 1006 | * \param joystick The joystick to query. |
| 1007 | * \return SDL_TRUE if the joystick has a modifiable LED, SDL_FALSE otherwise. |
| 1008 | * |
| 1009 | * \since This function is available since SDL 2.0.14. |
| 1010 | */ |
| 1011 | extern DECLSPEC SDL_bool SDLCALL SDL_JoystickHasLED(SDL_Joystick *joystick); |
| 1012 | |
| 1013 | /** |
| 1014 | * Query whether a joystick has rumble support. |
| 1015 | * |
| 1016 | * \param joystick The joystick to query. |
| 1017 | * \return SDL_TRUE if the joystick has rumble, SDL_FALSE otherwise. |
| 1018 | * |
| 1019 | * \since This function is available since SDL 2.0.18. |
| 1020 | * |
| 1021 | * \sa SDL_JoystickRumble |
| 1022 | */ |
| 1023 | extern DECLSPEC SDL_bool SDLCALL SDL_JoystickHasRumble(SDL_Joystick *joystick); |
| 1024 | |
| 1025 | /** |
| 1026 | * Query whether a joystick has rumble support on triggers. |
| 1027 | * |
| 1028 | * \param joystick The joystick to query. |
| 1029 | * \return SDL_TRUE if the joystick has trigger rumble, SDL_FALSE otherwise. |
| 1030 | * |
| 1031 | * \since This function is available since SDL 2.0.18. |
| 1032 | * |
| 1033 | * \sa SDL_JoystickRumbleTriggers |
| 1034 | */ |
| 1035 | extern DECLSPEC SDL_bool SDLCALL SDL_JoystickHasRumbleTriggers(SDL_Joystick *joystick); |
| 1036 | |
| 1037 | /** |
| 1038 | * Update a joystick's LED color. |
| 1039 | * |
| 1040 | * An example of a joystick LED is the light on the back of a PlayStation 4's |
| 1041 | * DualShock 4 controller. |
| 1042 | * |
| 1043 | * \param joystick The joystick to update. |
| 1044 | * \param red The intensity of the red LED. |
| 1045 | * \param green The intensity of the green LED. |
| 1046 | * \param blue The intensity of the blue LED. |
| 1047 | * \returns 0 on success, -1 if this joystick does not have a modifiable LED. |
| 1048 | * |
| 1049 | * \since This function is available since SDL 2.0.14. |
| 1050 | */ |
| 1051 | extern DECLSPEC int SDLCALL SDL_JoystickSetLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue); |
| 1052 | |
| 1053 | /** |
| 1054 | * Send a joystick specific effect packet |
| 1055 | * |
| 1056 | * \param joystick The joystick to affect. |
| 1057 | * \param data The data to send to the joystick. |
| 1058 | * \param size The size of the data to send to the joystick. |
| 1059 | * \returns 0, or -1 if this joystick or driver doesn't support effect |
| 1060 | * packets. |
| 1061 | * |
| 1062 | * \since This function is available since SDL 2.0.16. |
| 1063 | */ |
| 1064 | extern DECLSPEC int SDLCALL SDL_JoystickSendEffect(SDL_Joystick *joystick, const void *data, int size); |
| 1065 | |
| 1066 | /** |
| 1067 | * Close a joystick previously opened with SDL_JoystickOpen(). |
| 1068 | * |
| 1069 | * \param joystick The joystick device to close. |
| 1070 | * |
| 1071 | * \since This function is available since SDL 2.0.0. |
| 1072 | * |
| 1073 | * \sa SDL_JoystickOpen |
| 1074 | */ |
| 1075 | extern DECLSPEC void SDLCALL SDL_JoystickClose(SDL_Joystick *joystick); |
| 1076 | |
| 1077 | /** |
| 1078 | * Get the battery level of a joystick as SDL_JoystickPowerLevel. |
| 1079 | * |
| 1080 | * \param joystick the SDL_Joystick to query. |
| 1081 | * \returns the current battery level as SDL_JoystickPowerLevel on success or |
| 1082 | * `SDL_JOYSTICK_POWER_UNKNOWN` if it is unknown. |
| 1083 | * |
| 1084 | * \since This function is available since SDL 2.0.4. |
| 1085 | */ |
| 1086 | extern DECLSPEC SDL_JoystickPowerLevel SDLCALL SDL_JoystickCurrentPowerLevel(SDL_Joystick *joystick); |
| 1087 | |
| 1088 | /* Ends C function definitions when using C++ */ |
| 1089 | #ifdef __cplusplus |
| 1090 | } |
| 1091 | #endif |
| 1092 | #include "close_code.h" |
| 1093 | |
| 1094 | #endif /* SDL_joystick_h_ */ |
| 1095 | |
| 1096 | /* vi: set ts=4 sw=4 expandtab: */ |
| 1097 | |