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