SDL_joystick.h 44 KB

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