SDL_joystick.h 45 KB

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