🛠️🐜 Antkeeper superbuild with dependencies included https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1247 lines
39 KiB

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