include/SDL_haptic.h
author Ryan C. Gordon <icculus@icculus.org>
Tue, 15 Dec 2009 18:00:16 +0000
changeset 3567 fb9ea4b549c3
parent 3496 78fc8ea578b2
child 5126 ad4141d88412
permissions -rw-r--r--
Added a warning comment to SDL_putenv().

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