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