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