src/haptic/SDL_syshaptic.h
author Sam Lantinga
Sun, 20 Feb 2011 10:54:44 -0800
changeset 5360 220d3af9121f
parent 2713 0906692aa6a4
child 5535 96594ac5fd1a
permissions -rw-r--r--
Simple rumble API for haptic

Edgar Simo 2011-02-20 10:27:52 PST

Adding patch that adds a simplified API for the haptic subsystem built ontop of
the "real one" for those who want simple rumble without jumping through hoops.

Adds 4 functions:

- extern DECLSPEC int SDLCALL SDL_HapticRumbleSupported(SDL_Haptic * haptic);
- extern DECLSPEC int SDLCALL SDL_HapticRumbleInit(SDL_Haptic * haptic);
- extern DECLSPEC int SDLCALL SDL_HapticRumblePlay(SDL_Haptic * haptic, float
strength, Uint32 length );
- extern DECLSPEC int SDLCALL SDL_HapticRumbleStop(SDL_Haptic * haptic);

Also provided is test/testrumble.c which does test this.

This has all been tested on linux and has worked, but due to being built ontop
of the other haptic API it should work on all OS the same.
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@5360
    55
slouken@5360
    56
    int rumble_id;              /* ID of rumble effect for simple rumble API. */
slouken@5360
    57
    SDL_HapticEffect rumble_effect; /* Rumble effect. */
slouken@2713
    58
};
slouken@2713
    59
slouken@2713
    60
/* 
slouken@2713
    61
 * Scans the system for haptic devices.
slouken@2713
    62
 *
slouken@2713
    63
 * Returns 0 on success, -1 on error.
slouken@2713
    64
 */
slouken@2713
    65
extern int SDL_SYS_HapticInit(void);
slouken@2713
    66
slouken@2713
    67
/*
slouken@2713
    68
 * Gets the device dependent name of the haptic device
slouken@2713
    69
 */
slouken@2713
    70
extern const char *SDL_SYS_HapticName(int index);
slouken@2713
    71
slouken@2713
    72
/*
slouken@2713
    73
 * Opens the haptic device for usage.  The haptic device should have
slouken@2713
    74
 * the index value set previously.
slouken@2713
    75
 *
slouken@2713
    76
 * Returns 0 on success, -1 on error.
slouken@2713
    77
 */
slouken@2713
    78
extern int SDL_SYS_HapticOpen(SDL_Haptic * haptic);
slouken@2713
    79
slouken@2713
    80
/*
slouken@2713
    81
 * Returns the index of the haptic core pointer or -1 if none is found.
slouken@2713
    82
 */
slouken@2713
    83
int SDL_SYS_HapticMouse(void);
slouken@2713
    84
slouken@2713
    85
/*
slouken@2713
    86
 * Checks to see if the joystick has haptic capabilities.
slouken@2713
    87
 *
slouken@2713
    88
 * Returns >0 if haptic capabilities are detected, 0 if haptic
slouken@2713
    89
 * capabilities aren't detected and -1 on error.
slouken@2713
    90
 */
slouken@2713
    91
extern int SDL_SYS_JoystickIsHaptic(SDL_Joystick * joystick);
slouken@2713
    92
slouken@2713
    93
/*
slouken@2713
    94
 * Opens the haptic device for usage using the same device as
slouken@2713
    95
 * the joystick.
slouken@2713
    96
 *
slouken@2713
    97
 * Returns 0 on success, -1 on error.
slouken@2713
    98
 */
slouken@2713
    99
extern int SDL_SYS_HapticOpenFromJoystick(SDL_Haptic * haptic,
slouken@2713
   100
                                          SDL_Joystick * joystick);
slouken@2713
   101
/*
slouken@2713
   102
 * Checks to see if haptic device and joystick device are the same.
slouken@2713
   103
 *
slouken@2713
   104
 * Returns 1 if they are the same, 0 if they aren't.
slouken@2713
   105
 */
slouken@2713
   106
extern int SDL_SYS_JoystickSameHaptic(SDL_Haptic * haptic,
slouken@2713
   107
                                      SDL_Joystick * joystick);
slouken@2713
   108
slouken@2713
   109
/*
slouken@2713
   110
 * Closes a haptic device after usage.
slouken@2713
   111
 */
slouken@2713
   112
extern void SDL_SYS_HapticClose(SDL_Haptic * haptic);
slouken@2713
   113
slouken@2713
   114
/*
slouken@2713
   115
 * Performs a cleanup on the haptic subsystem.
slouken@2713
   116
 */
slouken@2713
   117
extern void SDL_SYS_HapticQuit(void);
slouken@2713
   118
slouken@2713
   119
/*
slouken@2713
   120
 * Creates a new haptic effect on the haptic device using base
slouken@2713
   121
 * as a template for the effect.
slouken@2713
   122
 *
slouken@2713
   123
 * Returns 0 on success, -1 on error.
slouken@2713
   124
 */
slouken@2713
   125
extern int SDL_SYS_HapticNewEffect(SDL_Haptic * haptic,
slouken@2713
   126
                                   struct haptic_effect *effect,
slouken@2713
   127
                                   SDL_HapticEffect * base);
slouken@2713
   128
slouken@2713
   129
/*
slouken@2713
   130
 * Updates the haptic effect on the haptic device using data
slouken@2713
   131
 * as a template.
slouken@2713
   132
 *
slouken@2713
   133
 * Returns 0 on success, -1 on error.
slouken@2713
   134
 */
slouken@2713
   135
extern int SDL_SYS_HapticUpdateEffect(SDL_Haptic * haptic,
slouken@2713
   136
                                      struct haptic_effect *effect,
slouken@2713
   137
                                      SDL_HapticEffect * data);
slouken@2713
   138
slouken@2713
   139
/*
slouken@2713
   140
 * Runs the effect on the haptic device.
slouken@2713
   141
 *
slouken@2713
   142
 * Returns 0 on success, -1 on error.
slouken@2713
   143
 */
slouken@2713
   144
extern int SDL_SYS_HapticRunEffect(SDL_Haptic * haptic,
slouken@2713
   145
                                   struct haptic_effect *effect,
slouken@2713
   146
                                   Uint32 iterations);
slouken@2713
   147
slouken@2713
   148
/*
slouken@2713
   149
 * Stops the effect on the haptic device.
slouken@2713
   150
 *
slouken@2713
   151
 * Returns 0 on success, -1 on error.
slouken@2713
   152
 */
slouken@2713
   153
extern int SDL_SYS_HapticStopEffect(SDL_Haptic * haptic,
slouken@2713
   154
                                    struct haptic_effect *effect);
slouken@2713
   155
slouken@2713
   156
/*
slouken@2713
   157
 * Cleanups up the effect on the haptic device.
slouken@2713
   158
 */
slouken@2713
   159
extern void SDL_SYS_HapticDestroyEffect(SDL_Haptic * haptic,
slouken@2713
   160
                                        struct haptic_effect *effect);
slouken@2713
   161
slouken@2713
   162
/*
slouken@2713
   163
 * Queries the device for the status of effect.
slouken@2713
   164
 *
slouken@2713
   165
 * Returns 0 if device is stopped, >0 if device is playing and
slouken@2713
   166
 * -1 on error.
slouken@2713
   167
 */
slouken@2713
   168
extern int SDL_SYS_HapticGetEffectStatus(SDL_Haptic * haptic,
slouken@2713
   169
                                         struct haptic_effect *effect);
slouken@2713
   170
slouken@2713
   171
/*
slouken@2713
   172
 * Sets the global gain of the haptic device.
slouken@2713
   173
 *
slouken@2713
   174
 * Returns 0 on success, -1 on error.
slouken@2713
   175
 */
slouken@2713
   176
extern int SDL_SYS_HapticSetGain(SDL_Haptic * haptic, int gain);
slouken@2713
   177
slouken@2713
   178
/*
slouken@2713
   179
 * Sets the autocenter feature of the haptic device.
slouken@2713
   180
 *
slouken@2713
   181
 * Returns 0 on success, -1 on error.
slouken@2713
   182
 */
slouken@2713
   183
extern int SDL_SYS_HapticSetAutocenter(SDL_Haptic * haptic, int autocenter);
slouken@2713
   184
slouken@2713
   185
/*
slouken@2713
   186
 * Pauses the haptic device.
slouken@2713
   187
 *
slouken@2713
   188
 * Returns 0 on success, -1 on error.
slouken@2713
   189
 */
slouken@2713
   190
extern int SDL_SYS_HapticPause(SDL_Haptic * haptic);
slouken@2713
   191
slouken@2713
   192
/*
slouken@2713
   193
 * Unpauses the haptic device.
slouken@2713
   194
 *
slouken@2713
   195
 * Returns 0 on success, -1 on error.
slouken@2713
   196
 */
slouken@2713
   197
extern int SDL_SYS_HapticUnpause(SDL_Haptic * haptic);
slouken@2713
   198
slouken@2713
   199
/*
slouken@2713
   200
 * Stops all the currently playing haptic effects on the device.
slouken@2713
   201
 *
slouken@2713
   202
 * Returns 0 on success, -1 on error.
slouken@2713
   203
 */
slouken@2713
   204
extern int SDL_SYS_HapticStopAll(SDL_Haptic * haptic);