SDL_haptic.h 42 KB

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