2 Simple DirectMedia Layer
3 Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
5 This software is provided 'as-is', without any express or implied
6 warranty. In no event will the authors be held liable for any damages
7 arising from the use of this software.
9 Permission is granted to anyone to use this software for any purpose,
10 including commercial applications, and to alter it and redistribute it
11 freely, subject to the following restrictions:
13 1. The origin of this software must not be misrepresented; you must not
14 claim that you wrote the original software. If you use this software
15 in a product, an acknowledgment in the product documentation would be
16 appreciated but is not required.
17 2. Altered source versions must be plainly marked as such, and must not be
18 misrepresented as being the original software.
19 3. This notice may not be removed or altered from any source distribution.
25 * \brief The SDL haptic subsystem allows you to control haptic (force feedback)
28 * The basic usage is as follows:
29 * - Initialize the subsystem (::SDL_INIT_HAPTIC).
30 * - Open a haptic device.
31 * - SDL_HapticOpen() to open from index.
32 * - SDL_HapticOpenFromJoystick() to open from an existing joystick.
33 * - Create an effect (::SDL_HapticEffect).
34 * - Upload the effect with SDL_HapticNewEffect().
35 * - Run the effect with SDL_HapticRunEffect().
36 * - (optional) Free the effect with SDL_HapticDestroyEffect().
37 * - Close the haptic device with SDL_HapticClose().
39 * \par Simple rumble example:
44 * haptic = SDL_HapticOpen( 0 );
48 * // Initialize simple rumble
49 * if (SDL_HapticRumbleInit( haptic ) != 0)
52 * // Play effect at 50% strength for 2 seconds
53 * if (SDL_HapticRumblePlay( haptic, 0.5, 2000 ) != 0)
58 * SDL_HapticClose( haptic );
61 * \par Complete example:
63 * int test_haptic( SDL_Joystick * joystick ) {
65 * SDL_HapticEffect effect;
69 * haptic = SDL_HapticOpenFromJoystick( joystick );
70 * if (haptic == NULL) return -1; // Most likely joystick isn't haptic
72 * // See if it can do sine waves
73 * if ((SDL_HapticQuery(haptic) & SDL_HAPTIC_SINE)==0) {
74 * SDL_HapticClose(haptic); // No sine effect
78 * // Create the effect
79 * memset( &effect, 0, sizeof(SDL_HapticEffect) ); // 0 is safe default
80 * effect.type = SDL_HAPTIC_SINE;
81 * effect.periodic.direction.type = SDL_HAPTIC_POLAR; // Polar coordinates
82 * effect.periodic.direction.dir[0] = 18000; // Force comes from south
83 * effect.periodic.period = 1000; // 1000 ms
84 * effect.periodic.magnitude = 20000; // 20000/32767 strength
85 * effect.periodic.length = 5000; // 5 seconds long
86 * effect.periodic.attack_length = 1000; // Takes 1 second to get max strength
87 * effect.periodic.fade_length = 1000; // Takes 1 second to fade away
89 * // Upload the effect
90 * effect_id = SDL_HapticNewEffect( haptic, &effect );
93 * SDL_HapticRunEffect( haptic, effect_id, 1 );
94 * SDL_Delay( 5000); // Wait for the effect to finish
96 * // We destroy the effect, although closing the device also does this
97 * SDL_HapticDestroyEffect( haptic, effect_id );
100 * SDL_HapticClose(haptic);
102 * return 0; // Success
107 #ifndef SDL_haptic_h_
108 #define SDL_haptic_h_
110 #include "SDL_stdinc.h"
111 #include "SDL_error.h"
112 #include "SDL_joystick.h"
114 #include "begin_code.h"
115 /* Set up for C function definitions, even when using C++ */
118 #endif /* __cplusplus */
120 /* FIXME: For SDL 2.1, adjust all the magnitude variables to be Uint16 (0xFFFF).
122 * At the moment the magnitude variables are mixed between signed/unsigned, and
123 * it is also not made clear that ALL of those variables expect a max of 0x7FFF.
125 * Some platforms may have higher precision than that (Linux FF, Windows XInput)
126 * so we should fix the inconsistency in favor of higher possible precision,
127 * adjusting for platforms that use different scales.
132 * \typedef SDL_Haptic
134 * \brief The haptic structure used to identify an SDL haptic.
137 * \sa SDL_HapticOpenFromJoystick
138 * \sa SDL_HapticClose
141 typedef struct _SDL_Haptic SDL_Haptic;
145 * \name Haptic features
147 * Different haptic features a device can have.
152 * \name Haptic effects
157 * \brief Constant effect supported.
159 * Constant haptic effect.
161 * \sa SDL_HapticCondition
163 #define SDL_HAPTIC_CONSTANT (1u<<0)
166 * \brief Sine wave effect supported.
168 * Periodic haptic effect that simulates sine waves.
170 * \sa SDL_HapticPeriodic
172 #define SDL_HAPTIC_SINE (1u<<1)
175 * \brief Left/Right effect supported.
177 * Haptic effect for direct control over high/low frequency motors.
179 * \sa SDL_HapticLeftRight
180 * \warning this value was SDL_HAPTIC_SQUARE right before 2.0.0 shipped. Sorry,
181 * we ran out of bits, and this is important for XInput devices.
183 #define SDL_HAPTIC_LEFTRIGHT (1u<<2)
185 /* !!! FIXME: put this back when we have more bits in 2.1 */
186 /* #define SDL_HAPTIC_SQUARE (1<<2) */
189 * \brief Triangle wave effect supported.
191 * Periodic haptic effect that simulates triangular waves.
193 * \sa SDL_HapticPeriodic
195 #define SDL_HAPTIC_TRIANGLE (1u<<3)
198 * \brief Sawtoothup wave effect supported.
200 * Periodic haptic effect that simulates saw tooth up waves.
202 * \sa SDL_HapticPeriodic
204 #define SDL_HAPTIC_SAWTOOTHUP (1u<<4)
207 * \brief Sawtoothdown wave effect supported.
209 * Periodic haptic effect that simulates saw tooth down waves.
211 * \sa SDL_HapticPeriodic
213 #define SDL_HAPTIC_SAWTOOTHDOWN (1u<<5)
216 * \brief Ramp effect supported.
218 * Ramp haptic effect.
222 #define SDL_HAPTIC_RAMP (1u<<6)
225 * \brief Spring effect supported - uses axes position.
227 * Condition haptic effect that simulates a spring. Effect is based on the
230 * \sa SDL_HapticCondition
232 #define SDL_HAPTIC_SPRING (1u<<7)
235 * \brief Damper effect supported - uses axes velocity.
237 * Condition haptic effect that simulates dampening. Effect is based on the
240 * \sa SDL_HapticCondition
242 #define SDL_HAPTIC_DAMPER (1u<<8)
245 * \brief Inertia effect supported - uses axes acceleration.
247 * Condition haptic effect that simulates inertia. Effect is based on the axes
250 * \sa SDL_HapticCondition
252 #define SDL_HAPTIC_INERTIA (1u<<9)
255 * \brief Friction effect supported - uses axes movement.
257 * Condition haptic effect that simulates friction. Effect is based on the
260 * \sa SDL_HapticCondition
262 #define SDL_HAPTIC_FRICTION (1u<<10)
265 * \brief Custom effect is supported.
267 * User defined custom haptic effect.
269 #define SDL_HAPTIC_CUSTOM (1u<<11)
271 /* @} *//* Haptic effects */
273 /* These last few are features the device has, not effects */
276 * \brief Device can set global gain.
278 * Device supports setting the global gain.
280 * \sa SDL_HapticSetGain
282 #define SDL_HAPTIC_GAIN (1u<<12)
285 * \brief Device can set autocenter.
287 * Device supports setting autocenter.
289 * \sa SDL_HapticSetAutocenter
291 #define SDL_HAPTIC_AUTOCENTER (1u<<13)
294 * \brief Device can be queried for effect status.
296 * Device supports querying effect status.
298 * \sa SDL_HapticGetEffectStatus
300 #define SDL_HAPTIC_STATUS (1u<<14)
303 * \brief Device can be paused.
305 * Devices supports being paused.
307 * \sa SDL_HapticPause
308 * \sa SDL_HapticUnpause
310 #define SDL_HAPTIC_PAUSE (1u<<15)
314 * \name Direction encodings
319 * \brief Uses polar coordinates for the direction.
321 * \sa SDL_HapticDirection
323 #define SDL_HAPTIC_POLAR 0
326 * \brief Uses cartesian coordinates for the direction.
328 * \sa SDL_HapticDirection
330 #define SDL_HAPTIC_CARTESIAN 1
333 * \brief Uses spherical coordinates for the direction.
335 * \sa SDL_HapticDirection
337 #define SDL_HAPTIC_SPHERICAL 2
340 * \brief Use this value to play an effect on the steering wheel axis. This
341 * provides better compatibility across platforms and devices as SDL will guess
343 * \sa SDL_HapticDirection
345 #define SDL_HAPTIC_STEERING_AXIS 3
347 /* @} *//* Direction encodings */
349 /* @} *//* Haptic features */
356 * \brief Used to play a device an infinite number of times.
358 * \sa SDL_HapticRunEffect
360 #define SDL_HAPTIC_INFINITY 4294967295U
364 * \brief Structure that represents a haptic direction.
366 * This is the direction where the force comes from,
367 * instead of the direction in which the force is exerted.
369 * Directions can be specified by:
370 * - ::SDL_HAPTIC_POLAR : Specified by polar coordinates.
371 * - ::SDL_HAPTIC_CARTESIAN : Specified by cartesian coordinates.
372 * - ::SDL_HAPTIC_SPHERICAL : Specified by spherical coordinates.
374 * Cardinal directions of the haptic device are relative to the positioning
375 * of the device. North is considered to be away from the user.
377 * The following diagram represents the cardinal directions:
392 (-1,0) West <----[ HAPTIC ]----> East (1,0)
405 * If type is ::SDL_HAPTIC_POLAR, direction is encoded by hundredths of a
406 * degree starting north and turning clockwise. ::SDL_HAPTIC_POLAR only uses
407 * the first \c dir parameter. The cardinal directions would be:
408 * - North: 0 (0 degrees)
409 * - East: 9000 (90 degrees)
410 * - South: 18000 (180 degrees)
411 * - West: 27000 (270 degrees)
413 * If type is ::SDL_HAPTIC_CARTESIAN, direction is encoded by three positions
414 * (X axis, Y axis and Z axis (with 3 axes)). ::SDL_HAPTIC_CARTESIAN uses
415 * the first three \c dir parameters. The cardinal directions would be:
421 * The Z axis represents the height of the effect if supported, otherwise
422 * it's unused. In cartesian encoding (1, 2) would be the same as (2, 4), you
423 * can use any multiple you want, only the direction matters.
425 * If type is ::SDL_HAPTIC_SPHERICAL, direction is encoded by two rotations.
426 * The first two \c dir parameters are used. The \c dir parameters are as
427 * follows (all values are in hundredths of degrees):
428 * - Degrees from (1, 0) rotated towards (0, 1).
429 * - Degrees towards (0, 0, 1) (device needs at least 3 axes).
432 * Example of force coming from the south with all encodings (force coming
433 * from the south means the user will have to pull the stick to counteract):
435 * SDL_HapticDirection direction;
437 * // Cartesian directions
438 * direction.type = SDL_HAPTIC_CARTESIAN; // Using cartesian direction encoding.
439 * direction.dir[0] = 0; // X position
440 * direction.dir[1] = 1; // Y position
441 * // Assuming the device has 2 axes, we don't need to specify third parameter.
443 * // Polar directions
444 * direction.type = SDL_HAPTIC_POLAR; // We'll be using polar direction encoding.
445 * direction.dir[0] = 18000; // Polar only uses first parameter
447 * // Spherical coordinates
448 * direction.type = SDL_HAPTIC_SPHERICAL; // Spherical encoding
449 * direction.dir[0] = 9000; // Since we only have two axes we don't need more parameters.
452 * \sa SDL_HAPTIC_POLAR
453 * \sa SDL_HAPTIC_CARTESIAN
454 * \sa SDL_HAPTIC_SPHERICAL
455 * \sa SDL_HAPTIC_STEERING_AXIS
456 * \sa SDL_HapticEffect
457 * \sa SDL_HapticNumAxes
459 typedef struct SDL_HapticDirection
461 Uint8 type; /**< The type of encoding. */
462 Sint32 dir[3]; /**< The encoded direction. */
463 } SDL_HapticDirection;
467 * \brief A structure containing a template for a Constant effect.
469 * This struct is exclusively for the ::SDL_HAPTIC_CONSTANT effect.
471 * A constant effect applies a constant force in the specified direction
474 * \sa SDL_HAPTIC_CONSTANT
475 * \sa SDL_HapticEffect
477 typedef struct SDL_HapticConstant
480 Uint16 type; /**< ::SDL_HAPTIC_CONSTANT */
481 SDL_HapticDirection direction; /**< Direction of the effect. */
484 Uint32 length; /**< Duration of the effect. */
485 Uint16 delay; /**< Delay before starting the effect. */
488 Uint16 button; /**< Button that triggers the effect. */
489 Uint16 interval; /**< How soon it can be triggered again after button. */
492 Sint16 level; /**< Strength of the constant effect. */
495 Uint16 attack_length; /**< Duration of the attack. */
496 Uint16 attack_level; /**< Level at the start of the attack. */
497 Uint16 fade_length; /**< Duration of the fade. */
498 Uint16 fade_level; /**< Level at the end of the fade. */
499 } SDL_HapticConstant;
502 * \brief A structure containing a template for a Periodic effect.
504 * The struct handles the following effects:
505 * - ::SDL_HAPTIC_SINE
506 * - ::SDL_HAPTIC_LEFTRIGHT
507 * - ::SDL_HAPTIC_TRIANGLE
508 * - ::SDL_HAPTIC_SAWTOOTHUP
509 * - ::SDL_HAPTIC_SAWTOOTHDOWN
511 * A periodic effect consists in a wave-shaped effect that repeats itself
512 * over time. The type determines the shape of the wave and the parameters
513 * determine the dimensions of the wave.
515 * Phase is given by hundredth of a degree meaning that giving the phase a value
516 * of 9000 will displace it 25% of its period. Here are sample values:
517 * - 0: No phase displacement.
518 * - 9000: Displaced 25% of its period.
519 * - 18000: Displaced 50% of its period.
520 * - 27000: Displaced 75% of its period.
521 * - 36000: Displaced 100% of its period, same as 0, but 0 is preferred.
533 | |__| |__| |__| |__| |
540 SDL_HAPTIC_SAWTOOTHUP
542 / | / | / | / | / | / | / |
543 / |/ |/ |/ |/ |/ |/ |
545 SDL_HAPTIC_SAWTOOTHDOWN
546 \ |\ |\ |\ |\ |\ |\ |
547 \ | \ | \ | \ | \ | \ | \ |
551 * \sa SDL_HAPTIC_SINE
552 * \sa SDL_HAPTIC_LEFTRIGHT
553 * \sa SDL_HAPTIC_TRIANGLE
554 * \sa SDL_HAPTIC_SAWTOOTHUP
555 * \sa SDL_HAPTIC_SAWTOOTHDOWN
556 * \sa SDL_HapticEffect
558 typedef struct SDL_HapticPeriodic
561 Uint16 type; /**< ::SDL_HAPTIC_SINE, ::SDL_HAPTIC_LEFTRIGHT,
562 ::SDL_HAPTIC_TRIANGLE, ::SDL_HAPTIC_SAWTOOTHUP or
563 ::SDL_HAPTIC_SAWTOOTHDOWN */
564 SDL_HapticDirection direction; /**< Direction of the effect. */
567 Uint32 length; /**< Duration of the effect. */
568 Uint16 delay; /**< Delay before starting the effect. */
571 Uint16 button; /**< Button that triggers the effect. */
572 Uint16 interval; /**< How soon it can be triggered again after button. */
575 Uint16 period; /**< Period of the wave. */
576 Sint16 magnitude; /**< Peak value; if negative, equivalent to 180 degrees extra phase shift. */
577 Sint16 offset; /**< Mean value of the wave. */
578 Uint16 phase; /**< Positive phase shift given by hundredth of a degree. */
581 Uint16 attack_length; /**< Duration of the attack. */
582 Uint16 attack_level; /**< Level at the start of the attack. */
583 Uint16 fade_length; /**< Duration of the fade. */
584 Uint16 fade_level; /**< Level at the end of the fade. */
585 } SDL_HapticPeriodic;
588 * \brief A structure containing a template for a Condition effect.
590 * The struct handles the following effects:
591 * - ::SDL_HAPTIC_SPRING: Effect based on axes position.
592 * - ::SDL_HAPTIC_DAMPER: Effect based on axes velocity.
593 * - ::SDL_HAPTIC_INERTIA: Effect based on axes acceleration.
594 * - ::SDL_HAPTIC_FRICTION: Effect based on axes movement.
596 * Direction is handled by condition internals instead of a direction member.
597 * The condition effect specific members have three parameters. The first
598 * refers to the X axis, the second refers to the Y axis and the third
599 * refers to the Z axis. The right terms refer to the positive side of the
600 * axis and the left terms refer to the negative side of the axis. Please
601 * refer to the ::SDL_HapticDirection diagram for which side is positive and
604 * \sa SDL_HapticDirection
605 * \sa SDL_HAPTIC_SPRING
606 * \sa SDL_HAPTIC_DAMPER
607 * \sa SDL_HAPTIC_INERTIA
608 * \sa SDL_HAPTIC_FRICTION
609 * \sa SDL_HapticEffect
611 typedef struct SDL_HapticCondition
614 Uint16 type; /**< ::SDL_HAPTIC_SPRING, ::SDL_HAPTIC_DAMPER,
615 ::SDL_HAPTIC_INERTIA or ::SDL_HAPTIC_FRICTION */
616 SDL_HapticDirection direction; /**< Direction of the effect - Not used ATM. */
619 Uint32 length; /**< Duration of the effect. */
620 Uint16 delay; /**< Delay before starting the effect. */
623 Uint16 button; /**< Button that triggers the effect. */
624 Uint16 interval; /**< How soon it can be triggered again after button. */
627 Uint16 right_sat[3]; /**< Level when joystick is to the positive side; max 0xFFFF. */
628 Uint16 left_sat[3]; /**< Level when joystick is to the negative side; max 0xFFFF. */
629 Sint16 right_coeff[3]; /**< How fast to increase the force towards the positive side. */
630 Sint16 left_coeff[3]; /**< How fast to increase the force towards the negative side. */
631 Uint16 deadband[3]; /**< Size of the dead zone; max 0xFFFF: whole axis-range when 0-centered. */
632 Sint16 center[3]; /**< Position of the dead zone. */
633 } SDL_HapticCondition;
636 * \brief A structure containing a template for a Ramp effect.
638 * This struct is exclusively for the ::SDL_HAPTIC_RAMP effect.
640 * The ramp effect starts at start strength and ends at end strength.
641 * It augments in linear fashion. If you use attack and fade with a ramp
642 * the effects get added to the ramp effect making the effect become
643 * quadratic instead of linear.
645 * \sa SDL_HAPTIC_RAMP
646 * \sa SDL_HapticEffect
648 typedef struct SDL_HapticRamp
651 Uint16 type; /**< ::SDL_HAPTIC_RAMP */
652 SDL_HapticDirection direction; /**< Direction of the effect. */
655 Uint32 length; /**< Duration of the effect. */
656 Uint16 delay; /**< Delay before starting the effect. */
659 Uint16 button; /**< Button that triggers the effect. */
660 Uint16 interval; /**< How soon it can be triggered again after button. */
663 Sint16 start; /**< Beginning strength level. */
664 Sint16 end; /**< Ending strength level. */
667 Uint16 attack_length; /**< Duration of the attack. */
668 Uint16 attack_level; /**< Level at the start of the attack. */
669 Uint16 fade_length; /**< Duration of the fade. */
670 Uint16 fade_level; /**< Level at the end of the fade. */
674 * \brief A structure containing a template for a Left/Right effect.
676 * This struct is exclusively for the ::SDL_HAPTIC_LEFTRIGHT effect.
678 * The Left/Right effect is used to explicitly control the large and small
679 * motors, commonly found in modern game controllers. The small (right) motor
680 * is high frequency, and the large (left) motor is low frequency.
682 * \sa SDL_HAPTIC_LEFTRIGHT
683 * \sa SDL_HapticEffect
685 typedef struct SDL_HapticLeftRight
688 Uint16 type; /**< ::SDL_HAPTIC_LEFTRIGHT */
691 Uint32 length; /**< Duration of the effect in milliseconds. */
694 Uint16 large_magnitude; /**< Control of the large controller motor. */
695 Uint16 small_magnitude; /**< Control of the small controller motor. */
696 } SDL_HapticLeftRight;
699 * \brief A structure containing a template for the ::SDL_HAPTIC_CUSTOM effect.
701 * This struct is exclusively for the ::SDL_HAPTIC_CUSTOM effect.
703 * A custom force feedback effect is much like a periodic effect, where the
704 * application can define its exact shape. You will have to allocate the
705 * data yourself. Data should consist of channels * samples Uint16 samples.
707 * If channels is one, the effect is rotated using the defined direction.
708 * Otherwise it uses the samples in data for the different axes.
710 * \sa SDL_HAPTIC_CUSTOM
711 * \sa SDL_HapticEffect
713 typedef struct SDL_HapticCustom
716 Uint16 type; /**< ::SDL_HAPTIC_CUSTOM */
717 SDL_HapticDirection direction; /**< Direction of the effect. */
720 Uint32 length; /**< Duration of the effect. */
721 Uint16 delay; /**< Delay before starting the effect. */
724 Uint16 button; /**< Button that triggers the effect. */
725 Uint16 interval; /**< How soon it can be triggered again after button. */
728 Uint8 channels; /**< Axes to use, minimum of one. */
729 Uint16 period; /**< Sample periods. */
730 Uint16 samples; /**< Amount of samples. */
731 Uint16 *data; /**< Should contain channels*samples items. */
734 Uint16 attack_length; /**< Duration of the attack. */
735 Uint16 attack_level; /**< Level at the start of the attack. */
736 Uint16 fade_length; /**< Duration of the fade. */
737 Uint16 fade_level; /**< Level at the end of the fade. */
741 * \brief The generic template for any haptic effect.
743 * All values max at 32767 (0x7FFF). Signed values also can be negative.
744 * Time values unless specified otherwise are in milliseconds.
746 * You can also pass ::SDL_HAPTIC_INFINITY to length instead of a 0-32767
747 * value. Neither delay, interval, attack_length nor fade_length support
748 * ::SDL_HAPTIC_INFINITY. Fade will also not be used since effect never ends.
750 * Additionally, the ::SDL_HAPTIC_RAMP effect does not support a duration of
751 * ::SDL_HAPTIC_INFINITY.
753 * Button triggers may not be supported on all devices, it is advised to not
754 * use them if possible. Buttons start at index 1 instead of index 0 like
757 * If both attack_length and fade_level are 0, the envelope is not used,
758 * otherwise both values are used.
762 * // Replay - All effects have this
763 * Uint32 length; // Duration of effect (ms).
764 * Uint16 delay; // Delay before starting effect.
766 * // Trigger - All effects have this
767 * Uint16 button; // Button that triggers effect.
768 * Uint16 interval; // How soon before effect can be triggered again.
770 * // Envelope - All effects except condition effects have this
771 * Uint16 attack_length; // Duration of the attack (ms).
772 * Uint16 attack_level; // Level at the start of the attack.
773 * Uint16 fade_length; // Duration of the fade out (ms).
774 * Uint16 fade_level; // Level at the end of the fade.
778 * Here we have an example of a constant effect evolution in time:
783 | effect level --> _________________
788 | attack_level --> | \
789 | | | <--- fade_level
791 +--------------------------------------------------> Time
793 attack_length fade_length
795 [------------------][-----------------------]
799 * Note either the attack_level or the fade_level may be above the actual
802 * \sa SDL_HapticConstant
803 * \sa SDL_HapticPeriodic
804 * \sa SDL_HapticCondition
806 * \sa SDL_HapticLeftRight
807 * \sa SDL_HapticCustom
809 typedef union SDL_HapticEffect
811 /* Common for all force feedback effects */
812 Uint16 type; /**< Effect type. */
813 SDL_HapticConstant constant; /**< Constant effect. */
814 SDL_HapticPeriodic periodic; /**< Periodic effect. */
815 SDL_HapticCondition condition; /**< Condition effect. */
816 SDL_HapticRamp ramp; /**< Ramp effect. */
817 SDL_HapticLeftRight leftright; /**< Left/Right effect. */
818 SDL_HapticCustom custom; /**< Custom effect. */
822 /* Function prototypes */
824 * \brief Count the number of haptic devices attached to the system.
826 * \return Number of haptic devices detected on the system.
828 extern DECLSPEC int SDLCALL SDL_NumHaptics(void);
831 * \brief Get the implementation dependent name of a haptic device.
833 * This can be called before any joysticks are opened.
834 * If no name can be found, this function returns NULL.
836 * \param device_index Index of the device to get its name.
837 * \return Name of the device or NULL on error.
841 extern DECLSPEC const char *SDLCALL SDL_HapticName(int device_index);
844 * \brief Opens a haptic device for use.
846 * The index passed as an argument refers to the N'th haptic device on this
849 * When opening a haptic device, its gain will be set to maximum and
850 * autocenter will be disabled. To modify these values use
851 * SDL_HapticSetGain() and SDL_HapticSetAutocenter().
853 * \param device_index Index of the device to open.
854 * \return Device identifier or NULL on error.
856 * \sa SDL_HapticIndex
857 * \sa SDL_HapticOpenFromMouse
858 * \sa SDL_HapticOpenFromJoystick
859 * \sa SDL_HapticClose
860 * \sa SDL_HapticSetGain
861 * \sa SDL_HapticSetAutocenter
862 * \sa SDL_HapticPause
863 * \sa SDL_HapticStopAll
865 extern DECLSPEC SDL_Haptic *SDLCALL SDL_HapticOpen(int device_index);
868 * \brief Checks if the haptic device at index has been opened.
870 * \param device_index Index to check to see if it has been opened.
871 * \return 1 if it has been opened or 0 if it hasn't.
874 * \sa SDL_HapticIndex
876 extern DECLSPEC int SDLCALL SDL_HapticOpened(int device_index);
879 * \brief Gets the index of a haptic device.
881 * \param haptic Haptic device to get the index of.
882 * \return The index of the haptic device or -1 on error.
885 * \sa SDL_HapticOpened
887 extern DECLSPEC int SDLCALL SDL_HapticIndex(SDL_Haptic * haptic);
890 * \brief Gets whether or not the current mouse has haptic capabilities.
892 * \return SDL_TRUE if the mouse is haptic, SDL_FALSE if it isn't.
894 * \sa SDL_HapticOpenFromMouse
896 extern DECLSPEC int SDLCALL SDL_MouseIsHaptic(void);
899 * \brief Tries to open a haptic device from the current mouse.
901 * \return The haptic device identifier or NULL on error.
903 * \sa SDL_MouseIsHaptic
906 extern DECLSPEC SDL_Haptic *SDLCALL SDL_HapticOpenFromMouse(void);
909 * \brief Checks to see if a joystick has haptic features.
911 * \param joystick Joystick to test for haptic capabilities.
912 * \return SDL_TRUE if the joystick is haptic, SDL_FALSE if it isn't
913 * or -1 if an error occurred.
915 * \sa SDL_HapticOpenFromJoystick
917 extern DECLSPEC int SDLCALL SDL_JoystickIsHaptic(SDL_Joystick * joystick);
920 * \brief Opens a haptic device for use from a joystick device.
922 * You must still close the haptic device separately. It will not be closed
925 * When opening from a joystick you should first close the haptic device before
926 * closing the joystick device. If not, on some implementations the haptic
927 * device will also get unallocated and you'll be unable to use force feedback
930 * \param joystick Joystick to create a haptic device from.
931 * \return A valid haptic device identifier on success or NULL on error.
934 * \sa SDL_HapticClose
936 extern DECLSPEC SDL_Haptic *SDLCALL SDL_HapticOpenFromJoystick(SDL_Joystick *
940 * \brief Closes a haptic device previously opened with SDL_HapticOpen().
942 * \param haptic Haptic device to close.
944 extern DECLSPEC void SDLCALL SDL_HapticClose(SDL_Haptic * haptic);
947 * \brief Returns the number of effects a haptic device can store.
949 * On some platforms this isn't fully supported, and therefore is an
950 * approximation. Always check to see if your created effect was actually
951 * created and do not rely solely on SDL_HapticNumEffects().
953 * \param haptic The haptic device to query effect max.
954 * \return The number of effects the haptic device can store or
957 * \sa SDL_HapticNumEffectsPlaying
958 * \sa SDL_HapticQuery
960 extern DECLSPEC int SDLCALL SDL_HapticNumEffects(SDL_Haptic * haptic);
963 * \brief Returns the number of effects a haptic device can play at the same
966 * This is not supported on all platforms, but will always return a value.
967 * Added here for the sake of completeness.
969 * \param haptic The haptic device to query maximum playing effects.
970 * \return The number of effects the haptic device can play at the same time
973 * \sa SDL_HapticNumEffects
974 * \sa SDL_HapticQuery
976 extern DECLSPEC int SDLCALL SDL_HapticNumEffectsPlaying(SDL_Haptic * haptic);
979 * \brief Gets the haptic device's supported features in bitwise manner.
983 * if (SDL_HapticQuery(haptic) & SDL_HAPTIC_CONSTANT) {
984 * printf("We have constant haptic effect!\n");
988 * \param haptic The haptic device to query.
989 * \return Haptic features in bitwise manner (OR'd).
991 * \sa SDL_HapticNumEffects
992 * \sa SDL_HapticEffectSupported
994 extern DECLSPEC unsigned int SDLCALL SDL_HapticQuery(SDL_Haptic * haptic);
998 * \brief Gets the number of haptic axes the device has.
1000 * \sa SDL_HapticDirection
1002 extern DECLSPEC int SDLCALL SDL_HapticNumAxes(SDL_Haptic * haptic);
1005 * \brief Checks to see if effect is supported by haptic.
1007 * \param haptic Haptic device to check on.
1008 * \param effect Effect to check to see if it is supported.
1009 * \return SDL_TRUE if effect is supported, SDL_FALSE if it isn't or -1 on error.
1011 * \sa SDL_HapticQuery
1012 * \sa SDL_HapticNewEffect
1014 extern DECLSPEC int SDLCALL SDL_HapticEffectSupported(SDL_Haptic * haptic,
1019 * \brief Creates a new haptic effect on the device.
1021 * \param haptic Haptic device to create the effect on.
1022 * \param effect Properties of the effect to create.
1023 * \return The identifier of the effect on success or -1 on error.
1025 * \sa SDL_HapticUpdateEffect
1026 * \sa SDL_HapticRunEffect
1027 * \sa SDL_HapticDestroyEffect
1029 extern DECLSPEC int SDLCALL SDL_HapticNewEffect(SDL_Haptic * haptic,
1030 SDL_HapticEffect * effect);
1033 * \brief Updates the properties of an effect.
1035 * Can be used dynamically, although behavior when dynamically changing
1036 * direction may be strange. Specifically the effect may reupload itself
1037 * and start playing from the start. You cannot change the type either when
1038 * running SDL_HapticUpdateEffect().
1040 * \param haptic Haptic device that has the effect.
1041 * \param effect Identifier of the effect to update.
1042 * \param data New effect properties to use.
1043 * \return 0 on success or -1 on error.
1045 * \sa SDL_HapticNewEffect
1046 * \sa SDL_HapticRunEffect
1047 * \sa SDL_HapticDestroyEffect
1049 extern DECLSPEC int SDLCALL SDL_HapticUpdateEffect(SDL_Haptic * haptic,
1051 SDL_HapticEffect * data);
1054 * \brief Runs the haptic effect on its associated haptic device.
1056 * If iterations are ::SDL_HAPTIC_INFINITY, it'll run the effect over and over
1057 * repeating the envelope (attack and fade) every time. If you only want the
1058 * effect to last forever, set ::SDL_HAPTIC_INFINITY in the effect's length
1061 * \param haptic Haptic device to run the effect on.
1062 * \param effect Identifier of the haptic effect to run.
1063 * \param iterations Number of iterations to run the effect. Use
1064 * ::SDL_HAPTIC_INFINITY for infinity.
1065 * \return 0 on success or -1 on error.
1067 * \sa SDL_HapticStopEffect
1068 * \sa SDL_HapticDestroyEffect
1069 * \sa SDL_HapticGetEffectStatus
1071 extern DECLSPEC int SDLCALL SDL_HapticRunEffect(SDL_Haptic * haptic,
1076 * \brief Stops the haptic effect on its associated haptic device.
1078 * \param haptic Haptic device to stop the effect on.
1079 * \param effect Identifier of the effect to stop.
1080 * \return 0 on success or -1 on error.
1082 * \sa SDL_HapticRunEffect
1083 * \sa SDL_HapticDestroyEffect
1085 extern DECLSPEC int SDLCALL SDL_HapticStopEffect(SDL_Haptic * haptic,
1089 * \brief Destroys a haptic effect on the device.
1091 * This will stop the effect if it's running. Effects are automatically
1092 * destroyed when the device is closed.
1094 * \param haptic Device to destroy the effect on.
1095 * \param effect Identifier of the effect to destroy.
1097 * \sa SDL_HapticNewEffect
1099 extern DECLSPEC void SDLCALL SDL_HapticDestroyEffect(SDL_Haptic * haptic,
1103 * \brief Gets the status of the current effect on the haptic device.
1105 * Device must support the ::SDL_HAPTIC_STATUS feature.
1107 * \param haptic Haptic device to query the effect status on.
1108 * \param effect Identifier of the effect to query its status.
1109 * \return 0 if it isn't playing, 1 if it is playing or -1 on error.
1111 * \sa SDL_HapticRunEffect
1112 * \sa SDL_HapticStopEffect
1114 extern DECLSPEC int SDLCALL SDL_HapticGetEffectStatus(SDL_Haptic * haptic,
1118 * \brief Sets the global gain of the device.
1120 * Device must support the ::SDL_HAPTIC_GAIN feature.
1122 * The user may specify the maximum gain by setting the environment variable
1123 * SDL_HAPTIC_GAIN_MAX which should be between 0 and 100. All calls to
1124 * SDL_HapticSetGain() will scale linearly using SDL_HAPTIC_GAIN_MAX as the
1127 * \param haptic Haptic device to set the gain on.
1128 * \param gain Value to set the gain to, should be between 0 and 100.
1129 * \return 0 on success or -1 on error.
1131 * \sa SDL_HapticQuery
1133 extern DECLSPEC int SDLCALL SDL_HapticSetGain(SDL_Haptic * haptic, int gain);
1136 * \brief Sets the global autocenter of the device.
1138 * Autocenter should be between 0 and 100. Setting it to 0 will disable
1141 * Device must support the ::SDL_HAPTIC_AUTOCENTER feature.
1143 * \param haptic Haptic device to set autocentering on.
1144 * \param autocenter Value to set autocenter to, 0 disables autocentering.
1145 * \return 0 on success or -1 on error.
1147 * \sa SDL_HapticQuery
1149 extern DECLSPEC int SDLCALL SDL_HapticSetAutocenter(SDL_Haptic * haptic,
1153 * \brief Pauses a haptic device.
1155 * Device must support the ::SDL_HAPTIC_PAUSE feature. Call
1156 * SDL_HapticUnpause() to resume playback.
1158 * Do not modify the effects nor add new ones while the device is paused.
1159 * That can cause all sorts of weird errors.
1161 * \param haptic Haptic device to pause.
1162 * \return 0 on success or -1 on error.
1164 * \sa SDL_HapticUnpause
1166 extern DECLSPEC int SDLCALL SDL_HapticPause(SDL_Haptic * haptic);
1169 * \brief Unpauses a haptic device.
1171 * Call to unpause after SDL_HapticPause().
1173 * \param haptic Haptic device to unpause.
1174 * \return 0 on success or -1 on error.
1176 * \sa SDL_HapticPause
1178 extern DECLSPEC int SDLCALL SDL_HapticUnpause(SDL_Haptic * haptic);
1181 * \brief Stops all the currently playing effects on a haptic device.
1183 * \param haptic Haptic device to stop.
1184 * \return 0 on success or -1 on error.
1186 extern DECLSPEC int SDLCALL SDL_HapticStopAll(SDL_Haptic * haptic);
1189 * \brief Checks to see if rumble is supported on a haptic device.
1191 * \param haptic Haptic device to check to see if it supports rumble.
1192 * \return SDL_TRUE if effect is supported, SDL_FALSE if it isn't or -1 on error.
1194 * \sa SDL_HapticRumbleInit
1195 * \sa SDL_HapticRumblePlay
1196 * \sa SDL_HapticRumbleStop
1198 extern DECLSPEC int SDLCALL SDL_HapticRumbleSupported(SDL_Haptic * haptic);
1201 * \brief Initializes the haptic device for simple rumble playback.
1203 * \param haptic Haptic device to initialize for simple rumble playback.
1204 * \return 0 on success or -1 on error.
1206 * \sa SDL_HapticOpen
1207 * \sa SDL_HapticRumbleSupported
1208 * \sa SDL_HapticRumblePlay
1209 * \sa SDL_HapticRumbleStop
1211 extern DECLSPEC int SDLCALL SDL_HapticRumbleInit(SDL_Haptic * haptic);
1214 * \brief Runs simple rumble on a haptic device
1216 * \param haptic Haptic device to play rumble effect on.
1217 * \param strength Strength of the rumble to play as a 0-1 float value.
1218 * \param length Length of the rumble to play in milliseconds.
1219 * \return 0 on success or -1 on error.
1221 * \sa SDL_HapticRumbleSupported
1222 * \sa SDL_HapticRumbleInit
1223 * \sa SDL_HapticRumbleStop
1225 extern DECLSPEC int SDLCALL SDL_HapticRumblePlay(SDL_Haptic * haptic, float strength, Uint32 length );
1228 * \brief Stops the simple rumble on a haptic device.
1230 * \param haptic Haptic to stop the rumble on.
1231 * \return 0 on success or -1 on error.
1233 * \sa SDL_HapticRumbleSupported
1234 * \sa SDL_HapticRumbleInit
1235 * \sa SDL_HapticRumblePlay
1237 extern DECLSPEC int SDLCALL SDL_HapticRumbleStop(SDL_Haptic * haptic);
1239 /* Ends C function definitions when using C++ */
1243 #include "close_code.h"
1245 #endif /* SDL_haptic_h_ */
1247 /* vi: set ts=4 sw=4 expandtab: */