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