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