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