SDL_joystick.h 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2023 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. * \brief 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_begin_code.h>
  40. /* Set up for C function definitions, even when using C++ */
  41. #ifdef __cplusplus
  42. extern "C" {
  43. #endif
  44. /**
  45. * \file SDL_joystick.h
  46. *
  47. * In order to use these functions, SDL_Init() must have been called
  48. * with the ::SDL_INIT_JOYSTICK flag. This causes SDL to scan the system
  49. * for joysticks, and load appropriate drivers.
  50. *
  51. * If you would like to receive joystick updates while the application
  52. * is in the background, you should set the following hint before calling
  53. * SDL_Init(): SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS
  54. */
  55. /**
  56. * The joystick structure used to identify an SDL joystick
  57. */
  58. #ifdef SDL_THREAD_SAFETY_ANALYSIS
  59. extern SDL_mutex *SDL_joystick_lock;
  60. #endif
  61. struct SDL_Joystick;
  62. typedef struct SDL_Joystick SDL_Joystick;
  63. /* A structure that encodes the stable unique id for a joystick device */
  64. typedef SDL_GUID SDL_JoystickGUID;
  65. /**
  66. * This is a unique ID for a joystick for the time it is connected to the system,
  67. * and is never reused for the lifetime of the application. If the joystick is
  68. * disconnected and reconnected, it will get a new ID.
  69. *
  70. * The ID value starts at 1 and increments from there. The value 0 is an invalid ID.
  71. */
  72. typedef Uint32 SDL_JoystickID;
  73. typedef enum
  74. {
  75. SDL_JOYSTICK_TYPE_UNKNOWN,
  76. SDL_JOYSTICK_TYPE_GAMEPAD,
  77. SDL_JOYSTICK_TYPE_WHEEL,
  78. SDL_JOYSTICK_TYPE_ARCADE_STICK,
  79. SDL_JOYSTICK_TYPE_FLIGHT_STICK,
  80. SDL_JOYSTICK_TYPE_DANCE_PAD,
  81. SDL_JOYSTICK_TYPE_GUITAR,
  82. SDL_JOYSTICK_TYPE_DRUM_KIT,
  83. SDL_JOYSTICK_TYPE_ARCADE_PAD,
  84. SDL_JOYSTICK_TYPE_THROTTLE
  85. } SDL_JoystickType;
  86. typedef enum
  87. {
  88. SDL_JOYSTICK_POWER_UNKNOWN = -1,
  89. SDL_JOYSTICK_POWER_EMPTY, /* <= 5% */
  90. SDL_JOYSTICK_POWER_LOW, /* <= 20% */
  91. SDL_JOYSTICK_POWER_MEDIUM, /* <= 70% */
  92. SDL_JOYSTICK_POWER_FULL, /* <= 100% */
  93. SDL_JOYSTICK_POWER_WIRED,
  94. SDL_JOYSTICK_POWER_MAX
  95. } SDL_JoystickPowerLevel;
  96. #define SDL_JOYSTICK_AXIS_MAX 32767
  97. #define SDL_JOYSTICK_AXIS_MIN -32768
  98. /* Set max recognized G-force from accelerometer
  99. See src/joystick/uikit/SDL_sysjoystick.m for notes on why this is needed
  100. */
  101. #define SDL_IPHONE_MAX_GFORCE 5.0
  102. /* Function prototypes */
  103. /**
  104. * Locking for atomic access to the joystick API
  105. *
  106. * The SDL joystick functions are thread-safe, however you can lock the
  107. * joysticks while processing to guarantee that the joystick list won't change
  108. * and joystick and gamepad events will not be delivered.
  109. *
  110. * \since This function is available since SDL 3.0.0.
  111. */
  112. extern DECLSPEC void SDLCALL SDL_LockJoysticks(void) SDL_ACQUIRE(SDL_joystick_lock);
  113. /**
  114. * Unlocking for atomic access to the joystick API
  115. *
  116. * \since This function is available since SDL 3.0.0.
  117. */
  118. extern DECLSPEC void SDLCALL SDL_UnlockJoysticks(void) SDL_RELEASE(SDL_joystick_lock);
  119. /**
  120. * Get a list of currently connected joysticks.
  121. *
  122. * \param count a pointer filled in with the number of joysticks returned
  123. * \returns a 0 terminated array of joystick instance IDs which should be
  124. * freed with SDL_free(), or NULL on error; call SDL_GetError() for
  125. * more details.
  126. *
  127. * \since This function is available since SDL 3.0.0.
  128. *
  129. * \sa SDL_OpenJoystick
  130. */
  131. extern DECLSPEC SDL_JoystickID *SDLCALL SDL_GetJoysticks(int *count);
  132. /**
  133. * Get the implementation dependent name of a joystick.
  134. *
  135. * This can be called before any joysticks are opened.
  136. *
  137. * \param instance_id the joystick instance ID
  138. * \returns the name of the selected joystick. If no name can be found, this
  139. * function returns NULL; call SDL_GetError() for more information.
  140. *
  141. * \since This function is available since SDL 3.0.0.
  142. *
  143. * \sa SDL_GetJoystickName
  144. * \sa SDL_OpenJoystick
  145. */
  146. extern DECLSPEC const char *SDLCALL SDL_GetJoystickInstanceName(SDL_JoystickID instance_id);
  147. /**
  148. * Get the implementation dependent path of a joystick.
  149. *
  150. * This can be called before any joysticks are opened.
  151. *
  152. * \param instance_id the joystick instance ID
  153. * \returns the path of the selected joystick. If no path can be found, this
  154. * function returns NULL; call SDL_GetError() for more information.
  155. *
  156. * \since This function is available since SDL 3.0.0.
  157. *
  158. * \sa SDL_GetJoystickPath
  159. * \sa SDL_OpenJoystick
  160. */
  161. extern DECLSPEC const char *SDLCALL SDL_GetJoystickInstancePath(SDL_JoystickID instance_id);
  162. /**
  163. * Get the player index of a joystick.
  164. *
  165. * This can be called before any joysticks are opened.
  166. *
  167. * \param instance_id the joystick instance ID
  168. * \returns the player index of a joystick, or -1 if it's not available
  169. *
  170. * \since This function is available since SDL 3.0.0.
  171. *
  172. * \sa SDL_GetJoystickPlayerIndex
  173. * \sa SDL_OpenJoystick
  174. */
  175. extern DECLSPEC int SDLCALL SDL_GetJoystickInstancePlayerIndex(SDL_JoystickID instance_id);
  176. /**
  177. * Get the implementation-dependent GUID of a joystick.
  178. *
  179. * This can be called before any joysticks are opened.
  180. *
  181. * \param instance_id the joystick instance ID
  182. * \returns the GUID of the selected joystick. If called on an invalid index,
  183. * this function returns a zero GUID
  184. *
  185. * \since This function is available since SDL 3.0.0.
  186. *
  187. * \sa SDL_GetJoystickGUID
  188. * \sa SDL_GetJoystickGUIDString
  189. */
  190. extern DECLSPEC SDL_JoystickGUID SDLCALL SDL_GetJoystickInstanceGUID(SDL_JoystickID instance_id);
  191. /**
  192. * Get the USB vendor ID of a joystick, if available.
  193. *
  194. * This can be called before any joysticks are opened. If the vendor ID isn't
  195. * available this function returns 0.
  196. *
  197. * \param instance_id the joystick instance ID
  198. * \returns the USB vendor ID of the selected joystick. If called on an
  199. * invalid index, this function returns zero
  200. *
  201. * \since This function is available since SDL 3.0.0.
  202. */
  203. extern DECLSPEC Uint16 SDLCALL SDL_GetJoystickInstanceVendor(SDL_JoystickID instance_id);
  204. /**
  205. * Get the USB product ID of a joystick, if available.
  206. *
  207. * This can be called before any joysticks are opened. If the product ID isn't
  208. * available this function returns 0.
  209. *
  210. * \param instance_id the joystick instance ID
  211. * \returns the USB product ID of the selected joystick. If called on an
  212. * invalid index, this function returns zero
  213. *
  214. * \since This function is available since SDL 3.0.0.
  215. */
  216. extern DECLSPEC Uint16 SDLCALL SDL_GetJoystickInstanceProduct(SDL_JoystickID instance_id);
  217. /**
  218. * Get the product version of a joystick, if available.
  219. *
  220. * This can be called before any joysticks are opened. If the product version
  221. * isn't available this function returns 0.
  222. *
  223. * \param instance_id the joystick instance ID
  224. * \returns the product version of the selected joystick. If called on an
  225. * invalid index, this function returns zero
  226. *
  227. * \since This function is available since SDL 3.0.0.
  228. */
  229. extern DECLSPEC Uint16 SDLCALL SDL_GetJoystickInstanceProductVersion(SDL_JoystickID instance_id);
  230. /**
  231. * Get the type of a joystick, if available.
  232. *
  233. * This can be called before any joysticks are opened.
  234. *
  235. * \param instance_id the joystick instance ID
  236. * \returns the SDL_JoystickType of the selected joystick. If called on an
  237. * invalid index, this function returns `SDL_JOYSTICK_TYPE_UNKNOWN`
  238. *
  239. * \since This function is available since SDL 3.0.0.
  240. */
  241. extern DECLSPEC SDL_JoystickType SDLCALL SDL_GetJoystickInstanceType(SDL_JoystickID instance_id);
  242. /**
  243. * Open a joystick for use.
  244. *
  245. * The joystick subsystem must be initialized before a joystick can be opened
  246. * for use.
  247. *
  248. * \param instance_id the joystick instance ID
  249. * \returns a joystick identifier or NULL if an error occurred; call
  250. * SDL_GetError() for more information.
  251. *
  252. * \since This function is available since SDL 3.0.0.
  253. *
  254. * \sa SDL_CloseJoystick
  255. */
  256. extern DECLSPEC SDL_Joystick *SDLCALL SDL_OpenJoystick(SDL_JoystickID instance_id);
  257. /**
  258. * Get the SDL_Joystick associated with an instance ID, if it has been opened.
  259. *
  260. * \param instance_id the instance ID to get the SDL_Joystick for
  261. * \returns an SDL_Joystick on success or NULL on failure or if it hasn't been
  262. * opened yet; call SDL_GetError() for more information.
  263. *
  264. * \since This function is available since SDL 3.0.0.
  265. */
  266. extern DECLSPEC SDL_Joystick *SDLCALL SDL_GetJoystickFromInstanceID(SDL_JoystickID instance_id);
  267. /**
  268. * Get the SDL_Joystick associated with a player index.
  269. *
  270. * \param player_index the player index to get the SDL_Joystick for
  271. * \returns an SDL_Joystick on success or NULL on failure; call SDL_GetError()
  272. * for more information.
  273. *
  274. * \since This function is available since SDL 3.0.0.
  275. */
  276. extern DECLSPEC SDL_Joystick *SDLCALL SDL_GetJoystickFromPlayerIndex(int player_index);
  277. /**
  278. * Attach a new virtual joystick.
  279. *
  280. * \param type type of joystick
  281. * \param naxes number of axes
  282. * \param nbuttons number of buttons
  283. * \param nhats number of hats
  284. * \returns the joystick instance ID, or 0 if an error occurred; call
  285. * SDL_GetError() for more information.
  286. *
  287. * \since This function is available since SDL 3.0.0.
  288. */
  289. extern DECLSPEC SDL_JoystickID SDLCALL SDL_AttachVirtualJoystick(SDL_JoystickType type,
  290. int naxes,
  291. int nbuttons,
  292. int nhats);
  293. /**
  294. * The structure that defines an extended virtual joystick description
  295. *
  296. * The caller must zero the structure and then initialize the version with `SDL_VIRTUAL_JOYSTICK_DESC_VERSION` before passing it to SDL_AttachVirtualJoystickEx()
  297. * All other elements of this structure are optional and can be left 0.
  298. *
  299. * \sa SDL_AttachVirtualJoystickEx
  300. */
  301. typedef struct SDL_VirtualJoystickDesc
  302. {
  303. Uint16 version; /**< `SDL_VIRTUAL_JOYSTICK_DESC_VERSION` */
  304. Uint16 type; /**< `SDL_JoystickType` */
  305. Uint16 naxes; /**< the number of axes on this joystick */
  306. Uint16 nbuttons; /**< the number of buttons on this joystick */
  307. Uint16 nhats; /**< the number of hats on this joystick */
  308. Uint16 vendor_id; /**< the USB vendor ID of this joystick */
  309. Uint16 product_id; /**< the USB product ID of this joystick */
  310. Uint16 padding; /**< unused */
  311. Uint32 button_mask; /**< A mask of which buttons are valid for this controller
  312. e.g. (1 << SDL_GAMEPAD_BUTTON_A) */
  313. Uint32 axis_mask; /**< A mask of which axes are valid for this controller
  314. e.g. (1 << SDL_GAMEPAD_AXIS_LEFTX) */
  315. const char *name; /**< the name of the joystick */
  316. void *userdata; /**< User data pointer passed to callbacks */
  317. void (SDLCALL *Update)(void *userdata); /**< Called when the joystick state should be updated */
  318. void (SDLCALL *SetPlayerIndex)(void *userdata, int player_index); /**< Called when the player index is set */
  319. int (SDLCALL *Rumble)(void *userdata, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble); /**< Implements SDL_RumbleJoystick() */
  320. int (SDLCALL *RumbleTriggers)(void *userdata, Uint16 left_rumble, Uint16 right_rumble); /**< Implements SDL_RumbleJoystickTriggers() */
  321. int (SDLCALL *SetLED)(void *userdata, Uint8 red, Uint8 green, Uint8 blue); /**< Implements SDL_SetJoystickLED() */
  322. int (SDLCALL *SendEffect)(void *userdata, const void *data, int size); /**< Implements SDL_SendJoystickEffect() */
  323. } SDL_VirtualJoystickDesc;
  324. /**
  325. * \brief The current version of the SDL_VirtualJoystickDesc structure
  326. */
  327. #define SDL_VIRTUAL_JOYSTICK_DESC_VERSION 1
  328. /**
  329. * Attach a new virtual joystick with extended properties.
  330. *
  331. * \param desc Joystick description
  332. * \returns the joystick instance ID, or 0 if an error occurred; call
  333. * SDL_GetError() for more information.
  334. *
  335. * \since This function is available since SDL 3.0.0.
  336. */
  337. extern DECLSPEC SDL_JoystickID SDLCALL SDL_AttachVirtualJoystickEx(const SDL_VirtualJoystickDesc *desc);
  338. /**
  339. * Detach a virtual joystick.
  340. *
  341. * \param instance_id the joystick instance ID, previously returned from
  342. * SDL_AttachVirtualJoystick()
  343. * \returns 0 on success or a negative error code on failure; call
  344. * SDL_GetError() for more information.
  345. *
  346. * \since This function is available since SDL 3.0.0.
  347. */
  348. extern DECLSPEC int SDLCALL SDL_DetachVirtualJoystick(SDL_JoystickID instance_id);
  349. /**
  350. * Query whether or not a joystick is virtual.
  351. *
  352. * \param instance_id the joystick instance ID
  353. * \returns SDL_TRUE if the joystick is virtual, SDL_FALSE otherwise.
  354. *
  355. * \since This function is available since SDL 3.0.0.
  356. */
  357. extern DECLSPEC SDL_bool SDLCALL SDL_IsJoystickVirtual(SDL_JoystickID instance_id);
  358. /**
  359. * Set values on an opened, virtual-joystick's axis.
  360. *
  361. * Please note that values set here will not be applied until the next call to
  362. * SDL_UpdateJoysticks, which can either be called directly, or can be called
  363. * indirectly through various other SDL APIs, including, but not limited to
  364. * the following: SDL_PollEvent, SDL_PumpEvents, SDL_WaitEventTimeout,
  365. * SDL_WaitEvent.
  366. *
  367. * Note that when sending trigger axes, you should scale the value to the full
  368. * range of Sint16. For example, a trigger at rest would have the value of
  369. * `SDL_JOYSTICK_AXIS_MIN`.
  370. *
  371. * \param joystick the virtual joystick on which to set state.
  372. * \param axis the specific axis on the virtual joystick to set.
  373. * \param value the new value for the specified axis.
  374. * \returns 0 on success or a negative error code on failure; call
  375. * SDL_GetError() for more information.
  376. *
  377. * \since This function is available since SDL 3.0.0.
  378. */
  379. extern DECLSPEC int SDLCALL SDL_SetJoystickVirtualAxis(SDL_Joystick *joystick, int axis, Sint16 value);
  380. /**
  381. * Set values on an opened, virtual-joystick's button.
  382. *
  383. * Please note that values set here will not be applied until the next call to
  384. * SDL_UpdateJoysticks, which can either be called directly, or can be called
  385. * indirectly through various other SDL APIs, including, but not limited to
  386. * the following: SDL_PollEvent, SDL_PumpEvents, SDL_WaitEventTimeout,
  387. * SDL_WaitEvent.
  388. *
  389. * \param joystick the virtual joystick on which to set state.
  390. * \param button the specific button on the virtual joystick to set.
  391. * \param value the new value for the specified button.
  392. * \returns 0 on success or a negative error code on failure; call
  393. * SDL_GetError() for more information.
  394. *
  395. * \since This function is available since SDL 3.0.0.
  396. */
  397. extern DECLSPEC int SDLCALL SDL_SetJoystickVirtualButton(SDL_Joystick *joystick, int button, Uint8 value);
  398. /**
  399. * Set values on an opened, virtual-joystick's hat.
  400. *
  401. * Please note that values set here will not be applied until the next call to
  402. * SDL_UpdateJoysticks, which can either be called directly, or can be called
  403. * indirectly through various other SDL APIs, including, but not limited to
  404. * the following: SDL_PollEvent, SDL_PumpEvents, SDL_WaitEventTimeout,
  405. * SDL_WaitEvent.
  406. *
  407. * \param joystick the virtual joystick on which to set state.
  408. * \param hat the specific hat on the virtual joystick to set.
  409. * \param value the new value for the specified hat.
  410. * \returns 0 on success or a negative error code on failure; call
  411. * SDL_GetError() for more information.
  412. *
  413. * \since This function is available since SDL 3.0.0.
  414. */
  415. extern DECLSPEC int SDLCALL SDL_SetJoystickVirtualHat(SDL_Joystick *joystick, int hat, Uint8 value);
  416. /**
  417. * Get the implementation dependent name of a joystick.
  418. *
  419. * \param joystick the SDL_Joystick obtained from SDL_OpenJoystick()
  420. * \returns the name of the selected joystick. If no name can be found, this
  421. * function returns NULL; call SDL_GetError() for more information.
  422. *
  423. * \since This function is available since SDL 3.0.0.
  424. *
  425. * \sa SDL_GetJoystickInstanceName
  426. * \sa SDL_OpenJoystick
  427. */
  428. extern DECLSPEC const char *SDLCALL SDL_GetJoystickName(SDL_Joystick *joystick);
  429. /**
  430. * Get the implementation dependent path of a joystick.
  431. *
  432. * \param joystick the SDL_Joystick obtained from SDL_OpenJoystick()
  433. * \returns the path of the selected joystick. If no path can be found, this
  434. * function returns NULL; call SDL_GetError() for more information.
  435. *
  436. * \since This function is available since SDL 3.0.0.
  437. *
  438. * \sa SDL_GetJoystickInstancePath
  439. */
  440. extern DECLSPEC const char *SDLCALL SDL_GetJoystickPath(SDL_Joystick *joystick);
  441. /**
  442. * Get the player index of an opened joystick.
  443. *
  444. * For XInput controllers this returns the XInput user index. Many joysticks
  445. * will not be able to supply this information.
  446. *
  447. * \param joystick the SDL_Joystick obtained from SDL_OpenJoystick()
  448. * \returns the player index, or -1 if it's not available.
  449. *
  450. * \since This function is available since SDL 3.0.0.
  451. */
  452. extern DECLSPEC int SDLCALL SDL_GetJoystickPlayerIndex(SDL_Joystick *joystick);
  453. /**
  454. * Set the player index of an opened joystick.
  455. *
  456. * \param joystick the SDL_Joystick obtained from SDL_OpenJoystick()
  457. * \param player_index Player index to assign to this joystick, or -1 to clear
  458. * the player index and turn off player LEDs.
  459. * \returns 0 on success or a negative error code on failure; call
  460. * SDL_GetError() for more information.
  461. *
  462. * \since This function is available since SDL 3.0.0.
  463. */
  464. extern DECLSPEC int SDLCALL SDL_SetJoystickPlayerIndex(SDL_Joystick *joystick, int player_index);
  465. /**
  466. * Get the implementation-dependent GUID for the joystick.
  467. *
  468. * This function requires an open joystick.
  469. *
  470. * \param joystick the SDL_Joystick obtained from SDL_OpenJoystick()
  471. * \returns the GUID of the given joystick. If called on an invalid index,
  472. * this function returns a zero GUID; call SDL_GetError() for more
  473. * information.
  474. *
  475. * \since This function is available since SDL 3.0.0.
  476. *
  477. * \sa SDL_GetJoystickInstanceGUID
  478. * \sa SDL_GetJoystickGUIDString
  479. */
  480. extern DECLSPEC SDL_JoystickGUID SDLCALL SDL_GetJoystickGUID(SDL_Joystick *joystick);
  481. /**
  482. * Get the USB vendor ID of an opened joystick, if available.
  483. *
  484. * If the vendor ID isn't available this function returns 0.
  485. *
  486. * \param joystick the SDL_Joystick obtained from SDL_OpenJoystick()
  487. * \returns the USB vendor ID of the selected joystick, or 0 if unavailable.
  488. *
  489. * \since This function is available since SDL 3.0.0.
  490. */
  491. extern DECLSPEC Uint16 SDLCALL SDL_GetJoystickVendor(SDL_Joystick *joystick);
  492. /**
  493. * Get the USB product ID of an opened joystick, if available.
  494. *
  495. * If the product ID isn't available this function returns 0.
  496. *
  497. * \param joystick the SDL_Joystick obtained from SDL_OpenJoystick()
  498. * \returns the USB product ID of the selected joystick, or 0 if unavailable.
  499. *
  500. * \since This function is available since SDL 3.0.0.
  501. */
  502. extern DECLSPEC Uint16 SDLCALL SDL_GetJoystickProduct(SDL_Joystick *joystick);
  503. /**
  504. * Get the product version of an opened joystick, if available.
  505. *
  506. * If the product version isn't available this function returns 0.
  507. *
  508. * \param joystick the SDL_Joystick obtained from SDL_OpenJoystick()
  509. * \returns the product version of the selected joystick, or 0 if unavailable.
  510. *
  511. * \since This function is available since SDL 3.0.0.
  512. */
  513. extern DECLSPEC Uint16 SDLCALL SDL_GetJoystickProductVersion(SDL_Joystick *joystick);
  514. /**
  515. * Get the firmware version of an opened joystick, if available.
  516. *
  517. * If the firmware version isn't available this function returns 0.
  518. *
  519. * \param joystick the SDL_Joystick obtained from SDL_OpenJoystick()
  520. * \returns the firmware version of the selected joystick, or 0 if
  521. * unavailable.
  522. *
  523. * \since This function is available since SDL 3.0.0.
  524. */
  525. extern DECLSPEC Uint16 SDLCALL SDL_GetJoystickFirmwareVersion(SDL_Joystick *joystick);
  526. /**
  527. * Get the serial number of an opened joystick, if available.
  528. *
  529. * Returns the serial number of the joystick, or NULL if it is not available.
  530. *
  531. * \param joystick the SDL_Joystick obtained from SDL_OpenJoystick()
  532. * \returns the serial number of the selected joystick, or NULL if
  533. * unavailable.
  534. *
  535. * \since This function is available since SDL 3.0.0.
  536. */
  537. extern DECLSPEC const char * SDLCALL SDL_GetJoystickSerial(SDL_Joystick *joystick);
  538. /**
  539. * Get the type of an opened joystick.
  540. *
  541. * \param joystick the SDL_Joystick obtained from SDL_OpenJoystick()
  542. * \returns the SDL_JoystickType of the selected joystick.
  543. *
  544. * \since This function is available since SDL 3.0.0.
  545. */
  546. extern DECLSPEC SDL_JoystickType SDLCALL SDL_GetJoystickType(SDL_Joystick *joystick);
  547. /**
  548. * Get an ASCII string representation for a given SDL_JoystickGUID.
  549. *
  550. * You should supply at least 33 bytes for pszGUID.
  551. *
  552. * \param guid the SDL_JoystickGUID you wish to convert to string
  553. * \param pszGUID buffer in which to write the ASCII string
  554. * \param cbGUID the size of pszGUID
  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_GetJoystickInstanceGUID
  561. * \sa SDL_GetJoystickGUID
  562. * \sa SDL_GetJoystickGUIDFromString
  563. */
  564. extern DECLSPEC int SDLCALL SDL_GetJoystickGUIDString(SDL_JoystickGUID guid, char *pszGUID, int cbGUID);
  565. /**
  566. * Convert a GUID string into a SDL_JoystickGUID structure.
  567. *
  568. * Performs no error checking. If this function is given a string containing
  569. * an invalid GUID, the function will silently succeed, but the GUID generated
  570. * will not be useful.
  571. *
  572. * \param pchGUID string containing an ASCII representation of a GUID
  573. * \returns a SDL_JoystickGUID structure.
  574. *
  575. * \since This function is available since SDL 3.0.0.
  576. *
  577. * \sa SDL_GetJoystickGUIDString
  578. */
  579. extern DECLSPEC SDL_JoystickGUID SDLCALL SDL_GetJoystickGUIDFromString(const char *pchGUID);
  580. /**
  581. * Get the device information encoded in a SDL_JoystickGUID structure
  582. *
  583. * \param guid the SDL_JoystickGUID you wish to get info about
  584. * \param vendor A pointer filled in with the device VID, or 0 if not
  585. * available
  586. * \param product A pointer filled in with the device PID, or 0 if not
  587. * available
  588. * \param version A pointer filled in with the device version, or 0 if not
  589. * available
  590. * \param crc16 A pointer filled in with a CRC used to distinguish different
  591. * products with the same VID/PID, or 0 if not available
  592. *
  593. * \since This function is available since SDL 3.0.0.
  594. *
  595. * \sa SDL_GetJoystickInstanceGUID
  596. */
  597. extern DECLSPEC void SDLCALL SDL_GetJoystickGUIDInfo(SDL_JoystickGUID guid, Uint16 *vendor, Uint16 *product, Uint16 *version, Uint16 *crc16);
  598. /**
  599. * Get the status of a specified joystick.
  600. *
  601. * \param joystick the joystick to query
  602. * \returns SDL_TRUE if the joystick has been opened, SDL_FALSE if it has not;
  603. * call SDL_GetError() for more information.
  604. *
  605. * \since This function is available since SDL 3.0.0.
  606. *
  607. * \sa SDL_CloseJoystick
  608. * \sa SDL_OpenJoystick
  609. */
  610. extern DECLSPEC SDL_bool SDLCALL SDL_JoystickConnected(SDL_Joystick *joystick);
  611. /**
  612. * Get the instance ID of an opened joystick.
  613. *
  614. * \param joystick an SDL_Joystick structure containing joystick information
  615. * \returns the instance ID of the specified joystick on success or 0 on
  616. * failure; call SDL_GetError() for more information.
  617. *
  618. * \since This function is available since SDL 3.0.0.
  619. *
  620. * \sa SDL_OpenJoystick
  621. */
  622. extern DECLSPEC SDL_JoystickID SDLCALL SDL_GetJoystickInstanceID(SDL_Joystick *joystick);
  623. /**
  624. * Get the number of general axis controls on a joystick.
  625. *
  626. * Often, the directional pad on a game controller will either look like 4
  627. * separate buttons or a POV hat, and not axes, but all of this is up to the
  628. * device and platform.
  629. *
  630. * \param joystick an SDL_Joystick structure containing joystick information
  631. * \returns the number of axis controls/number of axes on success or a
  632. * negative error code on failure; call SDL_GetError() for more
  633. * information.
  634. *
  635. * \since This function is available since SDL 3.0.0.
  636. *
  637. * \sa SDL_GetJoystickAxis
  638. * \sa SDL_OpenJoystick
  639. */
  640. extern DECLSPEC int SDLCALL SDL_GetNumJoystickAxes(SDL_Joystick *joystick);
  641. /**
  642. * Get the number of POV hats on a joystick.
  643. *
  644. * \param joystick an SDL_Joystick structure containing joystick information
  645. * \returns the number of POV hats on success or a negative error code on
  646. * failure; call SDL_GetError() for more information.
  647. *
  648. * \since This function is available since SDL 3.0.0.
  649. *
  650. * \sa SDL_GetJoystickHat
  651. * \sa SDL_OpenJoystick
  652. */
  653. extern DECLSPEC int SDLCALL SDL_GetNumJoystickHats(SDL_Joystick *joystick);
  654. /**
  655. * Get the number of buttons on a joystick.
  656. *
  657. * \param joystick an SDL_Joystick structure containing joystick information
  658. * \returns the number of buttons on success or a negative error code on
  659. * failure; call SDL_GetError() for more information.
  660. *
  661. * \since This function is available since SDL 3.0.0.
  662. *
  663. * \sa SDL_GetJoystickButton
  664. * \sa SDL_OpenJoystick
  665. */
  666. extern DECLSPEC int SDLCALL SDL_GetNumJoystickButtons(SDL_Joystick *joystick);
  667. /**
  668. * Set the state of joystick event processing.
  669. *
  670. * If joystick events are disabled, you must call SDL_UpdateJoysticks()
  671. * yourself and check the state of the joystick when you want joystick
  672. * information.
  673. *
  674. * \param enabled whether to process joystick events or not
  675. *
  676. * \since This function is available since SDL 3.0.0.
  677. *
  678. * \sa SDL_JoystickEventsEnabled
  679. */
  680. extern DECLSPEC void SDLCALL SDL_SetJoystickEventsEnabled(SDL_bool enabled);
  681. /**
  682. * Query the state of joystick event processing.
  683. *
  684. * If joystick events are disabled, you must call SDL_UpdateJoysticks()
  685. * yourself and check the state of the joystick when you want joystick
  686. * information.
  687. *
  688. * \returns SDL_TRUE if joystick events are being processed, SDL_FALSE
  689. * otherwise.
  690. *
  691. * \since This function is available since SDL 3.0.0.
  692. *
  693. * \sa SDL_SetJoystickEventsEnabled
  694. */
  695. extern DECLSPEC SDL_bool SDLCALL SDL_JoystickEventsEnabled(void);
  696. /**
  697. * Update the current state of the open joysticks.
  698. *
  699. * This is called automatically by the event loop if any joystick events are
  700. * enabled.
  701. *
  702. * \since This function is available since SDL 3.0.0.
  703. */
  704. extern DECLSPEC void SDLCALL SDL_UpdateJoysticks(void);
  705. /**
  706. * Get the current state of an axis control on a joystick.
  707. *
  708. * SDL makes no promises about what part of the joystick any given axis refers
  709. * to. Your game should have some sort of configuration UI to let users
  710. * specify what each axis should be bound to. Alternately, SDL's higher-level
  711. * Game Controller API makes a great effort to apply order to this lower-level
  712. * interface, so you know that a specific axis is the "left thumb stick," etc.
  713. *
  714. * The value returned by SDL_GetJoystickAxis() is a signed integer (-32768 to
  715. * 32767) representing the current position of the axis. It may be necessary
  716. * to impose certain tolerances on these values to account for jitter.
  717. *
  718. * \param joystick an SDL_Joystick structure containing joystick information
  719. * \param axis the axis to query; the axis indices start at index 0
  720. * \returns a 16-bit signed integer representing the current position of the
  721. * axis or 0 on failure; call SDL_GetError() for more information.
  722. *
  723. * \since This function is available since SDL 3.0.0.
  724. *
  725. * \sa SDL_GetNumJoystickAxes
  726. */
  727. extern DECLSPEC Sint16 SDLCALL SDL_GetJoystickAxis(SDL_Joystick *joystick,
  728. int axis);
  729. /**
  730. * Get the initial state of an axis control on a joystick.
  731. *
  732. * The state is a value ranging from -32768 to 32767.
  733. *
  734. * The axis indices start at index 0.
  735. *
  736. * \param joystick an SDL_Joystick structure containing joystick information
  737. * \param axis the axis to query; the axis indices start at index 0
  738. * \param state Upon return, the initial value is supplied here.
  739. * \returns SDL_TRUE if this axis has any initial value, or SDL_FALSE if not.
  740. *
  741. * \since This function is available since SDL 3.0.0.
  742. */
  743. extern DECLSPEC SDL_bool SDLCALL SDL_GetJoystickAxisInitialState(SDL_Joystick *joystick,
  744. int axis, Sint16 *state);
  745. /**
  746. * \name Hat positions
  747. */
  748. /* @{ */
  749. #define SDL_HAT_CENTERED 0x00
  750. #define SDL_HAT_UP 0x01
  751. #define SDL_HAT_RIGHT 0x02
  752. #define SDL_HAT_DOWN 0x04
  753. #define SDL_HAT_LEFT 0x08
  754. #define SDL_HAT_RIGHTUP (SDL_HAT_RIGHT|SDL_HAT_UP)
  755. #define SDL_HAT_RIGHTDOWN (SDL_HAT_RIGHT|SDL_HAT_DOWN)
  756. #define SDL_HAT_LEFTUP (SDL_HAT_LEFT|SDL_HAT_UP)
  757. #define SDL_HAT_LEFTDOWN (SDL_HAT_LEFT|SDL_HAT_DOWN)
  758. /* @} */
  759. /**
  760. * Get the current state of a POV hat on a joystick.
  761. *
  762. * The returned value will be one of the following positions:
  763. *
  764. * - `SDL_HAT_CENTERED`
  765. * - `SDL_HAT_UP`
  766. * - `SDL_HAT_RIGHT`
  767. * - `SDL_HAT_DOWN`
  768. * - `SDL_HAT_LEFT`
  769. * - `SDL_HAT_RIGHTUP`
  770. * - `SDL_HAT_RIGHTDOWN`
  771. * - `SDL_HAT_LEFTUP`
  772. * - `SDL_HAT_LEFTDOWN`
  773. *
  774. * \param joystick an SDL_Joystick structure containing joystick information
  775. * \param hat the hat index to get the state from; indices start at index 0
  776. * \returns the current hat position.
  777. *
  778. * \since This function is available since SDL 3.0.0.
  779. *
  780. * \sa SDL_GetNumJoystickHats
  781. */
  782. extern DECLSPEC Uint8 SDLCALL SDL_GetJoystickHat(SDL_Joystick *joystick,
  783. int hat);
  784. /**
  785. * Get the current state of a button on a joystick.
  786. *
  787. * \param joystick an SDL_Joystick structure containing joystick information
  788. * \param button the button index to get the state from; indices start at
  789. * index 0
  790. * \returns 1 if the specified button is pressed, 0 otherwise.
  791. *
  792. * \since This function is available since SDL 3.0.0.
  793. *
  794. * \sa SDL_GetNumJoystickButtons
  795. */
  796. extern DECLSPEC Uint8 SDLCALL SDL_GetJoystickButton(SDL_Joystick *joystick,
  797. int button);
  798. /**
  799. * Start a rumble effect.
  800. *
  801. * Each call to this function cancels any previous rumble effect, and calling
  802. * it with 0 intensity stops any rumbling.
  803. *
  804. * \param joystick The joystick to vibrate
  805. * \param low_frequency_rumble The intensity of the low frequency (left)
  806. * rumble motor, from 0 to 0xFFFF
  807. * \param high_frequency_rumble The intensity of the high frequency (right)
  808. * rumble motor, from 0 to 0xFFFF
  809. * \param duration_ms The duration of the rumble effect, in milliseconds
  810. * \returns 0, or -1 if rumble isn't supported on this joystick
  811. *
  812. * \since This function is available since SDL 3.0.0.
  813. *
  814. * \sa SDL_JoystickHasRumble
  815. */
  816. extern DECLSPEC int SDLCALL SDL_RumbleJoystick(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble, Uint32 duration_ms);
  817. /**
  818. * Start a rumble effect in the joystick's triggers
  819. *
  820. * Each call to this function cancels any previous trigger rumble effect, and
  821. * calling it with 0 intensity stops any rumbling.
  822. *
  823. * Note that this is rumbling of the _triggers_ and not the game controller as
  824. * a whole. This is currently only supported on Xbox One controllers. If you
  825. * want the (more common) whole-controller rumble, use SDL_RumbleJoystick()
  826. * instead.
  827. *
  828. * \param joystick The joystick to vibrate
  829. * \param left_rumble The intensity of the left trigger rumble motor, from 0
  830. * to 0xFFFF
  831. * \param right_rumble The intensity of the right trigger rumble motor, from 0
  832. * to 0xFFFF
  833. * \param duration_ms The duration of the rumble effect, in milliseconds
  834. * \returns 0 on success or a negative error code on failure; call
  835. * SDL_GetError() for more information.
  836. *
  837. * \since This function is available since SDL 3.0.0.
  838. *
  839. * \sa SDL_JoystickHasRumbleTriggers
  840. */
  841. extern DECLSPEC int SDLCALL SDL_RumbleJoystickTriggers(SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble, Uint32 duration_ms);
  842. /**
  843. * Query whether a joystick has an LED.
  844. *
  845. * An example of a joystick LED is the light on the back of a PlayStation 4's
  846. * DualShock 4 controller.
  847. *
  848. * \param joystick The joystick to query
  849. * \returns SDL_TRUE if the joystick has a modifiable LED, SDL_FALSE otherwise.
  850. *
  851. * \since This function is available since SDL 3.0.0.
  852. */
  853. extern DECLSPEC SDL_bool SDLCALL SDL_JoystickHasLED(SDL_Joystick *joystick);
  854. /**
  855. * Query whether a joystick has rumble support.
  856. *
  857. * \param joystick The joystick to query
  858. * \returns SDL_TRUE if the joystick has rumble, SDL_FALSE otherwise.
  859. *
  860. * \since This function is available since SDL 3.0.0.
  861. *
  862. * \sa SDL_RumbleJoystick
  863. */
  864. extern DECLSPEC SDL_bool SDLCALL SDL_JoystickHasRumble(SDL_Joystick *joystick);
  865. /**
  866. * Query whether a joystick has rumble support on triggers.
  867. *
  868. * \param joystick The joystick to query
  869. * \returns SDL_TRUE if the joystick has trigger rumble, SDL_FALSE otherwise.
  870. *
  871. * \since This function is available since SDL 3.0.0.
  872. *
  873. * \sa SDL_RumbleJoystickTriggers
  874. */
  875. extern DECLSPEC SDL_bool SDLCALL SDL_JoystickHasRumbleTriggers(SDL_Joystick *joystick);
  876. /**
  877. * Update a joystick's LED color.
  878. *
  879. * An example of a joystick LED is the light on the back of a PlayStation 4's
  880. * DualShock 4 controller.
  881. *
  882. * \param joystick The joystick to update
  883. * \param red The intensity of the red LED
  884. * \param green The intensity of the green LED
  885. * \param blue The intensity of the blue LED
  886. * \returns 0 on success or a negative error code on failure; call
  887. * SDL_GetError() for more information.
  888. *
  889. * \since This function is available since SDL 3.0.0.
  890. */
  891. extern DECLSPEC int SDLCALL SDL_SetJoystickLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue);
  892. /**
  893. * Send a joystick specific effect packet
  894. *
  895. * \param joystick The joystick to affect
  896. * \param data The data to send to the joystick
  897. * \param size The size of the data to send to the joystick
  898. * \returns 0 on success or a negative error code on failure; call
  899. * SDL_GetError() for more information.
  900. *
  901. * \since This function is available since SDL 3.0.0.
  902. */
  903. extern DECLSPEC int SDLCALL SDL_SendJoystickEffect(SDL_Joystick *joystick, const void *data, int size);
  904. /**
  905. * Close a joystick previously opened with SDL_OpenJoystick().
  906. *
  907. * \param joystick The joystick device to close
  908. *
  909. * \since This function is available since SDL 3.0.0.
  910. *
  911. * \sa SDL_OpenJoystick
  912. */
  913. extern DECLSPEC void SDLCALL SDL_CloseJoystick(SDL_Joystick *joystick);
  914. /**
  915. * Get the battery level of a joystick as SDL_JoystickPowerLevel.
  916. *
  917. * \param joystick the SDL_Joystick to query
  918. * \returns the current battery level as SDL_JoystickPowerLevel on success or
  919. * `SDL_JOYSTICK_POWER_UNKNOWN` if it is unknown
  920. *
  921. * \since This function is available since SDL 3.0.0.
  922. */
  923. extern DECLSPEC SDL_JoystickPowerLevel SDLCALL SDL_GetJoystickPowerLevel(SDL_Joystick *joystick);
  924. /* Ends C function definitions when using C++ */
  925. #ifdef __cplusplus
  926. }
  927. #endif
  928. #include <SDL3/SDL_close_code.h>
  929. #endif /* SDL_joystick_h_ */