SDL_joystick.h 40 KB

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