include/SDL_haptic.h
author Edgar Simo <bobbens@gmail.com>
Sun, 06 Jul 2008 16:53:32 +0000
branchgsoc2008_force_feedback
changeset 2497 0893fbf73b3d
parent 2495 66c02abeef0e
child 2498 ab567bd667bf
permissions -rw-r--r--
Renamed SDL_HapticQueryEffects to SDL_HapticQuery.
Added doxygen to SDL_Haptic.h.
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@2497
    23
/** \file SDL_haptic.h */
bobbens@2472
    24
/**
bobbens@2497
    25
 * \mainpage SDL_haptic
bobbens@2472
    26
 *
bobbens@2497
    27
 * The SDL Haptic subsystem allows you to control haptic (force feedback)
bobbens@2497
    28
 *  devices.
bobbens@2497
    29
 *
bobbens@2497
    30
 * The basic usage is as follows:
bobbens@2497
    31
 *   - Initialize the Subsystem (SDL_INIT_HAPTIC).
bobbens@2497
    32
 *   - Open a Haptic Device.
bobbens@2497
    33
 *     - SDL_HapticOpen(...) to open from index.
bobbens@2497
    34
 *     - SDL_HapticOpenFromJoystick(...) to open from an existing joystick.
bobbens@2497
    35
 *   - Create an effect (SDL_HapticEffect).
bobbens@2497
    36
 *   - Upload the effect with SDL_HapticNewEffect(...).
bobbens@2497
    37
 *   - Run the effect with SDL_HapticRunEffect(...).
bobbens@2497
    38
 *   - (optional) Free the effect with SDL_HapticDestroyEffect(...).
bobbens@2497
    39
 *   - Close the haptic device with SDL_HapticClose(...).
bobbens@2497
    40
 *
bobbens@2497
    41
 *
bobbens@2497
    42
 * Example:
bobbens@2497
    43
 *
bobbens@2497
    44
 * \code
bobbens@2497
    45
 * int test_haptic( SDL_Joystick * joystick ) {
bobbens@2497
    46
 *    SDL_Haptic *haptic;
bobbens@2497
    47
 *    SDL_HapticEffect effect;
bobbens@2497
    48
 *    int effect_id;
bobbens@2497
    49
 *
bobbens@2497
    50
 *    // Open the device
bobbens@2497
    51
 *    haptic = SDL_HapticOpenFromJoystick( joystick );
bobbens@2497
    52
 *    if (haptic == NULL) return -1; // Most likely joystick isn't haptic
bobbens@2497
    53
 *
bobbens@2497
    54
 *    // See if it can do sine waves
bobbens@2497
    55
 *    if ((SDL_HapticQueryEffects(haptic) & SDL_HAPTIC_SINE)==0) {
bobbens@2497
    56
 *       SDL_HapticClose(haptic); // No sine effect
bobbens@2497
    57
 *       return -1;
bobbens@2497
    58
 *    }
bobbens@2497
    59
 *
bobbens@2497
    60
 *    // Create the effect
bobbens@2497
    61
 *    memset( &effect, 0, sizeof(SDL_HapticEffect) ); // 0 is safe default
bobbens@2497
    62
 *    effect.type = SDL_HAPTIC_SINE;
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@2497
    73
 *    SDL_HapticRunEffect( haptic, effect_id );
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@2497
   102
#endif /* __cpluspuls */
bobbens@2472
   103
bobbens@2497
   104
/**
bobbens@2497
   105
 * \struct 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@2497
   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@2497
   215
 * \brief User defined custom haptic effect. TODO.
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@2481
   243
bobbens@2481
   244
bobbens@2497
   245
/**
bobbens@2497
   246
 * \struct SDL_HapticConstant
bobbens@2497
   247
 *
bobbens@2497
   248
 * \brief A structure containing a template for a Constant effect.
bobbens@2497
   249
 *
bobbens@2497
   250
 * The struct is exclusive to the SDL_HAPTIC_CONSTANT effect.
bobbens@2497
   251
 *
bobbens@2497
   252
 * \sa SDL_HAPTIC_CONSTANT
bobbens@2497
   253
 * \sa SDL_HapticEffect
bobbens@2497
   254
 */
bobbens@2497
   255
typedef struct SDL_HapticConstant {
bobbens@2497
   256
   /* Header */
bobbens@2497
   257
   Uint16 type; /**< SDL_HAPTIC_CONSTANT */
bobbens@2497
   258
   Uint16 direction;
bobbens@2497
   259
bobbens@2497
   260
   /* Replay */
bobbens@2497
   261
   Uint16 length; /**< Duration of the effect. */
bobbens@2497
   262
   Uint16 delay; /**< Delay before starting the effect. */
bobbens@2497
   263
bobbens@2497
   264
   /* Trigger */
bobbens@2497
   265
   Uint16 button; /**< Button that triggers the effect. */
bobbens@2497
   266
   Uint16 interval; /**< How soon it can be triggered again after button. */
bobbens@2497
   267
bobbens@2497
   268
   /* Constant */
bobbens@2497
   269
   Sint16 level; /**< Strength of the constant effect. */
bobbens@2497
   270
bobbens@2497
   271
   /* Envelope */
bobbens@2497
   272
   Uint16 attack_length; /**< Duration of the attack. */
bobbens@2497
   273
   Uint16 attack_level; /**< Level at the start of the attack. */
bobbens@2497
   274
   Uint16 fade_length; /**< Duration of the fade. */
bobbens@2497
   275
   Uint16 fade_level; /**< Level at the end of the fade. */
bobbens@2497
   276
} SDL_HapticConstant;
bobbens@2497
   277
/**
bobbens@2497
   278
 * \struct SDL_HapticPeriodic
bobbens@2497
   279
 *
bobbens@2497
   280
 * \brief A structure containing a template for a Periodic effect.
bobbens@2497
   281
 *
bobbens@2497
   282
 * The struct handles the following effects:
bobbens@2497
   283
 *   - SDL_HAPTIC_SINE
bobbens@2497
   284
 *   - SDL_HAPTIC_SQUARE
bobbens@2497
   285
 *   - SDL_HAPTIC_TRIANGLE
bobbens@2497
   286
 *   - SDL_HAPTIC_SAWTOOTHUP
bobbens@2497
   287
 *   - SDL_HAPTIC_SAWTOOTHDOWN
bobbens@2497
   288
 *
bobbens@2497
   289
 * \sa SDL_HAPTIC_SINE
bobbens@2497
   290
 * \sa SDL_HAPTIC_SQUARE
bobbens@2497
   291
 * \sa SDL_HAPTIC_TRIANGLE
bobbens@2497
   292
 * \sa SDL_HAPTIC_SAWTOOTHUP
bobbens@2497
   293
 * \sa SDL_HAPTIC_SAWTOOTHDOWN
bobbens@2497
   294
 * \sa SDL_HapticEffect
bobbens@2497
   295
 */
bobbens@2497
   296
typedef struct SDL_HapticPeriodic {
bobbens@2497
   297
   /* Header */
bobbens@2497
   298
   Uint16 type; /* SDL_HAPTIC_{SINE,SQUARE,TRIANGLE,SAWTOOTHUP,SAWTOOTHDOWN} */
bobbens@2497
   299
   Uint16 direction;
bobbens@2497
   300
bobbens@2497
   301
   /* Replay */
bobbens@2497
   302
   Uint16 length; /**< Duration of the effect. */
bobbens@2497
   303
   Uint16 delay; /**< Delay before starting the effect. */
bobbens@2497
   304
bobbens@2497
   305
   /* Trigger */
bobbens@2497
   306
   Uint16 button; /**< Button that triggers the effect. */
bobbens@2497
   307
   Uint16 interval; /**< How soon it can be triggered again after button. */
bobbens@2497
   308
bobbens@2497
   309
   /* Periodic */
bobbens@2497
   310
   Uint16 period; /**< Period of the wave. */
bobbens@2497
   311
   Sint16 magnitude; /**< Peak value. */
bobbens@2497
   312
   Sint16 offset; /**< Mean value of the wave. */
bobbens@2497
   313
   Uint16 phase; /**< Horizontal shift. */
bobbens@2497
   314
bobbens@2497
   315
   /* Envelope */
bobbens@2497
   316
   Uint16 attack_length; /**< Duration of the attack. */
bobbens@2497
   317
   Uint16 attack_level; /**< Level at the start of the attack. */
bobbens@2497
   318
   Uint16 fade_length; /**< Duration of the fade. */
bobbens@2497
   319
   Uint16 fade_level; /**< Level at the end of the fade. */
bobbens@2497
   320
} SDL_HapticPeriodic;
bobbens@2497
   321
/**
bobbens@2497
   322
 * \struct SDL_HapticCondition
bobbens@2497
   323
 *
bobbens@2497
   324
 * \brief A structure containing a template for a Condition effect.
bobbens@2497
   325
 *
bobbens@2497
   326
 * The struct handles the following effects:
bobbens@2497
   327
 *   - SDL_HAPTIC_SPRING
bobbens@2497
   328
 *   - SDL_HAPTIC_DAMPER
bobbens@2497
   329
 *   - SDL_HAPTIC_INERTIA
bobbens@2497
   330
 *   - SDL_HAPTIC_FRICTION
bobbens@2497
   331
 *
bobbens@2497
   332
 * \sa SDL_HAPTIC_SPRING
bobbens@2497
   333
 * \sa SDL_HAPTIC_DAMPER
bobbens@2497
   334
 * \sa SDL_HAPTIC_INERTIA
bobbens@2497
   335
 * \sa SDL_HAPTIC_FRICTION
bobbens@2497
   336
 * \sa SDL_HapticEffect
bobbens@2497
   337
 */
bobbens@2497
   338
typedef struct SDL_HapticCondition {
bobbens@2497
   339
   /* Header */
bobbens@2497
   340
   Uint16 type; /**< SDL_HAPTIC_{SPRING,DAMPER,INERTIA,FRICTION} */
bobbens@2497
   341
   Uint16 direction;
bobbens@2497
   342
bobbens@2497
   343
   /* Replay */
bobbens@2497
   344
   Uint16 length; /**< Duration of the effect. */
bobbens@2497
   345
   Uint16 delay; /**< Delay before starting the effect. */
bobbens@2497
   346
bobbens@2497
   347
   /* Trigger */
bobbens@2497
   348
   Uint16 button; /**< Button that triggers the effect. */
bobbens@2497
   349
   Uint16 interval; /**< How soon it can be triggered again after button. */
bobbens@2497
   350
bobbens@2497
   351
   /* Condition */
bobbens@2497
   352
   Uint16 right_sat; /**< Level when joystick is to the right. */
bobbens@2497
   353
   Uint16 left_sat; /**< Level when joystick is to the left. */
bobbens@2497
   354
   Sint16 right_coeff; /**< How fast to increase the force towards the right. */
bobbens@2497
   355
   Sint16 left_coeff; /**< How fast to increase the force towards the left. */
bobbens@2497
   356
   Uint16 deadband; /**< Size of the dead zone. */
bobbens@2497
   357
   Sint16 center; /**< Position of the dead zone. */
bobbens@2497
   358
} SDL_HapticCondition;
bobbens@2497
   359
/**
bobbens@2497
   360
 * \struct SDL_HapticRamp
bobbens@2497
   361
 *
bobbens@2497
   362
 * \brief A structure containing a template for a Ramp effect.
bobbens@2497
   363
 *
bobbens@2497
   364
 * This struct is exclusively for the SDL_HAPTIC_RAMP effect.
bobbens@2497
   365
 *
bobbens@2497
   366
 * \sa SDL_HAPTIC_RAMP
bobbens@2497
   367
 * \sa SDL_HapticEffect
bobbens@2497
   368
 */
bobbens@2497
   369
typedef struct SDL_HapticRamp {
bobbens@2497
   370
   /* Header */
bobbens@2497
   371
   Uint16 type; /**< SDL_HAPTIC_RAMP */
bobbens@2497
   372
   Uint16 direction;
bobbens@2497
   373
bobbens@2497
   374
   /* Replay */
bobbens@2497
   375
   Uint16 length; /**< Duration of the effect. */
bobbens@2497
   376
   Uint16 delay; /**< Delay before starting the effect. */
bobbens@2497
   377
bobbens@2497
   378
   /* Trigger */
bobbens@2497
   379
   Uint16 button; /**< Button that triggers the effect. */
bobbens@2497
   380
   Uint16 interval; /**< How soon it can be triggered again after button. */
bobbens@2497
   381
bobbens@2497
   382
   /* Ramp */
bobbens@2497
   383
   Sint16 start; /**< Beginning strength level. */
bobbens@2497
   384
   Sint16 end; /**< Ending strength level. */
bobbens@2497
   385
bobbens@2497
   386
   /* Envelope */
bobbens@2497
   387
   Uint16 attack_length; /**< Duration of the attack. */
bobbens@2497
   388
   Uint16 attack_level; /**< Level at the start of the attack. */
bobbens@2497
   389
   Uint16 fade_length; /**< Duration of the fade. */
bobbens@2497
   390
   Uint16 fade_level; /**< Level at the end of the fade. */
bobbens@2497
   391
} SDL_HapticRamp;
bobbens@2481
   392
/*
bobbens@2497
   393
 * \union SDL_HapticEffect
bobbens@2497
   394
 *
bobbens@2497
   395
 * \brief The generic template for any haptic effect.
bobbens@2497
   396
 *
bobbens@2481
   397
 * All values max at 32767 (0x7fff).  Signed values also can be negative.
bobbens@2481
   398
 * Time values unless specified otherwise are in milliseconds.
bobbens@2481
   399
 *
bobbens@2481
   400
 * Common parts:
bobbens@2481
   401
 * 
bobbens@2481
   402
 * Replay:
bobbens@2481
   403
 *    Uint16 length;    Duration of effect.
bobbens@2481
   404
 *    Uint16 delay;     Delay before starting effect.
bobbens@2481
   405
 *
bobbens@2481
   406
 * Trigger:
bobbens@2481
   407
 *    Uint16 button;    Button that triggers effect.
bobbens@2481
   408
 *    Uint16 interval;  How soon before effect can be triggered again.
bobbens@2481
   409
 *
bobbens@2481
   410
 * Envelope:
bobbens@2481
   411
 *    Uint16 attack_length;   Duration of the attack.
bobbens@2481
   412
 *    Uint16 attack_level;    Level at the start of the attack.
bobbens@2481
   413
 *    Uint16 fade_length;     Duration of the fade out.
bobbens@2481
   414
 *    Uint16 fade_level;      Level at the end of the fade.
bobbens@2497
   415
 *
bobbens@2497
   416
 * \sa SDL_HapticConstant
bobbens@2497
   417
 * \sa SDL_HapticPeriodic
bobbens@2497
   418
 * \sa SDL_HapticCondition
bobbens@2497
   419
 * \sa SDL_HaptiRamp
bobbens@2481
   420
 */
bobbens@2477
   421
typedef union SDL_HapticEffect {
bobbens@2477
   422
   /* Common for all force feedback effects */
bobbens@2497
   423
   Uint16 type; /**< Effect type */
bobbens@2497
   424
   SDL_HapticConstant constant; /**< Constant effect */
bobbens@2497
   425
   SDL_HapticPeriodic periodic; /**< Periodic effect */
bobbens@2497
   426
   SDL_HapticCondition condition; /**< Condition effect */
bobbens@2497
   427
   SDL_HapticRamp ramp; /**< Ramp effect */
bobbens@2477
   428
} SDL_HapticEffect;
bobbens@2477
   429
bobbens@2472
   430
bobbens@2472
   431
/* Function prototypes */
bobbens@2472
   432
/*
bobbens@2497
   433
 * \fn int SDL_NumHaptics(void)
bobbens@2497
   434
 *
bobbens@2497
   435
 * \brief Count the number of joysticks attached to the system.
bobbens@2497
   436
 *
bobbens@2497
   437
 *    \return Number of haptic devices detected on the system.
bobbens@2472
   438
 */
bobbens@2472
   439
extern DECLSPEC int SDLCALL SDL_NumHaptics(void);
bobbens@2472
   440
bobbens@2472
   441
/*
bobbens@2497
   442
 * \fn const char * SDL_HapticName(int device_index)
bobbens@2497
   443
 *
bobbens@2497
   444
 * \brief Get the implementation dependent name of a Haptic device.
bobbens@2472
   445
 * This can be called before any joysticks are opened.
bobbens@2472
   446
 * If no name can be found, this function returns NULL.
bobbens@2497
   447
 *
bobbens@2497
   448
 *    \param device_index Index of the device to get it's name.
bobbens@2497
   449
 *    \return Name of the device or NULL on error.
bobbens@2497
   450
 *
bobbens@2497
   451
 * \sa SDL_NumHaptics
bobbens@2472
   452
 */
bobbens@2472
   453
extern DECLSPEC const char *SDLCALL SDL_HapticName(int device_index);
bobbens@2472
   454
bobbens@2476
   455
/*
bobbens@2497
   456
 * \fn SDL_Haptic * SDL_HapticOpen(int device_Index)
bobbens@2497
   457
 *
bobbens@2497
   458
 * \brief Opens a Haptic device for usage - the index passed as an
bobbens@2476
   459
 * argument refers to the N'th Haptic device on this system.
bobbens@2476
   460
 *
bobbens@2476
   461
 * This function returns a Haptic device identifier, or Null
bobbens@2476
   462
 * if an error occurred.
bobbens@2497
   463
 *
bobbens@2497
   464
 *    \param device_index Index of the device to open.
bobbens@2497
   465
 *    \return Device identifier or NULL on error.
bobbens@2497
   466
 *
bobbens@2497
   467
 * \sa SDL_HapticOpenFromJoystick
bobbens@2497
   468
 * \sa SDL_HapticClose
bobbens@2476
   469
 */
bobbens@2476
   470
extern DECLSPEC SDL_Haptic * SDL_HapticOpen(int device_index);
bobbens@2476
   471
bobbens@2489
   472
/*
bobbens@2497
   473
 * \fn int SDL_JoystickIsHaptic(SDL_Joystick * joysticke)
bobbens@2489
   474
 *
bobbens@2497
   475
 * \brief Checks to see if a joystick has haptic features.
bobbens@2497
   476
 *
bobbens@2497
   477
 *    \param joystick Joystick to test for haptic capabilities.
bobbens@2497
   478
 *    \return SDL_TRUE if the joystick is haptic, SDL_FALSE if it isn't
bobbens@2497
   479
 *            or -1 if an error ocurred.
bobbens@2497
   480
 *
bobbens@2497
   481
 * \sa SDL_HapticOpenFromJoystick
bobbens@2489
   482
 */
bobbens@2489
   483
extern DECLSPEC int SDL_JoystickIsHaptic(SDL_Joystick * joystick);
bobbens@2489
   484
bobbens@2489
   485
/*
bobbens@2497
   486
 * \fn SDL_Haptic * SDL_HapticOpenFromJoystick(SDL_Joystick * joystick)
bobbens@2489
   487
 *
bobbens@2497
   488
 * \brief Opens a Haptic device for usage from a Joystick device.  Still has
bobbens@2497
   489
 * to be closed seperately to the joystick.
bobbens@2497
   490
 *
bobbens@2497
   491
 *    \param joystick Joystick to create a haptic device from.
bobbens@2497
   492
 *    \return A valid haptic device identifier on success or NULL on error.
bobbens@2497
   493
 *
bobbens@2497
   494
 * \sa SDL_HapticOpen
bobbens@2497
   495
 * \sa SDL_HapticClose
bobbens@2489
   496
 */
bobbens@2489
   497
extern DECLSPEC SDL_Haptic * SDL_HapticOpenFromJoystick(SDL_Joystick * joystick);
bobbens@2489
   498
bobbens@2476
   499
/* 
bobbens@2497
   500
 * \fn void SDL_HapticClose(SDL_Haptic * haptic)
bobbens@2497
   501
 *
bobbens@2497
   502
 * \brief Closes a Haptic device previously opened with SDL_HapticOpen.
bobbens@2497
   503
 *
bobbens@2497
   504
 *    \param haptic Haptic device to close.
bobbens@2476
   505
 */
bobbens@2476
   506
extern DECLSPEC void SDL_HapticClose(SDL_Haptic * haptic);
bobbens@2476
   507
bobbens@2477
   508
/*
bobbens@2497
   509
 * \fn int SDL_HapticNumEffects(SDL_Haptic * haptic)
bobbens@2497
   510
 *
bobbens@2497
   511
 * \brief Returns the number of effects a haptic device can store.
bobbens@2497
   512
 *
bobbens@2497
   513
 *    \param haptic The haptic device to query effect max.
bobbens@2497
   514
 *    \return The number of effects the haptic device can store or
bobbens@2497
   515
 *            -1 on error.
bobbens@2497
   516
 *
bobbens@2497
   517
 * \sa SDL_HapticQuery
bobbens@2478
   518
 */
bobbens@2478
   519
extern DECLSPEC int SDL_HapticNumEffects(SDL_Haptic * haptic);
bobbens@2478
   520
bobbens@2478
   521
/*
bobbens@2497
   522
 * \fn unsigned int SDL_HapticQueryEffects(SDL_Haptic * haptic)
bobbens@2478
   523
 *
bobbens@2497
   524
 * \brief Gets the haptic devices supported features in bitwise matter.
bobbens@2497
   525
 *
bobbens@2497
   526
 * Example: 
bobbens@2497
   527
 * \code
bobbens@2497
   528
 * if (SDL_HapticQueryEffects(haptic) & SDL_HAPTIC_CONSTANT) {
bobbens@2497
   529
 *    printf("We have constant haptic effect!");
bobbens@2497
   530
 * }
bobbens@2497
   531
 * \endcode
bobbens@2497
   532
 *    
bobbens@2497
   533
 *
bobbens@2497
   534
 *    \param haptic The haptic device to query.
bobbens@2497
   535
 *    \return Haptic features in bitwise manner (OR'd).
bobbens@2497
   536
 *
bobbens@2497
   537
 * \sa SDL_HapticNumEffects
bobbens@2497
   538
 * \sa SDL_HapticEffectSupported
bobbens@2478
   539
 */
bobbens@2497
   540
extern DECLSPEC unsigned int SDL_HapticQuery(SDL_Haptic * haptic);
bobbens@2478
   541
bobbens@2478
   542
/*
bobbens@2497
   543
 * \fn int SDL_HapticEffectSupported
bobbens@2486
   544
 *
bobbens@2497
   545
 * \brief Checks to see if effect is supported by haptic.
bobbens@2497
   546
 *
bobbens@2497
   547
 *    \param haptic Haptic device to check on.
bobbens@2497
   548
 *    \param effect Effect to check to see if it is supported.
bobbens@2497
   549
 *    \return SDL_TRUE if effect is supported, SDL_FALSE if it isn't or 
bobbens@2497
   550
 *            -1 on error.
bobbens@2497
   551
 * 
bobbens@2497
   552
 * \sa SDL_HapticQuery
bobbens@2497
   553
 * \sa SDL_HapticNewEffect
bobbens@2486
   554
 */
bobbens@2486
   555
extern DECLSPEC int SDL_HapticEffectSupported(SDL_Haptic * haptic, SDL_HapticEffect * effect);
bobbens@2486
   556
bobbens@2486
   557
/*
bobbens@2497
   558
 * \fn int SDL_HapticNewEffect(SDL_Haptic * haptic, SDL_HapticEffect * effect)
bobbens@2483
   559
 *
bobbens@2497
   560
 * \brief Creates a new haptic effect on the device.
bobbens@2497
   561
 *
bobbens@2497
   562
 *    \param haptic Haptic device to create the effect on.
bobbens@2497
   563
 *    \param effect Properties of the effect to create.
bobbens@2497
   564
 *    \return The id of the effect on success or -1 on error.
bobbens@2497
   565
 *
bobbens@2497
   566
 * \sa SDL_HapticUpdateEffect
bobbens@2497
   567
 * \sa SDL_HapticRunEffect
bobbens@2497
   568
 * \sa SDL_HapticDestroyEffect
bobbens@2477
   569
 */
bobbens@2477
   570
extern DECLSPEC int SDL_HapticNewEffect(SDL_Haptic * haptic, SDL_HapticEffect * effect);
bobbens@2477
   571
bobbens@2477
   572
/*
bobbens@2497
   573
 * \fn int SDL_HapticUpdateEffect(SDL_Haptic * haptic, int effect, SDL_HapticEffect * data)
bobbens@2497
   574
 *
bobbens@2497
   575
 * \brief Updates an effect.  Can be used dynamically, although behaviour when
bobbens@2488
   576
 * dynamically changing direction may be strange.  Specifically the effect
bobbens@2488
   577
 * may reupload itself and start playing from the start.  You cannot change
bobbens@2488
   578
 * the type either when running UpdateEffect.
bobbens@2488
   579
 *
bobbens@2497
   580
 *    \param haptic Haptic device that has the effect.
bobbens@2497
   581
 *    \param effect Effect to update.
bobbens@2497
   582
 *    \param data New effect properties to use.
bobbens@2497
   583
 *    \return The id of the effect on success or -1 on error.
bobbens@2497
   584
 *
bobbens@2497
   585
 * \sa SDL_HapticNewEffect
bobbens@2497
   586
 * \sa SDL_HapticRunEffect
bobbens@2497
   587
 * \sa SDL_HapticDestroyEffect
bobbens@2488
   588
 */
bobbens@2488
   589
extern DECLSPEC int SDL_HapticUpdateEffect(SDL_Haptic * haptic, int effect, SDL_HapticEffect * data);
bobbens@2488
   590
bobbens@2488
   591
/*
bobbens@2497
   592
 * \fn int SDL_HapticRunEffects(SDL_Haptic * haptic, int effect)
bobbens@2483
   593
 *
bobbens@2497
   594
 * \brief Runs the haptic effect on it's assosciated haptic device.
bobbens@2497
   595
 *
bobbens@2497
   596
 *    \param haptic Haptic device to run the effect on.
bobbens@2497
   597
 *    \param effect Identifier of the haptic effect to run.
bobbens@2497
   598
 *    \return 0 on success or -1 on error.
bobbens@2497
   599
 *
bobbens@2497
   600
 * \sa SDL_HapticStopEffect
bobbens@2497
   601
 * \sa SDL_HapticDestroyEffect
bobbens@2497
   602
 * \sa SDL_HapticGetEffectStatus
bobbens@2477
   603
 */
bobbens@2477
   604
extern DECLSPEC int SDL_HapticRunEffect(SDL_Haptic * haptic, int effect);
bobbens@2477
   605
bobbens@2477
   606
/*
bobbens@2497
   607
 * \fn int SDL_HapticStopEffect(SDL_Haptic * haptic, int effect)
bobbens@2485
   608
 *
bobbens@2497
   609
 * \brief Stops the haptic effect on it's assosciated haptic device.
bobbens@2497
   610
 *
bobbens@2497
   611
 *    \param haptic Haptic device to stop the effect on.
bobbens@2497
   612
 *    \praam effect Identifier of the effect to stop.
bobbens@2497
   613
 *    \return 0 on success or -1 on error.
bobbens@2497
   614
 *
bobbens@2497
   615
 * \sa SDL_HapticRunEffect
bobbens@2497
   616
 * \sa SDL_HapticDestroyEffect
bobbens@2485
   617
 */
bobbens@2485
   618
extern DECLSPEC int SDL_HapticStopEffect(SDL_Haptic * haptic, int effect);
bobbens@2485
   619
bobbens@2485
   620
/*
bobbens@2497
   621
 * \fn void SDL_HapticDestroyEffect(SDL_Haptic * haptic, int effect)
bobbens@2497
   622
 *
bobbens@2497
   623
 * \brief Destroys a haptic effect on the device.  This will stop the effect
bobbens@2497
   624
 * if it's running.  Effects are automatically destroyed when the device is
bobbens@2497
   625
 * closed.
bobbens@2497
   626
 *
bobbens@2497
   627
 *    \param haptic Device to destroy the effect on.
bobbens@2497
   628
 *    \param effect Identifier of the effect to destroy.
bobbens@2497
   629
 * 
bobbens@2497
   630
 * \sa SDL_HapticNewEffect
bobbens@2477
   631
 */
bobbens@2477
   632
extern DECLSPEC void SDL_HapticDestroyEffect(SDL_Haptic * haptic, int effect);
bobbens@2477
   633
bobbens@2483
   634
/*
bobbens@2497
   635
 * \fn int SDL_HapticGetEffectStatus(SDL_Haptic *haptic, int effect)
bobbens@2495
   636
 *
bobbens@2497
   637
 * \brief Gets the status of the current effect on the haptic device.
bobbens@2497
   638
 *
bobbens@2497
   639
 * Device must support the SDL_HAPTIC_STATUS feature.
bobbens@2497
   640
 *
bobbens@2497
   641
 *    \param haptic Haptic device to query the effect status on.
bobbens@2497
   642
 *    \param effect Identifier of the effect to query it's status.
bobbens@2497
   643
 *    \return 0 if it isn't playing, SDL_HAPTIC_PLAYING if it is playing
bobbens@2497
   644
 *            or -1 on error.
bobbens@2497
   645
 *
bobbens@2497
   646
 * \sa SDL_HapticRunEffect
bobbens@2497
   647
 * \sa SDL_HapticStopEffect
bobbens@2495
   648
 */
bobbens@2495
   649
extern DECLSPEC int SDL_HapticGetEffectStatus(SDL_Haptic *haptic, int effect);
bobbens@2495
   650
bobbens@2495
   651
/*
bobbens@2497
   652
 * \fn int SDL_HapticSetGain(SDL_Haptic * haptic, int gain)
bobbens@2483
   653
 *
bobbens@2497
   654
 * \brief Sets the global gain of the device.  Gain should be between 0 and 100.
bobbens@2497
   655
 *
bobbens@2497
   656
 * Device must support the SDL_HAPTIC_GAIN feature.
bobbens@2497
   657
 *
bobbens@2497
   658
 *    \param haptic Haptic device to set the gain on.
bobbens@2497
   659
 *    \param gain Value to set the gain to, should be between 0 and 100.
bobbens@2497
   660
 *    \return 0 on success or -1 on error.
bobbens@2497
   661
 *
bobbens@2497
   662
 * \sa SDL_HapticQuery
bobbens@2483
   663
 */
bobbens@2483
   664
extern DECLSPEC int SDL_HapticSetGain(SDL_Haptic * haptic, int gain);
bobbens@2483
   665
bobbens@2484
   666
/*
bobbens@2497
   667
 * \fn int SDL_HapticSetAutocenter(SDL_Haptic * haptic, int autocenter)
bobbens@2497
   668
 *
bobbens@2497
   669
 * \brief Sets the global autocenter of the device.  Autocenter should be between
bobbens@2484
   670
 * 0 and 100.  Setting it to 0 will disable autocentering.
bobbens@2484
   671
 *
bobbens@2497
   672
 * Device must support the SDL_HAPTIC_AUTOCENTER feature.
bobbens@2497
   673
 *
bobbens@2497
   674
 *    \param haptic Haptic device to set autocentering on.
bobbens@2497
   675
 *    \param autocenter Value to set autocenter to, 0 disables autocentering.
bobbens@2497
   676
 *    \return 0 on success or -1 on error.
bobbens@2497
   677
 *
bobbens@2497
   678
 * \sa SDL_HapticQuery
bobbens@2484
   679
 */
bobbens@2484
   680
extern DECLSPEC int SDL_HapticSetAutocenter(SDL_Haptic * haptic, int autocenter);
bobbens@2484
   681
bobbens@2472
   682
bobbens@2472
   683
/* Ends C function definitions when using C++ */
bobbens@2472
   684
#ifdef __cplusplus
bobbens@2472
   685
/* *INDENT-OFF* */
bobbens@2472
   686
}
bobbens@2472
   687
/* *INDENT-ON* */
bobbens@2472
   688
#endif
bobbens@2472
   689
#include "close_code.h"
bobbens@2472
   690
bobbens@2472
   691
#endif /* _SDL_haptic_h */
bobbens@2472
   692
bobbens@2472
   693
/* vi: set ts=4 sw=4 expandtab: */
bobbens@2472
   694
bobbens@2472
   695