SDL_haptic.h 44 KB

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