SDL_haptic.h 43 KB

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