SDL_haptic.h 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2025 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. * # CategoryHaptic
  20. *
  21. * The SDL haptic subsystem manages haptic (force feedback) devices.
  22. *
  23. * The basic usage is as follows:
  24. *
  25. * - Initialize the subsystem (SDL_INIT_HAPTIC).
  26. * - Open a haptic device.
  27. * - SDL_OpenHaptic() to open from index.
  28. * - SDL_OpenHapticFromJoystick() to open from an existing joystick.
  29. * - Create an effect (SDL_HapticEffect).
  30. * - Upload the effect with SDL_CreateHapticEffect().
  31. * - Run the effect with SDL_RunHapticEffect().
  32. * - (optional) Free the effect with SDL_DestroyHapticEffect().
  33. * - Close the haptic device with SDL_CloseHaptic().
  34. *
  35. * Simple rumble example:
  36. *
  37. * ```c
  38. * SDL_Haptic *haptic = NULL;
  39. *
  40. * // Open the device
  41. * SDL_HapticID *haptics = SDL_GetHaptics(NULL);
  42. * if (haptics) {
  43. * haptic = SDL_OpenHaptic(haptics[0]);
  44. * SDL_free(haptics);
  45. * }
  46. * if (haptic == NULL)
  47. * return;
  48. *
  49. * // Initialize simple rumble
  50. * if (!SDL_InitHapticRumble(haptic))
  51. * return;
  52. *
  53. * // Play effect at 50% strength for 2 seconds
  54. * if (!SDL_PlayHapticRumble(haptic, 0.5, 2000))
  55. * return;
  56. * SDL_Delay(2000);
  57. *
  58. * // Clean up
  59. * SDL_CloseHaptic(haptic);
  60. * ```
  61. *
  62. * Complete example:
  63. *
  64. * ```c
  65. * bool test_haptic(SDL_Joystick *joystick)
  66. * {
  67. * SDL_Haptic *haptic;
  68. * SDL_HapticEffect effect;
  69. * SDL_HapticEffectID effect_id;
  70. *
  71. * // Open the device
  72. * haptic = SDL_OpenHapticFromJoystick(joystick);
  73. * if (haptic == NULL) return false; // Most likely joystick isn't haptic
  74. *
  75. * // See if it can do sine waves
  76. * if ((SDL_GetHapticFeatures(haptic) & SDL_HAPTIC_SINE)==0) {
  77. * SDL_CloseHaptic(haptic); // No sine effect
  78. * return false;
  79. * }
  80. *
  81. * // Create the effect
  82. * SDL_memset(&effect, 0, sizeof(SDL_HapticEffect)); // 0 is safe default
  83. * effect.type = SDL_HAPTIC_SINE;
  84. * effect.periodic.direction.type = SDL_HAPTIC_POLAR; // Polar coordinates
  85. * effect.periodic.direction.dir[0] = 18000; // Force comes from south
  86. * effect.periodic.period = 1000; // 1000 ms
  87. * effect.periodic.magnitude = 20000; // 20000/32767 strength
  88. * effect.periodic.length = 5000; // 5 seconds long
  89. * effect.periodic.attack_length = 1000; // Takes 1 second to get max strength
  90. * effect.periodic.fade_length = 1000; // Takes 1 second to fade away
  91. *
  92. * // Upload the effect
  93. * effect_id = SDL_CreateHapticEffect(haptic, &effect);
  94. *
  95. * // Test the effect
  96. * SDL_RunHapticEffect(haptic, effect_id, 1);
  97. * SDL_Delay(5000); // Wait for the effect to finish
  98. *
  99. * // We destroy the effect, although closing the device also does this
  100. * SDL_DestroyHapticEffect(haptic, effect_id);
  101. *
  102. * // Close the device
  103. * SDL_CloseHaptic(haptic);
  104. *
  105. * return true; // Success
  106. * }
  107. * ```
  108. *
  109. * Note that the SDL haptic subsystem is not thread-safe.
  110. */
  111. #ifndef SDL_haptic_h_
  112. #define SDL_haptic_h_
  113. #include <SDL3/SDL_stdinc.h>
  114. #include <SDL3/SDL_error.h>
  115. #include <SDL3/SDL_joystick.h>
  116. #include <SDL3/SDL_begin_code.h>
  117. /* Set up for C function definitions, even when using C++ */
  118. #ifdef __cplusplus
  119. extern "C" {
  120. #endif /* __cplusplus */
  121. /* FIXME:
  122. *
  123. * At the moment the magnitude variables are mixed between signed/unsigned, and
  124. * it is also not made clear that ALL of those variables expect a max of 0x7FFF.
  125. *
  126. * Some platforms may have higher precision than that (Linux FF, Windows XInput)
  127. * so we should fix the inconsistency in favor of higher possible precision,
  128. * adjusting for platforms that use different scales.
  129. * -flibit
  130. */
  131. /**
  132. * The haptic structure used to identify an SDL haptic.
  133. *
  134. * \since This struct is available since SDL 3.2.0.
  135. *
  136. * \sa SDL_OpenHaptic
  137. * \sa SDL_OpenHapticFromJoystick
  138. * \sa SDL_CloseHaptic
  139. */
  140. typedef struct SDL_Haptic SDL_Haptic;
  141. /*
  142. * Misc defines.
  143. */
  144. /**
  145. * Used to play a device an infinite number of times.
  146. *
  147. * \since This macro is available since SDL 3.2.0.
  148. *
  149. * \sa SDL_RunHapticEffect
  150. */
  151. #define SDL_HAPTIC_INFINITY 4294967295U
  152. /**
  153. * \name Haptic features
  154. *
  155. * Different haptic features a device can have.
  156. */
  157. /* @{ */
  158. /**
  159. * \name Haptic effects
  160. */
  161. /* @{ */
  162. /**
  163. * Type of haptic effect.
  164. */
  165. typedef Uint16 SDL_HapticEffectType;
  166. /**
  167. * Constant effect supported.
  168. *
  169. * Constant haptic effect.
  170. *
  171. * \since This macro is available since SDL 3.2.0.
  172. *
  173. * \sa SDL_HapticCondition
  174. */
  175. #define SDL_HAPTIC_CONSTANT (1u<<0)
  176. /**
  177. * Sine wave effect supported.
  178. *
  179. * Periodic haptic effect that simulates sine waves.
  180. *
  181. * \since This macro is available since SDL 3.2.0.
  182. *
  183. * \sa SDL_HapticPeriodic
  184. */
  185. #define SDL_HAPTIC_SINE (1u<<1)
  186. /**
  187. * Square wave effect supported.
  188. *
  189. * Periodic haptic effect that simulates square waves.
  190. *
  191. * \since This macro is available since SDL 3.2.0.
  192. *
  193. * \sa SDL_HapticPeriodic
  194. */
  195. #define SDL_HAPTIC_SQUARE (1u<<2)
  196. /**
  197. * Triangle wave effect supported.
  198. *
  199. * Periodic haptic effect that simulates triangular waves.
  200. *
  201. * \since This macro is available since SDL 3.2.0.
  202. *
  203. * \sa SDL_HapticPeriodic
  204. */
  205. #define SDL_HAPTIC_TRIANGLE (1u<<3)
  206. /**
  207. * Sawtoothup wave effect supported.
  208. *
  209. * Periodic haptic effect that simulates saw tooth up waves.
  210. *
  211. * \since This macro is available since SDL 3.2.0.
  212. *
  213. * \sa SDL_HapticPeriodic
  214. */
  215. #define SDL_HAPTIC_SAWTOOTHUP (1u<<4)
  216. /**
  217. * Sawtoothdown wave effect supported.
  218. *
  219. * Periodic haptic effect that simulates saw tooth down waves.
  220. *
  221. * \since This macro is available since SDL 3.2.0.
  222. *
  223. * \sa SDL_HapticPeriodic
  224. */
  225. #define SDL_HAPTIC_SAWTOOTHDOWN (1u<<5)
  226. /**
  227. * Ramp effect supported.
  228. *
  229. * Ramp haptic effect.
  230. *
  231. * \since This macro is available since SDL 3.2.0.
  232. *
  233. * \sa SDL_HapticRamp
  234. */
  235. #define SDL_HAPTIC_RAMP (1u<<6)
  236. /**
  237. * Spring effect supported - uses axes position.
  238. *
  239. * Condition haptic effect that simulates a spring. Effect is based on the
  240. * axes position.
  241. *
  242. * \since This macro is available since SDL 3.2.0.
  243. *
  244. * \sa SDL_HapticCondition
  245. */
  246. #define SDL_HAPTIC_SPRING (1u<<7)
  247. /**
  248. * Damper effect supported - uses axes velocity.
  249. *
  250. * Condition haptic effect that simulates dampening. Effect is based on the
  251. * axes velocity.
  252. *
  253. * \since This macro is available since SDL 3.2.0.
  254. *
  255. * \sa SDL_HapticCondition
  256. */
  257. #define SDL_HAPTIC_DAMPER (1u<<8)
  258. /**
  259. * Inertia effect supported - uses axes acceleration.
  260. *
  261. * Condition haptic effect that simulates inertia. Effect is based on the axes
  262. * acceleration.
  263. *
  264. * \since This macro is available since SDL 3.2.0.
  265. *
  266. * \sa SDL_HapticCondition
  267. */
  268. #define SDL_HAPTIC_INERTIA (1u<<9)
  269. /**
  270. * Friction effect supported - uses axes movement.
  271. *
  272. * Condition haptic effect that simulates friction. Effect is based on the
  273. * axes movement.
  274. *
  275. * \since This macro is available since SDL 3.2.0.
  276. *
  277. * \sa SDL_HapticCondition
  278. */
  279. #define SDL_HAPTIC_FRICTION (1u<<10)
  280. /**
  281. * Left/Right effect supported.
  282. *
  283. * Haptic effect for direct control over high/low frequency motors.
  284. *
  285. * \since This macro is available since SDL 3.2.0.
  286. *
  287. * \sa SDL_HapticLeftRight
  288. */
  289. #define SDL_HAPTIC_LEFTRIGHT (1u<<11)
  290. /**
  291. * Reserved for future use.
  292. *
  293. * \since This macro is available since SDL 3.2.0.
  294. */
  295. #define SDL_HAPTIC_RESERVED1 (1u<<12)
  296. /**
  297. * Reserved for future use.
  298. *
  299. * \since This macro is available since SDL 3.2.0.
  300. */
  301. #define SDL_HAPTIC_RESERVED2 (1u<<13)
  302. /**
  303. * Reserved for future use.
  304. *
  305. * \since This macro is available since SDL 3.2.0.
  306. */
  307. #define SDL_HAPTIC_RESERVED3 (1u<<14)
  308. /**
  309. * Custom effect is supported.
  310. *
  311. * User defined custom haptic effect.
  312. *
  313. * \since This macro is available since SDL 3.2.0.
  314. */
  315. #define SDL_HAPTIC_CUSTOM (1u<<15)
  316. /* @} *//* Haptic effects */
  317. /* These last few are features the device has, not effects */
  318. /**
  319. * Device can set global gain.
  320. *
  321. * Device supports setting the global gain.
  322. *
  323. * \since This macro is available since SDL 3.2.0.
  324. *
  325. * \sa SDL_SetHapticGain
  326. */
  327. #define SDL_HAPTIC_GAIN (1u<<16)
  328. /**
  329. * Device can set autocenter.
  330. *
  331. * Device supports setting autocenter.
  332. *
  333. * \since This macro is available since SDL 3.2.0.
  334. *
  335. * \sa SDL_SetHapticAutocenter
  336. */
  337. #define SDL_HAPTIC_AUTOCENTER (1u<<17)
  338. /**
  339. * Device can be queried for effect status.
  340. *
  341. * Device supports querying effect status.
  342. *
  343. * \since This macro is available since SDL 3.2.0.
  344. *
  345. * \sa SDL_GetHapticEffectStatus
  346. */
  347. #define SDL_HAPTIC_STATUS (1u<<18)
  348. /**
  349. * Device can be paused.
  350. *
  351. * Devices supports being paused.
  352. *
  353. * \since This macro is available since SDL 3.2.0.
  354. *
  355. * \sa SDL_PauseHaptic
  356. * \sa SDL_ResumeHaptic
  357. */
  358. #define SDL_HAPTIC_PAUSE (1u<<19)
  359. /**
  360. * \name Direction encodings
  361. */
  362. /* @{ */
  363. /**
  364. * Type of coordinates used for haptic direction.
  365. */
  366. typedef Uint8 SDL_HapticDirectionType;
  367. /**
  368. * Uses polar coordinates for the direction.
  369. *
  370. * \since This macro is available since SDL 3.2.0.
  371. *
  372. * \sa SDL_HapticDirection
  373. */
  374. #define SDL_HAPTIC_POLAR 0
  375. /**
  376. * Uses cartesian coordinates for the direction.
  377. *
  378. * \since This macro is available since SDL 3.2.0.
  379. *
  380. * \sa SDL_HapticDirection
  381. */
  382. #define SDL_HAPTIC_CARTESIAN 1
  383. /**
  384. * Uses spherical coordinates for the direction.
  385. *
  386. * \since This macro is available since SDL 3.2.0.
  387. *
  388. * \sa SDL_HapticDirection
  389. */
  390. #define SDL_HAPTIC_SPHERICAL 2
  391. /**
  392. * Use this value to play an effect on the steering wheel axis.
  393. *
  394. * This provides better compatibility across platforms and devices as SDL will
  395. * guess the correct axis.
  396. *
  397. * \since This macro is available since SDL 3.2.0.
  398. *
  399. * \sa SDL_HapticDirection
  400. */
  401. #define SDL_HAPTIC_STEERING_AXIS 3
  402. /* @} *//* Direction encodings */
  403. /* @} *//* Haptic features */
  404. /**
  405. * ID for haptic effects.
  406. *
  407. * This is -1 if the ID is invalid.
  408. *
  409. * \sa SDL_CreateHapticEffect
  410. */
  411. typedef int SDL_HapticEffectID;
  412. /**
  413. * Structure that represents a haptic direction.
  414. *
  415. * This is the direction where the force comes from, instead of the direction
  416. * in which the force is exerted.
  417. *
  418. * Directions can be specified by:
  419. *
  420. * - SDL_HAPTIC_POLAR : Specified by polar coordinates.
  421. * - SDL_HAPTIC_CARTESIAN : Specified by cartesian coordinates.
  422. * - SDL_HAPTIC_SPHERICAL : Specified by spherical coordinates.
  423. *
  424. * Cardinal directions of the haptic device are relative to the positioning of
  425. * the device. North is considered to be away from the user.
  426. *
  427. * The following diagram represents the cardinal directions:
  428. *
  429. * ```
  430. * .--.
  431. * |__| .-------.
  432. * |=.| |.-----.|
  433. * |--| || ||
  434. * | | |'-----'|
  435. * |__|~')_____('
  436. * [ COMPUTER ]
  437. *
  438. *
  439. * North (0,-1)
  440. * ^
  441. * |
  442. * |
  443. * (-1,0) West <----[ HAPTIC ]----> East (1,0)
  444. * |
  445. * |
  446. * v
  447. * South (0,1)
  448. *
  449. *
  450. * [ USER ]
  451. * \|||/
  452. * (o o)
  453. * ---ooO-(_)-Ooo---
  454. * ```
  455. *
  456. * If type is SDL_HAPTIC_POLAR, direction is encoded by hundredths of a degree
  457. * starting north and turning clockwise. SDL_HAPTIC_POLAR only uses the first
  458. * `dir` parameter. The cardinal directions would be:
  459. *
  460. * - North: 0 (0 degrees)
  461. * - East: 9000 (90 degrees)
  462. * - South: 18000 (180 degrees)
  463. * - West: 27000 (270 degrees)
  464. *
  465. * If type is SDL_HAPTIC_CARTESIAN, direction is encoded by three positions (X
  466. * axis, Y axis and Z axis (with 3 axes)). SDL_HAPTIC_CARTESIAN uses the first
  467. * three `dir` parameters. The cardinal directions would be:
  468. *
  469. * - North: 0,-1, 0
  470. * - East: 1, 0, 0
  471. * - South: 0, 1, 0
  472. * - West: -1, 0, 0
  473. *
  474. * The Z axis represents the height of the effect if supported, otherwise it's
  475. * unused. In cartesian encoding (1, 2) would be the same as (2, 4), you can
  476. * use any multiple you want, only the direction matters.
  477. *
  478. * If type is SDL_HAPTIC_SPHERICAL, direction is encoded by two rotations. The
  479. * first two `dir` parameters are used. The `dir` parameters are as follows
  480. * (all values are in hundredths of degrees):
  481. *
  482. * - Degrees from (1, 0) rotated towards (0, 1).
  483. * - Degrees towards (0, 0, 1) (device needs at least 3 axes).
  484. *
  485. * Example of force coming from the south with all encodings (force coming
  486. * from the south means the user will have to pull the stick to counteract):
  487. *
  488. * ```c
  489. * SDL_HapticDirection direction;
  490. *
  491. * // Cartesian directions
  492. * direction.type = SDL_HAPTIC_CARTESIAN; // Using cartesian direction encoding.
  493. * direction.dir[0] = 0; // X position
  494. * direction.dir[1] = 1; // Y position
  495. * // Assuming the device has 2 axes, we don't need to specify third parameter.
  496. *
  497. * // Polar directions
  498. * direction.type = SDL_HAPTIC_POLAR; // We'll be using polar direction encoding.
  499. * direction.dir[0] = 18000; // Polar only uses first parameter
  500. *
  501. * // Spherical coordinates
  502. * direction.type = SDL_HAPTIC_SPHERICAL; // Spherical encoding
  503. * direction.dir[0] = 9000; // Since we only have two axes we don't need more parameters.
  504. * ```
  505. *
  506. * \since This struct is available since SDL 3.2.0.
  507. *
  508. * \sa SDL_HAPTIC_POLAR
  509. * \sa SDL_HAPTIC_CARTESIAN
  510. * \sa SDL_HAPTIC_SPHERICAL
  511. * \sa SDL_HAPTIC_STEERING_AXIS
  512. * \sa SDL_HapticEffect
  513. * \sa SDL_GetNumHapticAxes
  514. */
  515. typedef struct SDL_HapticDirection
  516. {
  517. SDL_HapticDirectionType type; /**< The type of encoding. */
  518. Sint32 dir[3]; /**< The encoded direction. */
  519. } SDL_HapticDirection;
  520. /**
  521. * A structure containing a template for a Constant effect.
  522. *
  523. * This struct is exclusively for the SDL_HAPTIC_CONSTANT effect.
  524. *
  525. * A constant effect applies a constant force in the specified direction to
  526. * the joystick.
  527. *
  528. * \since This struct is available since SDL 3.2.0.
  529. *
  530. * \sa SDL_HAPTIC_CONSTANT
  531. * \sa SDL_HapticEffect
  532. */
  533. typedef struct SDL_HapticConstant
  534. {
  535. /* Header */
  536. SDL_HapticEffectType type; /**< SDL_HAPTIC_CONSTANT */
  537. SDL_HapticDirection direction; /**< Direction of the effect. */
  538. /* Replay */
  539. Uint32 length; /**< Duration of the effect. */
  540. Uint16 delay; /**< Delay before starting the effect. */
  541. /* Trigger */
  542. Uint16 button; /**< Button that triggers the effect. */
  543. Uint16 interval; /**< How soon it can be triggered again after button. */
  544. /* Constant */
  545. Sint16 level; /**< Strength of the constant effect. */
  546. /* Envelope */
  547. Uint16 attack_length; /**< Duration of the attack. */
  548. Uint16 attack_level; /**< Level at the start of the attack. */
  549. Uint16 fade_length; /**< Duration of the fade. */
  550. Uint16 fade_level; /**< Level at the end of the fade. */
  551. } SDL_HapticConstant;
  552. /**
  553. * A structure containing a template for a Periodic effect.
  554. *
  555. * The struct handles the following effects:
  556. *
  557. * - SDL_HAPTIC_SINE
  558. * - SDL_HAPTIC_SQUARE
  559. * - SDL_HAPTIC_TRIANGLE
  560. * - SDL_HAPTIC_SAWTOOTHUP
  561. * - SDL_HAPTIC_SAWTOOTHDOWN
  562. *
  563. * A periodic effect consists in a wave-shaped effect that repeats itself over
  564. * time. The type determines the shape of the wave and the parameters
  565. * determine the dimensions of the wave.
  566. *
  567. * Phase is given by hundredth of a degree meaning that giving the phase a
  568. * value of 9000 will displace it 25% of its period. Here are sample values:
  569. *
  570. * - 0: No phase displacement.
  571. * - 9000: Displaced 25% of its period.
  572. * - 18000: Displaced 50% of its period.
  573. * - 27000: Displaced 75% of its period.
  574. * - 36000: Displaced 100% of its period, same as 0, but 0 is preferred.
  575. *
  576. * Examples:
  577. *
  578. * ```
  579. * SDL_HAPTIC_SINE
  580. * __ __ __ __
  581. * / \ / \ / \ /
  582. * / \__/ \__/ \__/
  583. *
  584. * SDL_HAPTIC_SQUARE
  585. * __ __ __ __ __
  586. * | | | | | | | | | |
  587. * | |__| |__| |__| |__| |
  588. *
  589. * SDL_HAPTIC_TRIANGLE
  590. * /\ /\ /\ /\ /\
  591. * / \ / \ / \ / \ /
  592. * / \/ \/ \/ \/
  593. *
  594. * SDL_HAPTIC_SAWTOOTHUP
  595. * /| /| /| /| /| /| /|
  596. * / | / | / | / | / | / | / |
  597. * / |/ |/ |/ |/ |/ |/ |
  598. *
  599. * SDL_HAPTIC_SAWTOOTHDOWN
  600. * \ |\ |\ |\ |\ |\ |\ |
  601. * \ | \ | \ | \ | \ | \ | \ |
  602. * \| \| \| \| \| \| \|
  603. * ```
  604. *
  605. * \since This struct is available since SDL 3.2.0.
  606. *
  607. * \sa SDL_HAPTIC_SINE
  608. * \sa SDL_HAPTIC_SQUARE
  609. * \sa SDL_HAPTIC_TRIANGLE
  610. * \sa SDL_HAPTIC_SAWTOOTHUP
  611. * \sa SDL_HAPTIC_SAWTOOTHDOWN
  612. * \sa SDL_HapticEffect
  613. */
  614. typedef struct SDL_HapticPeriodic
  615. {
  616. /* Header */
  617. SDL_HapticEffectType type; /**< SDL_HAPTIC_SINE, SDL_HAPTIC_SQUARE
  618. SDL_HAPTIC_TRIANGLE, SDL_HAPTIC_SAWTOOTHUP or
  619. SDL_HAPTIC_SAWTOOTHDOWN */
  620. SDL_HapticDirection direction; /**< Direction of the effect. */
  621. /* Replay */
  622. Uint32 length; /**< Duration of the effect. */
  623. Uint16 delay; /**< Delay before starting the effect. */
  624. /* Trigger */
  625. Uint16 button; /**< Button that triggers the effect. */
  626. Uint16 interval; /**< How soon it can be triggered again after button. */
  627. /* Periodic */
  628. Uint16 period; /**< Period of the wave. */
  629. Sint16 magnitude; /**< Peak value; if negative, equivalent to 180 degrees extra phase shift. */
  630. Sint16 offset; /**< Mean value of the wave. */
  631. Uint16 phase; /**< Positive phase shift given by hundredth of a degree. */
  632. /* Envelope */
  633. Uint16 attack_length; /**< Duration of the attack. */
  634. Uint16 attack_level; /**< Level at the start of the attack. */
  635. Uint16 fade_length; /**< Duration of the fade. */
  636. Uint16 fade_level; /**< Level at the end of the fade. */
  637. } SDL_HapticPeriodic;
  638. /**
  639. * A structure containing a template for a Condition effect.
  640. *
  641. * The struct handles the following effects:
  642. *
  643. * - SDL_HAPTIC_SPRING: Effect based on axes position.
  644. * - SDL_HAPTIC_DAMPER: Effect based on axes velocity.
  645. * - SDL_HAPTIC_INERTIA: Effect based on axes acceleration.
  646. * - SDL_HAPTIC_FRICTION: Effect based on axes movement.
  647. *
  648. * Direction is handled by condition internals instead of a direction member.
  649. * The condition effect specific members have three parameters. The first
  650. * refers to the X axis, the second refers to the Y axis and the third refers
  651. * to the Z axis. The right terms refer to the positive side of the axis and
  652. * the left terms refer to the negative side of the axis. Please refer to the
  653. * SDL_HapticDirection diagram for which side is positive and which is
  654. * negative.
  655. *
  656. * \since This struct is available since SDL 3.2.0.
  657. *
  658. * \sa SDL_HapticDirection
  659. * \sa SDL_HAPTIC_SPRING
  660. * \sa SDL_HAPTIC_DAMPER
  661. * \sa SDL_HAPTIC_INERTIA
  662. * \sa SDL_HAPTIC_FRICTION
  663. * \sa SDL_HapticEffect
  664. */
  665. typedef struct SDL_HapticCondition
  666. {
  667. /* Header */
  668. SDL_HapticEffectType type; /**< SDL_HAPTIC_SPRING, SDL_HAPTIC_DAMPER,
  669. SDL_HAPTIC_INERTIA or SDL_HAPTIC_FRICTION */
  670. SDL_HapticDirection direction; /**< Direction of the effect. */
  671. /* Replay */
  672. Uint32 length; /**< Duration of the effect. */
  673. Uint16 delay; /**< Delay before starting the effect. */
  674. /* Trigger */
  675. Uint16 button; /**< Button that triggers the effect. */
  676. Uint16 interval; /**< How soon it can be triggered again after button. */
  677. /* Condition */
  678. Uint16 right_sat[3]; /**< Level when joystick is to the positive side; max 0xFFFF. */
  679. Uint16 left_sat[3]; /**< Level when joystick is to the negative side; max 0xFFFF. */
  680. Sint16 right_coeff[3]; /**< How fast to increase the force towards the positive side. */
  681. Sint16 left_coeff[3]; /**< How fast to increase the force towards the negative side. */
  682. Uint16 deadband[3]; /**< Size of the dead zone; max 0xFFFF: whole axis-range when 0-centered. */
  683. Sint16 center[3]; /**< Position of the dead zone. */
  684. } SDL_HapticCondition;
  685. /**
  686. * A structure containing a template for a Ramp effect.
  687. *
  688. * This struct is exclusively for the SDL_HAPTIC_RAMP effect.
  689. *
  690. * The ramp effect starts at start strength and ends at end strength. It
  691. * augments in linear fashion. If you use attack and fade with a ramp the
  692. * effects get added to the ramp effect making the effect become quadratic
  693. * instead of linear.
  694. *
  695. * \since This struct is available since SDL 3.2.0.
  696. *
  697. * \sa SDL_HAPTIC_RAMP
  698. * \sa SDL_HapticEffect
  699. */
  700. typedef struct SDL_HapticRamp
  701. {
  702. /* Header */
  703. SDL_HapticEffectType type; /**< SDL_HAPTIC_RAMP */
  704. SDL_HapticDirection direction; /**< Direction of the effect. */
  705. /* Replay */
  706. Uint32 length; /**< Duration of the effect. */
  707. Uint16 delay; /**< Delay before starting the effect. */
  708. /* Trigger */
  709. Uint16 button; /**< Button that triggers the effect. */
  710. Uint16 interval; /**< How soon it can be triggered again after button. */
  711. /* Ramp */
  712. Sint16 start; /**< Beginning strength level. */
  713. Sint16 end; /**< Ending strength level. */
  714. /* Envelope */
  715. Uint16 attack_length; /**< Duration of the attack. */
  716. Uint16 attack_level; /**< Level at the start of the attack. */
  717. Uint16 fade_length; /**< Duration of the fade. */
  718. Uint16 fade_level; /**< Level at the end of the fade. */
  719. } SDL_HapticRamp;
  720. /**
  721. * A structure containing a template for a Left/Right effect.
  722. *
  723. * This struct is exclusively for the SDL_HAPTIC_LEFTRIGHT effect.
  724. *
  725. * The Left/Right effect is used to explicitly control the large and small
  726. * motors, commonly found in modern game controllers. The small (right) motor
  727. * is high frequency, and the large (left) motor is low frequency.
  728. *
  729. * \since This struct is available since SDL 3.2.0.
  730. *
  731. * \sa SDL_HAPTIC_LEFTRIGHT
  732. * \sa SDL_HapticEffect
  733. */
  734. typedef struct SDL_HapticLeftRight
  735. {
  736. /* Header */
  737. SDL_HapticEffectType type; /**< SDL_HAPTIC_LEFTRIGHT */
  738. /* Replay */
  739. Uint32 length; /**< Duration of the effect in milliseconds. */
  740. /* Rumble */
  741. Uint16 large_magnitude; /**< Control of the large controller motor. */
  742. Uint16 small_magnitude; /**< Control of the small controller motor. */
  743. } SDL_HapticLeftRight;
  744. /**
  745. * A structure containing a template for the SDL_HAPTIC_CUSTOM effect.
  746. *
  747. * This struct is exclusively for the SDL_HAPTIC_CUSTOM effect.
  748. *
  749. * A custom force feedback effect is much like a periodic effect, where the
  750. * application can define its exact shape. You will have to allocate the data
  751. * yourself. Data should consist of channels * samples Uint16 samples.
  752. *
  753. * If channels is one, the effect is rotated using the defined direction.
  754. * Otherwise it uses the samples in data for the different axes.
  755. *
  756. * \since This struct is available since SDL 3.2.0.
  757. *
  758. * \sa SDL_HAPTIC_CUSTOM
  759. * \sa SDL_HapticEffect
  760. */
  761. typedef struct SDL_HapticCustom
  762. {
  763. /* Header */
  764. SDL_HapticEffectType type; /**< SDL_HAPTIC_CUSTOM */
  765. SDL_HapticDirection direction; /**< Direction of the effect. */
  766. /* Replay */
  767. Uint32 length; /**< Duration of the effect. */
  768. Uint16 delay; /**< Delay before starting the effect. */
  769. /* Trigger */
  770. Uint16 button; /**< Button that triggers the effect. */
  771. Uint16 interval; /**< How soon it can be triggered again after button. */
  772. /* Custom */
  773. Uint8 channels; /**< Axes to use, minimum of one. */
  774. Uint16 period; /**< Sample periods. */
  775. Uint16 samples; /**< Amount of samples. */
  776. Uint16 *data; /**< Should contain channels*samples items. */
  777. /* Envelope */
  778. Uint16 attack_length; /**< Duration of the attack. */
  779. Uint16 attack_level; /**< Level at the start of the attack. */
  780. Uint16 fade_length; /**< Duration of the fade. */
  781. Uint16 fade_level; /**< Level at the end of the fade. */
  782. } SDL_HapticCustom;
  783. /**
  784. * The generic template for any haptic effect.
  785. *
  786. * All values max at 32767 (0x7FFF). Signed values also can be negative. Time
  787. * values unless specified otherwise are in milliseconds.
  788. *
  789. * You can also pass SDL_HAPTIC_INFINITY to length instead of a 0-32767 value.
  790. * Neither delay, interval, attack_length nor fade_length support
  791. * SDL_HAPTIC_INFINITY. Fade will also not be used since effect never ends.
  792. *
  793. * Additionally, the SDL_HAPTIC_RAMP effect does not support a duration of
  794. * SDL_HAPTIC_INFINITY.
  795. *
  796. * Button triggers may not be supported on all devices, it is advised to not
  797. * use them if possible. Buttons start at index 1 instead of index 0 like the
  798. * joystick.
  799. *
  800. * If both attack_length and fade_level are 0, the envelope is not used,
  801. * otherwise both values are used.
  802. *
  803. * Common parts:
  804. *
  805. * ```c
  806. * // Replay - All effects have this
  807. * Uint32 length; // Duration of effect (ms).
  808. * Uint16 delay; // Delay before starting effect.
  809. *
  810. * // Trigger - All effects have this
  811. * Uint16 button; // Button that triggers effect.
  812. * Uint16 interval; // How soon before effect can be triggered again.
  813. *
  814. * // Envelope - All effects except condition effects have this
  815. * Uint16 attack_length; // Duration of the attack (ms).
  816. * Uint16 attack_level; // Level at the start of the attack.
  817. * Uint16 fade_length; // Duration of the fade out (ms).
  818. * Uint16 fade_level; // Level at the end of the fade.
  819. * ```
  820. *
  821. * Here we have an example of a constant effect evolution in time:
  822. *
  823. * ```
  824. * Strength
  825. * ^
  826. * |
  827. * | effect level --> _________________
  828. * | / \
  829. * | / \
  830. * | / \
  831. * | / \
  832. * | attack_level --> | \
  833. * | | | <--- fade_level
  834. * |
  835. * +--------------------------------------------------> Time
  836. * [--] [---]
  837. * attack_length fade_length
  838. *
  839. * [------------------][-----------------------]
  840. * delay length
  841. * ```
  842. *
  843. * Note either the attack_level or the fade_level may be above the actual
  844. * effect level.
  845. *
  846. * \since This struct is available since SDL 3.2.0.
  847. *
  848. * \sa SDL_HapticConstant
  849. * \sa SDL_HapticPeriodic
  850. * \sa SDL_HapticCondition
  851. * \sa SDL_HapticRamp
  852. * \sa SDL_HapticLeftRight
  853. * \sa SDL_HapticCustom
  854. */
  855. typedef union SDL_HapticEffect
  856. {
  857. /* Common for all force feedback effects */
  858. SDL_HapticEffectType type; /**< Effect type. */
  859. SDL_HapticConstant constant; /**< Constant effect. */
  860. SDL_HapticPeriodic periodic; /**< Periodic effect. */
  861. SDL_HapticCondition condition; /**< Condition effect. */
  862. SDL_HapticRamp ramp; /**< Ramp effect. */
  863. SDL_HapticLeftRight leftright; /**< Left/Right effect. */
  864. SDL_HapticCustom custom; /**< Custom effect. */
  865. } SDL_HapticEffect;
  866. /**
  867. * This is a unique ID for a haptic device for the time it is connected to the
  868. * system, and is never reused for the lifetime of the application.
  869. *
  870. * If the haptic device is disconnected and reconnected, it will get a new ID.
  871. *
  872. * The value 0 is an invalid ID.
  873. *
  874. * \since This datatype is available since SDL 3.2.0.
  875. */
  876. typedef Uint32 SDL_HapticID;
  877. /* Function prototypes */
  878. /**
  879. * Get a list of currently connected haptic devices.
  880. *
  881. * \param count a pointer filled in with the number of haptic devices
  882. * returned, may be NULL.
  883. * \returns a 0 terminated array of haptic device instance IDs or NULL on
  884. * failure; call SDL_GetError() for more information. This should be
  885. * freed with SDL_free() when it is no longer needed.
  886. *
  887. * \since This function is available since SDL 3.2.0.
  888. *
  889. * \sa SDL_OpenHaptic
  890. */
  891. extern SDL_DECLSPEC SDL_HapticID * SDLCALL SDL_GetHaptics(int *count);
  892. /**
  893. * Get the implementation dependent name of a haptic device.
  894. *
  895. * This can be called before any haptic devices are opened.
  896. *
  897. * \param instance_id the haptic device instance ID.
  898. * \returns the name of the selected haptic device. If no name can be found,
  899. * this function returns NULL; call SDL_GetError() for more
  900. * information.
  901. *
  902. * \since This function is available since SDL 3.2.0.
  903. *
  904. * \sa SDL_GetHapticName
  905. * \sa SDL_OpenHaptic
  906. */
  907. extern SDL_DECLSPEC const char * SDLCALL SDL_GetHapticNameForID(SDL_HapticID instance_id);
  908. /**
  909. * Open a haptic device for use.
  910. *
  911. * The index passed as an argument refers to the N'th haptic device on this
  912. * system.
  913. *
  914. * When opening a haptic device, its gain will be set to maximum and
  915. * autocenter will be disabled. To modify these values use SDL_SetHapticGain()
  916. * and SDL_SetHapticAutocenter().
  917. *
  918. * \param instance_id the haptic device instance ID.
  919. * \returns the device identifier or NULL on failure; call SDL_GetError() for
  920. * more information.
  921. *
  922. * \since This function is available since SDL 3.2.0.
  923. *
  924. * \sa SDL_CloseHaptic
  925. * \sa SDL_GetHaptics
  926. * \sa SDL_OpenHapticFromJoystick
  927. * \sa SDL_OpenHapticFromMouse
  928. * \sa SDL_SetHapticAutocenter
  929. * \sa SDL_SetHapticGain
  930. */
  931. extern SDL_DECLSPEC SDL_Haptic * SDLCALL SDL_OpenHaptic(SDL_HapticID instance_id);
  932. /**
  933. * Get the SDL_Haptic associated with an instance ID, if it has been opened.
  934. *
  935. * \param instance_id the instance ID to get the SDL_Haptic for.
  936. * \returns an SDL_Haptic on success or NULL on failure or if it hasn't been
  937. * opened yet; call SDL_GetError() for more information.
  938. *
  939. * \since This function is available since SDL 3.2.0.
  940. */
  941. extern SDL_DECLSPEC SDL_Haptic * SDLCALL SDL_GetHapticFromID(SDL_HapticID instance_id);
  942. /**
  943. * Get the instance ID of an opened haptic device.
  944. *
  945. * \param haptic the SDL_Haptic device to query.
  946. * \returns the instance ID of the specified haptic device on success or 0 on
  947. * failure; call SDL_GetError() for more information.
  948. *
  949. * \since This function is available since SDL 3.2.0.
  950. */
  951. extern SDL_DECLSPEC SDL_HapticID SDLCALL SDL_GetHapticID(SDL_Haptic *haptic);
  952. /**
  953. * Get the implementation dependent name of a haptic device.
  954. *
  955. * \param haptic the SDL_Haptic obtained from SDL_OpenJoystick().
  956. * \returns the name of the selected haptic device. If no name can be found,
  957. * this function returns NULL; call SDL_GetError() for more
  958. * information.
  959. *
  960. * \since This function is available since SDL 3.2.0.
  961. *
  962. * \sa SDL_GetHapticNameForID
  963. */
  964. extern SDL_DECLSPEC const char * SDLCALL SDL_GetHapticName(SDL_Haptic *haptic);
  965. /**
  966. * Query whether or not the current mouse has haptic capabilities.
  967. *
  968. * \returns true if the mouse is haptic or false if it isn't.
  969. *
  970. * \since This function is available since SDL 3.2.0.
  971. *
  972. * \sa SDL_OpenHapticFromMouse
  973. */
  974. extern SDL_DECLSPEC bool SDLCALL SDL_IsMouseHaptic(void);
  975. /**
  976. * Try to open a haptic device from the current mouse.
  977. *
  978. * \returns the haptic device identifier or NULL on failure; call
  979. * SDL_GetError() for more information.
  980. *
  981. * \since This function is available since SDL 3.2.0.
  982. *
  983. * \sa SDL_CloseHaptic
  984. * \sa SDL_IsMouseHaptic
  985. */
  986. extern SDL_DECLSPEC SDL_Haptic * SDLCALL SDL_OpenHapticFromMouse(void);
  987. /**
  988. * Query if a joystick has haptic features.
  989. *
  990. * \param joystick the SDL_Joystick to test for haptic capabilities.
  991. * \returns true if the joystick is haptic or false if it isn't.
  992. *
  993. * \since This function is available since SDL 3.2.0.
  994. *
  995. * \sa SDL_OpenHapticFromJoystick
  996. */
  997. extern SDL_DECLSPEC bool SDLCALL SDL_IsJoystickHaptic(SDL_Joystick *joystick);
  998. /**
  999. * Open a haptic device for use from a joystick device.
  1000. *
  1001. * You must still close the haptic device separately. It will not be closed
  1002. * with the joystick.
  1003. *
  1004. * When opened from a joystick you should first close the haptic device before
  1005. * closing the joystick device. If not, on some implementations the haptic
  1006. * device will also get unallocated and you'll be unable to use force feedback
  1007. * on that device.
  1008. *
  1009. * \param joystick the SDL_Joystick to create a haptic device from.
  1010. * \returns a valid haptic device identifier on success or NULL on failure;
  1011. * call SDL_GetError() for more information.
  1012. *
  1013. * \since This function is available since SDL 3.2.0.
  1014. *
  1015. * \sa SDL_CloseHaptic
  1016. * \sa SDL_IsJoystickHaptic
  1017. */
  1018. extern SDL_DECLSPEC SDL_Haptic * SDLCALL SDL_OpenHapticFromJoystick(SDL_Joystick *joystick);
  1019. /**
  1020. * Close a haptic device previously opened with SDL_OpenHaptic().
  1021. *
  1022. * \param haptic the SDL_Haptic device to close.
  1023. *
  1024. * \since This function is available since SDL 3.2.0.
  1025. *
  1026. * \sa SDL_OpenHaptic
  1027. */
  1028. extern SDL_DECLSPEC void SDLCALL SDL_CloseHaptic(SDL_Haptic *haptic);
  1029. /**
  1030. * Get the number of effects a haptic device can store.
  1031. *
  1032. * On some platforms this isn't fully supported, and therefore is an
  1033. * approximation. Always check to see if your created effect was actually
  1034. * created and do not rely solely on SDL_GetMaxHapticEffects().
  1035. *
  1036. * \param haptic the SDL_Haptic device to query.
  1037. * \returns the number of effects the haptic device can store or a negative
  1038. * error code on failure; call SDL_GetError() for more information.
  1039. *
  1040. * \since This function is available since SDL 3.2.0.
  1041. *
  1042. * \sa SDL_GetMaxHapticEffectsPlaying
  1043. * \sa SDL_GetHapticFeatures
  1044. */
  1045. extern SDL_DECLSPEC int SDLCALL SDL_GetMaxHapticEffects(SDL_Haptic *haptic);
  1046. /**
  1047. * Get the number of effects a haptic device can play at the same time.
  1048. *
  1049. * This is not supported on all platforms, but will always return a value.
  1050. *
  1051. * \param haptic the SDL_Haptic device to query maximum playing effects.
  1052. * \returns the number of effects the haptic device can play at the same time
  1053. * or -1 on failure; call SDL_GetError() for more information.
  1054. *
  1055. * \since This function is available since SDL 3.2.0.
  1056. *
  1057. * \sa SDL_GetMaxHapticEffects
  1058. * \sa SDL_GetHapticFeatures
  1059. */
  1060. extern SDL_DECLSPEC int SDLCALL SDL_GetMaxHapticEffectsPlaying(SDL_Haptic *haptic);
  1061. /**
  1062. * Get the haptic device's supported features in bitwise manner.
  1063. *
  1064. * \param haptic the SDL_Haptic device to query.
  1065. * \returns a list of supported haptic features in bitwise manner (OR'd), or 0
  1066. * on failure; call SDL_GetError() for more information.
  1067. *
  1068. * \since This function is available since SDL 3.2.0.
  1069. *
  1070. * \sa SDL_HapticEffectSupported
  1071. * \sa SDL_GetMaxHapticEffects
  1072. */
  1073. extern SDL_DECLSPEC Uint32 SDLCALL SDL_GetHapticFeatures(SDL_Haptic *haptic);
  1074. /**
  1075. * Get the number of haptic axes the device has.
  1076. *
  1077. * The number of haptic axes might be useful if working with the
  1078. * SDL_HapticDirection effect.
  1079. *
  1080. * \param haptic the SDL_Haptic device to query.
  1081. * \returns the number of axes on success or -1 on failure; call
  1082. * SDL_GetError() for more information.
  1083. *
  1084. * \since This function is available since SDL 3.2.0.
  1085. */
  1086. extern SDL_DECLSPEC int SDLCALL SDL_GetNumHapticAxes(SDL_Haptic *haptic);
  1087. /**
  1088. * Check to see if an effect is supported by a haptic device.
  1089. *
  1090. * \param haptic the SDL_Haptic device to query.
  1091. * \param effect the desired effect to query.
  1092. * \returns true if the effect is supported or false if it isn't.
  1093. *
  1094. * \since This function is available since SDL 3.2.0.
  1095. *
  1096. * \sa SDL_CreateHapticEffect
  1097. * \sa SDL_GetHapticFeatures
  1098. */
  1099. extern SDL_DECLSPEC bool SDLCALL SDL_HapticEffectSupported(SDL_Haptic *haptic, const SDL_HapticEffect *effect);
  1100. /**
  1101. * Create a new haptic effect on a specified device.
  1102. *
  1103. * \param haptic an SDL_Haptic device to create the effect on.
  1104. * \param effect an SDL_HapticEffect structure containing the properties of
  1105. * the effect to create.
  1106. * \returns the ID of the effect on success or -1 on failure; call
  1107. * SDL_GetError() for more information.
  1108. *
  1109. * \since This function is available since SDL 3.2.0.
  1110. *
  1111. * \sa SDL_DestroyHapticEffect
  1112. * \sa SDL_RunHapticEffect
  1113. * \sa SDL_UpdateHapticEffect
  1114. */
  1115. extern SDL_DECLSPEC SDL_HapticEffectID SDLCALL SDL_CreateHapticEffect(SDL_Haptic *haptic, const SDL_HapticEffect *effect);
  1116. /**
  1117. * Update the properties of an effect.
  1118. *
  1119. * Can be used dynamically, although behavior when dynamically changing
  1120. * direction may be strange. Specifically the effect may re-upload itself and
  1121. * start playing from the start. You also cannot change the type either when
  1122. * running SDL_UpdateHapticEffect().
  1123. *
  1124. * \param haptic the SDL_Haptic device that has the effect.
  1125. * \param effect the identifier of the effect to update.
  1126. * \param data an SDL_HapticEffect structure containing the new effect
  1127. * properties to use.
  1128. * \returns true on success or false on failure; call SDL_GetError() for more
  1129. * information.
  1130. *
  1131. * \since This function is available since SDL 3.2.0.
  1132. *
  1133. * \sa SDL_CreateHapticEffect
  1134. * \sa SDL_RunHapticEffect
  1135. */
  1136. extern SDL_DECLSPEC bool SDLCALL SDL_UpdateHapticEffect(SDL_Haptic *haptic, SDL_HapticEffectID effect, const SDL_HapticEffect *data);
  1137. /**
  1138. * Run the haptic effect on its associated haptic device.
  1139. *
  1140. * To repeat the effect over and over indefinitely, set `iterations` to
  1141. * `SDL_HAPTIC_INFINITY`. (Repeats the envelope - attack and fade.) To make
  1142. * one instance of the effect last indefinitely (so the effect does not fade),
  1143. * set the effect's `length` in its structure/union to `SDL_HAPTIC_INFINITY`
  1144. * instead.
  1145. *
  1146. * \param haptic the SDL_Haptic device to run the effect on.
  1147. * \param effect the ID of the haptic effect to run.
  1148. * \param iterations the number of iterations to run the effect; use
  1149. * `SDL_HAPTIC_INFINITY` to repeat forever.
  1150. * \returns true on success or false on failure; call SDL_GetError() for more
  1151. * information.
  1152. *
  1153. * \since This function is available since SDL 3.2.0.
  1154. *
  1155. * \sa SDL_GetHapticEffectStatus
  1156. * \sa SDL_StopHapticEffect
  1157. * \sa SDL_StopHapticEffects
  1158. */
  1159. extern SDL_DECLSPEC bool SDLCALL SDL_RunHapticEffect(SDL_Haptic *haptic, SDL_HapticEffectID effect, Uint32 iterations);
  1160. /**
  1161. * Stop the haptic effect on its associated haptic device.
  1162. *
  1163. * \param haptic the SDL_Haptic device to stop the effect on.
  1164. * \param effect the ID of the haptic effect to stop.
  1165. * \returns true on success or false on failure; call SDL_GetError() for more
  1166. * information.
  1167. *
  1168. * \since This function is available since SDL 3.2.0.
  1169. *
  1170. * \sa SDL_RunHapticEffect
  1171. * \sa SDL_StopHapticEffects
  1172. */
  1173. extern SDL_DECLSPEC bool SDLCALL SDL_StopHapticEffect(SDL_Haptic *haptic, SDL_HapticEffectID effect);
  1174. /**
  1175. * Destroy a haptic effect on the device.
  1176. *
  1177. * This will stop the effect if it's running. Effects are automatically
  1178. * destroyed when the device is closed.
  1179. *
  1180. * \param haptic the SDL_Haptic device to destroy the effect on.
  1181. * \param effect the ID of the haptic effect to destroy.
  1182. *
  1183. * \since This function is available since SDL 3.2.0.
  1184. *
  1185. * \sa SDL_CreateHapticEffect
  1186. */
  1187. extern SDL_DECLSPEC void SDLCALL SDL_DestroyHapticEffect(SDL_Haptic *haptic, SDL_HapticEffectID effect);
  1188. /**
  1189. * Get the status of the current effect on the specified haptic device.
  1190. *
  1191. * Device must support the SDL_HAPTIC_STATUS feature.
  1192. *
  1193. * \param haptic the SDL_Haptic device to query for the effect status on.
  1194. * \param effect the ID of the haptic effect to query its status.
  1195. * \returns true if it is playing, false if it isn't playing or haptic status
  1196. * isn't supported.
  1197. *
  1198. * \since This function is available since SDL 3.2.0.
  1199. *
  1200. * \sa SDL_GetHapticFeatures
  1201. */
  1202. extern SDL_DECLSPEC bool SDLCALL SDL_GetHapticEffectStatus(SDL_Haptic *haptic, SDL_HapticEffectID effect);
  1203. /**
  1204. * Set the global gain of the specified haptic device.
  1205. *
  1206. * Device must support the SDL_HAPTIC_GAIN feature.
  1207. *
  1208. * The user may specify the maximum gain by setting the environment variable
  1209. * `SDL_HAPTIC_GAIN_MAX` which should be between 0 and 100. All calls to
  1210. * SDL_SetHapticGain() will scale linearly using `SDL_HAPTIC_GAIN_MAX` as the
  1211. * maximum.
  1212. *
  1213. * \param haptic the SDL_Haptic device to set the gain on.
  1214. * \param gain value to set the gain to, should be between 0 and 100 (0 -
  1215. * 100).
  1216. * \returns true on success or false on failure; call SDL_GetError() for more
  1217. * information.
  1218. *
  1219. * \since This function is available since SDL 3.2.0.
  1220. *
  1221. * \sa SDL_GetHapticFeatures
  1222. */
  1223. extern SDL_DECLSPEC bool SDLCALL SDL_SetHapticGain(SDL_Haptic *haptic, int gain);
  1224. /**
  1225. * Set the global autocenter of the device.
  1226. *
  1227. * Autocenter should be between 0 and 100. Setting it to 0 will disable
  1228. * autocentering.
  1229. *
  1230. * Device must support the SDL_HAPTIC_AUTOCENTER feature.
  1231. *
  1232. * \param haptic the SDL_Haptic device to set autocentering on.
  1233. * \param autocenter value to set autocenter to (0-100).
  1234. * \returns true on success or false on failure; call SDL_GetError() for more
  1235. * information.
  1236. *
  1237. * \since This function is available since SDL 3.2.0.
  1238. *
  1239. * \sa SDL_GetHapticFeatures
  1240. */
  1241. extern SDL_DECLSPEC bool SDLCALL SDL_SetHapticAutocenter(SDL_Haptic *haptic, int autocenter);
  1242. /**
  1243. * Pause a haptic device.
  1244. *
  1245. * Device must support the `SDL_HAPTIC_PAUSE` feature. Call SDL_ResumeHaptic()
  1246. * to resume playback.
  1247. *
  1248. * Do not modify the effects nor add new ones while the device is paused. That
  1249. * can cause all sorts of weird errors.
  1250. *
  1251. * \param haptic the SDL_Haptic device to pause.
  1252. * \returns true on success or false on failure; call SDL_GetError() for more
  1253. * information.
  1254. *
  1255. * \since This function is available since SDL 3.2.0.
  1256. *
  1257. * \sa SDL_ResumeHaptic
  1258. */
  1259. extern SDL_DECLSPEC bool SDLCALL SDL_PauseHaptic(SDL_Haptic *haptic);
  1260. /**
  1261. * Resume a haptic device.
  1262. *
  1263. * Call to unpause after SDL_PauseHaptic().
  1264. *
  1265. * \param haptic the SDL_Haptic device to unpause.
  1266. * \returns true on success or false on failure; call SDL_GetError() for more
  1267. * information.
  1268. *
  1269. * \since This function is available since SDL 3.2.0.
  1270. *
  1271. * \sa SDL_PauseHaptic
  1272. */
  1273. extern SDL_DECLSPEC bool SDLCALL SDL_ResumeHaptic(SDL_Haptic *haptic);
  1274. /**
  1275. * Stop all the currently playing effects on a haptic device.
  1276. *
  1277. * \param haptic the SDL_Haptic device to stop.
  1278. * \returns true on success or false on failure; call SDL_GetError() for more
  1279. * information.
  1280. *
  1281. * \since This function is available since SDL 3.2.0.
  1282. *
  1283. * \sa SDL_RunHapticEffect
  1284. * \sa SDL_StopHapticEffects
  1285. */
  1286. extern SDL_DECLSPEC bool SDLCALL SDL_StopHapticEffects(SDL_Haptic *haptic);
  1287. /**
  1288. * Check whether rumble is supported on a haptic device.
  1289. *
  1290. * \param haptic haptic device to check for rumble support.
  1291. * \returns true if the effect is supported or false if it isn't.
  1292. *
  1293. * \since This function is available since SDL 3.2.0.
  1294. *
  1295. * \sa SDL_InitHapticRumble
  1296. */
  1297. extern SDL_DECLSPEC bool SDLCALL SDL_HapticRumbleSupported(SDL_Haptic *haptic);
  1298. /**
  1299. * Initialize a haptic device for simple rumble playback.
  1300. *
  1301. * \param haptic the haptic device to initialize for simple rumble playback.
  1302. * \returns true on success or false on failure; call SDL_GetError() for more
  1303. * information.
  1304. *
  1305. * \since This function is available since SDL 3.2.0.
  1306. *
  1307. * \sa SDL_PlayHapticRumble
  1308. * \sa SDL_StopHapticRumble
  1309. * \sa SDL_HapticRumbleSupported
  1310. */
  1311. extern SDL_DECLSPEC bool SDLCALL SDL_InitHapticRumble(SDL_Haptic *haptic);
  1312. /**
  1313. * Run a simple rumble effect on a haptic device.
  1314. *
  1315. * \param haptic the haptic device to play the rumble effect on.
  1316. * \param strength strength of the rumble to play as a 0-1 float value.
  1317. * \param length length of the rumble to play in milliseconds.
  1318. * \returns true on success or false on failure; call SDL_GetError() for more
  1319. * information.
  1320. *
  1321. * \since This function is available since SDL 3.2.0.
  1322. *
  1323. * \sa SDL_InitHapticRumble
  1324. * \sa SDL_StopHapticRumble
  1325. */
  1326. extern SDL_DECLSPEC bool SDLCALL SDL_PlayHapticRumble(SDL_Haptic *haptic, float strength, Uint32 length);
  1327. /**
  1328. * Stop the simple rumble on a haptic device.
  1329. *
  1330. * \param haptic the haptic device to stop the rumble effect on.
  1331. * \returns true on success or false on failure; call SDL_GetError() for more
  1332. * information.
  1333. *
  1334. * \since This function is available since SDL 3.2.0.
  1335. *
  1336. * \sa SDL_PlayHapticRumble
  1337. */
  1338. extern SDL_DECLSPEC bool SDLCALL SDL_StopHapticRumble(SDL_Haptic *haptic);
  1339. /* Ends C function definitions when using C++ */
  1340. #ifdef __cplusplus
  1341. }
  1342. #endif
  1343. #include <SDL3/SDL_close_code.h>
  1344. #endif /* SDL_haptic_h_ */