include/SDL_haptic.h
author Edgar Simo <bobbens@gmail.com>
Sun, 06 Jul 2008 17:06:37 +0000
branchgsoc2008_force_feedback
changeset 2498 ab567bd667bf
parent 2497 0893fbf73b3d
child 2499 cc2b270608b2
permissions -rw-r--r--
Fixed various mistakes in the doxygen.
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@2498
    23
/** \file SDL_Haptic.h */
bobbens@2498
    24
bobbens@2472
    25
/**
bobbens@2497
    26
 * \mainpage SDL_haptic
bobbens@2472
    27
 *
bobbens@2498
    28
 * \brief The SDL Haptic subsystem allows you to control haptic (force feedback)
bobbens@2497
    29
 *  devices.
bobbens@2497
    30
 *
bobbens@2497
    31
 * The basic usage is as follows:
bobbens@2497
    32
 *   - Initialize the Subsystem (SDL_INIT_HAPTIC).
bobbens@2497
    33
 *   - Open a Haptic Device.
bobbens@2497
    34
 *     - SDL_HapticOpen(...) to open from index.
bobbens@2497
    35
 *     - SDL_HapticOpenFromJoystick(...) to open from an existing joystick.
bobbens@2497
    36
 *   - Create an effect (SDL_HapticEffect).
bobbens@2497
    37
 *   - Upload the effect with SDL_HapticNewEffect(...).
bobbens@2497
    38
 *   - Run the effect with SDL_HapticRunEffect(...).
bobbens@2497
    39
 *   - (optional) Free the effect with SDL_HapticDestroyEffect(...).
bobbens@2497
    40
 *   - Close the haptic device with SDL_HapticClose(...).
bobbens@2497
    41
 *
bobbens@2497
    42
 *
bobbens@2497
    43
 * Example:
bobbens@2497
    44
 *
bobbens@2497
    45
 * \code
bobbens@2497
    46
 * int test_haptic( SDL_Joystick * joystick ) {
bobbens@2497
    47
 *    SDL_Haptic *haptic;
bobbens@2497
    48
 *    SDL_HapticEffect effect;
bobbens@2497
    49
 *    int effect_id;
bobbens@2497
    50
 *
bobbens@2497
    51
 *    // Open the device
bobbens@2497
    52
 *    haptic = SDL_HapticOpenFromJoystick( joystick );
bobbens@2497
    53
 *    if (haptic == NULL) return -1; // Most likely joystick isn't haptic
bobbens@2497
    54
 *
bobbens@2497
    55
 *    // See if it can do sine waves
bobbens@2497
    56
 *    if ((SDL_HapticQueryEffects(haptic) & SDL_HAPTIC_SINE)==0) {
bobbens@2497
    57
 *       SDL_HapticClose(haptic); // No sine effect
bobbens@2497
    58
 *       return -1;
bobbens@2497
    59
 *    }
bobbens@2497
    60
 *
bobbens@2497
    61
 *    // Create the effect
bobbens@2497
    62
 *    memset( &effect, 0, sizeof(SDL_HapticEffect) ); // 0 is safe default
bobbens@2497
    63
 *    effect.type = SDL_HAPTIC_SINE;
bobbens@2497
    64
 *    effect.periodic.period = 1000; // 1000 ms
bobbens@2497
    65
 *    effect.periodic.magnitude = 20000; // 20000/32767 strength
bobbens@2497
    66
 *    effect.periodic.length = 5000; // 5 seconds long
bobbens@2497
    67
 *    effect.periodic.attack_length = 1000; // Takes 1 second to get max strength
bobbens@2497
    68
 *    effect.periodic.fade_length = 1000; // Takes 1 second to fade away
bobbens@2497
    69
 *
bobbens@2497
    70
 *    // Upload the effect
bobbens@2497
    71
 *    effect_id = SDL_HapticNewEffect( haptic, &effect );
bobbens@2497
    72
 *
bobbens@2497
    73
 *    // Test the effect
bobbens@2497
    74
 *    SDL_HapticRunEffect( haptic, effect_id );
bobbens@2497
    75
 *    SDL_Delay( 5000); // Wait for the effect to finish
bobbens@2497
    76
 *
bobbens@2497
    77
 *    // We destroy the effect, although closing the device also does this
bobbens@2497
    78
 *    SDL_HapticDestroyEffect( haptic, effect_id );
bobbens@2497
    79
 *
bobbens@2497
    80
 *    // Close the device
bobbens@2497
    81
 *    SDL_HapticClose(haptic);
bobbens@2497
    82
 *
bobbens@2497
    83
 *    return 0; // Success
bobbens@2497
    84
 * }
bobbens@2497
    85
 * \endcode
bobbens@2497
    86
 *
bobbens@2497
    87
 * \author Edgar Simo Serra
bobbens@2472
    88
 */
bobbens@2472
    89
bobbens@2472
    90
#ifndef _SDL_haptic_h
bobbens@2472
    91
#define _SDL_haptic_h
bobbens@2472
    92
bobbens@2472
    93
#include "SDL_stdinc.h"
bobbens@2472
    94
#include "SDL_error.h"
bobbens@2489
    95
#include "SDL_joystick.h"
bobbens@2472
    96
bobbens@2472
    97
#include "begin_code.h"
bobbens@2472
    98
/* Set up for C function definitions, even when using C++ */
bobbens@2472
    99
#ifdef __cplusplus
bobbens@2472
   100
/* *INDENT-OFF* */
bobbens@2472
   101
extern "C" {
bobbens@2472
   102
   /* *INDENT-ON* */                                                         
bobbens@2497
   103
#endif /* __cpluspuls */
bobbens@2472
   104
bobbens@2497
   105
/**
bobbens@2498
   106
 * \typedef SDL_Haptic
bobbens@2497
   107
 *
bobbens@2497
   108
 * \brief The haptic structure used to identify an SDL haptic.
bobbens@2497
   109
 *
bobbens@2497
   110
 * \sa SDL_HapticOpen
bobbens@2497
   111
 * \sa SDL_HapticOpenFromJoystick
bobbens@2497
   112
 * \sa SDL_HapticClose
bobbens@2497
   113
 */
bobbens@2472
   114
struct _SDL_Haptic;                                                     
bobbens@2472
   115
typedef struct _SDL_Haptic SDL_Haptic;
bobbens@2472
   116
bobbens@2472
   117
bobbens@2495
   118
/*
bobbens@2495
   119
 * Different haptic features a device can have.
bobbens@2495
   120
 */
bobbens@2497
   121
/**
bobbens@2497
   122
 * \def SDL_HAPTIC_CONSTANT
bobbens@2497
   123
 *
bobbens@2497
   124
 * \brief Constant haptic effect.
bobbens@2497
   125
 *
bobbens@2497
   126
 * \sa SDL_HapticCondition
bobbens@2497
   127
 */
bobbens@2495
   128
#define SDL_HAPTIC_CONSTANT   (1<<0) /* Constant effect supported */
bobbens@2497
   129
/**
bobbens@2497
   130
 * \def SDL_HAPTIC_SINE
bobbens@2497
   131
 *
bobbens@2497
   132
 * \brief Periodic haptic effect that simulates sine waves.
bobbens@2497
   133
 *
bobbens@2497
   134
 * \sa SDL_HapticPeriodic
bobbens@2497
   135
 */
bobbens@2495
   136
#define SDL_HAPTIC_SINE       (1<<1) /* Sine wave effect supported */
bobbens@2497
   137
/**
bobbens@2497
   138
 * \def SDL_HAPTIC_SQUARE
bobbens@2497
   139
 *
bobbens@2497
   140
 * \brief Periodic haptic effect that simulates square waves.
bobbens@2497
   141
 *
bobbens@2497
   142
 * \sa SDL_HapticPeriodic
bobbens@2497
   143
 */
bobbens@2495
   144
#define SDL_HAPTIC_SQUARE     (1<<2) /* Square wave effect supported */
bobbens@2497
   145
/**
bobbens@2497
   146
 * \def SDL_HAPTIC_TRIANGLE
bobbens@2497
   147
 *
bobbens@2497
   148
 * \brief Periodic haptic effect that simulates triangular waves.
bobbens@2497
   149
 *
bobbens@2497
   150
 * \sa SDL_HapticPeriodic
bobbens@2497
   151
 */
bobbens@2495
   152
#define SDL_HAPTIC_TRIANGLE   (1<<3) /* Triangle wave effect supported */
bobbens@2497
   153
/**
bobbens@2497
   154
 * \def SDL_HAPTIC_SAWTOOTHUP
bobbens@2497
   155
 *
bobbens@2497
   156
 * \brief Periodic haptic effect that simulates saw tooth up waves.
bobbens@2497
   157
 *
bobbens@2497
   158
 * \sa SDL_HapticPeriodic
bobbens@2497
   159
 */
bobbens@2495
   160
#define SDL_HAPTIC_SAWTOOTHUP (1<<4) /* Sawtoothup wave effect supported */
bobbens@2497
   161
/**
bobbens@2497
   162
 * \def SDL_HAPTIC_SAWTOOTHDOWN
bobbens@2497
   163
 *
bobbens@2497
   164
 * \brief Periodic haptic effect that simulates saw tooth down waves.
bobbens@2497
   165
 *
bobbens@2497
   166
 * \sa SDL_HapticPeriodic
bobbens@2497
   167
 */
bobbens@2495
   168
#define SDL_HAPTIC_SAWTOOTHDOWN (1<<5) /* Sawtoothdown wave effect supported */
bobbens@2497
   169
/**
bobbens@2497
   170
 * \def SDL_HAPTIC_RAMP
bobbens@2497
   171
 *
bobbens@2497
   172
 * \brief Ramp haptic effect.
bobbens@2497
   173
 *
bobbens@2497
   174
 * \sa SDL_HapticRamp
bobbens@2497
   175
 */
bobbens@2495
   176
#define SDL_HAPTIC_RAMP       (1<<6) /* Ramp effect supported */
bobbens@2497
   177
/**
bobbens@2497
   178
 * \def SDL_HAPTIC_SPRING
bobbens@2497
   179
 *
bobbens@2497
   180
 * \brief Condition haptic effect that simulates a spring.  Effect is based on the
bobbens@2497
   181
 * axes position.
bobbens@2497
   182
 *
bobbens@2497
   183
 * \sa SDL_HapticCondition
bobbens@2497
   184
 */
bobbens@2495
   185
#define SDL_HAPTIC_SPRING     (1<<7) /* Spring effect supported - uses axes position */
bobbens@2497
   186
/**
bobbens@2497
   187
 * \def SDL_HAPTIC_DAMPER
bobbens@2497
   188
 *
bobbens@2497
   189
 * \brief Condition haptic effect that simulates dampening.  Effect is based on the
bobbens@2497
   190
 * axes velocity.
bobbens@2497
   191
 *
bobbens@2497
   192
 * \sa SDL_HapticCondition
bobbens@2497
   193
 */
bobbens@2495
   194
#define SDL_HAPTIC_DAMPER     (1<<8) /* Damper effect supported - uses axes velocity */
bobbens@2497
   195
/**
bobbens@2497
   196
 * \def SDL_HAPTIC_INERTIA
bobbens@2497
   197
 *
bobbens@2497
   198
 * \brief Condition haptic effect that simulates inertia.  Effect is based on the axes
bobbens@2497
   199
 * acceleration.
bobbens@2497
   200
 *
bobbens@2497
   201
 * \sa SDL_HapticCondition
bobbens@2497
   202
 */
bobbens@2495
   203
#define SDL_HAPTIC_INERTIA    (1<<9) /* Inertia effect supported - uses axes acceleration */
bobbens@2497
   204
/**
bobbens@2497
   205
 * \def SDL_HAPTIC_FRICTION
bobbens@2497
   206
 *
bobbens@2497
   207
 * \brief Condition haptic effect that simulates friction.  Effect is based on the axes
bobbens@2497
   208
 * movement.
bobbens@2497
   209
 *
bobbens@2497
   210
 * \sa SDL_HapticCondition
bobbens@2497
   211
 */
bobbens@2495
   212
#define SDL_HAPTIC_FRICTION   (1<<10) /* Friction effect supported - uses axes movement */
bobbens@2497
   213
/**
bobbens@2497
   214
 * \def SDL_HAPTIC_CUSTOM
bobbens@2497
   215
 *
bobbens@2497
   216
 * \brief User defined custom haptic effect. TODO.
bobbens@2497
   217
 */
bobbens@2495
   218
#define SDL_HAPTIC_CUSTOM     (1<<11) /* Custom effect is supported */
bobbens@2487
   219
/* These last two are features the device has, not effects */
bobbens@2497
   220
/**
bobbens@2497
   221
 * \def SDL_HAPTIC_GAIN
bobbens@2497
   222
 *
bobbens@2497
   223
 * \brief Device supports setting the global gain.
bobbens@2497
   224
 *
bobbens@2497
   225
 * \sa SDL_HapticSetGain
bobbens@2497
   226
 */
bobbens@2495
   227
#define SDL_HAPTIC_GAIN       (1<<12) /* Device can set global gain */
bobbens@2497
   228
/**
bobbens@2497
   229
 * \def SDL_HAPTIC_AUTOCENTER
bobbens@2497
   230
 *
bobbens@2497
   231
 * \brief Device supports setting autocenter.
bobbens@2497
   232
 *
bobbens@2497
   233
 * \sa SDL_HapticSetAutocenter
bobbens@2497
   234
 */
bobbens@2495
   235
#define SDL_HAPTIC_AUTOCENTER (1<<13) /* Device can set autocenter */
bobbens@2497
   236
/**
bobbens@2497
   237
 * \def SDL_HAPTIC_STATUS
bobbens@2497
   238
 *
bobbens@2497
   239
 * \brief Device can be queried for effect status.
bobbens@2497
   240
 *
bobbens@2497
   241
 * \sa SDL_HapticGetEffectStatus
bobbens@2497
   242
 */
bobbens@2495
   243
#define SDL_HAPTIC_STATUS     (1<<14) /* Device can be queried for effect status */
bobbens@2481
   244
bobbens@2481
   245
bobbens@2497
   246
/**
bobbens@2497
   247
 * \struct SDL_HapticConstant
bobbens@2497
   248
 *
bobbens@2497
   249
 * \brief A structure containing a template for a Constant effect.
bobbens@2497
   250
 *
bobbens@2497
   251
 * The struct is exclusive to the SDL_HAPTIC_CONSTANT effect.
bobbens@2497
   252
 *
bobbens@2497
   253
 * \sa SDL_HAPTIC_CONSTANT
bobbens@2497
   254
 * \sa SDL_HapticEffect
bobbens@2497
   255
 */
bobbens@2497
   256
typedef struct SDL_HapticConstant {
bobbens@2497
   257
   /* Header */
bobbens@2497
   258
   Uint16 type; /**< SDL_HAPTIC_CONSTANT */
bobbens@2497
   259
   Uint16 direction;
bobbens@2497
   260
bobbens@2497
   261
   /* Replay */
bobbens@2497
   262
   Uint16 length; /**< Duration of the effect. */
bobbens@2497
   263
   Uint16 delay; /**< Delay before starting the effect. */
bobbens@2497
   264
bobbens@2497
   265
   /* Trigger */
bobbens@2497
   266
   Uint16 button; /**< Button that triggers the effect. */
bobbens@2497
   267
   Uint16 interval; /**< How soon it can be triggered again after button. */
bobbens@2497
   268
bobbens@2497
   269
   /* Constant */
bobbens@2497
   270
   Sint16 level; /**< Strength of the constant effect. */
bobbens@2497
   271
bobbens@2497
   272
   /* Envelope */
bobbens@2497
   273
   Uint16 attack_length; /**< Duration of the attack. */
bobbens@2497
   274
   Uint16 attack_level; /**< Level at the start of the attack. */
bobbens@2497
   275
   Uint16 fade_length; /**< Duration of the fade. */
bobbens@2497
   276
   Uint16 fade_level; /**< Level at the end of the fade. */
bobbens@2497
   277
} SDL_HapticConstant;
bobbens@2497
   278
/**
bobbens@2497
   279
 * \struct SDL_HapticPeriodic
bobbens@2497
   280
 *
bobbens@2497
   281
 * \brief A structure containing a template for a Periodic effect.
bobbens@2497
   282
 *
bobbens@2497
   283
 * The struct handles the following effects:
bobbens@2497
   284
 *   - SDL_HAPTIC_SINE
bobbens@2497
   285
 *   - SDL_HAPTIC_SQUARE
bobbens@2497
   286
 *   - SDL_HAPTIC_TRIANGLE
bobbens@2497
   287
 *   - SDL_HAPTIC_SAWTOOTHUP
bobbens@2497
   288
 *   - SDL_HAPTIC_SAWTOOTHDOWN
bobbens@2497
   289
 *
bobbens@2497
   290
 * \sa SDL_HAPTIC_SINE
bobbens@2497
   291
 * \sa SDL_HAPTIC_SQUARE
bobbens@2497
   292
 * \sa SDL_HAPTIC_TRIANGLE
bobbens@2497
   293
 * \sa SDL_HAPTIC_SAWTOOTHUP
bobbens@2497
   294
 * \sa SDL_HAPTIC_SAWTOOTHDOWN
bobbens@2497
   295
 * \sa SDL_HapticEffect
bobbens@2497
   296
 */
bobbens@2497
   297
typedef struct SDL_HapticPeriodic {
bobbens@2497
   298
   /* Header */
bobbens@2497
   299
   Uint16 type; /* SDL_HAPTIC_{SINE,SQUARE,TRIANGLE,SAWTOOTHUP,SAWTOOTHDOWN} */
bobbens@2497
   300
   Uint16 direction;
bobbens@2497
   301
bobbens@2497
   302
   /* Replay */
bobbens@2497
   303
   Uint16 length; /**< Duration of the effect. */
bobbens@2497
   304
   Uint16 delay; /**< Delay before starting the effect. */
bobbens@2497
   305
bobbens@2497
   306
   /* Trigger */
bobbens@2497
   307
   Uint16 button; /**< Button that triggers the effect. */
bobbens@2497
   308
   Uint16 interval; /**< How soon it can be triggered again after button. */
bobbens@2497
   309
bobbens@2497
   310
   /* Periodic */
bobbens@2497
   311
   Uint16 period; /**< Period of the wave. */
bobbens@2497
   312
   Sint16 magnitude; /**< Peak value. */
bobbens@2497
   313
   Sint16 offset; /**< Mean value of the wave. */
bobbens@2497
   314
   Uint16 phase; /**< Horizontal shift. */
bobbens@2497
   315
bobbens@2497
   316
   /* Envelope */
bobbens@2497
   317
   Uint16 attack_length; /**< Duration of the attack. */
bobbens@2497
   318
   Uint16 attack_level; /**< Level at the start of the attack. */
bobbens@2497
   319
   Uint16 fade_length; /**< Duration of the fade. */
bobbens@2497
   320
   Uint16 fade_level; /**< Level at the end of the fade. */
bobbens@2497
   321
} SDL_HapticPeriodic;
bobbens@2497
   322
/**
bobbens@2497
   323
 * \struct SDL_HapticCondition
bobbens@2497
   324
 *
bobbens@2497
   325
 * \brief A structure containing a template for a Condition effect.
bobbens@2497
   326
 *
bobbens@2497
   327
 * The struct handles the following effects:
bobbens@2497
   328
 *   - SDL_HAPTIC_SPRING
bobbens@2497
   329
 *   - SDL_HAPTIC_DAMPER
bobbens@2497
   330
 *   - SDL_HAPTIC_INERTIA
bobbens@2497
   331
 *   - SDL_HAPTIC_FRICTION
bobbens@2497
   332
 *
bobbens@2497
   333
 * \sa SDL_HAPTIC_SPRING
bobbens@2497
   334
 * \sa SDL_HAPTIC_DAMPER
bobbens@2497
   335
 * \sa SDL_HAPTIC_INERTIA
bobbens@2497
   336
 * \sa SDL_HAPTIC_FRICTION
bobbens@2497
   337
 * \sa SDL_HapticEffect
bobbens@2497
   338
 */
bobbens@2497
   339
typedef struct SDL_HapticCondition {
bobbens@2497
   340
   /* Header */
bobbens@2497
   341
   Uint16 type; /**< SDL_HAPTIC_{SPRING,DAMPER,INERTIA,FRICTION} */
bobbens@2497
   342
   Uint16 direction;
bobbens@2497
   343
bobbens@2497
   344
   /* Replay */
bobbens@2497
   345
   Uint16 length; /**< Duration of the effect. */
bobbens@2497
   346
   Uint16 delay; /**< Delay before starting the effect. */
bobbens@2497
   347
bobbens@2497
   348
   /* Trigger */
bobbens@2497
   349
   Uint16 button; /**< Button that triggers the effect. */
bobbens@2497
   350
   Uint16 interval; /**< How soon it can be triggered again after button. */
bobbens@2497
   351
bobbens@2497
   352
   /* Condition */
bobbens@2497
   353
   Uint16 right_sat; /**< Level when joystick is to the right. */
bobbens@2497
   354
   Uint16 left_sat; /**< Level when joystick is to the left. */
bobbens@2497
   355
   Sint16 right_coeff; /**< How fast to increase the force towards the right. */
bobbens@2497
   356
   Sint16 left_coeff; /**< How fast to increase the force towards the left. */
bobbens@2497
   357
   Uint16 deadband; /**< Size of the dead zone. */
bobbens@2497
   358
   Sint16 center; /**< Position of the dead zone. */
bobbens@2497
   359
} SDL_HapticCondition;
bobbens@2497
   360
/**
bobbens@2497
   361
 * \struct SDL_HapticRamp
bobbens@2497
   362
 *
bobbens@2497
   363
 * \brief A structure containing a template for a Ramp effect.
bobbens@2497
   364
 *
bobbens@2497
   365
 * This struct is exclusively for the SDL_HAPTIC_RAMP effect.
bobbens@2497
   366
 *
bobbens@2497
   367
 * \sa SDL_HAPTIC_RAMP
bobbens@2497
   368
 * \sa SDL_HapticEffect
bobbens@2497
   369
 */
bobbens@2497
   370
typedef struct SDL_HapticRamp {
bobbens@2497
   371
   /* Header */
bobbens@2497
   372
   Uint16 type; /**< SDL_HAPTIC_RAMP */
bobbens@2497
   373
   Uint16 direction;
bobbens@2497
   374
bobbens@2497
   375
   /* Replay */
bobbens@2497
   376
   Uint16 length; /**< Duration of the effect. */
bobbens@2497
   377
   Uint16 delay; /**< Delay before starting the effect. */
bobbens@2497
   378
bobbens@2497
   379
   /* Trigger */
bobbens@2497
   380
   Uint16 button; /**< Button that triggers the effect. */
bobbens@2497
   381
   Uint16 interval; /**< How soon it can be triggered again after button. */
bobbens@2497
   382
bobbens@2497
   383
   /* Ramp */
bobbens@2497
   384
   Sint16 start; /**< Beginning strength level. */
bobbens@2497
   385
   Sint16 end; /**< Ending strength level. */
bobbens@2497
   386
bobbens@2497
   387
   /* Envelope */
bobbens@2497
   388
   Uint16 attack_length; /**< Duration of the attack. */
bobbens@2497
   389
   Uint16 attack_level; /**< Level at the start of the attack. */
bobbens@2497
   390
   Uint16 fade_length; /**< Duration of the fade. */
bobbens@2497
   391
   Uint16 fade_level; /**< Level at the end of the fade. */
bobbens@2497
   392
} SDL_HapticRamp;
bobbens@2498
   393
/**
bobbens@2497
   394
 * \union SDL_HapticEffect
bobbens@2497
   395
 *
bobbens@2497
   396
 * \brief The generic template for any haptic effect.
bobbens@2497
   397
 *
bobbens@2481
   398
 * All values max at 32767 (0x7fff).  Signed values also can be negative.
bobbens@2481
   399
 * Time values unless specified otherwise are in milliseconds.
bobbens@2481
   400
 *
bobbens@2481
   401
 * Common parts:
bobbens@2481
   402
 * 
bobbens@2481
   403
 * Replay:
bobbens@2481
   404
 *    Uint16 length;    Duration of effect.
bobbens@2481
   405
 *    Uint16 delay;     Delay before starting effect.
bobbens@2481
   406
 *
bobbens@2481
   407
 * Trigger:
bobbens@2481
   408
 *    Uint16 button;    Button that triggers effect.
bobbens@2481
   409
 *    Uint16 interval;  How soon before effect can be triggered again.
bobbens@2481
   410
 *
bobbens@2481
   411
 * Envelope:
bobbens@2481
   412
 *    Uint16 attack_length;   Duration of the attack.
bobbens@2481
   413
 *    Uint16 attack_level;    Level at the start of the attack.
bobbens@2481
   414
 *    Uint16 fade_length;     Duration of the fade out.
bobbens@2481
   415
 *    Uint16 fade_level;      Level at the end of the fade.
bobbens@2497
   416
 *
bobbens@2497
   417
 * \sa SDL_HapticConstant
bobbens@2497
   418
 * \sa SDL_HapticPeriodic
bobbens@2497
   419
 * \sa SDL_HapticCondition
bobbens@2497
   420
 * \sa SDL_HaptiRamp
bobbens@2481
   421
 */
bobbens@2477
   422
typedef union SDL_HapticEffect {
bobbens@2477
   423
   /* Common for all force feedback effects */
bobbens@2497
   424
   Uint16 type; /**< Effect type */
bobbens@2497
   425
   SDL_HapticConstant constant; /**< Constant effect */
bobbens@2497
   426
   SDL_HapticPeriodic periodic; /**< Periodic effect */
bobbens@2497
   427
   SDL_HapticCondition condition; /**< Condition effect */
bobbens@2497
   428
   SDL_HapticRamp ramp; /**< Ramp effect */
bobbens@2477
   429
} SDL_HapticEffect;
bobbens@2477
   430
bobbens@2472
   431
bobbens@2472
   432
/* Function prototypes */
bobbens@2498
   433
/**
bobbens@2497
   434
 * \fn int SDL_NumHaptics(void)
bobbens@2497
   435
 *
bobbens@2497
   436
 * \brief Count the number of joysticks attached to the system.
bobbens@2497
   437
 *
bobbens@2497
   438
 *    \return Number of haptic devices detected on the system.
bobbens@2472
   439
 */
bobbens@2472
   440
extern DECLSPEC int SDLCALL SDL_NumHaptics(void);
bobbens@2472
   441
bobbens@2498
   442
/**
bobbens@2497
   443
 * \fn const char * SDL_HapticName(int device_index)
bobbens@2497
   444
 *
bobbens@2497
   445
 * \brief Get the implementation dependent name of a Haptic device.
bobbens@2472
   446
 * This can be called before any joysticks are opened.
bobbens@2472
   447
 * If no name can be found, this function returns NULL.
bobbens@2497
   448
 *
bobbens@2497
   449
 *    \param device_index Index of the device to get it's name.
bobbens@2497
   450
 *    \return Name of the device or NULL on error.
bobbens@2497
   451
 *
bobbens@2497
   452
 * \sa SDL_NumHaptics
bobbens@2472
   453
 */
bobbens@2472
   454
extern DECLSPEC const char *SDLCALL SDL_HapticName(int device_index);
bobbens@2472
   455
bobbens@2498
   456
/**
bobbens@2497
   457
 * \fn SDL_Haptic * SDL_HapticOpen(int device_Index)
bobbens@2497
   458
 *
bobbens@2497
   459
 * \brief Opens a Haptic device for usage - the index passed as an
bobbens@2476
   460
 * argument refers to the N'th Haptic device on this system.
bobbens@2476
   461
 *
bobbens@2476
   462
 * This function returns a Haptic device identifier, or Null
bobbens@2476
   463
 * if an error occurred.
bobbens@2497
   464
 *
bobbens@2497
   465
 *    \param device_index Index of the device to open.
bobbens@2497
   466
 *    \return Device identifier or NULL on error.
bobbens@2497
   467
 *
bobbens@2497
   468
 * \sa SDL_HapticOpenFromJoystick
bobbens@2497
   469
 * \sa SDL_HapticClose
bobbens@2476
   470
 */
bobbens@2476
   471
extern DECLSPEC SDL_Haptic * SDL_HapticOpen(int device_index);
bobbens@2476
   472
bobbens@2498
   473
/**
bobbens@2498
   474
 * \fn int SDL_JoystickIsHaptic(SDL_Joystick * joystick)
bobbens@2489
   475
 *
bobbens@2497
   476
 * \brief Checks to see if a joystick has haptic features.
bobbens@2497
   477
 *
bobbens@2497
   478
 *    \param joystick Joystick to test for haptic capabilities.
bobbens@2497
   479
 *    \return SDL_TRUE if the joystick is haptic, SDL_FALSE if it isn't
bobbens@2497
   480
 *            or -1 if an error ocurred.
bobbens@2497
   481
 *
bobbens@2497
   482
 * \sa SDL_HapticOpenFromJoystick
bobbens@2489
   483
 */
bobbens@2489
   484
extern DECLSPEC int SDL_JoystickIsHaptic(SDL_Joystick * joystick);
bobbens@2489
   485
bobbens@2498
   486
/**
bobbens@2497
   487
 * \fn SDL_Haptic * SDL_HapticOpenFromJoystick(SDL_Joystick * joystick)
bobbens@2489
   488
 *
bobbens@2497
   489
 * \brief Opens a Haptic device for usage from a Joystick device.  Still has
bobbens@2497
   490
 * to be closed seperately to the joystick.
bobbens@2497
   491
 *
bobbens@2497
   492
 *    \param joystick Joystick to create a haptic device from.
bobbens@2497
   493
 *    \return A valid haptic device identifier on success or NULL on error.
bobbens@2497
   494
 *
bobbens@2497
   495
 * \sa SDL_HapticOpen
bobbens@2497
   496
 * \sa SDL_HapticClose
bobbens@2489
   497
 */
bobbens@2489
   498
extern DECLSPEC SDL_Haptic * SDL_HapticOpenFromJoystick(SDL_Joystick * joystick);
bobbens@2489
   499
bobbens@2498
   500
/**
bobbens@2497
   501
 * \fn void SDL_HapticClose(SDL_Haptic * haptic)
bobbens@2497
   502
 *
bobbens@2497
   503
 * \brief Closes a Haptic device previously opened with SDL_HapticOpen.
bobbens@2497
   504
 *
bobbens@2497
   505
 *    \param haptic Haptic device to close.
bobbens@2476
   506
 */
bobbens@2476
   507
extern DECLSPEC void SDL_HapticClose(SDL_Haptic * haptic);
bobbens@2476
   508
bobbens@2498
   509
/**
bobbens@2497
   510
 * \fn int SDL_HapticNumEffects(SDL_Haptic * haptic)
bobbens@2497
   511
 *
bobbens@2497
   512
 * \brief Returns the number of effects a haptic device can store.
bobbens@2497
   513
 *
bobbens@2497
   514
 *    \param haptic The haptic device to query effect max.
bobbens@2497
   515
 *    \return The number of effects the haptic device can store or
bobbens@2497
   516
 *            -1 on error.
bobbens@2497
   517
 *
bobbens@2497
   518
 * \sa SDL_HapticQuery
bobbens@2478
   519
 */
bobbens@2478
   520
extern DECLSPEC int SDL_HapticNumEffects(SDL_Haptic * haptic);
bobbens@2478
   521
bobbens@2498
   522
/**
bobbens@2497
   523
 * \fn unsigned int SDL_HapticQueryEffects(SDL_Haptic * haptic)
bobbens@2478
   524
 *
bobbens@2497
   525
 * \brief Gets the haptic devices supported features in bitwise matter.
bobbens@2497
   526
 *
bobbens@2497
   527
 * Example: 
bobbens@2497
   528
 * \code
bobbens@2497
   529
 * if (SDL_HapticQueryEffects(haptic) & SDL_HAPTIC_CONSTANT) {
bobbens@2497
   530
 *    printf("We have constant haptic effect!");
bobbens@2497
   531
 * }
bobbens@2497
   532
 * \endcode
bobbens@2497
   533
 *    
bobbens@2497
   534
 *
bobbens@2497
   535
 *    \param haptic The haptic device to query.
bobbens@2497
   536
 *    \return Haptic features in bitwise manner (OR'd).
bobbens@2497
   537
 *
bobbens@2497
   538
 * \sa SDL_HapticNumEffects
bobbens@2497
   539
 * \sa SDL_HapticEffectSupported
bobbens@2478
   540
 */
bobbens@2497
   541
extern DECLSPEC unsigned int SDL_HapticQuery(SDL_Haptic * haptic);
bobbens@2478
   542
bobbens@2498
   543
/**
bobbens@2497
   544
 * \fn int SDL_HapticEffectSupported
bobbens@2486
   545
 *
bobbens@2497
   546
 * \brief Checks to see if effect is supported by haptic.
bobbens@2497
   547
 *
bobbens@2497
   548
 *    \param haptic Haptic device to check on.
bobbens@2497
   549
 *    \param effect Effect to check to see if it is supported.
bobbens@2497
   550
 *    \return SDL_TRUE if effect is supported, SDL_FALSE if it isn't or 
bobbens@2497
   551
 *            -1 on error.
bobbens@2497
   552
 * 
bobbens@2497
   553
 * \sa SDL_HapticQuery
bobbens@2497
   554
 * \sa SDL_HapticNewEffect
bobbens@2486
   555
 */
bobbens@2486
   556
extern DECLSPEC int SDL_HapticEffectSupported(SDL_Haptic * haptic, SDL_HapticEffect * effect);
bobbens@2486
   557
bobbens@2498
   558
/**
bobbens@2497
   559
 * \fn int SDL_HapticNewEffect(SDL_Haptic * haptic, SDL_HapticEffect * effect)
bobbens@2483
   560
 *
bobbens@2497
   561
 * \brief Creates a new haptic effect on the device.
bobbens@2497
   562
 *
bobbens@2497
   563
 *    \param haptic Haptic device to create the effect on.
bobbens@2497
   564
 *    \param effect Properties of the effect to create.
bobbens@2497
   565
 *    \return The id of the effect on success or -1 on error.
bobbens@2497
   566
 *
bobbens@2497
   567
 * \sa SDL_HapticUpdateEffect
bobbens@2497
   568
 * \sa SDL_HapticRunEffect
bobbens@2497
   569
 * \sa SDL_HapticDestroyEffect
bobbens@2477
   570
 */
bobbens@2477
   571
extern DECLSPEC int SDL_HapticNewEffect(SDL_Haptic * haptic, SDL_HapticEffect * effect);
bobbens@2477
   572
bobbens@2498
   573
/**
bobbens@2497
   574
 * \fn int SDL_HapticUpdateEffect(SDL_Haptic * haptic, int effect, SDL_HapticEffect * data)
bobbens@2497
   575
 *
bobbens@2497
   576
 * \brief Updates an effect.  Can be used dynamically, although behaviour when
bobbens@2488
   577
 * dynamically changing direction may be strange.  Specifically the effect
bobbens@2488
   578
 * may reupload itself and start playing from the start.  You cannot change
bobbens@2488
   579
 * the type either when running UpdateEffect.
bobbens@2488
   580
 *
bobbens@2497
   581
 *    \param haptic Haptic device that has the effect.
bobbens@2497
   582
 *    \param effect Effect to update.
bobbens@2497
   583
 *    \param data New effect properties to use.
bobbens@2497
   584
 *    \return The id of the effect on success or -1 on error.
bobbens@2497
   585
 *
bobbens@2497
   586
 * \sa SDL_HapticNewEffect
bobbens@2497
   587
 * \sa SDL_HapticRunEffect
bobbens@2497
   588
 * \sa SDL_HapticDestroyEffect
bobbens@2488
   589
 */
bobbens@2488
   590
extern DECLSPEC int SDL_HapticUpdateEffect(SDL_Haptic * haptic, int effect, SDL_HapticEffect * data);
bobbens@2488
   591
bobbens@2498
   592
/**
bobbens@2497
   593
 * \fn int SDL_HapticRunEffects(SDL_Haptic * haptic, int effect)
bobbens@2483
   594
 *
bobbens@2497
   595
 * \brief Runs the haptic effect on it's assosciated haptic device.
bobbens@2497
   596
 *
bobbens@2497
   597
 *    \param haptic Haptic device to run the effect on.
bobbens@2497
   598
 *    \param effect Identifier of the haptic effect to run.
bobbens@2497
   599
 *    \return 0 on success or -1 on error.
bobbens@2497
   600
 *
bobbens@2497
   601
 * \sa SDL_HapticStopEffect
bobbens@2497
   602
 * \sa SDL_HapticDestroyEffect
bobbens@2497
   603
 * \sa SDL_HapticGetEffectStatus
bobbens@2477
   604
 */
bobbens@2477
   605
extern DECLSPEC int SDL_HapticRunEffect(SDL_Haptic * haptic, int effect);
bobbens@2477
   606
bobbens@2498
   607
/**
bobbens@2497
   608
 * \fn int SDL_HapticStopEffect(SDL_Haptic * haptic, int effect)
bobbens@2485
   609
 *
bobbens@2497
   610
 * \brief Stops the haptic effect on it's assosciated haptic device.
bobbens@2497
   611
 *
bobbens@2497
   612
 *    \param haptic Haptic device to stop the effect on.
bobbens@2497
   613
 *    \praam effect Identifier of the effect to stop.
bobbens@2497
   614
 *    \return 0 on success or -1 on error.
bobbens@2497
   615
 *
bobbens@2497
   616
 * \sa SDL_HapticRunEffect
bobbens@2497
   617
 * \sa SDL_HapticDestroyEffect
bobbens@2485
   618
 */
bobbens@2485
   619
extern DECLSPEC int SDL_HapticStopEffect(SDL_Haptic * haptic, int effect);
bobbens@2485
   620
bobbens@2498
   621
/**
bobbens@2497
   622
 * \fn void SDL_HapticDestroyEffect(SDL_Haptic * haptic, int effect)
bobbens@2497
   623
 *
bobbens@2497
   624
 * \brief Destroys a haptic effect on the device.  This will stop the effect
bobbens@2497
   625
 * if it's running.  Effects are automatically destroyed when the device is
bobbens@2497
   626
 * closed.
bobbens@2497
   627
 *
bobbens@2497
   628
 *    \param haptic Device to destroy the effect on.
bobbens@2497
   629
 *    \param effect Identifier of the effect to destroy.
bobbens@2497
   630
 * 
bobbens@2497
   631
 * \sa SDL_HapticNewEffect
bobbens@2477
   632
 */
bobbens@2477
   633
extern DECLSPEC void SDL_HapticDestroyEffect(SDL_Haptic * haptic, int effect);
bobbens@2477
   634
bobbens@2498
   635
/**
bobbens@2497
   636
 * \fn int SDL_HapticGetEffectStatus(SDL_Haptic *haptic, int effect)
bobbens@2495
   637
 *
bobbens@2497
   638
 * \brief Gets the status of the current effect on the haptic device.
bobbens@2497
   639
 *
bobbens@2497
   640
 * Device must support the SDL_HAPTIC_STATUS feature.
bobbens@2497
   641
 *
bobbens@2497
   642
 *    \param haptic Haptic device to query the effect status on.
bobbens@2497
   643
 *    \param effect Identifier of the effect to query it's status.
bobbens@2497
   644
 *    \return 0 if it isn't playing, SDL_HAPTIC_PLAYING if it is playing
bobbens@2497
   645
 *            or -1 on error.
bobbens@2497
   646
 *
bobbens@2497
   647
 * \sa SDL_HapticRunEffect
bobbens@2497
   648
 * \sa SDL_HapticStopEffect
bobbens@2495
   649
 */
bobbens@2495
   650
extern DECLSPEC int SDL_HapticGetEffectStatus(SDL_Haptic *haptic, int effect);
bobbens@2495
   651
bobbens@2498
   652
/**
bobbens@2497
   653
 * \fn int SDL_HapticSetGain(SDL_Haptic * haptic, int gain)
bobbens@2483
   654
 *
bobbens@2497
   655
 * \brief Sets the global gain of the device.  Gain should be between 0 and 100.
bobbens@2497
   656
 *
bobbens@2497
   657
 * Device must support the SDL_HAPTIC_GAIN feature.
bobbens@2497
   658
 *
bobbens@2497
   659
 *    \param haptic Haptic device to set the gain on.
bobbens@2497
   660
 *    \param gain Value to set the gain to, should be between 0 and 100.
bobbens@2497
   661
 *    \return 0 on success or -1 on error.
bobbens@2497
   662
 *
bobbens@2497
   663
 * \sa SDL_HapticQuery
bobbens@2483
   664
 */
bobbens@2483
   665
extern DECLSPEC int SDL_HapticSetGain(SDL_Haptic * haptic, int gain);
bobbens@2483
   666
bobbens@2498
   667
/**
bobbens@2497
   668
 * \fn int SDL_HapticSetAutocenter(SDL_Haptic * haptic, int autocenter)
bobbens@2497
   669
 *
bobbens@2497
   670
 * \brief Sets the global autocenter of the device.  Autocenter should be between
bobbens@2484
   671
 * 0 and 100.  Setting it to 0 will disable autocentering.
bobbens@2484
   672
 *
bobbens@2497
   673
 * Device must support the SDL_HAPTIC_AUTOCENTER feature.
bobbens@2497
   674
 *
bobbens@2497
   675
 *    \param haptic Haptic device to set autocentering on.
bobbens@2497
   676
 *    \param autocenter Value to set autocenter to, 0 disables autocentering.
bobbens@2497
   677
 *    \return 0 on success or -1 on error.
bobbens@2497
   678
 *
bobbens@2497
   679
 * \sa SDL_HapticQuery
bobbens@2484
   680
 */
bobbens@2484
   681
extern DECLSPEC int SDL_HapticSetAutocenter(SDL_Haptic * haptic, int autocenter);
bobbens@2484
   682
bobbens@2472
   683
bobbens@2472
   684
/* Ends C function definitions when using C++ */
bobbens@2472
   685
#ifdef __cplusplus
bobbens@2472
   686
/* *INDENT-OFF* */
bobbens@2472
   687
}
bobbens@2472
   688
/* *INDENT-ON* */
bobbens@2472
   689
#endif
bobbens@2472
   690
#include "close_code.h"
bobbens@2472
   691
bobbens@2472
   692
#endif /* _SDL_haptic_h */
bobbens@2472
   693
bobbens@2472
   694
/* vi: set ts=4 sw=4 expandtab: */
bobbens@2472
   695
bobbens@2472
   696