SDL_haptic.h 44 KB

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