SDL_joystick.h 35 KB

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