include/SDL_haptic.h
author Edgar Simo <bobbens@gmail.com>
Wed, 02 Jul 2008 08:24:35 +0000
branchgsoc2008_force_feedback
changeset 2489 96adc8025331
parent 2488 8e2bdbccf7ff
child 2495 66c02abeef0e
permissions -rw-r--r--
Exposed some of the joystick stuff to the haptic subsystem.
Added SDL_JoystickIsHaptic().
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@2472
    49
/* Different effects that can be generated */
bobbens@2472
    50
#define SDL_HAPTIC_CONSTANT   (1<<0)
bobbens@2487
    51
#define SDL_HAPTIC_SINE       (1<<1)
bobbens@2487
    52
#define SDL_HAPTIC_SQUARE     (1<<2)
bobbens@2487
    53
#define SDL_HAPTIC_TRIANGLE   (1<<3)
bobbens@2487
    54
#define SDL_HAPTIC_SAWTOOTHUP (1<<4)
bobbens@2487
    55
#define SDL_HAPTIC_SAWTOOTHDOWN (1<<5)
bobbens@2487
    56
#define SDL_HAPTIC_RAMP       (1<<6)
bobbens@2487
    57
#define SDL_HAPTIC_SPRING     (1<<7)
bobbens@2487
    58
#define SDL_HAPTIC_FRICTION   (1<<8)
bobbens@2487
    59
#define SDL_HAPTIC_DAMPER     (1<<9)
bobbens@2487
    60
#define SDL_HAPTIC_INERTIA    (1<<10)
bobbens@2487
    61
#define SDL_HAPTIC_CUSTOM     (1<<11)
bobbens@2487
    62
/* These last two are features the device has, not effects */
bobbens@2487
    63
#define SDL_HAPTIC_GAIN       (1<<12)
bobbens@2487
    64
#define SDL_HAPTIC_AUTOCENTER (1<<13)
bobbens@2481
    65
bobbens@2481
    66
bobbens@2481
    67
/*
bobbens@2481
    68
 * All values max at 32767 (0x7fff).  Signed values also can be negative.
bobbens@2481
    69
 * Time values unless specified otherwise are in milliseconds.
bobbens@2481
    70
 *
bobbens@2481
    71
 * Common parts:
bobbens@2481
    72
 * 
bobbens@2481
    73
 * Replay:
bobbens@2481
    74
 *    Uint16 length;    Duration of effect.
bobbens@2481
    75
 *    Uint16 delay;     Delay before starting effect.
bobbens@2481
    76
 *
bobbens@2481
    77
 * Trigger:
bobbens@2481
    78
 *    Uint16 button;    Button that triggers effect.
bobbens@2481
    79
 *    Uint16 interval;  How soon before effect can be triggered again.
bobbens@2481
    80
 *
bobbens@2481
    81
 * Envelope:
bobbens@2481
    82
 *    Uint16 attack_length;   Duration of the attack.
bobbens@2481
    83
 *    Uint16 attack_level;    Level at the start of the attack.
bobbens@2481
    84
 *    Uint16 fade_length;     Duration of the fade out.
bobbens@2481
    85
 *    Uint16 fade_level;      Level at the end of the fade.
bobbens@2481
    86
 */
bobbens@2477
    87
typedef struct SDL_HapticConstant {
bobbens@2477
    88
   /* Header */
bobbens@2481
    89
   Uint16 type; /* SDL_HAPTIC_CONSTANT */
bobbens@2480
    90
   Uint16 direction;
bobbens@2480
    91
bobbens@2480
    92
   /* Replay */
bobbens@2477
    93
   Uint16 length;
bobbens@2477
    94
   Uint16 delay;
bobbens@2480
    95
bobbens@2480
    96
   /* Trigger */
bobbens@2480
    97
   Uint16 button;
bobbens@2480
    98
   Uint16 interval;
bobbens@2480
    99
bobbens@2480
   100
   /* Constant */
bobbens@2481
   101
   Sint16 level; /* Strength of the constant effect. */
bobbens@2480
   102
bobbens@2480
   103
   /* Envelope */
bobbens@2480
   104
   Uint16 attack_length;
bobbens@2480
   105
   Uint16 attack_level;
bobbens@2480
   106
   Uint16 fade_length;
bobbens@2480
   107
   Uint16 fade_level;
bobbens@2480
   108
} SDL_HapticConstant;
bobbens@2480
   109
typedef struct SDL_HapticPeriodic {
bobbens@2480
   110
   /* Header */
bobbens@2487
   111
   Uint16 type; /* SDL_HAPTIC_{SINE,SQUARE,TRIANGLE,SAWTOOTHUP,SAWTOOTHDOWN} */
bobbens@2477
   112
   Uint16 direction;
bobbens@2480
   113
bobbens@2480
   114
   /* Replay */
bobbens@2480
   115
   Uint16 length;
bobbens@2480
   116
   Uint16 delay;
bobbens@2480
   117
bobbens@2480
   118
   /* Trigger */
bobbens@2480
   119
   Uint16 button;
bobbens@2480
   120
   Uint16 interval;
bobbens@2480
   121
bobbens@2480
   122
   /* Periodic */
bobbens@2481
   123
   Uint16 period; /* Period of the wave */
bobbens@2481
   124
   Sint16 magnitude; /* Peak value */
bobbens@2481
   125
   Sint16 offset; /* Mean value of the wave */
bobbens@2481
   126
   Uint16 phase; /* Horizontal shift */
bobbens@2480
   127
bobbens@2480
   128
   /* Envelope */
bobbens@2480
   129
   Uint16 attack_length;
bobbens@2480
   130
   Uint16 attack_level;
bobbens@2480
   131
   Uint16 fade_length;
bobbens@2480
   132
   Uint16 fade_level;
bobbens@2480
   133
} SDL_HapticPeriodic;
bobbens@2482
   134
typedef struct SDL_HapticCondition {
bobbens@2482
   135
   /* Header */
bobbens@2482
   136
   Uint16 type; /* SDL_HAPTIC_{SPRING,DAMPER,INERTIA,FRICTION} */
bobbens@2482
   137
   Uint16 direction;
bobbens@2482
   138
bobbens@2482
   139
   /* Replay */
bobbens@2482
   140
   Uint16 length;
bobbens@2482
   141
   Uint16 delay;
bobbens@2482
   142
bobbens@2482
   143
   /* Trigger */
bobbens@2482
   144
   Uint16 button;
bobbens@2482
   145
   Uint16 interval;
bobbens@2482
   146
bobbens@2482
   147
   /* Condition */
bobbens@2482
   148
   Uint16 right_sat; /* Level when joystick is to the right. */
bobbens@2482
   149
   Uint16 left_sat; /* Level when joystick is to the left */
bobbens@2482
   150
   Sint16 right_coeff; /* How fast to increase the force towards the right */
bobbens@2482
   151
   Sint16 left_coeff; /* How fast to increase the force towards the left */
bobbens@2482
   152
   Uint16 deadband; /* Size of the dead zone */
bobbens@2482
   153
   Sint16 center; /* Position of the dead zone */
bobbens@2482
   154
} SDL_HapticCondition;
bobbens@2482
   155
typedef struct SDL_HapticRamp {
bobbens@2482
   156
   /* Header */
bobbens@2482
   157
   Uint16 type; /* SDL_HAPTIC_RAMP */
bobbens@2482
   158
   Uint16 direction;
bobbens@2482
   159
bobbens@2482
   160
   /* Replay */
bobbens@2482
   161
   Uint16 length;
bobbens@2482
   162
   Uint16 delay;
bobbens@2482
   163
bobbens@2482
   164
   /* Trigger */
bobbens@2482
   165
   Uint16 button;
bobbens@2482
   166
   Uint16 interval;
bobbens@2482
   167
bobbens@2482
   168
   /* Ramp */
bobbens@2482
   169
   Sint16 start;
bobbens@2482
   170
   Sint16 end;
bobbens@2482
   171
bobbens@2482
   172
   /* Envelope */
bobbens@2482
   173
   Uint16 attack_length;
bobbens@2482
   174
   Uint16 attack_level;
bobbens@2482
   175
   Uint16 fade_length;
bobbens@2482
   176
   Uint16 fade_level;
bobbens@2482
   177
} SDL_HapticRamp;
bobbens@2477
   178
bobbens@2477
   179
typedef union SDL_HapticEffect {
bobbens@2477
   180
   /* Common for all force feedback effects */
bobbens@2477
   181
   Uint16 type; /* Effect type */
bobbens@2477
   182
   SDL_HapticConstant constant; /* Constant effect */
bobbens@2480
   183
   SDL_HapticPeriodic periodic; /* Periodic effect */
bobbens@2482
   184
   SDL_HapticCondition condition; /* Condition effect */
bobbens@2482
   185
   SDL_HapticRamp ramp; /* Ramp effect */
bobbens@2477
   186
} SDL_HapticEffect;
bobbens@2477
   187
bobbens@2472
   188
bobbens@2472
   189
/* Function prototypes */
bobbens@2472
   190
/*
bobbens@2472
   191
 * Count the number of joysticks attached to the system
bobbens@2472
   192
 */
bobbens@2472
   193
extern DECLSPEC int SDLCALL SDL_NumHaptics(void);
bobbens@2472
   194
bobbens@2472
   195
/*
bobbens@2476
   196
 * Get the implementation dependent name of a Haptic device.
bobbens@2472
   197
 * This can be called before any joysticks are opened.
bobbens@2472
   198
 * If no name can be found, this function returns NULL.
bobbens@2472
   199
 */
bobbens@2472
   200
extern DECLSPEC const char *SDLCALL SDL_HapticName(int device_index);
bobbens@2472
   201
bobbens@2476
   202
/*
bobbens@2476
   203
 * Opens a Haptic device for usage - the index passed as an
bobbens@2476
   204
 * argument refers to the N'th Haptic device on this system.
bobbens@2476
   205
 *
bobbens@2476
   206
 * This function returns a Haptic device identifier, or Null
bobbens@2476
   207
 * if an error occurred.
bobbens@2476
   208
 */
bobbens@2476
   209
extern DECLSPEC SDL_Haptic * SDL_HapticOpen(int device_index);
bobbens@2476
   210
bobbens@2489
   211
/*
bobbens@2489
   212
 * Checks to see if a joystick has haptic features.
bobbens@2489
   213
 *
bobbens@2489
   214
 * Returns SDL_TRUE if the joystick is haptic, SDL_FALSE if it isn't
bobbens@2489
   215
 * and -1 on error.
bobbens@2489
   216
 */
bobbens@2489
   217
extern DECLSPEC int SDL_JoystickIsHaptic(SDL_Joystick * joystick);
bobbens@2489
   218
bobbens@2489
   219
/*
bobbens@2489
   220
 * Opens a Haptic device for usage from a Joystick device.
bobbens@2489
   221
 *
bobbens@2489
   222
 * Returns a valid pointer to a haptic device on success or NULL
bobbens@2489
   223
 * if an error occurred.
bobbens@2489
   224
 */
bobbens@2489
   225
extern DECLSPEC SDL_Haptic * SDL_HapticOpenFromJoystick(SDL_Joystick * joystick);
bobbens@2489
   226
bobbens@2476
   227
/* 
bobbens@2476
   228
 * Closes a Haptic device previously opened with SDL_HapticOpen.
bobbens@2476
   229
 */
bobbens@2476
   230
extern DECLSPEC void SDL_HapticClose(SDL_Haptic * haptic);
bobbens@2476
   231
bobbens@2477
   232
/*
bobbens@2478
   233
 * Returns the number of effects a haptic device can store.
bobbens@2478
   234
 */
bobbens@2478
   235
extern DECLSPEC int SDL_HapticNumEffects(SDL_Haptic * haptic);
bobbens@2478
   236
bobbens@2478
   237
/*
bobbens@2478
   238
 * Returns the supported effects.  Individual effects can be queried by
bobbens@2478
   239
 * bitwise operators.
bobbens@2478
   240
 *
bobbens@2478
   241
 * Example:  (SDL_HapticQueryEffects(haptic) & SDL_HAPTIC_CONSTANT)
bobbens@2478
   242
 */
bobbens@2478
   243
extern DECLSPEC unsigned int SDL_HapticQueryEffects(SDL_Haptic * haptic);
bobbens@2478
   244
bobbens@2478
   245
/*
bobbens@2486
   246
 * Checks to see if effect is supported by haptic.
bobbens@2486
   247
 *
bobbens@2486
   248
 * Returns SDL_TRUE if effect is supported, SDL_FALSE if it isn't and -1
bobbens@2486
   249
 * on error.
bobbens@2486
   250
 */
bobbens@2486
   251
extern DECLSPEC int SDL_HapticEffectSupported(SDL_Haptic * haptic, SDL_HapticEffect * effect);
bobbens@2486
   252
bobbens@2486
   253
/*
bobbens@2477
   254
 * Creates a new haptic effect on the device.
bobbens@2483
   255
 *
bobbens@2483
   256
 * Returns the id of the effect on success, -1 on failure.
bobbens@2477
   257
 */
bobbens@2477
   258
extern DECLSPEC int SDL_HapticNewEffect(SDL_Haptic * haptic, SDL_HapticEffect * effect);
bobbens@2477
   259
bobbens@2477
   260
/*
bobbens@2488
   261
 * Uploads an effect.  Can be used dynamically, although behaviour when
bobbens@2488
   262
 * dynamically changing direction may be strange.  Specifically the effect
bobbens@2488
   263
 * may reupload itself and start playing from the start.  You cannot change
bobbens@2488
   264
 * the type either when running UpdateEffect.
bobbens@2488
   265
 *
bobbens@2488
   266
 * Returns the id of the effect on success, -1 on failure.
bobbens@2488
   267
 */
bobbens@2488
   268
extern DECLSPEC int SDL_HapticUpdateEffect(SDL_Haptic * haptic, int effect, SDL_HapticEffect * data);
bobbens@2488
   269
bobbens@2488
   270
/*
bobbens@2477
   271
 * Runs the haptic effect on it's assosciated haptic device.
bobbens@2483
   272
 *
bobbens@2483
   273
 * Returns 0 on success or -1 on failure.
bobbens@2477
   274
 */
bobbens@2477
   275
extern DECLSPEC int SDL_HapticRunEffect(SDL_Haptic * haptic, int effect);
bobbens@2477
   276
bobbens@2477
   277
/*
bobbens@2485
   278
 * Stops the haptic effect on it's assosciated haptic device.
bobbens@2485
   279
 *
bobbens@2485
   280
 * Returns 0 on success or -1 on failure.
bobbens@2485
   281
 */
bobbens@2485
   282
extern DECLSPEC int SDL_HapticStopEffect(SDL_Haptic * haptic, int effect);
bobbens@2485
   283
bobbens@2485
   284
/*
bobbens@2485
   285
 * Destroys a haptic effect on the device.  This will stop the effect if it's
bobbens@2485
   286
 * running.
bobbens@2477
   287
 */
bobbens@2477
   288
extern DECLSPEC void SDL_HapticDestroyEffect(SDL_Haptic * haptic, int effect);
bobbens@2477
   289
bobbens@2483
   290
/*
bobbens@2483
   291
 * Sets the global gain of the device.  Gain should be between 0 and 100.
bobbens@2483
   292
 *
bobbens@2483
   293
 * Returns 0 on success or -1 on failure.
bobbens@2483
   294
 */
bobbens@2483
   295
extern DECLSPEC int SDL_HapticSetGain(SDL_Haptic * haptic, int gain);
bobbens@2483
   296
bobbens@2484
   297
/*
bobbens@2484
   298
 * Sets the global autocenter of the device.  Autocenter should be between
bobbens@2484
   299
 * 0 and 100.  Setting it to 0 will disable autocentering.
bobbens@2484
   300
 *
bobbens@2484
   301
 * Returns 0 on success or -1 on failure.
bobbens@2484
   302
 */
bobbens@2484
   303
extern DECLSPEC int SDL_HapticSetAutocenter(SDL_Haptic * haptic, int autocenter);
bobbens@2484
   304
bobbens@2472
   305
bobbens@2472
   306
/* Ends C function definitions when using C++ */
bobbens@2472
   307
#ifdef __cplusplus
bobbens@2472
   308
/* *INDENT-OFF* */
bobbens@2472
   309
}
bobbens@2472
   310
/* *INDENT-ON* */
bobbens@2472
   311
#endif
bobbens@2472
   312
#include "close_code.h"
bobbens@2472
   313
bobbens@2472
   314
#endif /* _SDL_haptic_h */
bobbens@2472
   315
bobbens@2472
   316
/* vi: set ts=4 sw=4 expandtab: */
bobbens@2472
   317
bobbens@2472
   318