include/SDL_haptic.h
author Edgar Simo <bobbens@gmail.com>
Tue, 01 Jul 2008 10:44:42 +0000
branchgsoc2008_force_feedback
changeset 2481 5d0ea4576f20
parent 2480 b883974445fc
child 2482 b51ad78812d5
permissions -rw-r--r--
More comments.
Clamped values in struct ff_effect.
Added waveforms.
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@2472
    55
#define SDL_HAPTIC_RUMBLE     (1<<6)
bobbens@2472
    56
#define SDL_HAPTIC_INERTIA    (1<<7)
bobbens@2472
    57
#define SDL_HAPTIC_GAIN       (1<<8)
bobbens@2472
    58
#define SDL_HAPTIC_AUTOCENTER (1<<9)
bobbens@2472
    59
bobbens@2481
    60
typedef enum SDL_waveform {
bobbens@2481
    61
   SDL_WAVEFORM_SINE,
bobbens@2481
    62
   SDL_WAVEFORM_SQUARE,
bobbens@2481
    63
   SDL_WAVEFORM_TRIANGLE,
bobbens@2481
    64
   SDL_WAVEFORM_SAWTOOTHUP,
bobbens@2481
    65
   SDL_WAVEFORM_SAWTOOTHDOWN
bobbens@2481
    66
} SDL_waveform;
bobbens@2481
    67
bobbens@2481
    68
bobbens@2481
    69
/*
bobbens@2481
    70
 * All values max at 32767 (0x7fff).  Signed values also can be negative.
bobbens@2481
    71
 * Time values unless specified otherwise are in milliseconds.
bobbens@2481
    72
 *
bobbens@2481
    73
 * Common parts:
bobbens@2481
    74
 * 
bobbens@2481
    75
 * Replay:
bobbens@2481
    76
 *    Uint16 length;    Duration of effect.
bobbens@2481
    77
 *    Uint16 delay;     Delay before starting effect.
bobbens@2481
    78
 *
bobbens@2481
    79
 * Trigger:
bobbens@2481
    80
 *    Uint16 button;    Button that triggers effect.
bobbens@2481
    81
 *    Uint16 interval;  How soon before effect can be triggered again.
bobbens@2481
    82
 *
bobbens@2481
    83
 * Envelope:
bobbens@2481
    84
 *    Uint16 attack_length;   Duration of the attack.
bobbens@2481
    85
 *    Uint16 attack_level;    Level at the start of the attack.
bobbens@2481
    86
 *    Uint16 fade_length;     Duration of the fade out.
bobbens@2481
    87
 *    Uint16 fade_level;      Level at the end of the fade.
bobbens@2481
    88
 */
bobbens@2477
    89
typedef struct SDL_HapticConstant {
bobbens@2477
    90
   /* Header */
bobbens@2481
    91
   Uint16 type; /* SDL_HAPTIC_CONSTANT */
bobbens@2480
    92
   Uint16 direction;
bobbens@2480
    93
bobbens@2480
    94
   /* Replay */
bobbens@2477
    95
   Uint16 length;
bobbens@2477
    96
   Uint16 delay;
bobbens@2480
    97
bobbens@2480
    98
   /* Trigger */
bobbens@2480
    99
   Uint16 button;
bobbens@2480
   100
   Uint16 interval;
bobbens@2480
   101
bobbens@2480
   102
   /* Constant */
bobbens@2481
   103
   Sint16 level; /* Strength of the constant effect. */
bobbens@2480
   104
bobbens@2480
   105
   /* Envelope */
bobbens@2480
   106
   Uint16 attack_length;
bobbens@2480
   107
   Uint16 attack_level;
bobbens@2480
   108
   Uint16 fade_length;
bobbens@2480
   109
   Uint16 fade_level;
bobbens@2480
   110
} SDL_HapticConstant;
bobbens@2480
   111
typedef struct SDL_HapticPeriodic {
bobbens@2480
   112
   /* Header */
bobbens@2481
   113
   Uint16 type; /* SDL_HAPTIC_PERIODIC */
bobbens@2477
   114
   Uint16 direction;
bobbens@2480
   115
bobbens@2480
   116
   /* Replay */
bobbens@2480
   117
   Uint16 length;
bobbens@2480
   118
   Uint16 delay;
bobbens@2480
   119
bobbens@2480
   120
   /* Trigger */
bobbens@2480
   121
   Uint16 button;
bobbens@2480
   122
   Uint16 interval;
bobbens@2480
   123
bobbens@2480
   124
   /* Periodic */
bobbens@2481
   125
   SDL_waveform waveform; /* Type of effect */
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@2477
   137
bobbens@2477
   138
typedef union SDL_HapticEffect {
bobbens@2477
   139
   /* Common for all force feedback effects */
bobbens@2477
   140
   Uint16 type; /* Effect type */
bobbens@2477
   141
   SDL_HapticConstant constant; /* Constant effect */
bobbens@2480
   142
   SDL_HapticPeriodic periodic; /* Periodic effect */
bobbens@2477
   143
} SDL_HapticEffect;
bobbens@2477
   144
bobbens@2472
   145
bobbens@2472
   146
/* Function prototypes */
bobbens@2472
   147
/*
bobbens@2472
   148
 * Count the number of joysticks attached to the system
bobbens@2472
   149
 */
bobbens@2472
   150
extern DECLSPEC int SDLCALL SDL_NumHaptics(void);
bobbens@2472
   151
bobbens@2472
   152
/*
bobbens@2476
   153
 * Get the implementation dependent name of a Haptic device.
bobbens@2472
   154
 * This can be called before any joysticks are opened.
bobbens@2472
   155
 * If no name can be found, this function returns NULL.
bobbens@2472
   156
 */
bobbens@2472
   157
extern DECLSPEC const char *SDLCALL SDL_HapticName(int device_index);
bobbens@2472
   158
bobbens@2476
   159
/*
bobbens@2476
   160
 * Opens a Haptic device for usage - the index passed as an
bobbens@2476
   161
 * argument refers to the N'th Haptic device on this system.
bobbens@2476
   162
 *
bobbens@2476
   163
 * This function returns a Haptic device identifier, or Null
bobbens@2476
   164
 * if an error occurred.
bobbens@2476
   165
 */
bobbens@2476
   166
extern DECLSPEC SDL_Haptic * SDL_HapticOpen(int device_index);
bobbens@2476
   167
bobbens@2476
   168
/* 
bobbens@2476
   169
 * Closes a Haptic device previously opened with SDL_HapticOpen.
bobbens@2476
   170
 */
bobbens@2476
   171
extern DECLSPEC void SDL_HapticClose(SDL_Haptic * haptic);
bobbens@2476
   172
bobbens@2477
   173
/*
bobbens@2478
   174
 * Returns the number of effects a haptic device can store.
bobbens@2478
   175
 */
bobbens@2478
   176
extern DECLSPEC int SDL_HapticNumEffects(SDL_Haptic * haptic);
bobbens@2478
   177
bobbens@2478
   178
/*
bobbens@2478
   179
 * Returns the supported effects.  Individual effects can be queried by
bobbens@2478
   180
 * bitwise operators.
bobbens@2478
   181
 *
bobbens@2478
   182
 * Example:  (SDL_HapticQueryEffects(haptic) & SDL_HAPTIC_CONSTANT)
bobbens@2478
   183
 */
bobbens@2478
   184
extern DECLSPEC unsigned int SDL_HapticQueryEffects(SDL_Haptic * haptic);
bobbens@2478
   185
bobbens@2478
   186
/*
bobbens@2477
   187
 * Creates a new haptic effect on the device.
bobbens@2477
   188
 */
bobbens@2477
   189
extern DECLSPEC int SDL_HapticNewEffect(SDL_Haptic * haptic, SDL_HapticEffect * effect);
bobbens@2477
   190
bobbens@2477
   191
/*
bobbens@2477
   192
 * Runs the haptic effect on it's assosciated haptic device.
bobbens@2477
   193
 */
bobbens@2477
   194
extern DECLSPEC int SDL_HapticRunEffect(SDL_Haptic * haptic, int effect);
bobbens@2477
   195
bobbens@2477
   196
/*
bobbens@2477
   197
 * Destroys a haptic effect on the device.
bobbens@2477
   198
 */
bobbens@2477
   199
extern DECLSPEC void SDL_HapticDestroyEffect(SDL_Haptic * haptic, int effect);
bobbens@2477
   200
bobbens@2472
   201
bobbens@2472
   202
/* Ends C function definitions when using C++ */
bobbens@2472
   203
#ifdef __cplusplus
bobbens@2472
   204
/* *INDENT-OFF* */
bobbens@2472
   205
}
bobbens@2472
   206
/* *INDENT-ON* */
bobbens@2472
   207
#endif
bobbens@2472
   208
#include "close_code.h"
bobbens@2472
   209
bobbens@2472
   210
#endif /* _SDL_haptic_h */
bobbens@2472
   211
bobbens@2472
   212
/* vi: set ts=4 sw=4 expandtab: */
bobbens@2472
   213
bobbens@2472
   214