include/SDL_haptic.h
author Sam Lantinga <slouken@libsdl.org>
Mon, 25 Aug 2008 09:55:03 +0000
changeset 2713 0906692aa6a4
child 3407 d3baf5ac4e37
permissions -rw-r--r--
Final merge of Google Summer of Code 2008 work...

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