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