SDL_joystick.h 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2024 Sam Lantinga <[email protected]>
  4. This software is provided 'as-is', without any express or implied
  5. warranty. In no event will the authors be held liable for any damages
  6. arising from the use of this software.
  7. Permission is granted to anyone to use this software for any purpose,
  8. including commercial applications, and to alter it and redistribute it
  9. freely, subject to the following restrictions:
  10. 1. The origin of this software must not be misrepresented; you must not
  11. claim that you wrote the original software. If you use this software
  12. in a product, an acknowledgment in the product documentation would be
  13. appreciated but is not required.
  14. 2. Altered source versions must be plainly marked as such, and must not be
  15. misrepresented as being the original software.
  16. 3. This notice may not be removed or altered from any source distribution.
  17. */
  18. /**
  19. * # CategoryJoystick
  20. *
  21. * SDL joystick support.
  22. *
  23. * This is the lower-level joystick handling. If you want the simpler option,
  24. * where what buttons does what is well-defined, you should use the gamepad
  25. * API instead.
  26. *
  27. * The term "instance_id" is the current instantiation of a joystick device in
  28. * the system, if the joystick is removed and then re-inserted then it will
  29. * get a new instance_id, instance_id's are monotonically increasing
  30. * identifiers of a joystick plugged in.
  31. *
  32. * The term "player_index" is the number assigned to a player on a specific
  33. * controller. For XInput controllers this returns the XInput user index. Many
  34. * joysticks will not be able to supply this information.
  35. *
  36. * SDL_GUID is used as a stable 128-bit identifier for a joystick device that
  37. * does not change over time. It identifies class of the device (a X360 wired
  38. * controller for example). This identifier is platform dependent.
  39. *
  40. * In order to use these functions, SDL_Init() must have been called with the
  41. * SDL_INIT_JOYSTICK flag. This causes SDL to scan the system for joysticks,
  42. * and load appropriate drivers.
  43. *
  44. * If you would like to receive joystick updates while the application is in
  45. * the background, you should set the following hint before calling
  46. * SDL_Init(): SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS
  47. */
  48. #ifndef SDL_joystick_h_
  49. #define SDL_joystick_h_
  50. #include <SDL3/SDL_stdinc.h>
  51. #include <SDL3/SDL_error.h>
  52. #include <SDL3/SDL_guid.h>
  53. #include <SDL3/SDL_mutex.h>
  54. #include <SDL3/SDL_power.h>
  55. #include <SDL3/SDL_properties.h>
  56. #include <SDL3/SDL_sensor.h>
  57. #include <SDL3/SDL_begin_code.h>
  58. /* Set up for C function definitions, even when using C++ */
  59. #ifdef __cplusplus
  60. extern "C" {
  61. #endif
  62. #ifdef SDL_THREAD_SAFETY_ANALYSIS
  63. /*
  64. * This is not an exported symbol from SDL, this is only in the headers to
  65. * help Clang's thread safety analysis tools to function. Do not attempt
  66. * to access this symbol from your app, it will not work!
  67. */
  68. extern SDL_Mutex *SDL_joystick_lock;
  69. #endif
  70. /**
  71. * The joystick structure used to identify an SDL joystick.
  72. *
  73. * This is opaque data.
  74. *
  75. * \since This struct is available since SDL 3.0.0.
  76. */
  77. typedef struct SDL_Joystick SDL_Joystick;
  78. /**
  79. * This is a unique ID for a joystick for the time it is connected to the
  80. * system, and is never reused for the lifetime of the application.
  81. *
  82. * If the joystick is disconnected and reconnected, it will get a new ID.
  83. *
  84. * The ID value starts at 1 and increments from there. The value 0 is an
  85. * invalid ID.
  86. *
  87. * \since This datatype is available since SDL 3.0.0.
  88. */
  89. typedef Uint32 SDL_JoystickID;
  90. /**
  91. * An enum of some common joystick types.
  92. *
  93. * In some cases, SDL can identify a low-level joystick as being a certain
  94. * type of device, and will report it through SDL_GetJoystickType (or
  95. * SDL_GetJoystickTypeForID).
  96. *
  97. * This is by no means a complete list of everything that can be plugged into
  98. * a computer.
  99. *
  100. * \since This enum is available since SDL 3.0.0.
  101. */
  102. typedef enum SDL_JoystickType
  103. {
  104. SDL_JOYSTICK_TYPE_UNKNOWN,
  105. SDL_JOYSTICK_TYPE_GAMEPAD,
  106. SDL_JOYSTICK_TYPE_WHEEL,
  107. SDL_JOYSTICK_TYPE_ARCADE_STICK,
  108. SDL_JOYSTICK_TYPE_FLIGHT_STICK,
  109. SDL_JOYSTICK_TYPE_DANCE_PAD,
  110. SDL_JOYSTICK_TYPE_GUITAR,
  111. SDL_JOYSTICK_TYPE_DRUM_KIT,
  112. SDL_JOYSTICK_TYPE_ARCADE_PAD,
  113. SDL_JOYSTICK_TYPE_THROTTLE
  114. } SDL_JoystickType;
  115. /**
  116. * Possible connection states for a joystick device.
  117. *
  118. * This is used by SDL_GetJoystickConnectionState to report how a device is
  119. * connected to the system.
  120. *
  121. * \since This enum is available since SDL 3.0.0.
  122. */
  123. typedef enum SDL_JoystickConnectionState
  124. {
  125. SDL_JOYSTICK_CONNECTION_INVALID = -1,
  126. SDL_JOYSTICK_CONNECTION_UNKNOWN,
  127. SDL_JOYSTICK_CONNECTION_WIRED,
  128. SDL_JOYSTICK_CONNECTION_WIRELESS
  129. } SDL_JoystickConnectionState;
  130. /**
  131. * The largest value an SDL_Joystick's axis can report.
  132. *
  133. * \since This macro is available since SDL 3.0.0.
  134. *
  135. * \sa SDL_JOYSTICK_AXIS_MIN
  136. */
  137. #define SDL_JOYSTICK_AXIS_MAX 32767
  138. /**
  139. * The smallest value an SDL_Joystick's axis can report.
  140. *
  141. * This is a negative number!
  142. *
  143. * \since This macro is available since SDL 3.0.0.
  144. *
  145. * \sa SDL_JOYSTICK_AXIS_MAX
  146. */
  147. #define SDL_JOYSTICK_AXIS_MIN -32768
  148. /* Set max recognized G-force from accelerometer
  149. See src/joystick/uikit/SDL_sysjoystick.m for notes on why this is needed
  150. */
  151. #define SDL_IPHONE_MAX_GFORCE 5.0
  152. /* Function prototypes */
  153. /**
  154. * Locking for atomic access to the joystick API.
  155. *
  156. * The SDL joystick functions are thread-safe, however you can lock the
  157. * joysticks while processing to guarantee that the joystick list won't change
  158. * and joystick and gamepad events will not be delivered.
  159. *
  160. * \since This function is available since SDL 3.0.0.
  161. */
  162. extern SDL_DECLSPEC void SDLCALL SDL_LockJoysticks(void) SDL_ACQUIRE(SDL_joystick_lock);
  163. /**
  164. * Unlocking for atomic access to the joystick API.
  165. *
  166. * \since This function is available since SDL 3.0.0.
  167. */
  168. extern SDL_DECLSPEC void SDLCALL SDL_UnlockJoysticks(void) SDL_RELEASE(SDL_joystick_lock);
  169. /**
  170. * Return whether a joystick is currently connected.
  171. *
  172. * \returns SDL_TRUE if a joystick is connected, SDL_FALSE otherwise.
  173. *
  174. * \since This function is available since SDL 3.0.0.
  175. *
  176. * \sa SDL_GetJoysticks
  177. */
  178. extern SDL_DECLSPEC SDL_bool SDLCALL SDL_HasJoystick(void);
  179. /**
  180. * Get a list of currently connected joysticks.
  181. *
  182. * This returns temporary memory which will be automatically freed later, and
  183. * can be claimed with SDL_ClaimTemporaryMemory().
  184. *
  185. * \param count a pointer filled in with the number of joysticks returned, may
  186. * be NULL.
  187. * \returns a 0 terminated array of joystick instance IDs or NULL on failure;
  188. * call SDL_GetError() for more information.
  189. *
  190. * \since This function is available since SDL 3.0.0.
  191. *
  192. * \sa SDL_HasJoystick
  193. * \sa SDL_OpenJoystick
  194. */
  195. extern SDL_DECLSPEC const SDL_JoystickID * SDLCALL SDL_GetJoysticks(int *count);
  196. /**
  197. * Get the implementation dependent name of a joystick.
  198. *
  199. * This can be called before any joysticks are opened.
  200. *
  201. * This returns temporary memory which will be automatically freed later, and
  202. * can be claimed with SDL_ClaimTemporaryMemory().
  203. *
  204. * \param instance_id the joystick instance ID.
  205. * \returns the name of the selected joystick. If no name can be found, this
  206. * function returns NULL; call SDL_GetError() for more information.
  207. *
  208. * \since This function is available since SDL 3.0.0.
  209. *
  210. * \sa SDL_GetJoystickName
  211. * \sa SDL_GetJoysticks
  212. */
  213. extern SDL_DECLSPEC const char * SDLCALL SDL_GetJoystickNameForID(SDL_JoystickID instance_id);
  214. /**
  215. * Get the implementation dependent path of a joystick.
  216. *
  217. * This can be called before any joysticks are opened.
  218. *
  219. * This returns temporary memory which will be automatically freed later, and
  220. * can be claimed with SDL_ClaimTemporaryMemory().
  221. *
  222. * \param instance_id the joystick instance ID.
  223. * \returns the path of the selected joystick. If no path can be found, this
  224. * function returns NULL; call SDL_GetError() for more information.
  225. *
  226. * \since This function is available since SDL 3.0.0.
  227. *
  228. * \sa SDL_GetJoystickPath
  229. * \sa SDL_GetJoysticks
  230. */
  231. extern SDL_DECLSPEC const char * SDLCALL SDL_GetJoystickPathForID(SDL_JoystickID instance_id);
  232. /**
  233. * Get the player index of a joystick.
  234. *
  235. * This can be called before any joysticks are opened.
  236. *
  237. * \param instance_id the joystick instance ID.
  238. * \returns the player index of a joystick, or -1 if it's not available.
  239. *
  240. * \since This function is available since SDL 3.0.0.
  241. *
  242. * \sa SDL_GetJoystickPlayerIndex
  243. * \sa SDL_GetJoysticks
  244. */
  245. extern SDL_DECLSPEC int SDLCALL SDL_GetJoystickPlayerIndexForID(SDL_JoystickID instance_id);
  246. /**
  247. * Get the implementation-dependent GUID of a joystick.
  248. *
  249. * This can be called before any joysticks are opened.
  250. *
  251. * \param instance_id the joystick instance ID.
  252. * \returns the GUID of the selected joystick. If called with an invalid
  253. * instance_id, this function returns a zero GUID.
  254. *
  255. * \since This function is available since SDL 3.0.0.
  256. *
  257. * \sa SDL_GetJoystickGUID
  258. * \sa SDL_GUIDToString
  259. */
  260. extern SDL_DECLSPEC SDL_GUID SDLCALL SDL_GetJoystickGUIDForID(SDL_JoystickID instance_id);
  261. /**
  262. * Get the USB vendor ID of a joystick, if available.
  263. *
  264. * This can be called before any joysticks are opened. If the vendor ID isn't
  265. * available this function returns 0.
  266. *
  267. * \param instance_id the joystick instance ID.
  268. * \returns the USB vendor ID of the selected joystick. If called with an
  269. * invalid instance_id, this function returns 0.
  270. *
  271. * \since This function is available since SDL 3.0.0.
  272. *
  273. * \sa SDL_GetJoystickVendor
  274. * \sa SDL_GetJoysticks
  275. */
  276. extern SDL_DECLSPEC Uint16 SDLCALL SDL_GetJoystickVendorForID(SDL_JoystickID instance_id);
  277. /**
  278. * Get the USB product ID of a joystick, if available.
  279. *
  280. * This can be called before any joysticks are opened. If the product ID isn't
  281. * available this function returns 0.
  282. *
  283. * \param instance_id the joystick instance ID.
  284. * \returns the USB product ID of the selected joystick. If called with an
  285. * invalid instance_id, this function returns 0.
  286. *
  287. * \since This function is available since SDL 3.0.0.
  288. *
  289. * \sa SDL_GetJoystickProduct
  290. * \sa SDL_GetJoysticks
  291. */
  292. extern SDL_DECLSPEC Uint16 SDLCALL SDL_GetJoystickProductForID(SDL_JoystickID instance_id);
  293. /**
  294. * Get the product version of a joystick, if available.
  295. *
  296. * This can be called before any joysticks are opened. If the product version
  297. * isn't available this function returns 0.
  298. *
  299. * \param instance_id the joystick instance ID.
  300. * \returns the product version of the selected joystick. If called with an
  301. * invalid instance_id, this function returns 0.
  302. *
  303. * \since This function is available since SDL 3.0.0.
  304. *
  305. * \sa SDL_GetJoystickProductVersion
  306. * \sa SDL_GetJoysticks
  307. */
  308. extern SDL_DECLSPEC Uint16 SDLCALL SDL_GetJoystickProductVersionForID(SDL_JoystickID instance_id);
  309. /**
  310. * Get the type of a joystick, if available.
  311. *
  312. * This can be called before any joysticks are opened.
  313. *
  314. * \param instance_id the joystick instance ID.
  315. * \returns the SDL_JoystickType of the selected joystick. If called with an
  316. * invalid instance_id, this function returns
  317. * `SDL_JOYSTICK_TYPE_UNKNOWN`.
  318. *
  319. * \since This function is available since SDL 3.0.0.
  320. *
  321. * \sa SDL_GetJoystickType
  322. * \sa SDL_GetJoysticks
  323. */
  324. extern SDL_DECLSPEC SDL_JoystickType SDLCALL SDL_GetJoystickTypeForID(SDL_JoystickID instance_id);
  325. /**
  326. * Open a joystick for use.
  327. *
  328. * The joystick subsystem must be initialized before a joystick can be opened
  329. * for use.
  330. *
  331. * \param instance_id the joystick instance ID.
  332. * \returns a joystick identifier or NULL on failure; call SDL_GetError() for
  333. * more information.
  334. *
  335. * \since This function is available since SDL 3.0.0.
  336. *
  337. * \sa SDL_CloseJoystick
  338. */
  339. extern SDL_DECLSPEC SDL_Joystick * SDLCALL SDL_OpenJoystick(SDL_JoystickID instance_id);
  340. /**
  341. * Get the SDL_Joystick associated with an instance ID, if it has been opened.
  342. *
  343. * \param instance_id the instance ID to get the SDL_Joystick for.
  344. * \returns an SDL_Joystick on success or NULL on failure or if it hasn't been
  345. * opened yet; call SDL_GetError() for more information.
  346. *
  347. * \since This function is available since SDL 3.0.0.
  348. */
  349. extern SDL_DECLSPEC SDL_Joystick * SDLCALL SDL_GetJoystickFromID(SDL_JoystickID instance_id);
  350. /**
  351. * Get the SDL_Joystick associated with a player index.
  352. *
  353. * \param player_index the player index to get the SDL_Joystick for.
  354. * \returns an SDL_Joystick on success or NULL on failure; call SDL_GetError()
  355. * for more information.
  356. *
  357. * \since This function is available since SDL 3.0.0.
  358. *
  359. * \sa SDL_GetJoystickPlayerIndex
  360. * \sa SDL_SetJoystickPlayerIndex
  361. */
  362. extern SDL_DECLSPEC SDL_Joystick * SDLCALL SDL_GetJoystickFromPlayerIndex(int player_index);
  363. /**
  364. * The structure that describes a virtual joystick touchpad.
  365. *
  366. * \since This struct is available since SDL 3.0.0.
  367. *
  368. * \sa SDL_VirtualJoystickDesc
  369. */
  370. typedef struct SDL_VirtualJoystickTouchpadDesc
  371. {
  372. Uint16 nfingers; /**< the number of simultaneous fingers on this touchpad */
  373. Uint16 padding[3];
  374. } SDL_VirtualJoystickTouchpadDesc;
  375. /**
  376. * The structure that describes a virtual joystick sensor.
  377. *
  378. * \since This struct is available since SDL 3.0.0.
  379. *
  380. * \sa SDL_VirtualJoystickDesc
  381. */
  382. typedef struct SDL_VirtualJoystickSensorDesc
  383. {
  384. SDL_SensorType type; /**< the type of this sensor */
  385. float rate; /**< the update frequency of this sensor, may be 0.0f */
  386. } SDL_VirtualJoystickSensorDesc;
  387. /**
  388. * The structure that describes a virtual joystick.
  389. *
  390. * All elements of this structure are optional and can be left 0.
  391. *
  392. * \since This struct is available since SDL 3.0.0.
  393. *
  394. * \sa SDL_AttachVirtualJoystick
  395. * \sa SDL_VirtualJoystickSensorDesc
  396. * \sa SDL_VirtualJoystickTouchpadDesc
  397. */
  398. typedef struct SDL_VirtualJoystickDesc
  399. {
  400. Uint16 type; /**< `SDL_JoystickType` */
  401. Uint16 padding; /**< unused */
  402. Uint16 vendor_id; /**< the USB vendor ID of this joystick */
  403. Uint16 product_id; /**< the USB product ID of this joystick */
  404. Uint16 naxes; /**< the number of axes on this joystick */
  405. Uint16 nbuttons; /**< the number of buttons on this joystick */
  406. Uint16 nballs; /**< the number of balls on this joystick */
  407. Uint16 nhats; /**< the number of hats on this joystick */
  408. Uint16 ntouchpads; /**< the number of touchpads on this joystick, requires `touchpads` to point at valid descriptions */
  409. Uint16 nsensors; /**< the number of sensors on this joystick, requires `sensors` to point at valid descriptions */
  410. Uint16 padding2[2]; /**< unused */
  411. Uint32 button_mask; /**< A mask of which buttons are valid for this controller
  412. e.g. (1 << SDL_GAMEPAD_BUTTON_SOUTH) */
  413. Uint32 axis_mask; /**< A mask of which axes are valid for this controller
  414. e.g. (1 << SDL_GAMEPAD_AXIS_LEFTX) */
  415. const char *name; /**< the name of the joystick */
  416. const SDL_VirtualJoystickTouchpadDesc *touchpads; /**< A pointer to an array of touchpad descriptions, required if `ntouchpads` is > 0 */
  417. const SDL_VirtualJoystickSensorDesc *sensors; /**< A pointer to an array of sensor descriptions, required if `nsensors` is > 0 */
  418. void *userdata; /**< User data pointer passed to callbacks */
  419. void (SDLCALL *Update)(void *userdata); /**< Called when the joystick state should be updated */
  420. void (SDLCALL *SetPlayerIndex)(void *userdata, int player_index); /**< Called when the player index is set */
  421. int (SDLCALL *Rumble)(void *userdata, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble); /**< Implements SDL_RumbleJoystick() */
  422. int (SDLCALL *RumbleTriggers)(void *userdata, Uint16 left_rumble, Uint16 right_rumble); /**< Implements SDL_RumbleJoystickTriggers() */
  423. int (SDLCALL *SetLED)(void *userdata, Uint8 red, Uint8 green, Uint8 blue); /**< Implements SDL_SetJoystickLED() */
  424. int (SDLCALL *SendEffect)(void *userdata, const void *data, int size); /**< Implements SDL_SendJoystickEffect() */
  425. int (SDLCALL *SetSensorsEnabled)(void *userdata, SDL_bool enabled); /**< Implements SDL_SetGamepadSensorEnabled() */
  426. } SDL_VirtualJoystickDesc;
  427. /**
  428. * Attach a new virtual joystick.
  429. *
  430. * \param desc joystick description.
  431. * \returns the joystick instance ID, or 0 on failure; call SDL_GetError() for
  432. * more information.
  433. *
  434. * \since This function is available since SDL 3.0.0.
  435. *
  436. * \sa SDL_DetachVirtualJoystick
  437. */
  438. extern SDL_DECLSPEC SDL_JoystickID SDLCALL SDL_AttachVirtualJoystick(const SDL_VirtualJoystickDesc *desc);
  439. /**
  440. * Detach a virtual joystick.
  441. *
  442. * \param instance_id the joystick instance ID, previously returned from
  443. * SDL_AttachVirtualJoystick().
  444. * \returns 0 on success or a negative error code on failure; call
  445. * SDL_GetError() for more information.
  446. *
  447. * \since This function is available since SDL 3.0.0.
  448. *
  449. * \sa SDL_AttachVirtualJoystick
  450. */
  451. extern SDL_DECLSPEC int SDLCALL SDL_DetachVirtualJoystick(SDL_JoystickID instance_id);
  452. /**
  453. * Query whether or not a joystick is virtual.
  454. *
  455. * \param instance_id the joystick instance ID.
  456. * \returns SDL_TRUE if the joystick is virtual, SDL_FALSE otherwise.
  457. *
  458. * \since This function is available since SDL 3.0.0.
  459. */
  460. extern SDL_DECLSPEC SDL_bool SDLCALL SDL_IsJoystickVirtual(SDL_JoystickID instance_id);
  461. /**
  462. * Set the state of an axis on an opened virtual joystick.
  463. *
  464. * Please note that values set here will not be applied until the next call to
  465. * SDL_UpdateJoysticks, which can either be called directly, or can be called
  466. * indirectly through various other SDL APIs, including, but not limited to
  467. * the following: SDL_PollEvent, SDL_PumpEvents, SDL_WaitEventTimeout,
  468. * SDL_WaitEvent.
  469. *
  470. * Note that when sending trigger axes, you should scale the value to the full
  471. * range of Sint16. For example, a trigger at rest would have the value of
  472. * `SDL_JOYSTICK_AXIS_MIN`.
  473. *
  474. * \param joystick the virtual joystick on which to set state.
  475. * \param axis the index of the axis on the virtual joystick to update.
  476. * \param value the new value for the specified axis.
  477. * \returns 0 on success or a negative error code on failure; call
  478. * SDL_GetError() for more information.
  479. *
  480. * \since This function is available since SDL 3.0.0.
  481. */
  482. extern SDL_DECLSPEC int SDLCALL SDL_SetJoystickVirtualAxis(SDL_Joystick *joystick, int axis, Sint16 value);
  483. /**
  484. * Generate ball motion on an opened virtual joystick.
  485. *
  486. * Please note that values set here will not be applied until the next call to
  487. * SDL_UpdateJoysticks, which can either be called directly, or can be called
  488. * indirectly through various other SDL APIs, including, but not limited to
  489. * the following: SDL_PollEvent, SDL_PumpEvents, SDL_WaitEventTimeout,
  490. * SDL_WaitEvent.
  491. *
  492. * \param joystick the virtual joystick on which to set state.
  493. * \param ball the index of the ball on the virtual joystick to update.
  494. * \param xrel the relative motion on the X axis.
  495. * \param yrel the relative motion on the Y axis.
  496. * \returns 0 on success or a negative error code on failure; call
  497. * SDL_GetError() for more information.
  498. *
  499. * \since This function is available since SDL 3.0.0.
  500. */
  501. extern SDL_DECLSPEC int SDLCALL SDL_SetJoystickVirtualBall(SDL_Joystick *joystick, int ball, Sint16 xrel, Sint16 yrel);
  502. /**
  503. * Set the state of a button on an opened virtual joystick.
  504. *
  505. * Please note that values set here will not be applied until the next call to
  506. * SDL_UpdateJoysticks, which can either be called directly, or can be called
  507. * indirectly through various other SDL APIs, including, but not limited to
  508. * the following: SDL_PollEvent, SDL_PumpEvents, SDL_WaitEventTimeout,
  509. * SDL_WaitEvent.
  510. *
  511. * \param joystick the virtual joystick on which to set state.
  512. * \param button the index of the button on the virtual joystick to update.
  513. * \param value the new value for the specified button.
  514. * \returns 0 on success or a negative error code on failure; call
  515. * SDL_GetError() for more information.
  516. *
  517. * \since This function is available since SDL 3.0.0.
  518. */
  519. extern SDL_DECLSPEC int SDLCALL SDL_SetJoystickVirtualButton(SDL_Joystick *joystick, int button, Uint8 value);
  520. /**
  521. * Set the state of a hat on an opened virtual joystick.
  522. *
  523. * Please note that values set here will not be applied until the next call to
  524. * SDL_UpdateJoysticks, which can either be called directly, or can be called
  525. * indirectly through various other SDL APIs, including, but not limited to
  526. * the following: SDL_PollEvent, SDL_PumpEvents, SDL_WaitEventTimeout,
  527. * SDL_WaitEvent.
  528. *
  529. * \param joystick the virtual joystick on which to set state.
  530. * \param hat the index of the hat on the virtual joystick to update.
  531. * \param value the new value for the specified hat.
  532. * \returns 0 on success or a negative error code on failure; call
  533. * SDL_GetError() for more information.
  534. *
  535. * \since This function is available since SDL 3.0.0.
  536. */
  537. extern SDL_DECLSPEC int SDLCALL SDL_SetJoystickVirtualHat(SDL_Joystick *joystick, int hat, Uint8 value);
  538. /**
  539. * Set touchpad finger state on an opened virtual joystick.
  540. *
  541. * Please note that values set here will not be applied until the next call to
  542. * SDL_UpdateJoysticks, which can either be called directly, or can be called
  543. * indirectly through various other SDL APIs, including, but not limited to
  544. * the following: SDL_PollEvent, SDL_PumpEvents, SDL_WaitEventTimeout,
  545. * SDL_WaitEvent.
  546. *
  547. * \param joystick the virtual joystick on which to set state.
  548. * \param touchpad the index of the touchpad on the virtual joystick to
  549. * update.
  550. * \param finger the index of the finger on the touchpad to set.
  551. * \param state `SDL_PRESSED` if the finger is pressed, `SDL_RELEASED` if the
  552. * finger is released.
  553. * \param x the x coordinate of the finger on the touchpad, normalized 0 to 1,
  554. * with the origin in the upper left.
  555. * \param y the y coordinate of the finger on the touchpad, normalized 0 to 1,
  556. * with the origin in the upper left.
  557. * \param pressure the pressure of the finger.
  558. * \returns 0 on success or a negative error code on failure; call
  559. * SDL_GetError() for more information.
  560. *
  561. * \since This function is available since SDL 3.0.0.
  562. */
  563. extern SDL_DECLSPEC int SDLCALL SDL_SetJoystickVirtualTouchpad(SDL_Joystick *joystick, int touchpad, int finger, Uint8 state, float x, float y, float pressure);
  564. /**
  565. * Send a sensor update for an opened virtual joystick.
  566. *
  567. * Please note that values set here will not be applied until the next call to
  568. * SDL_UpdateJoysticks, which can either be called directly, or can be called
  569. * indirectly through various other SDL APIs, including, but not limited to
  570. * the following: SDL_PollEvent, SDL_PumpEvents, SDL_WaitEventTimeout,
  571. * SDL_WaitEvent.
  572. *
  573. * \param joystick the virtual joystick on which to set state.
  574. * \param type the type of the sensor on the virtual joystick to update.
  575. * \param sensor_timestamp a 64-bit timestamp in nanoseconds associated with
  576. * the sensor reading.
  577. * \param data the data associated with the sensor reading.
  578. * \param num_values the number of values pointed to by `data`.
  579. * \returns 0 on success or a negative error code on failure; call
  580. * SDL_GetError() for more information.
  581. *
  582. * \since This function is available since SDL 3.0.0.
  583. */
  584. extern SDL_DECLSPEC int SDLCALL SDL_SendJoystickVirtualSensorData(SDL_Joystick *joystick, SDL_SensorType type, Uint64 sensor_timestamp, const float *data, int num_values);
  585. /**
  586. * Get the properties associated with a joystick.
  587. *
  588. * The following read-only properties are provided by SDL:
  589. *
  590. * - `SDL_PROP_JOYSTICK_CAP_MONO_LED_BOOLEAN`: true if this joystick has an
  591. * LED that has adjustable brightness
  592. * - `SDL_PROP_JOYSTICK_CAP_RGB_LED_BOOLEAN`: true if this joystick has an LED
  593. * that has adjustable color
  594. * - `SDL_PROP_JOYSTICK_CAP_PLAYER_LED_BOOLEAN`: true if this joystick has a
  595. * player LED
  596. * - `SDL_PROP_JOYSTICK_CAP_RUMBLE_BOOLEAN`: true if this joystick has
  597. * left/right rumble
  598. * - `SDL_PROP_JOYSTICK_CAP_TRIGGER_RUMBLE_BOOLEAN`: true if this joystick has
  599. * simple trigger rumble
  600. *
  601. * \param joystick the SDL_Joystick obtained from SDL_OpenJoystick().
  602. * \returns a valid property ID on success or 0 on failure; call
  603. * SDL_GetError() for more information.
  604. *
  605. * \since This function is available since SDL 3.0.0.
  606. */
  607. extern SDL_DECLSPEC SDL_PropertiesID SDLCALL SDL_GetJoystickProperties(SDL_Joystick *joystick);
  608. #define SDL_PROP_JOYSTICK_CAP_MONO_LED_BOOLEAN "SDL.joystick.cap.mono_led"
  609. #define SDL_PROP_JOYSTICK_CAP_RGB_LED_BOOLEAN "SDL.joystick.cap.rgb_led"
  610. #define SDL_PROP_JOYSTICK_CAP_PLAYER_LED_BOOLEAN "SDL.joystick.cap.player_led"
  611. #define SDL_PROP_JOYSTICK_CAP_RUMBLE_BOOLEAN "SDL.joystick.cap.rumble"
  612. #define SDL_PROP_JOYSTICK_CAP_TRIGGER_RUMBLE_BOOLEAN "SDL.joystick.cap.trigger_rumble"
  613. /**
  614. * Get the implementation dependent name of a joystick.
  615. *
  616. * This returns temporary memory which will be automatically freed later, and
  617. * can be claimed with SDL_ClaimTemporaryMemory().
  618. *
  619. * \param joystick the SDL_Joystick obtained from SDL_OpenJoystick().
  620. * \returns the name of the selected joystick. If no name can be found, this
  621. * function returns NULL; call SDL_GetError() for more information.
  622. *
  623. * \since This function is available since SDL 3.0.0.
  624. *
  625. * \sa SDL_GetJoystickNameForID
  626. */
  627. extern SDL_DECLSPEC const char * SDLCALL SDL_GetJoystickName(SDL_Joystick *joystick);
  628. /**
  629. * Get the implementation dependent path of a joystick.
  630. *
  631. * This returns temporary memory which will be automatically freed later, and
  632. * can be claimed with SDL_ClaimTemporaryMemory().
  633. *
  634. * \param joystick the SDL_Joystick obtained from SDL_OpenJoystick().
  635. * \returns the path of the selected joystick. If no path can be found, this
  636. * function returns NULL; call SDL_GetError() for more information.
  637. *
  638. * \since This function is available since SDL 3.0.0.
  639. *
  640. * \sa SDL_GetJoystickPathForID
  641. */
  642. extern SDL_DECLSPEC const char * SDLCALL SDL_GetJoystickPath(SDL_Joystick *joystick);
  643. /**
  644. * Get the player index of an opened joystick.
  645. *
  646. * For XInput controllers this returns the XInput user index. Many joysticks
  647. * will not be able to supply this information.
  648. *
  649. * \param joystick the SDL_Joystick obtained from SDL_OpenJoystick().
  650. * \returns the player index, or -1 if it's not available.
  651. *
  652. * \since This function is available since SDL 3.0.0.
  653. *
  654. * \sa SDL_SetJoystickPlayerIndex
  655. */
  656. extern SDL_DECLSPEC int SDLCALL SDL_GetJoystickPlayerIndex(SDL_Joystick *joystick);
  657. /**
  658. * Set the player index of an opened joystick.
  659. *
  660. * \param joystick the SDL_Joystick obtained from SDL_OpenJoystick().
  661. * \param player_index player index to assign to this joystick, or -1 to clear
  662. * the player index and turn off player LEDs.
  663. * \returns 0 on success or a negative error code on failure; call
  664. * SDL_GetError() for more information.
  665. *
  666. * \since This function is available since SDL 3.0.0.
  667. *
  668. * \sa SDL_GetJoystickPlayerIndex
  669. */
  670. extern SDL_DECLSPEC int SDLCALL SDL_SetJoystickPlayerIndex(SDL_Joystick *joystick, int player_index);
  671. /**
  672. * Get the implementation-dependent GUID for the joystick.
  673. *
  674. * This function requires an open joystick.
  675. *
  676. * \param joystick the SDL_Joystick obtained from SDL_OpenJoystick().
  677. * \returns the GUID of the given joystick. If called on an invalid index,
  678. * this function returns a zero GUID; call SDL_GetError() for more
  679. * information.
  680. *
  681. * \since This function is available since SDL 3.0.0.
  682. *
  683. * \sa SDL_GetJoystickGUIDForID
  684. * \sa SDL_GUIDToString
  685. */
  686. extern SDL_DECLSPEC SDL_GUID SDLCALL SDL_GetJoystickGUID(SDL_Joystick *joystick);
  687. /**
  688. * Get the USB vendor ID of an opened joystick, if available.
  689. *
  690. * If the vendor ID isn't available this function returns 0.
  691. *
  692. * \param joystick the SDL_Joystick obtained from SDL_OpenJoystick().
  693. * \returns the USB vendor ID of the selected joystick, or 0 if unavailable.
  694. *
  695. * \since This function is available since SDL 3.0.0.
  696. *
  697. * \sa SDL_GetJoystickVendorForID
  698. */
  699. extern SDL_DECLSPEC Uint16 SDLCALL SDL_GetJoystickVendor(SDL_Joystick *joystick);
  700. /**
  701. * Get the USB product ID of an opened joystick, if available.
  702. *
  703. * If the product ID isn't available this function returns 0.
  704. *
  705. * \param joystick the SDL_Joystick obtained from SDL_OpenJoystick().
  706. * \returns the USB product ID of the selected joystick, or 0 if unavailable.
  707. *
  708. * \since This function is available since SDL 3.0.0.
  709. *
  710. * \sa SDL_GetJoystickProductForID
  711. */
  712. extern SDL_DECLSPEC Uint16 SDLCALL SDL_GetJoystickProduct(SDL_Joystick *joystick);
  713. /**
  714. * Get the product version of an opened joystick, if available.
  715. *
  716. * If the product version isn't available this function returns 0.
  717. *
  718. * \param joystick the SDL_Joystick obtained from SDL_OpenJoystick().
  719. * \returns the product version of the selected joystick, or 0 if unavailable.
  720. *
  721. * \since This function is available since SDL 3.0.0.
  722. *
  723. * \sa SDL_GetJoystickProductVersionForID
  724. */
  725. extern SDL_DECLSPEC Uint16 SDLCALL SDL_GetJoystickProductVersion(SDL_Joystick *joystick);
  726. /**
  727. * Get the firmware version of an opened joystick, if available.
  728. *
  729. * If the firmware version isn't available this function returns 0.
  730. *
  731. * \param joystick the SDL_Joystick obtained from SDL_OpenJoystick().
  732. * \returns the firmware version of the selected joystick, or 0 if
  733. * unavailable.
  734. *
  735. * \since This function is available since SDL 3.0.0.
  736. */
  737. extern SDL_DECLSPEC Uint16 SDLCALL SDL_GetJoystickFirmwareVersion(SDL_Joystick *joystick);
  738. /**
  739. * Get the serial number of an opened joystick, if available.
  740. *
  741. * Returns the serial number of the joystick, or NULL if it is not available.
  742. *
  743. * This returns temporary memory which will be automatically freed later, and
  744. * can be claimed with SDL_ClaimTemporaryMemory().
  745. *
  746. * \param joystick the SDL_Joystick obtained from SDL_OpenJoystick().
  747. * \returns the serial number of the selected joystick, or NULL if
  748. * unavailable.
  749. *
  750. * \since This function is available since SDL 3.0.0.
  751. */
  752. extern SDL_DECLSPEC const char * SDLCALL SDL_GetJoystickSerial(SDL_Joystick *joystick);
  753. /**
  754. * Get the type of an opened joystick.
  755. *
  756. * \param joystick the SDL_Joystick obtained from SDL_OpenJoystick().
  757. * \returns the SDL_JoystickType of the selected joystick.
  758. *
  759. * \since This function is available since SDL 3.0.0.
  760. *
  761. * \sa SDL_GetJoystickTypeForID
  762. */
  763. extern SDL_DECLSPEC SDL_JoystickType SDLCALL SDL_GetJoystickType(SDL_Joystick *joystick);
  764. extern SDL_DECLSPEC SDL_GUID SDLCALL SDL_GUIDFromString(const char *pchGUID);
  765. /**
  766. * Get the device information encoded in a SDL_GUID structure.
  767. *
  768. * \param guid the SDL_GUID you wish to get info about.
  769. * \param vendor a pointer filled in with the device VID, or 0 if not
  770. * available.
  771. * \param product a pointer filled in with the device PID, or 0 if not
  772. * available.
  773. * \param version a pointer filled in with the device version, or 0 if not
  774. * available.
  775. * \param crc16 a pointer filled in with a CRC used to distinguish different
  776. * products with the same VID/PID, or 0 if not available.
  777. *
  778. * \since This function is available since SDL 3.0.0.
  779. *
  780. * \sa SDL_GetJoystickGUIDForID
  781. */
  782. extern SDL_DECLSPEC void SDLCALL SDL_GetJoystickGUIDInfo(SDL_GUID guid, Uint16 *vendor, Uint16 *product, Uint16 *version, Uint16 *crc16);
  783. /**
  784. * Get the status of a specified joystick.
  785. *
  786. * \param joystick the joystick to query.
  787. * \returns SDL_TRUE if the joystick has been opened, SDL_FALSE if it has not;
  788. * call SDL_GetError() for more information.
  789. *
  790. * \since This function is available since SDL 3.0.0.
  791. */
  792. extern SDL_DECLSPEC SDL_bool SDLCALL SDL_JoystickConnected(SDL_Joystick *joystick);
  793. /**
  794. * Get the instance ID of an opened joystick.
  795. *
  796. * \param joystick an SDL_Joystick structure containing joystick information.
  797. * \returns the instance ID of the specified joystick on success or 0 on
  798. * failure; call SDL_GetError() for more information.
  799. *
  800. * \since This function is available since SDL 3.0.0.
  801. */
  802. extern SDL_DECLSPEC SDL_JoystickID SDLCALL SDL_GetJoystickID(SDL_Joystick *joystick);
  803. /**
  804. * Get the number of general axis controls on a joystick.
  805. *
  806. * Often, the directional pad on a game controller will either look like 4
  807. * separate buttons or a POV hat, and not axes, but all of this is up to the
  808. * device and platform.
  809. *
  810. * \param joystick an SDL_Joystick structure containing joystick information.
  811. * \returns the number of axis controls/number of axes on success or a
  812. * negative error code on failure; call SDL_GetError() for more
  813. * information.
  814. *
  815. * \since This function is available since SDL 3.0.0.
  816. *
  817. * \sa SDL_GetJoystickAxis
  818. * \sa SDL_GetNumJoystickBalls
  819. * \sa SDL_GetNumJoystickButtons
  820. * \sa SDL_GetNumJoystickHats
  821. */
  822. extern SDL_DECLSPEC int SDLCALL SDL_GetNumJoystickAxes(SDL_Joystick *joystick);
  823. /**
  824. * Get the number of trackballs on a joystick.
  825. *
  826. * Joystick trackballs have only relative motion events associated with them
  827. * and their state cannot be polled.
  828. *
  829. * Most joysticks do not have trackballs.
  830. *
  831. * \param joystick an SDL_Joystick structure containing joystick information.
  832. * \returns the number of trackballs on success or a negative error code on
  833. * failure; call SDL_GetError() for more information.
  834. *
  835. * \since This function is available since SDL 3.0.0.
  836. *
  837. * \sa SDL_GetJoystickBall
  838. * \sa SDL_GetNumJoystickAxes
  839. * \sa SDL_GetNumJoystickButtons
  840. * \sa SDL_GetNumJoystickHats
  841. */
  842. extern SDL_DECLSPEC int SDLCALL SDL_GetNumJoystickBalls(SDL_Joystick *joystick);
  843. /**
  844. * Get the number of POV hats on a joystick.
  845. *
  846. * \param joystick an SDL_Joystick structure containing joystick information.
  847. * \returns the number of POV hats on success or a negative error code on
  848. * failure; call SDL_GetError() for more information.
  849. *
  850. * \since This function is available since SDL 3.0.0.
  851. *
  852. * \sa SDL_GetJoystickHat
  853. * \sa SDL_GetNumJoystickAxes
  854. * \sa SDL_GetNumJoystickBalls
  855. * \sa SDL_GetNumJoystickButtons
  856. */
  857. extern SDL_DECLSPEC int SDLCALL SDL_GetNumJoystickHats(SDL_Joystick *joystick);
  858. /**
  859. * Get the number of buttons on a joystick.
  860. *
  861. * \param joystick an SDL_Joystick structure containing joystick information.
  862. * \returns the number of buttons on success or a negative error code on
  863. * failure; call SDL_GetError() for more information.
  864. *
  865. * \since This function is available since SDL 3.0.0.
  866. *
  867. * \sa SDL_GetJoystickButton
  868. * \sa SDL_GetNumJoystickAxes
  869. * \sa SDL_GetNumJoystickBalls
  870. * \sa SDL_GetNumJoystickHats
  871. */
  872. extern SDL_DECLSPEC int SDLCALL SDL_GetNumJoystickButtons(SDL_Joystick *joystick);
  873. /**
  874. * Set the state of joystick event processing.
  875. *
  876. * If joystick events are disabled, you must call SDL_UpdateJoysticks()
  877. * yourself and check the state of the joystick when you want joystick
  878. * information.
  879. *
  880. * \param enabled whether to process joystick events or not.
  881. *
  882. * \since This function is available since SDL 3.0.0.
  883. *
  884. * \sa SDL_JoystickEventsEnabled
  885. * \sa SDL_UpdateJoysticks
  886. */
  887. extern SDL_DECLSPEC void SDLCALL SDL_SetJoystickEventsEnabled(SDL_bool enabled);
  888. /**
  889. * Query the state of joystick event processing.
  890. *
  891. * If joystick events are disabled, you must call SDL_UpdateJoysticks()
  892. * yourself and check the state of the joystick when you want joystick
  893. * information.
  894. *
  895. * \returns SDL_TRUE if joystick events are being processed, SDL_FALSE
  896. * otherwise.
  897. *
  898. * \since This function is available since SDL 3.0.0.
  899. *
  900. * \sa SDL_SetJoystickEventsEnabled
  901. */
  902. extern SDL_DECLSPEC SDL_bool SDLCALL SDL_JoystickEventsEnabled(void);
  903. /**
  904. * Update the current state of the open joysticks.
  905. *
  906. * This is called automatically by the event loop if any joystick events are
  907. * enabled.
  908. *
  909. * \since This function is available since SDL 3.0.0.
  910. */
  911. extern SDL_DECLSPEC void SDLCALL SDL_UpdateJoysticks(void);
  912. /**
  913. * Get the current state of an axis control on a joystick.
  914. *
  915. * SDL makes no promises about what part of the joystick any given axis refers
  916. * to. Your game should have some sort of configuration UI to let users
  917. * specify what each axis should be bound to. Alternately, SDL's higher-level
  918. * Game Controller API makes a great effort to apply order to this lower-level
  919. * interface, so you know that a specific axis is the "left thumb stick," etc.
  920. *
  921. * The value returned by SDL_GetJoystickAxis() is a signed integer (-32768 to
  922. * 32767) representing the current position of the axis. It may be necessary
  923. * to impose certain tolerances on these values to account for jitter.
  924. *
  925. * \param joystick an SDL_Joystick structure containing joystick information.
  926. * \param axis the axis to query; the axis indices start at index 0.
  927. * \returns a 16-bit signed integer representing the current position of the
  928. * axis or 0 on failure; call SDL_GetError() for more information.
  929. *
  930. * \since This function is available since SDL 3.0.0.
  931. *
  932. * \sa SDL_GetNumJoystickAxes
  933. */
  934. extern SDL_DECLSPEC Sint16 SDLCALL SDL_GetJoystickAxis(SDL_Joystick *joystick, int axis);
  935. /**
  936. * Get the initial state of an axis control on a joystick.
  937. *
  938. * The state is a value ranging from -32768 to 32767.
  939. *
  940. * The axis indices start at index 0.
  941. *
  942. * \param joystick an SDL_Joystick structure containing joystick information.
  943. * \param axis the axis to query; the axis indices start at index 0.
  944. * \param state upon return, the initial value is supplied here.
  945. * \returns SDL_TRUE if this axis has any initial value, or SDL_FALSE if not.
  946. *
  947. * \since This function is available since SDL 3.0.0.
  948. */
  949. extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetJoystickAxisInitialState(SDL_Joystick *joystick, int axis, Sint16 *state);
  950. /**
  951. * Get the ball axis change since the last poll.
  952. *
  953. * Trackballs can only return relative motion since the last call to
  954. * SDL_GetJoystickBall(), these motion deltas are placed into `dx` and `dy`.
  955. *
  956. * Most joysticks do not have trackballs.
  957. *
  958. * \param joystick the SDL_Joystick to query.
  959. * \param ball the ball index to query; ball indices start at index 0.
  960. * \param dx stores the difference in the x axis position since the last poll.
  961. * \param dy stores the difference in the y axis position since the last poll.
  962. * \returns 0 on success or a negative error code on failure; call
  963. * SDL_GetError() for more information.
  964. *
  965. * \since This function is available since SDL 3.0.0.
  966. *
  967. * \sa SDL_GetNumJoystickBalls
  968. */
  969. extern SDL_DECLSPEC int SDLCALL SDL_GetJoystickBall(SDL_Joystick *joystick, int ball, int *dx, int *dy);
  970. /**
  971. * Get the current state of a POV hat on a joystick.
  972. *
  973. * The returned value will be one of the `SDL_HAT_*` values.
  974. *
  975. * \param joystick an SDL_Joystick structure containing joystick information.
  976. * \param hat the hat index to get the state from; indices start at index 0.
  977. * \returns the current hat position.
  978. *
  979. * \since This function is available since SDL 3.0.0.
  980. *
  981. * \sa SDL_GetNumJoystickHats
  982. */
  983. extern SDL_DECLSPEC Uint8 SDLCALL SDL_GetJoystickHat(SDL_Joystick *joystick, int hat);
  984. #define SDL_HAT_CENTERED 0x00u
  985. #define SDL_HAT_UP 0x01u
  986. #define SDL_HAT_RIGHT 0x02u
  987. #define SDL_HAT_DOWN 0x04u
  988. #define SDL_HAT_LEFT 0x08u
  989. #define SDL_HAT_RIGHTUP (SDL_HAT_RIGHT|SDL_HAT_UP)
  990. #define SDL_HAT_RIGHTDOWN (SDL_HAT_RIGHT|SDL_HAT_DOWN)
  991. #define SDL_HAT_LEFTUP (SDL_HAT_LEFT|SDL_HAT_UP)
  992. #define SDL_HAT_LEFTDOWN (SDL_HAT_LEFT|SDL_HAT_DOWN)
  993. /**
  994. * Get the current state of a button on a joystick.
  995. *
  996. * \param joystick an SDL_Joystick structure containing joystick information.
  997. * \param button the button index to get the state from; indices start at
  998. * index 0.
  999. * \returns 1 if the specified button is pressed, 0 otherwise.
  1000. *
  1001. * \since This function is available since SDL 3.0.0.
  1002. *
  1003. * \sa SDL_GetNumJoystickButtons
  1004. */
  1005. extern SDL_DECLSPEC Uint8 SDLCALL SDL_GetJoystickButton(SDL_Joystick *joystick, int button);
  1006. /**
  1007. * Start a rumble effect.
  1008. *
  1009. * Each call to this function cancels any previous rumble effect, and calling
  1010. * it with 0 intensity stops any rumbling.
  1011. *
  1012. * This function requires you to process SDL events or call
  1013. * SDL_UpdateJoysticks() to update rumble state.
  1014. *
  1015. * \param joystick the joystick to vibrate.
  1016. * \param low_frequency_rumble the intensity of the low frequency (left)
  1017. * rumble motor, from 0 to 0xFFFF.
  1018. * \param high_frequency_rumble the intensity of the high frequency (right)
  1019. * rumble motor, from 0 to 0xFFFF.
  1020. * \param duration_ms the duration of the rumble effect, in milliseconds.
  1021. * \returns 0, or -1 if rumble isn't supported on this joystick.
  1022. *
  1023. * \since This function is available since SDL 3.0.0.
  1024. */
  1025. extern SDL_DECLSPEC int SDLCALL SDL_RumbleJoystick(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble, Uint32 duration_ms);
  1026. /**
  1027. * Start a rumble effect in the joystick's triggers.
  1028. *
  1029. * Each call to this function cancels any previous trigger rumble effect, and
  1030. * calling it with 0 intensity stops any rumbling.
  1031. *
  1032. * Note that this is rumbling of the _triggers_ and not the game controller as
  1033. * a whole. This is currently only supported on Xbox One controllers. If you
  1034. * want the (more common) whole-controller rumble, use SDL_RumbleJoystick()
  1035. * instead.
  1036. *
  1037. * This function requires you to process SDL events or call
  1038. * SDL_UpdateJoysticks() to update rumble state.
  1039. *
  1040. * \param joystick the joystick to vibrate.
  1041. * \param left_rumble the intensity of the left trigger rumble motor, from 0
  1042. * to 0xFFFF.
  1043. * \param right_rumble the intensity of the right trigger rumble motor, from 0
  1044. * to 0xFFFF.
  1045. * \param duration_ms the duration of the rumble effect, in milliseconds.
  1046. * \returns 0 on success or a negative error code on failure; call
  1047. * SDL_GetError() for more information.
  1048. *
  1049. * \since This function is available since SDL 3.0.0.
  1050. *
  1051. * \sa SDL_RumbleJoystick
  1052. */
  1053. extern SDL_DECLSPEC int SDLCALL SDL_RumbleJoystickTriggers(SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble, Uint32 duration_ms);
  1054. /**
  1055. * Update a joystick's LED color.
  1056. *
  1057. * An example of a joystick LED is the light on the back of a PlayStation 4's
  1058. * DualShock 4 controller.
  1059. *
  1060. * For joysticks with a single color LED, the maximum of the RGB values will
  1061. * be used as the LED brightness.
  1062. *
  1063. * \param joystick the joystick to update.
  1064. * \param red the intensity of the red LED.
  1065. * \param green the intensity of the green LED.
  1066. * \param blue the intensity of the blue LED.
  1067. * \returns 0 on success or a negative error code on failure; call
  1068. * SDL_GetError() for more information.
  1069. *
  1070. * \since This function is available since SDL 3.0.0.
  1071. */
  1072. extern SDL_DECLSPEC int SDLCALL SDL_SetJoystickLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue);
  1073. /**
  1074. * Send a joystick specific effect packet.
  1075. *
  1076. * \param joystick the joystick to affect.
  1077. * \param data the data to send to the joystick.
  1078. * \param size the size of the data to send to the joystick.
  1079. * \returns 0 on success or a negative error code on failure; call
  1080. * SDL_GetError() for more information.
  1081. *
  1082. * \since This function is available since SDL 3.0.0.
  1083. */
  1084. extern SDL_DECLSPEC int SDLCALL SDL_SendJoystickEffect(SDL_Joystick *joystick, const void *data, int size);
  1085. /**
  1086. * Close a joystick previously opened with SDL_OpenJoystick().
  1087. *
  1088. * \param joystick the joystick device to close.
  1089. *
  1090. * \since This function is available since SDL 3.0.0.
  1091. *
  1092. * \sa SDL_OpenJoystick
  1093. */
  1094. extern SDL_DECLSPEC void SDLCALL SDL_CloseJoystick(SDL_Joystick *joystick);
  1095. /**
  1096. * Get the connection state of a joystick.
  1097. *
  1098. * \param joystick the joystick to query.
  1099. * \returns the connection state on success or
  1100. * `SDL_JOYSTICK_CONNECTION_INVALID` on failure; call SDL_GetError()
  1101. * for more information.
  1102. *
  1103. * \since This function is available since SDL 3.0.0.
  1104. */
  1105. extern SDL_DECLSPEC SDL_JoystickConnectionState SDLCALL SDL_GetJoystickConnectionState(SDL_Joystick *joystick);
  1106. /**
  1107. * Get the battery state of a joystick.
  1108. *
  1109. * You should never take a battery status as absolute truth. Batteries
  1110. * (especially failing batteries) are delicate hardware, and the values
  1111. * reported here are best estimates based on what that hardware reports. It's
  1112. * not uncommon for older batteries to lose stored power much faster than it
  1113. * reports, or completely drain when reporting it has 20 percent left, etc.
  1114. *
  1115. * \param joystick the joystick to query.
  1116. * \param percent a pointer filled in with the percentage of battery life
  1117. * left, between 0 and 100, or NULL to ignore. This will be
  1118. * filled in with -1 we can't determine a value or there is no
  1119. * battery.
  1120. * \returns the current battery state or `SDL_POWERSTATE_ERROR` on failure;
  1121. * call SDL_GetError() for more information.
  1122. *
  1123. * \since This function is available since SDL 3.0.0.
  1124. */
  1125. extern SDL_DECLSPEC SDL_PowerState SDLCALL SDL_GetJoystickPowerInfo(SDL_Joystick *joystick, int *percent);
  1126. /* Ends C function definitions when using C++ */
  1127. #ifdef __cplusplus
  1128. }
  1129. #endif
  1130. #include <SDL3/SDL_close_code.h>
  1131. #endif /* SDL_joystick_h_ */