2 Simple DirectMedia Layer
3 Copyright (C) 1997-2016 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 */
121 * \typedef SDL_Haptic
123 * \brief The haptic structure used to identify an SDL haptic.
126 * \sa SDL_HapticOpenFromJoystick
127 * \sa SDL_HapticClose
130 typedef struct _SDL_Haptic SDL_Haptic;
134 * \name Haptic features
136 * Different haptic features a device can have.
141 * \name Haptic effects
146 * \brief Constant effect supported.
148 * Constant haptic effect.
150 * \sa SDL_HapticCondition
152 #define SDL_HAPTIC_CONSTANT (1u<<0)
155 * \brief Sine wave effect supported.
157 * Periodic haptic effect that simulates sine waves.
159 * \sa SDL_HapticPeriodic
161 #define SDL_HAPTIC_SINE (1u<<1)
164 * \brief Left/Right effect supported.
166 * Haptic effect for direct control over high/low frequency motors.
168 * \sa SDL_HapticLeftRight
169 * \warning this value was SDL_HAPTIC_SQUARE right before 2.0.0 shipped. Sorry,
170 * we ran out of bits, and this is important for XInput devices.
172 #define SDL_HAPTIC_LEFTRIGHT (1u<<2)
174 /* !!! FIXME: put this back when we have more bits in 2.1 */
175 /* #define SDL_HAPTIC_SQUARE (1<<2) */
178 * \brief Triangle wave effect supported.
180 * Periodic haptic effect that simulates triangular waves.
182 * \sa SDL_HapticPeriodic
184 #define SDL_HAPTIC_TRIANGLE (1u<<3)
187 * \brief Sawtoothup wave effect supported.
189 * Periodic haptic effect that simulates saw tooth up waves.
191 * \sa SDL_HapticPeriodic
193 #define SDL_HAPTIC_SAWTOOTHUP (1u<<4)
196 * \brief Sawtoothdown wave effect supported.
198 * Periodic haptic effect that simulates saw tooth down waves.
200 * \sa SDL_HapticPeriodic
202 #define SDL_HAPTIC_SAWTOOTHDOWN (1u<<5)
205 * \brief Ramp effect supported.
207 * Ramp haptic effect.
211 #define SDL_HAPTIC_RAMP (1u<<6)
214 * \brief Spring effect supported - uses axes position.
216 * Condition haptic effect that simulates a spring. Effect is based on the
219 * \sa SDL_HapticCondition
221 #define SDL_HAPTIC_SPRING (1u<<7)
224 * \brief Damper effect supported - uses axes velocity.
226 * Condition haptic effect that simulates dampening. Effect is based on the
229 * \sa SDL_HapticCondition
231 #define SDL_HAPTIC_DAMPER (1u<<8)
234 * \brief Inertia effect supported - uses axes acceleration.
236 * Condition haptic effect that simulates inertia. Effect is based on the axes
239 * \sa SDL_HapticCondition
241 #define SDL_HAPTIC_INERTIA (1u<<9)
244 * \brief Friction effect supported - uses axes movement.
246 * Condition haptic effect that simulates friction. Effect is based on the
249 * \sa SDL_HapticCondition
251 #define SDL_HAPTIC_FRICTION (1u<<10)
254 * \brief Custom effect is supported.
256 * User defined custom haptic effect.
258 #define SDL_HAPTIC_CUSTOM (1u<<11)
260 /* @} *//* Haptic effects */
262 /* These last few are features the device has, not effects */
265 * \brief Device can set global gain.
267 * Device supports setting the global gain.
269 * \sa SDL_HapticSetGain
271 #define SDL_HAPTIC_GAIN (1u<<12)
274 * \brief Device can set autocenter.
276 * Device supports setting autocenter.
278 * \sa SDL_HapticSetAutocenter
280 #define SDL_HAPTIC_AUTOCENTER (1u<<13)
283 * \brief Device can be queried for effect status.
285 * Device can be queried for effect status.
287 * \sa SDL_HapticGetEffectStatus
289 #define SDL_HAPTIC_STATUS (1u<<14)
292 * \brief Device can be paused.
294 * \sa SDL_HapticPause
295 * \sa SDL_HapticUnpause
297 #define SDL_HAPTIC_PAUSE (1u<<15)
301 * \name Direction encodings
306 * \brief Uses polar coordinates for the direction.
308 * \sa SDL_HapticDirection
310 #define SDL_HAPTIC_POLAR 0
313 * \brief Uses cartesian coordinates for the direction.
315 * \sa SDL_HapticDirection
317 #define SDL_HAPTIC_CARTESIAN 1
320 * \brief Uses spherical coordinates for the direction.
322 * \sa SDL_HapticDirection
324 #define SDL_HAPTIC_SPHERICAL 2
326 /* @} *//* Direction encodings */
328 /* @} *//* Haptic features */
335 * \brief Used to play a device an infinite number of times.
337 * \sa SDL_HapticRunEffect
339 #define SDL_HAPTIC_INFINITY 4294967295U
343 * \brief Structure that represents a haptic direction.
345 * This is the direction where the force comes from,
346 * instead of the direction in which the force is exerted.
348 * Directions can be specified by:
349 * - ::SDL_HAPTIC_POLAR : Specified by polar coordinates.
350 * - ::SDL_HAPTIC_CARTESIAN : Specified by cartesian coordinates.
351 * - ::SDL_HAPTIC_SPHERICAL : Specified by spherical coordinates.
353 * Cardinal directions of the haptic device are relative to the positioning
354 * of the device. North is considered to be away from the user.
356 * The following diagram represents the cardinal directions:
371 (-1,0) West <----[ HAPTIC ]----> East (1,0)
384 * If type is ::SDL_HAPTIC_POLAR, direction is encoded by hundredths of a
385 * degree starting north and turning clockwise. ::SDL_HAPTIC_POLAR only uses
386 * the first \c dir parameter. The cardinal directions would be:
387 * - North: 0 (0 degrees)
388 * - East: 9000 (90 degrees)
389 * - South: 18000 (180 degrees)
390 * - West: 27000 (270 degrees)
392 * If type is ::SDL_HAPTIC_CARTESIAN, direction is encoded by three positions
393 * (X axis, Y axis and Z axis (with 3 axes)). ::SDL_HAPTIC_CARTESIAN uses
394 * the first three \c dir parameters. The cardinal directions would be:
400 * The Z axis represents the height of the effect if supported, otherwise
401 * it's unused. In cartesian encoding (1, 2) would be the same as (2, 4), you
402 * can use any multiple you want, only the direction matters.
404 * If type is ::SDL_HAPTIC_SPHERICAL, direction is encoded by two rotations.
405 * The first two \c dir parameters are used. The \c dir parameters are as
406 * follows (all values are in hundredths of degrees):
407 * - Degrees from (1, 0) rotated towards (0, 1).
408 * - Degrees towards (0, 0, 1) (device needs at least 3 axes).
411 * Example of force coming from the south with all encodings (force coming
412 * from the south means the user will have to pull the stick to counteract):
414 * SDL_HapticDirection direction;
416 * // Cartesian directions
417 * direction.type = SDL_HAPTIC_CARTESIAN; // Using cartesian direction encoding.
418 * direction.dir[0] = 0; // X position
419 * direction.dir[1] = 1; // Y position
420 * // Assuming the device has 2 axes, we don't need to specify third parameter.
422 * // Polar directions
423 * direction.type = SDL_HAPTIC_POLAR; // We'll be using polar direction encoding.
424 * direction.dir[0] = 18000; // Polar only uses first parameter
426 * // Spherical coordinates
427 * direction.type = SDL_HAPTIC_SPHERICAL; // Spherical encoding
428 * direction.dir[0] = 9000; // Since we only have two axes we don't need more parameters.
431 * \sa SDL_HAPTIC_POLAR
432 * \sa SDL_HAPTIC_CARTESIAN
433 * \sa SDL_HAPTIC_SPHERICAL
434 * \sa SDL_HapticEffect
435 * \sa SDL_HapticNumAxes
437 typedef struct SDL_HapticDirection
439 Uint8 type; /**< The type of encoding. */
440 Sint32 dir[3]; /**< The encoded direction. */
441 } SDL_HapticDirection;
445 * \brief A structure containing a template for a Constant effect.
447 * The struct is exclusive to the ::SDL_HAPTIC_CONSTANT effect.
449 * A constant effect applies a constant force in the specified direction
452 * \sa SDL_HAPTIC_CONSTANT
453 * \sa SDL_HapticEffect
455 typedef struct SDL_HapticConstant
458 Uint16 type; /**< ::SDL_HAPTIC_CONSTANT */
459 SDL_HapticDirection direction; /**< Direction of the effect. */
462 Uint32 length; /**< Duration of the effect. */
463 Uint16 delay; /**< Delay before starting the effect. */
466 Uint16 button; /**< Button that triggers the effect. */
467 Uint16 interval; /**< How soon it can be triggered again after button. */
470 Sint16 level; /**< Strength of the constant effect. */
473 Uint16 attack_length; /**< Duration of the attack. */
474 Uint16 attack_level; /**< Level at the start of the attack. */
475 Uint16 fade_length; /**< Duration of the fade. */
476 Uint16 fade_level; /**< Level at the end of the fade. */
477 } SDL_HapticConstant;
480 * \brief A structure containing a template for a Periodic effect.
482 * The struct handles the following effects:
483 * - ::SDL_HAPTIC_SINE
484 * - ::SDL_HAPTIC_LEFTRIGHT
485 * - ::SDL_HAPTIC_TRIANGLE
486 * - ::SDL_HAPTIC_SAWTOOTHUP
487 * - ::SDL_HAPTIC_SAWTOOTHDOWN
489 * A periodic effect consists in a wave-shaped effect that repeats itself
490 * over time. The type determines the shape of the wave and the parameters
491 * determine the dimensions of the wave.
493 * Phase is given by hundredth of a degree meaning that giving the phase a value
494 * of 9000 will displace it 25% of its period. Here are sample values:
495 * - 0: No phase displacement.
496 * - 9000: Displaced 25% of its period.
497 * - 18000: Displaced 50% of its period.
498 * - 27000: Displaced 75% of its period.
499 * - 36000: Displaced 100% of its period, same as 0, but 0 is preferred.
511 | |__| |__| |__| |__| |
518 SDL_HAPTIC_SAWTOOTHUP
520 / | / | / | / | / | / | / |
521 / |/ |/ |/ |/ |/ |/ |
523 SDL_HAPTIC_SAWTOOTHDOWN
524 \ |\ |\ |\ |\ |\ |\ |
525 \ | \ | \ | \ | \ | \ | \ |
529 * \sa SDL_HAPTIC_SINE
530 * \sa SDL_HAPTIC_LEFTRIGHT
531 * \sa SDL_HAPTIC_TRIANGLE
532 * \sa SDL_HAPTIC_SAWTOOTHUP
533 * \sa SDL_HAPTIC_SAWTOOTHDOWN
534 * \sa SDL_HapticEffect
536 typedef struct SDL_HapticPeriodic
539 Uint16 type; /**< ::SDL_HAPTIC_SINE, ::SDL_HAPTIC_LEFTRIGHT,
540 ::SDL_HAPTIC_TRIANGLE, ::SDL_HAPTIC_SAWTOOTHUP or
541 ::SDL_HAPTIC_SAWTOOTHDOWN */
542 SDL_HapticDirection direction; /**< Direction of the effect. */
545 Uint32 length; /**< Duration of the effect. */
546 Uint16 delay; /**< Delay before starting the effect. */
549 Uint16 button; /**< Button that triggers the effect. */
550 Uint16 interval; /**< How soon it can be triggered again after button. */
553 Uint16 period; /**< Period of the wave. */
554 Sint16 magnitude; /**< Peak value; if negative, equivalent to 180 degrees extra phase shift. */
555 Sint16 offset; /**< Mean value of the wave. */
556 Uint16 phase; /**< Positive phase shift given by hundredth of a degree. */
559 Uint16 attack_length; /**< Duration of the attack. */
560 Uint16 attack_level; /**< Level at the start of the attack. */
561 Uint16 fade_length; /**< Duration of the fade. */
562 Uint16 fade_level; /**< Level at the end of the fade. */
563 } SDL_HapticPeriodic;
566 * \brief A structure containing a template for a Condition effect.
568 * The struct handles the following effects:
569 * - ::SDL_HAPTIC_SPRING: Effect based on axes position.
570 * - ::SDL_HAPTIC_DAMPER: Effect based on axes velocity.
571 * - ::SDL_HAPTIC_INERTIA: Effect based on axes acceleration.
572 * - ::SDL_HAPTIC_FRICTION: Effect based on axes movement.
574 * Direction is handled by condition internals instead of a direction member.
575 * The condition effect specific members have three parameters. The first
576 * refers to the X axis, the second refers to the Y axis and the third
577 * refers to the Z axis. The right terms refer to the positive side of the
578 * axis and the left terms refer to the negative side of the axis. Please
579 * refer to the ::SDL_HapticDirection diagram for which side is positive and
582 * \sa SDL_HapticDirection
583 * \sa SDL_HAPTIC_SPRING
584 * \sa SDL_HAPTIC_DAMPER
585 * \sa SDL_HAPTIC_INERTIA
586 * \sa SDL_HAPTIC_FRICTION
587 * \sa SDL_HapticEffect
589 typedef struct SDL_HapticCondition
592 Uint16 type; /**< ::SDL_HAPTIC_SPRING, ::SDL_HAPTIC_DAMPER,
593 ::SDL_HAPTIC_INERTIA or ::SDL_HAPTIC_FRICTION */
594 SDL_HapticDirection direction; /**< Direction of the effect - Not used ATM. */
597 Uint32 length; /**< Duration of the effect. */
598 Uint16 delay; /**< Delay before starting the effect. */
601 Uint16 button; /**< Button that triggers the effect. */
602 Uint16 interval; /**< How soon it can be triggered again after button. */
605 Uint16 right_sat[3]; /**< Level when joystick is to the positive side; max 0xFFFF. */
606 Uint16 left_sat[3]; /**< Level when joystick is to the negative side; max 0xFFFF. */
607 Sint16 right_coeff[3]; /**< How fast to increase the force towards the positive side. */
608 Sint16 left_coeff[3]; /**< How fast to increase the force towards the negative side. */
609 Uint16 deadband[3]; /**< Size of the dead zone; max 0xFFFF: whole axis-range when 0-centered. */
610 Sint16 center[3]; /**< Position of the dead zone. */
611 } SDL_HapticCondition;
614 * \brief A structure containing a template for a Ramp effect.
616 * This struct is exclusively for the ::SDL_HAPTIC_RAMP effect.
618 * The ramp effect starts at start strength and ends at end strength.
619 * It augments in linear fashion. If you use attack and fade with a ramp
620 * the effects get added to the ramp effect making the effect become
621 * quadratic instead of linear.
623 * \sa SDL_HAPTIC_RAMP
624 * \sa SDL_HapticEffect
626 typedef struct SDL_HapticRamp
629 Uint16 type; /**< ::SDL_HAPTIC_RAMP */
630 SDL_HapticDirection direction; /**< Direction of the effect. */
633 Uint32 length; /**< Duration of the effect. */
634 Uint16 delay; /**< Delay before starting the effect. */
637 Uint16 button; /**< Button that triggers the effect. */
638 Uint16 interval; /**< How soon it can be triggered again after button. */
641 Sint16 start; /**< Beginning strength level. */
642 Sint16 end; /**< Ending strength level. */
645 Uint16 attack_length; /**< Duration of the attack. */
646 Uint16 attack_level; /**< Level at the start of the attack. */
647 Uint16 fade_length; /**< Duration of the fade. */
648 Uint16 fade_level; /**< Level at the end of the fade. */
652 * \brief A structure containing a template for a Left/Right effect.
654 * This struct is exclusively for the ::SDL_HAPTIC_LEFTRIGHT effect.
656 * The Left/Right effect is used to explicitly control the large and small
657 * motors, commonly found in modern game controllers. One motor is high
658 * frequency, the other is low frequency.
660 * \sa SDL_HAPTIC_LEFTRIGHT
661 * \sa SDL_HapticEffect
663 typedef struct SDL_HapticLeftRight
666 Uint16 type; /**< ::SDL_HAPTIC_LEFTRIGHT */
669 Uint32 length; /**< Duration of the effect. */
672 Uint16 large_magnitude; /**< Control of the large controller motor. */
673 Uint16 small_magnitude; /**< Control of the small controller motor. */
674 } SDL_HapticLeftRight;
677 * \brief A structure containing a template for the ::SDL_HAPTIC_CUSTOM effect.
679 * A custom force feedback effect is much like a periodic effect, where the
680 * application can define its exact shape. You will have to allocate the
681 * data yourself. Data should consist of channels * samples Uint16 samples.
683 * If channels is one, the effect is rotated using the defined direction.
684 * Otherwise it uses the samples in data for the different axes.
686 * \sa SDL_HAPTIC_CUSTOM
687 * \sa SDL_HapticEffect
689 typedef struct SDL_HapticCustom
692 Uint16 type; /**< ::SDL_HAPTIC_CUSTOM */
693 SDL_HapticDirection direction; /**< Direction of the effect. */
696 Uint32 length; /**< Duration of the effect. */
697 Uint16 delay; /**< Delay before starting the effect. */
700 Uint16 button; /**< Button that triggers the effect. */
701 Uint16 interval; /**< How soon it can be triggered again after button. */
704 Uint8 channels; /**< Axes to use, minimum of one. */
705 Uint16 period; /**< Sample periods. */
706 Uint16 samples; /**< Amount of samples. */
707 Uint16 *data; /**< Should contain channels*samples items. */
710 Uint16 attack_length; /**< Duration of the attack. */
711 Uint16 attack_level; /**< Level at the start of the attack. */
712 Uint16 fade_length; /**< Duration of the fade. */
713 Uint16 fade_level; /**< Level at the end of the fade. */
717 * \brief The generic template for any haptic effect.
719 * All values max at 32767 (0x7FFF). Signed values also can be negative.
720 * Time values unless specified otherwise are in milliseconds.
722 * You can also pass ::SDL_HAPTIC_INFINITY to length instead of a 0-32767
723 * value. Neither delay, interval, attack_length nor fade_length support
724 * ::SDL_HAPTIC_INFINITY. Fade will also not be used since effect never ends.
726 * Additionally, the ::SDL_HAPTIC_RAMP effect does not support a duration of
727 * ::SDL_HAPTIC_INFINITY.
729 * Button triggers may not be supported on all devices, it is advised to not
730 * use them if possible. Buttons start at index 1 instead of index 0 like
733 * If both attack_length and fade_level are 0, the envelope is not used,
734 * otherwise both values are used.
738 * // Replay - All effects have this
739 * Uint32 length; // Duration of effect (ms).
740 * Uint16 delay; // Delay before starting effect.
742 * // Trigger - All effects have this
743 * Uint16 button; // Button that triggers effect.
744 * Uint16 interval; // How soon before effect can be triggered again.
746 * // Envelope - All effects except condition effects have this
747 * Uint16 attack_length; // Duration of the attack (ms).
748 * Uint16 attack_level; // Level at the start of the attack.
749 * Uint16 fade_length; // Duration of the fade out (ms).
750 * Uint16 fade_level; // Level at the end of the fade.
754 * Here we have an example of a constant effect evolution in time:
759 | effect level --> _________________
764 | attack_level --> | \
765 | | | <--- fade_level
767 +--------------------------------------------------> Time
769 attack_length fade_length
771 [------------------][-----------------------]
775 * Note either the attack_level or the fade_level may be above the actual
778 * \sa SDL_HapticConstant
779 * \sa SDL_HapticPeriodic
780 * \sa SDL_HapticCondition
782 * \sa SDL_HapticLeftRight
783 * \sa SDL_HapticCustom
785 typedef union SDL_HapticEffect
787 /* Common for all force feedback effects */
788 Uint16 type; /**< Effect type. */
789 SDL_HapticConstant constant; /**< Constant effect. */
790 SDL_HapticPeriodic periodic; /**< Periodic effect. */
791 SDL_HapticCondition condition; /**< Condition effect. */
792 SDL_HapticRamp ramp; /**< Ramp effect. */
793 SDL_HapticLeftRight leftright; /**< Left/Right effect. */
794 SDL_HapticCustom custom; /**< Custom effect. */
798 /* Function prototypes */
800 * \brief Count the number of haptic devices attached to the system.
802 * \return Number of haptic devices detected on the system.
804 extern DECLSPEC int SDLCALL SDL_NumHaptics(void);
807 * \brief Get the implementation dependent name of a Haptic device.
809 * This can be called before any joysticks are opened.
810 * If no name can be found, this function returns NULL.
812 * \param device_index Index of the device to get its name.
813 * \return Name of the device or NULL on error.
817 extern DECLSPEC const char *SDLCALL SDL_HapticName(int device_index);
820 * \brief Opens a Haptic device for usage.
822 * The index passed as an argument refers to the N'th Haptic device on this
825 * When opening a haptic device, its gain will be set to maximum and
826 * autocenter will be disabled. To modify these values use
827 * SDL_HapticSetGain() and SDL_HapticSetAutocenter().
829 * \param device_index Index of the device to open.
830 * \return Device identifier or NULL on error.
832 * \sa SDL_HapticIndex
833 * \sa SDL_HapticOpenFromMouse
834 * \sa SDL_HapticOpenFromJoystick
835 * \sa SDL_HapticClose
836 * \sa SDL_HapticSetGain
837 * \sa SDL_HapticSetAutocenter
838 * \sa SDL_HapticPause
839 * \sa SDL_HapticStopAll
841 extern DECLSPEC SDL_Haptic *SDLCALL SDL_HapticOpen(int device_index);
844 * \brief Checks if the haptic device at index has been opened.
846 * \param device_index Index to check to see if it has been opened.
847 * \return 1 if it has been opened or 0 if it hasn't.
850 * \sa SDL_HapticIndex
852 extern DECLSPEC int SDLCALL SDL_HapticOpened(int device_index);
855 * \brief Gets the index of a haptic device.
857 * \param haptic Haptic device to get the index of.
858 * \return The index of the haptic device or -1 on error.
861 * \sa SDL_HapticOpened
863 extern DECLSPEC int SDLCALL SDL_HapticIndex(SDL_Haptic * haptic);
866 * \brief Gets whether or not the current mouse has haptic capabilities.
868 * \return SDL_TRUE if the mouse is haptic, SDL_FALSE if it isn't.
870 * \sa SDL_HapticOpenFromMouse
872 extern DECLSPEC int SDLCALL SDL_MouseIsHaptic(void);
875 * \brief Tries to open a haptic device from the current mouse.
877 * \return The haptic device identifier or NULL on error.
879 * \sa SDL_MouseIsHaptic
882 extern DECLSPEC SDL_Haptic *SDLCALL SDL_HapticOpenFromMouse(void);
885 * \brief Checks to see if a joystick has haptic features.
887 * \param joystick Joystick to test for haptic capabilities.
888 * \return 1 if the joystick is haptic, 0 if it isn't
889 * or -1 if an error ocurred.
891 * \sa SDL_HapticOpenFromJoystick
893 extern DECLSPEC int SDLCALL SDL_JoystickIsHaptic(SDL_Joystick * joystick);
896 * \brief Opens a Haptic device for usage from a Joystick device.
898 * You must still close the haptic device separately. It will not be closed
901 * When opening from a joystick you should first close the haptic device before
902 * closing the joystick device. If not, on some implementations the haptic
903 * device will also get unallocated and you'll be unable to use force feedback
906 * \param joystick Joystick to create a haptic device from.
907 * \return A valid haptic device identifier on success or NULL on error.
910 * \sa SDL_HapticClose
912 extern DECLSPEC SDL_Haptic *SDLCALL SDL_HapticOpenFromJoystick(SDL_Joystick *
916 * \brief Closes a Haptic device previously opened with SDL_HapticOpen().
918 * \param haptic Haptic device to close.
920 extern DECLSPEC void SDLCALL SDL_HapticClose(SDL_Haptic * haptic);
923 * \brief Returns the number of effects a haptic device can store.
925 * On some platforms this isn't fully supported, and therefore is an
926 * approximation. Always check to see if your created effect was actually
927 * created and do not rely solely on SDL_HapticNumEffects().
929 * \param haptic The haptic device to query effect max.
930 * \return The number of effects the haptic device can store or
933 * \sa SDL_HapticNumEffectsPlaying
934 * \sa SDL_HapticQuery
936 extern DECLSPEC int SDLCALL SDL_HapticNumEffects(SDL_Haptic * haptic);
939 * \brief Returns the number of effects a haptic device can play at the same
942 * This is not supported on all platforms, but will always return a value.
943 * Added here for the sake of completeness.
945 * \param haptic The haptic device to query maximum playing effects.
946 * \return The number of effects the haptic device can play at the same time
949 * \sa SDL_HapticNumEffects
950 * \sa SDL_HapticQuery
952 extern DECLSPEC int SDLCALL SDL_HapticNumEffectsPlaying(SDL_Haptic * haptic);
955 * \brief Gets the haptic device's supported features in bitwise manner.
959 * if (SDL_HapticQuery(haptic) & SDL_HAPTIC_CONSTANT) {
960 * printf("We have constant haptic effect!");
964 * \param haptic The haptic device to query.
965 * \return Haptic features in bitwise manner (OR'd).
967 * \sa SDL_HapticNumEffects
968 * \sa SDL_HapticEffectSupported
970 extern DECLSPEC unsigned int SDLCALL SDL_HapticQuery(SDL_Haptic * haptic);
974 * \brief Gets the number of haptic axes the device has.
976 * \sa SDL_HapticDirection
978 extern DECLSPEC int SDLCALL SDL_HapticNumAxes(SDL_Haptic * haptic);
981 * \brief Checks to see if effect is supported by haptic.
983 * \param haptic Haptic device to check on.
984 * \param effect Effect to check to see if it is supported.
985 * \return SDL_TRUE if effect is supported, SDL_FALSE if it isn't or -1 on error.
987 * \sa SDL_HapticQuery
988 * \sa SDL_HapticNewEffect
990 extern DECLSPEC int SDLCALL SDL_HapticEffectSupported(SDL_Haptic * haptic,
995 * \brief Creates a new haptic effect on the device.
997 * \param haptic Haptic device to create the effect on.
998 * \param effect Properties of the effect to create.
999 * \return The id of the effect on success or -1 on error.
1001 * \sa SDL_HapticUpdateEffect
1002 * \sa SDL_HapticRunEffect
1003 * \sa SDL_HapticDestroyEffect
1005 extern DECLSPEC int SDLCALL SDL_HapticNewEffect(SDL_Haptic * haptic,
1006 SDL_HapticEffect * effect);
1009 * \brief Updates the properties of an effect.
1011 * Can be used dynamically, although behaviour when dynamically changing
1012 * direction may be strange. Specifically the effect may reupload itself
1013 * and start playing from the start. You cannot change the type either when
1014 * running SDL_HapticUpdateEffect().
1016 * \param haptic Haptic device that has the effect.
1017 * \param effect Effect to update.
1018 * \param data New effect properties to use.
1019 * \return 0 on success or -1 on error.
1021 * \sa SDL_HapticNewEffect
1022 * \sa SDL_HapticRunEffect
1023 * \sa SDL_HapticDestroyEffect
1025 extern DECLSPEC int SDLCALL SDL_HapticUpdateEffect(SDL_Haptic * haptic,
1027 SDL_HapticEffect * data);
1030 * \brief Runs the haptic effect on its associated haptic device.
1032 * If iterations are ::SDL_HAPTIC_INFINITY, it'll run the effect over and over
1033 * repeating the envelope (attack and fade) every time. If you only want the
1034 * effect to last forever, set ::SDL_HAPTIC_INFINITY in the effect's length
1037 * \param haptic Haptic device to run the effect on.
1038 * \param effect Identifier of the haptic effect to run.
1039 * \param iterations Number of iterations to run the effect. Use
1040 * ::SDL_HAPTIC_INFINITY for infinity.
1041 * \return 0 on success or -1 on error.
1043 * \sa SDL_HapticStopEffect
1044 * \sa SDL_HapticDestroyEffect
1045 * \sa SDL_HapticGetEffectStatus
1047 extern DECLSPEC int SDLCALL SDL_HapticRunEffect(SDL_Haptic * haptic,
1052 * \brief Stops the haptic effect on its associated haptic device.
1054 * \param haptic Haptic device to stop the effect on.
1055 * \param effect Identifier of the effect to stop.
1056 * \return 0 on success or -1 on error.
1058 * \sa SDL_HapticRunEffect
1059 * \sa SDL_HapticDestroyEffect
1061 extern DECLSPEC int SDLCALL SDL_HapticStopEffect(SDL_Haptic * haptic,
1065 * \brief Destroys a haptic effect on the device.
1067 * This will stop the effect if it's running. Effects are automatically
1068 * destroyed when the device is closed.
1070 * \param haptic Device to destroy the effect on.
1071 * \param effect Identifier of the effect to destroy.
1073 * \sa SDL_HapticNewEffect
1075 extern DECLSPEC void SDLCALL SDL_HapticDestroyEffect(SDL_Haptic * haptic,
1079 * \brief Gets the status of the current effect on the haptic device.
1081 * Device must support the ::SDL_HAPTIC_STATUS feature.
1083 * \param haptic Haptic device to query the effect status on.
1084 * \param effect Identifier of the effect to query its status.
1085 * \return 0 if it isn't playing, 1 if it is playing or -1 on error.
1087 * \sa SDL_HapticRunEffect
1088 * \sa SDL_HapticStopEffect
1090 extern DECLSPEC int SDLCALL SDL_HapticGetEffectStatus(SDL_Haptic * haptic,
1094 * \brief Sets the global gain of the device.
1096 * Device must support the ::SDL_HAPTIC_GAIN feature.
1098 * The user may specify the maximum gain by setting the environment variable
1099 * SDL_HAPTIC_GAIN_MAX which should be between 0 and 100. All calls to
1100 * SDL_HapticSetGain() will scale linearly using SDL_HAPTIC_GAIN_MAX as the
1103 * \param haptic Haptic device to set the gain on.
1104 * \param gain Value to set the gain to, should be between 0 and 100.
1105 * \return 0 on success or -1 on error.
1107 * \sa SDL_HapticQuery
1109 extern DECLSPEC int SDLCALL SDL_HapticSetGain(SDL_Haptic * haptic, int gain);
1112 * \brief Sets the global autocenter of the device.
1114 * Autocenter should be between 0 and 100. Setting it to 0 will disable
1117 * Device must support the ::SDL_HAPTIC_AUTOCENTER feature.
1119 * \param haptic Haptic device to set autocentering on.
1120 * \param autocenter Value to set autocenter to, 0 disables autocentering.
1121 * \return 0 on success or -1 on error.
1123 * \sa SDL_HapticQuery
1125 extern DECLSPEC int SDLCALL SDL_HapticSetAutocenter(SDL_Haptic * haptic,
1129 * \brief Pauses a haptic device.
1131 * Device must support the ::SDL_HAPTIC_PAUSE feature. Call
1132 * SDL_HapticUnpause() to resume playback.
1134 * Do not modify the effects nor add new ones while the device is paused.
1135 * That can cause all sorts of weird errors.
1137 * \param haptic Haptic device to pause.
1138 * \return 0 on success or -1 on error.
1140 * \sa SDL_HapticUnpause
1142 extern DECLSPEC int SDLCALL SDL_HapticPause(SDL_Haptic * haptic);
1145 * \brief Unpauses a haptic device.
1147 * Call to unpause after SDL_HapticPause().
1149 * \param haptic Haptic device to unpause.
1150 * \return 0 on success or -1 on error.
1152 * \sa SDL_HapticPause
1154 extern DECLSPEC int SDLCALL SDL_HapticUnpause(SDL_Haptic * haptic);
1157 * \brief Stops all the currently playing effects on a haptic device.
1159 * \param haptic Haptic device to stop.
1160 * \return 0 on success or -1 on error.
1162 extern DECLSPEC int SDLCALL SDL_HapticStopAll(SDL_Haptic * haptic);
1165 * \brief Checks to see if rumble is supported on a haptic device.
1167 * \param haptic Haptic device to check to see if it supports rumble.
1168 * \return SDL_TRUE if effect is supported, SDL_FALSE if it isn't or -1 on error.
1170 * \sa SDL_HapticRumbleInit
1171 * \sa SDL_HapticRumblePlay
1172 * \sa SDL_HapticRumbleStop
1174 extern DECLSPEC int SDLCALL SDL_HapticRumbleSupported(SDL_Haptic * haptic);
1177 * \brief Initializes the haptic device for simple rumble playback.
1179 * \param haptic Haptic device to initialize for simple rumble playback.
1180 * \return 0 on success or -1 on error.
1182 * \sa SDL_HapticOpen
1183 * \sa SDL_HapticRumbleSupported
1184 * \sa SDL_HapticRumblePlay
1185 * \sa SDL_HapticRumbleStop
1187 extern DECLSPEC int SDLCALL SDL_HapticRumbleInit(SDL_Haptic * haptic);
1190 * \brief Runs simple rumble on a haptic device
1192 * \param haptic Haptic device to play 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 * \return 0 on success or -1 on error.
1197 * \sa SDL_HapticRumbleSupported
1198 * \sa SDL_HapticRumbleInit
1199 * \sa SDL_HapticRumbleStop
1201 extern DECLSPEC int SDLCALL SDL_HapticRumblePlay(SDL_Haptic * haptic, float strength, Uint32 length );
1204 * \brief Stops the simple rumble on a haptic device.
1206 * \param haptic Haptic to stop the rumble on.
1207 * \return 0 on success or -1 on error.
1209 * \sa SDL_HapticRumbleSupported
1210 * \sa SDL_HapticRumbleInit
1211 * \sa SDL_HapticRumblePlay
1213 extern DECLSPEC int SDLCALL SDL_HapticRumbleStop(SDL_Haptic * haptic);
1215 /* Ends C function definitions when using C++ */
1219 #include "close_code.h"
1221 #endif /* _SDL_haptic_h */
1223 /* vi: set ts=4 sw=4 expandtab: */