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