SDL_joystick.h 45 KB

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