include/SDL_haptic.h
author Edgar Simo <bobbens@gmail.com>
Thu, 03 Jul 2008 09:58:27 +0000
branchgsoc2008_force_feedback
changeset 2495 66c02abeef0e
parent 2489 96adc8025331
child 2497 0893fbf73b3d
permissions -rw-r--r--
Added SDL_HapticGetEffectStatus().
More comments.
bobbens@2472
     1
/*
bobbens@2472
     2
    SDL - Simple DirectMedia Layer
bobbens@2472
     3
    Copyright (C) 2008 Edgar Simo
bobbens@2472
     4
bobbens@2472
     5
    This library is free software; you can redistribute it and/or
bobbens@2472
     6
    modify it under the terms of the GNU Lesser General Public
bobbens@2472
     7
    License as published by the Free Software Foundation; either
bobbens@2472
     8
    version 2.1 of the License, or (at your option) any later version.
bobbens@2472
     9
bobbens@2472
    10
    This library is distributed in the hope that it will be useful,
bobbens@2472
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
bobbens@2472
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
bobbens@2472
    13
    Lesser General Public License for more details.
bobbens@2472
    14
bobbens@2472
    15
    You should have received a copy of the GNU Lesser General Public
bobbens@2472
    16
    License along with this library; if not, write to the Free Software
bobbens@2472
    17
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
bobbens@2472
    18
bobbens@2472
    19
    Sam Lantinga
bobbens@2472
    20
    slouken@libsdl.org
bobbens@2472
    21
*/
bobbens@2472
    22
bobbens@2472
    23
/**
bobbens@2472
    24
 * \file SDL_haptic.h
bobbens@2472
    25
 *
bobbens@2472
    26
 * Include file for SDL haptic subsystem
bobbens@2472
    27
 */
bobbens@2472
    28
bobbens@2472
    29
#ifndef _SDL_haptic_h
bobbens@2472
    30
#define _SDL_haptic_h
bobbens@2472
    31
bobbens@2472
    32
#include "SDL_stdinc.h"
bobbens@2472
    33
#include "SDL_error.h"
bobbens@2489
    34
#include "SDL_joystick.h"
bobbens@2472
    35
bobbens@2472
    36
#include "begin_code.h"
bobbens@2472
    37
/* Set up for C function definitions, even when using C++ */
bobbens@2472
    38
#ifdef __cplusplus
bobbens@2472
    39
/* *INDENT-OFF* */
bobbens@2472
    40
extern "C" {
bobbens@2472
    41
   /* *INDENT-ON* */                                                         
bobbens@2472
    42
#endif
bobbens@2472
    43
bobbens@2472
    44
/* The haptic structure used to identify an SDL haptic */
bobbens@2472
    45
struct _SDL_Haptic;                                                     
bobbens@2472
    46
typedef struct _SDL_Haptic SDL_Haptic;
bobbens@2472
    47
bobbens@2472
    48
bobbens@2495
    49
/*
bobbens@2495
    50
 * Different haptic features a device can have.
bobbens@2495
    51
 */
bobbens@2495
    52
#define SDL_HAPTIC_CONSTANT   (1<<0) /* Constant effect supported */
bobbens@2495
    53
#define SDL_HAPTIC_SINE       (1<<1) /* Sine wave effect supported */
bobbens@2495
    54
#define SDL_HAPTIC_SQUARE     (1<<2) /* Square wave effect supported */
bobbens@2495
    55
#define SDL_HAPTIC_TRIANGLE   (1<<3) /* Triangle wave effect supported */
bobbens@2495
    56
#define SDL_HAPTIC_SAWTOOTHUP (1<<4) /* Sawtoothup wave effect supported */
bobbens@2495
    57
#define SDL_HAPTIC_SAWTOOTHDOWN (1<<5) /* Sawtoothdown wave effect supported */
bobbens@2495
    58
#define SDL_HAPTIC_RAMP       (1<<6) /* Ramp effect supported */
bobbens@2495
    59
#define SDL_HAPTIC_SPRING     (1<<7) /* Spring effect supported - uses axes position */
bobbens@2495
    60
#define SDL_HAPTIC_DAMPER     (1<<8) /* Damper effect supported - uses axes velocity */
bobbens@2495
    61
#define SDL_HAPTIC_INERTIA    (1<<9) /* Inertia effect supported - uses axes acceleration */
bobbens@2495
    62
#define SDL_HAPTIC_FRICTION   (1<<10) /* Friction effect supported - uses axes movement */
bobbens@2495
    63
#define SDL_HAPTIC_CUSTOM     (1<<11) /* Custom effect is supported */
bobbens@2487
    64
/* These last two are features the device has, not effects */
bobbens@2495
    65
#define SDL_HAPTIC_GAIN       (1<<12) /* Device can set global gain */
bobbens@2495
    66
#define SDL_HAPTIC_AUTOCENTER (1<<13) /* Device can set autocenter */
bobbens@2495
    67
#define SDL_HAPTIC_STATUS     (1<<14) /* Device can be queried for effect status */
bobbens@2481
    68
bobbens@2481
    69
bobbens@2481
    70
/*
bobbens@2481
    71
 * All values max at 32767 (0x7fff).  Signed values also can be negative.
bobbens@2481
    72
 * Time values unless specified otherwise are in milliseconds.
bobbens@2481
    73
 *
bobbens@2481
    74
 * Common parts:
bobbens@2481
    75
 * 
bobbens@2481
    76
 * Replay:
bobbens@2481
    77
 *    Uint16 length;    Duration of effect.
bobbens@2481
    78
 *    Uint16 delay;     Delay before starting effect.
bobbens@2481
    79
 *
bobbens@2481
    80
 * Trigger:
bobbens@2481
    81
 *    Uint16 button;    Button that triggers effect.
bobbens@2481
    82
 *    Uint16 interval;  How soon before effect can be triggered again.
bobbens@2481
    83
 *
bobbens@2481
    84
 * Envelope:
bobbens@2481
    85
 *    Uint16 attack_length;   Duration of the attack.
bobbens@2481
    86
 *    Uint16 attack_level;    Level at the start of the attack.
bobbens@2481
    87
 *    Uint16 fade_length;     Duration of the fade out.
bobbens@2481
    88
 *    Uint16 fade_level;      Level at the end of the fade.
bobbens@2481
    89
 */
bobbens@2477
    90
typedef struct SDL_HapticConstant {
bobbens@2477
    91
   /* Header */
bobbens@2481
    92
   Uint16 type; /* SDL_HAPTIC_CONSTANT */
bobbens@2480
    93
   Uint16 direction;
bobbens@2480
    94
bobbens@2480
    95
   /* Replay */
bobbens@2477
    96
   Uint16 length;
bobbens@2477
    97
   Uint16 delay;
bobbens@2480
    98
bobbens@2480
    99
   /* Trigger */
bobbens@2480
   100
   Uint16 button;
bobbens@2480
   101
   Uint16 interval;
bobbens@2480
   102
bobbens@2480
   103
   /* Constant */
bobbens@2481
   104
   Sint16 level; /* Strength of the constant effect. */
bobbens@2480
   105
bobbens@2480
   106
   /* Envelope */
bobbens@2480
   107
   Uint16 attack_length;
bobbens@2480
   108
   Uint16 attack_level;
bobbens@2480
   109
   Uint16 fade_length;
bobbens@2480
   110
   Uint16 fade_level;
bobbens@2480
   111
} SDL_HapticConstant;
bobbens@2480
   112
typedef struct SDL_HapticPeriodic {
bobbens@2480
   113
   /* Header */
bobbens@2487
   114
   Uint16 type; /* SDL_HAPTIC_{SINE,SQUARE,TRIANGLE,SAWTOOTHUP,SAWTOOTHDOWN} */
bobbens@2477
   115
   Uint16 direction;
bobbens@2480
   116
bobbens@2480
   117
   /* Replay */
bobbens@2480
   118
   Uint16 length;
bobbens@2480
   119
   Uint16 delay;
bobbens@2480
   120
bobbens@2480
   121
   /* Trigger */
bobbens@2480
   122
   Uint16 button;
bobbens@2480
   123
   Uint16 interval;
bobbens@2480
   124
bobbens@2480
   125
   /* Periodic */
bobbens@2481
   126
   Uint16 period; /* Period of the wave */
bobbens@2481
   127
   Sint16 magnitude; /* Peak value */
bobbens@2481
   128
   Sint16 offset; /* Mean value of the wave */
bobbens@2481
   129
   Uint16 phase; /* Horizontal shift */
bobbens@2480
   130
bobbens@2480
   131
   /* Envelope */
bobbens@2480
   132
   Uint16 attack_length;
bobbens@2480
   133
   Uint16 attack_level;
bobbens@2480
   134
   Uint16 fade_length;
bobbens@2480
   135
   Uint16 fade_level;
bobbens@2480
   136
} SDL_HapticPeriodic;
bobbens@2482
   137
typedef struct SDL_HapticCondition {
bobbens@2482
   138
   /* Header */
bobbens@2482
   139
   Uint16 type; /* SDL_HAPTIC_{SPRING,DAMPER,INERTIA,FRICTION} */
bobbens@2482
   140
   Uint16 direction;
bobbens@2482
   141
bobbens@2482
   142
   /* Replay */
bobbens@2482
   143
   Uint16 length;
bobbens@2482
   144
   Uint16 delay;
bobbens@2482
   145
bobbens@2482
   146
   /* Trigger */
bobbens@2482
   147
   Uint16 button;
bobbens@2482
   148
   Uint16 interval;
bobbens@2482
   149
bobbens@2482
   150
   /* Condition */
bobbens@2482
   151
   Uint16 right_sat; /* Level when joystick is to the right. */
bobbens@2482
   152
   Uint16 left_sat; /* Level when joystick is to the left */
bobbens@2482
   153
   Sint16 right_coeff; /* How fast to increase the force towards the right */
bobbens@2482
   154
   Sint16 left_coeff; /* How fast to increase the force towards the left */
bobbens@2482
   155
   Uint16 deadband; /* Size of the dead zone */
bobbens@2482
   156
   Sint16 center; /* Position of the dead zone */
bobbens@2482
   157
} SDL_HapticCondition;
bobbens@2482
   158
typedef struct SDL_HapticRamp {
bobbens@2482
   159
   /* Header */
bobbens@2482
   160
   Uint16 type; /* SDL_HAPTIC_RAMP */
bobbens@2482
   161
   Uint16 direction;
bobbens@2482
   162
bobbens@2482
   163
   /* Replay */
bobbens@2482
   164
   Uint16 length;
bobbens@2482
   165
   Uint16 delay;
bobbens@2482
   166
bobbens@2482
   167
   /* Trigger */
bobbens@2482
   168
   Uint16 button;
bobbens@2482
   169
   Uint16 interval;
bobbens@2482
   170
bobbens@2482
   171
   /* Ramp */
bobbens@2495
   172
   Sint16 start; /* Beginning strength level. */
bobbens@2495
   173
   Sint16 end; /* Ending strength level. */
bobbens@2482
   174
bobbens@2482
   175
   /* Envelope */
bobbens@2482
   176
   Uint16 attack_length;
bobbens@2482
   177
   Uint16 attack_level;
bobbens@2482
   178
   Uint16 fade_length;
bobbens@2482
   179
   Uint16 fade_level;
bobbens@2482
   180
} SDL_HapticRamp;
bobbens@2477
   181
bobbens@2477
   182
typedef union SDL_HapticEffect {
bobbens@2477
   183
   /* Common for all force feedback effects */
bobbens@2477
   184
   Uint16 type; /* Effect type */
bobbens@2477
   185
   SDL_HapticConstant constant; /* Constant effect */
bobbens@2480
   186
   SDL_HapticPeriodic periodic; /* Periodic effect */
bobbens@2482
   187
   SDL_HapticCondition condition; /* Condition effect */
bobbens@2482
   188
   SDL_HapticRamp ramp; /* Ramp effect */
bobbens@2477
   189
} SDL_HapticEffect;
bobbens@2477
   190
bobbens@2472
   191
bobbens@2472
   192
/* Function prototypes */
bobbens@2472
   193
/*
bobbens@2472
   194
 * Count the number of joysticks attached to the system
bobbens@2472
   195
 */
bobbens@2472
   196
extern DECLSPEC int SDLCALL SDL_NumHaptics(void);
bobbens@2472
   197
bobbens@2472
   198
/*
bobbens@2476
   199
 * Get the implementation dependent name of a Haptic device.
bobbens@2472
   200
 * This can be called before any joysticks are opened.
bobbens@2472
   201
 * If no name can be found, this function returns NULL.
bobbens@2472
   202
 */
bobbens@2472
   203
extern DECLSPEC const char *SDLCALL SDL_HapticName(int device_index);
bobbens@2472
   204
bobbens@2476
   205
/*
bobbens@2476
   206
 * Opens a Haptic device for usage - the index passed as an
bobbens@2476
   207
 * argument refers to the N'th Haptic device on this system.
bobbens@2476
   208
 *
bobbens@2476
   209
 * This function returns a Haptic device identifier, or Null
bobbens@2476
   210
 * if an error occurred.
bobbens@2476
   211
 */
bobbens@2476
   212
extern DECLSPEC SDL_Haptic * SDL_HapticOpen(int device_index);
bobbens@2476
   213
bobbens@2489
   214
/*
bobbens@2489
   215
 * Checks to see if a joystick has haptic features.
bobbens@2489
   216
 *
bobbens@2489
   217
 * Returns SDL_TRUE if the joystick is haptic, SDL_FALSE if it isn't
bobbens@2489
   218
 * and -1 on error.
bobbens@2489
   219
 */
bobbens@2489
   220
extern DECLSPEC int SDL_JoystickIsHaptic(SDL_Joystick * joystick);
bobbens@2489
   221
bobbens@2489
   222
/*
bobbens@2489
   223
 * Opens a Haptic device for usage from a Joystick device.
bobbens@2489
   224
 *
bobbens@2489
   225
 * Returns a valid pointer to a haptic device on success or NULL
bobbens@2489
   226
 * if an error occurred.
bobbens@2489
   227
 */
bobbens@2489
   228
extern DECLSPEC SDL_Haptic * SDL_HapticOpenFromJoystick(SDL_Joystick * joystick);
bobbens@2489
   229
bobbens@2476
   230
/* 
bobbens@2476
   231
 * Closes a Haptic device previously opened with SDL_HapticOpen.
bobbens@2476
   232
 */
bobbens@2476
   233
extern DECLSPEC void SDL_HapticClose(SDL_Haptic * haptic);
bobbens@2476
   234
bobbens@2477
   235
/*
bobbens@2478
   236
 * Returns the number of effects a haptic device can store.
bobbens@2478
   237
 */
bobbens@2478
   238
extern DECLSPEC int SDL_HapticNumEffects(SDL_Haptic * haptic);
bobbens@2478
   239
bobbens@2478
   240
/*
bobbens@2478
   241
 * Returns the supported effects.  Individual effects can be queried by
bobbens@2478
   242
 * bitwise operators.
bobbens@2478
   243
 *
bobbens@2478
   244
 * Example:  (SDL_HapticQueryEffects(haptic) & SDL_HAPTIC_CONSTANT)
bobbens@2478
   245
 */
bobbens@2478
   246
extern DECLSPEC unsigned int SDL_HapticQueryEffects(SDL_Haptic * haptic);
bobbens@2478
   247
bobbens@2478
   248
/*
bobbens@2486
   249
 * Checks to see if effect is supported by haptic.
bobbens@2486
   250
 *
bobbens@2486
   251
 * Returns SDL_TRUE if effect is supported, SDL_FALSE if it isn't and -1
bobbens@2486
   252
 * on error.
bobbens@2486
   253
 */
bobbens@2486
   254
extern DECLSPEC int SDL_HapticEffectSupported(SDL_Haptic * haptic, SDL_HapticEffect * effect);
bobbens@2486
   255
bobbens@2486
   256
/*
bobbens@2477
   257
 * Creates a new haptic effect on the device.
bobbens@2483
   258
 *
bobbens@2483
   259
 * Returns the id of the effect on success, -1 on failure.
bobbens@2477
   260
 */
bobbens@2477
   261
extern DECLSPEC int SDL_HapticNewEffect(SDL_Haptic * haptic, SDL_HapticEffect * effect);
bobbens@2477
   262
bobbens@2477
   263
/*
bobbens@2488
   264
 * Uploads an effect.  Can be used dynamically, although behaviour when
bobbens@2488
   265
 * dynamically changing direction may be strange.  Specifically the effect
bobbens@2488
   266
 * may reupload itself and start playing from the start.  You cannot change
bobbens@2488
   267
 * the type either when running UpdateEffect.
bobbens@2488
   268
 *
bobbens@2488
   269
 * Returns the id of the effect on success, -1 on failure.
bobbens@2488
   270
 */
bobbens@2488
   271
extern DECLSPEC int SDL_HapticUpdateEffect(SDL_Haptic * haptic, int effect, SDL_HapticEffect * data);
bobbens@2488
   272
bobbens@2488
   273
/*
bobbens@2477
   274
 * Runs the haptic effect on it's assosciated haptic device.
bobbens@2483
   275
 *
bobbens@2483
   276
 * Returns 0 on success or -1 on failure.
bobbens@2477
   277
 */
bobbens@2477
   278
extern DECLSPEC int SDL_HapticRunEffect(SDL_Haptic * haptic, int effect);
bobbens@2477
   279
bobbens@2477
   280
/*
bobbens@2485
   281
 * Stops the haptic effect on it's assosciated haptic device.
bobbens@2485
   282
 *
bobbens@2485
   283
 * Returns 0 on success or -1 on failure.
bobbens@2485
   284
 */
bobbens@2485
   285
extern DECLSPEC int SDL_HapticStopEffect(SDL_Haptic * haptic, int effect);
bobbens@2485
   286
bobbens@2485
   287
/*
bobbens@2485
   288
 * Destroys a haptic effect on the device.  This will stop the effect if it's
bobbens@2485
   289
 * running.
bobbens@2477
   290
 */
bobbens@2477
   291
extern DECLSPEC void SDL_HapticDestroyEffect(SDL_Haptic * haptic, int effect);
bobbens@2477
   292
bobbens@2483
   293
/*
bobbens@2495
   294
 * Gets the status of the current effect on the haptic device.
bobbens@2495
   295
 *
bobbens@2495
   296
 * Returns 0 if it isn't playing, SDL_HAPTIC_PLAYING if it is playing
bobbens@2495
   297
 * or -1 on failure.
bobbens@2495
   298
 */
bobbens@2495
   299
extern DECLSPEC int SDL_HapticGetEffectStatus(SDL_Haptic *haptic, int effect);
bobbens@2495
   300
bobbens@2495
   301
/*
bobbens@2483
   302
 * Sets the global gain of the device.  Gain should be between 0 and 100.
bobbens@2483
   303
 *
bobbens@2483
   304
 * Returns 0 on success or -1 on failure.
bobbens@2483
   305
 */
bobbens@2483
   306
extern DECLSPEC int SDL_HapticSetGain(SDL_Haptic * haptic, int gain);
bobbens@2483
   307
bobbens@2484
   308
/*
bobbens@2484
   309
 * Sets the global autocenter of the device.  Autocenter should be between
bobbens@2484
   310
 * 0 and 100.  Setting it to 0 will disable autocentering.
bobbens@2484
   311
 *
bobbens@2484
   312
 * Returns 0 on success or -1 on failure.
bobbens@2484
   313
 */
bobbens@2484
   314
extern DECLSPEC int SDL_HapticSetAutocenter(SDL_Haptic * haptic, int autocenter);
bobbens@2484
   315
bobbens@2472
   316
bobbens@2472
   317
/* Ends C function definitions when using C++ */
bobbens@2472
   318
#ifdef __cplusplus
bobbens@2472
   319
/* *INDENT-OFF* */
bobbens@2472
   320
}
bobbens@2472
   321
/* *INDENT-ON* */
bobbens@2472
   322
#endif
bobbens@2472
   323
#include "close_code.h"
bobbens@2472
   324
bobbens@2472
   325
#endif /* _SDL_haptic_h */
bobbens@2472
   326
bobbens@2472
   327
/* vi: set ts=4 sw=4 expandtab: */
bobbens@2472
   328
bobbens@2472
   329