src/haptic/SDL_syshaptic.h
author Sam Lantinga <slouken@libsdl.org>
Mon, 25 Aug 2008 09:55:03 +0000
changeset 2713 0906692aa6a4
child 5360 220d3af9121f
permissions -rw-r--r--
Final merge of Google Summer of Code 2008 work...

Force Feedback for SDL
by Edgar Simo, mentored by Ryan C. Gordon
slouken@2713
     1
/*
slouken@2713
     2
    SDL - Simple DirectMedia Layer
slouken@2713
     3
    Copyright (C) 2008 Edgar Simo
slouken@2713
     4
slouken@2713
     5
    This library is free software; you can redistribute it and/or
slouken@2713
     6
    modify it under the terms of the GNU Lesser General Public
slouken@2713
     7
    License as published by the Free Software Foundation; either
slouken@2713
     8
    version 2.1 of the License, or (at your option) any later version.
slouken@2713
     9
slouken@2713
    10
    This library is distributed in the hope that it will be useful,
slouken@2713
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
slouken@2713
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
slouken@2713
    13
    Lesser General Public License for more details.
slouken@2713
    14
slouken@2713
    15
    You should have received a copy of the GNU Lesser General Public
slouken@2713
    16
    License along with this library; if not, write to the Free Software
slouken@2713
    17
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
slouken@2713
    18
slouken@2713
    19
    Sam Lantinga
slouken@2713
    20
    slouken@libsdl.org
slouken@2713
    21
*/
slouken@2713
    22
slouken@2713
    23
#include "SDL_config.h"
slouken@2713
    24
slouken@2713
    25
#include "SDL_haptic.h"
slouken@2713
    26
slouken@2713
    27
slouken@2713
    28
/*
slouken@2713
    29
 * Number of haptic devices on the system.
slouken@2713
    30
 */
slouken@2713
    31
extern Uint8 SDL_numhaptics;
slouken@2713
    32
slouken@2713
    33
slouken@2713
    34
struct haptic_effect
slouken@2713
    35
{
slouken@2713
    36
    SDL_HapticEffect effect;    /* The current event */
slouken@2713
    37
    struct haptic_hweffect *hweffect;   /* The hardware behind the event */
slouken@2713
    38
};
slouken@2713
    39
slouken@2713
    40
/*
slouken@2713
    41
 * The real SDL_Haptic struct.
slouken@2713
    42
 */
slouken@2713
    43
struct _SDL_Haptic
slouken@2713
    44
{
slouken@2713
    45
    Uint8 index;                /* Stores index it is attached to */
slouken@2713
    46
slouken@2713
    47
    struct haptic_effect *effects;      /* Allocated effects */
slouken@2713
    48
    int neffects;               /* Maximum amount of effects */
slouken@2713
    49
    int nplaying;               /* Maximum amount of effects to play at the same time */
slouken@2713
    50
    unsigned int supported;     /* Supported effects */
slouken@2713
    51
    int naxes;                  /* Number of axes on the device. */
slouken@2713
    52
slouken@2713
    53
    struct haptic_hwdata *hwdata;       /* Driver dependent */
slouken@2713
    54
    int ref_count;              /* Count for multiple opens */
slouken@2713
    55
};
slouken@2713
    56
slouken@2713
    57
/* 
slouken@2713
    58
 * Scans the system for haptic devices.
slouken@2713
    59
 *
slouken@2713
    60
 * Returns 0 on success, -1 on error.
slouken@2713
    61
 */
slouken@2713
    62
extern int SDL_SYS_HapticInit(void);
slouken@2713
    63
slouken@2713
    64
/*
slouken@2713
    65
 * Gets the device dependent name of the haptic device
slouken@2713
    66
 */
slouken@2713
    67
extern const char *SDL_SYS_HapticName(int index);
slouken@2713
    68
slouken@2713
    69
/*
slouken@2713
    70
 * Opens the haptic device for usage.  The haptic device should have
slouken@2713
    71
 * the index value set previously.
slouken@2713
    72
 *
slouken@2713
    73
 * Returns 0 on success, -1 on error.
slouken@2713
    74
 */
slouken@2713
    75
extern int SDL_SYS_HapticOpen(SDL_Haptic * haptic);
slouken@2713
    76
slouken@2713
    77
/*
slouken@2713
    78
 * Returns the index of the haptic core pointer or -1 if none is found.
slouken@2713
    79
 */
slouken@2713
    80
int SDL_SYS_HapticMouse(void);
slouken@2713
    81
slouken@2713
    82
/*
slouken@2713
    83
 * Checks to see if the joystick has haptic capabilities.
slouken@2713
    84
 *
slouken@2713
    85
 * Returns >0 if haptic capabilities are detected, 0 if haptic
slouken@2713
    86
 * capabilities aren't detected and -1 on error.
slouken@2713
    87
 */
slouken@2713
    88
extern int SDL_SYS_JoystickIsHaptic(SDL_Joystick * joystick);
slouken@2713
    89
slouken@2713
    90
/*
slouken@2713
    91
 * Opens the haptic device for usage using the same device as
slouken@2713
    92
 * the joystick.
slouken@2713
    93
 *
slouken@2713
    94
 * Returns 0 on success, -1 on error.
slouken@2713
    95
 */
slouken@2713
    96
extern int SDL_SYS_HapticOpenFromJoystick(SDL_Haptic * haptic,
slouken@2713
    97
                                          SDL_Joystick * joystick);
slouken@2713
    98
/*
slouken@2713
    99
 * Checks to see if haptic device and joystick device are the same.
slouken@2713
   100
 *
slouken@2713
   101
 * Returns 1 if they are the same, 0 if they aren't.
slouken@2713
   102
 */
slouken@2713
   103
extern int SDL_SYS_JoystickSameHaptic(SDL_Haptic * haptic,
slouken@2713
   104
                                      SDL_Joystick * joystick);
slouken@2713
   105
slouken@2713
   106
/*
slouken@2713
   107
 * Closes a haptic device after usage.
slouken@2713
   108
 */
slouken@2713
   109
extern void SDL_SYS_HapticClose(SDL_Haptic * haptic);
slouken@2713
   110
slouken@2713
   111
/*
slouken@2713
   112
 * Performs a cleanup on the haptic subsystem.
slouken@2713
   113
 */
slouken@2713
   114
extern void SDL_SYS_HapticQuit(void);
slouken@2713
   115
slouken@2713
   116
/*
slouken@2713
   117
 * Creates a new haptic effect on the haptic device using base
slouken@2713
   118
 * as a template for the effect.
slouken@2713
   119
 *
slouken@2713
   120
 * Returns 0 on success, -1 on error.
slouken@2713
   121
 */
slouken@2713
   122
extern int SDL_SYS_HapticNewEffect(SDL_Haptic * haptic,
slouken@2713
   123
                                   struct haptic_effect *effect,
slouken@2713
   124
                                   SDL_HapticEffect * base);
slouken@2713
   125
slouken@2713
   126
/*
slouken@2713
   127
 * Updates the haptic effect on the haptic device using data
slouken@2713
   128
 * as a template.
slouken@2713
   129
 *
slouken@2713
   130
 * Returns 0 on success, -1 on error.
slouken@2713
   131
 */
slouken@2713
   132
extern int SDL_SYS_HapticUpdateEffect(SDL_Haptic * haptic,
slouken@2713
   133
                                      struct haptic_effect *effect,
slouken@2713
   134
                                      SDL_HapticEffect * data);
slouken@2713
   135
slouken@2713
   136
/*
slouken@2713
   137
 * Runs the effect on the haptic device.
slouken@2713
   138
 *
slouken@2713
   139
 * Returns 0 on success, -1 on error.
slouken@2713
   140
 */
slouken@2713
   141
extern int SDL_SYS_HapticRunEffect(SDL_Haptic * haptic,
slouken@2713
   142
                                   struct haptic_effect *effect,
slouken@2713
   143
                                   Uint32 iterations);
slouken@2713
   144
slouken@2713
   145
/*
slouken@2713
   146
 * Stops the effect on the haptic device.
slouken@2713
   147
 *
slouken@2713
   148
 * Returns 0 on success, -1 on error.
slouken@2713
   149
 */
slouken@2713
   150
extern int SDL_SYS_HapticStopEffect(SDL_Haptic * haptic,
slouken@2713
   151
                                    struct haptic_effect *effect);
slouken@2713
   152
slouken@2713
   153
/*
slouken@2713
   154
 * Cleanups up the effect on the haptic device.
slouken@2713
   155
 */
slouken@2713
   156
extern void SDL_SYS_HapticDestroyEffect(SDL_Haptic * haptic,
slouken@2713
   157
                                        struct haptic_effect *effect);
slouken@2713
   158
slouken@2713
   159
/*
slouken@2713
   160
 * Queries the device for the status of effect.
slouken@2713
   161
 *
slouken@2713
   162
 * Returns 0 if device is stopped, >0 if device is playing and
slouken@2713
   163
 * -1 on error.
slouken@2713
   164
 */
slouken@2713
   165
extern int SDL_SYS_HapticGetEffectStatus(SDL_Haptic * haptic,
slouken@2713
   166
                                         struct haptic_effect *effect);
slouken@2713
   167
slouken@2713
   168
/*
slouken@2713
   169
 * Sets the global gain of the haptic device.
slouken@2713
   170
 *
slouken@2713
   171
 * Returns 0 on success, -1 on error.
slouken@2713
   172
 */
slouken@2713
   173
extern int SDL_SYS_HapticSetGain(SDL_Haptic * haptic, int gain);
slouken@2713
   174
slouken@2713
   175
/*
slouken@2713
   176
 * Sets the autocenter feature of the haptic device.
slouken@2713
   177
 *
slouken@2713
   178
 * Returns 0 on success, -1 on error.
slouken@2713
   179
 */
slouken@2713
   180
extern int SDL_SYS_HapticSetAutocenter(SDL_Haptic * haptic, int autocenter);
slouken@2713
   181
slouken@2713
   182
/*
slouken@2713
   183
 * Pauses the haptic device.
slouken@2713
   184
 *
slouken@2713
   185
 * Returns 0 on success, -1 on error.
slouken@2713
   186
 */
slouken@2713
   187
extern int SDL_SYS_HapticPause(SDL_Haptic * haptic);
slouken@2713
   188
slouken@2713
   189
/*
slouken@2713
   190
 * Unpauses the haptic device.
slouken@2713
   191
 *
slouken@2713
   192
 * Returns 0 on success, -1 on error.
slouken@2713
   193
 */
slouken@2713
   194
extern int SDL_SYS_HapticUnpause(SDL_Haptic * haptic);
slouken@2713
   195
slouken@2713
   196
/*
slouken@2713
   197
 * Stops all the currently playing haptic effects on the device.
slouken@2713
   198
 *
slouken@2713
   199
 * Returns 0 on success, -1 on error.
slouken@2713
   200
 */
slouken@2713
   201
extern int SDL_SYS_HapticStopAll(SDL_Haptic * haptic);