include/SDL_haptic.h
author Edgar Simo <bobbens@gmail.com>
Tue, 01 Jul 2008 16:42:12 +0000
branchgsoc2008_force_feedback
changeset 2487 4c8e25ef2d97
parent 2486 24dd8b8669fa
child 2488 8e2bdbccf7ff
permissions -rw-r--r--
Merged seperate waveforms into types to be more compatible.
     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 /**
    24  * \file SDL_haptic.h
    25  *
    26  * Include file for SDL haptic subsystem
    27  */
    28 
    29 #ifndef _SDL_haptic_h
    30 #define _SDL_haptic_h
    31 
    32 #include "SDL_stdinc.h"
    33 #include "SDL_error.h"
    34 
    35 #include "begin_code.h"
    36 /* Set up for C function definitions, even when using C++ */
    37 #ifdef __cplusplus
    38 /* *INDENT-OFF* */
    39 extern "C" {
    40    /* *INDENT-ON* */                                                         
    41 #endif
    42 
    43 /* The haptic structure used to identify an SDL haptic */
    44 struct _SDL_Haptic;                                                     
    45 typedef struct _SDL_Haptic SDL_Haptic;
    46 
    47 
    48 /* Different effects that can be generated */
    49 #define SDL_HAPTIC_CONSTANT   (1<<0)
    50 #define SDL_HAPTIC_SINE       (1<<1)
    51 #define SDL_HAPTIC_SQUARE     (1<<2)
    52 #define SDL_HAPTIC_TRIANGLE   (1<<3)
    53 #define SDL_HAPTIC_SAWTOOTHUP (1<<4)
    54 #define SDL_HAPTIC_SAWTOOTHDOWN (1<<5)
    55 #define SDL_HAPTIC_RAMP       (1<<6)
    56 #define SDL_HAPTIC_SPRING     (1<<7)
    57 #define SDL_HAPTIC_FRICTION   (1<<8)
    58 #define SDL_HAPTIC_DAMPER     (1<<9)
    59 #define SDL_HAPTIC_INERTIA    (1<<10)
    60 #define SDL_HAPTIC_CUSTOM     (1<<11)
    61 /* These last two are features the device has, not effects */
    62 #define SDL_HAPTIC_GAIN       (1<<12)
    63 #define SDL_HAPTIC_AUTOCENTER (1<<13)
    64 
    65 
    66 /*
    67  * All values max at 32767 (0x7fff).  Signed values also can be negative.
    68  * Time values unless specified otherwise are in milliseconds.
    69  *
    70  * Common parts:
    71  * 
    72  * Replay:
    73  *    Uint16 length;    Duration of effect.
    74  *    Uint16 delay;     Delay before starting effect.
    75  *
    76  * Trigger:
    77  *    Uint16 button;    Button that triggers effect.
    78  *    Uint16 interval;  How soon before effect can be triggered again.
    79  *
    80  * Envelope:
    81  *    Uint16 attack_length;   Duration of the attack.
    82  *    Uint16 attack_level;    Level at the start of the attack.
    83  *    Uint16 fade_length;     Duration of the fade out.
    84  *    Uint16 fade_level;      Level at the end of the fade.
    85  */
    86 typedef struct SDL_HapticConstant {
    87    /* Header */
    88    Uint16 type; /* SDL_HAPTIC_CONSTANT */
    89    Uint16 direction;
    90 
    91    /* Replay */
    92    Uint16 length;
    93    Uint16 delay;
    94 
    95    /* Trigger */
    96    Uint16 button;
    97    Uint16 interval;
    98 
    99    /* Constant */
   100    Sint16 level; /* Strength of the constant effect. */
   101 
   102    /* Envelope */
   103    Uint16 attack_length;
   104    Uint16 attack_level;
   105    Uint16 fade_length;
   106    Uint16 fade_level;
   107 } SDL_HapticConstant;
   108 typedef struct SDL_HapticPeriodic {
   109    /* Header */
   110    Uint16 type; /* SDL_HAPTIC_{SINE,SQUARE,TRIANGLE,SAWTOOTHUP,SAWTOOTHDOWN} */
   111    Uint16 direction;
   112 
   113    /* Replay */
   114    Uint16 length;
   115    Uint16 delay;
   116 
   117    /* Trigger */
   118    Uint16 button;
   119    Uint16 interval;
   120 
   121    /* Periodic */
   122    Uint16 period; /* Period of the wave */
   123    Sint16 magnitude; /* Peak value */
   124    Sint16 offset; /* Mean value of the wave */
   125    Uint16 phase; /* Horizontal shift */
   126 
   127    /* Envelope */
   128    Uint16 attack_length;
   129    Uint16 attack_level;
   130    Uint16 fade_length;
   131    Uint16 fade_level;
   132 } SDL_HapticPeriodic;
   133 typedef struct SDL_HapticCondition {
   134    /* Header */
   135    Uint16 type; /* SDL_HAPTIC_{SPRING,DAMPER,INERTIA,FRICTION} */
   136    Uint16 direction;
   137 
   138    /* Replay */
   139    Uint16 length;
   140    Uint16 delay;
   141 
   142    /* Trigger */
   143    Uint16 button;
   144    Uint16 interval;
   145 
   146    /* Condition */
   147    Uint16 right_sat; /* Level when joystick is to the right. */
   148    Uint16 left_sat; /* Level when joystick is to the left */
   149    Sint16 right_coeff; /* How fast to increase the force towards the right */
   150    Sint16 left_coeff; /* How fast to increase the force towards the left */
   151    Uint16 deadband; /* Size of the dead zone */
   152    Sint16 center; /* Position of the dead zone */
   153 } SDL_HapticCondition;
   154 typedef struct SDL_HapticRamp {
   155    /* Header */
   156    Uint16 type; /* SDL_HAPTIC_RAMP */
   157    Uint16 direction;
   158 
   159    /* Replay */
   160    Uint16 length;
   161    Uint16 delay;
   162 
   163    /* Trigger */
   164    Uint16 button;
   165    Uint16 interval;
   166 
   167    /* Ramp */
   168    Sint16 start;
   169    Sint16 end;
   170 
   171    /* Envelope */
   172    Uint16 attack_length;
   173    Uint16 attack_level;
   174    Uint16 fade_length;
   175    Uint16 fade_level;
   176 } SDL_HapticRamp;
   177 
   178 typedef union SDL_HapticEffect {
   179    /* Common for all force feedback effects */
   180    Uint16 type; /* Effect type */
   181    SDL_HapticConstant constant; /* Constant effect */
   182    SDL_HapticPeriodic periodic; /* Periodic effect */
   183    SDL_HapticCondition condition; /* Condition effect */
   184    SDL_HapticRamp ramp; /* Ramp effect */
   185 } SDL_HapticEffect;
   186 
   187 
   188 /* Function prototypes */
   189 /*
   190  * Count the number of joysticks attached to the system
   191  */
   192 extern DECLSPEC int SDLCALL SDL_NumHaptics(void);
   193 
   194 /*
   195  * Get the implementation dependent name of a Haptic device.
   196  * This can be called before any joysticks are opened.
   197  * If no name can be found, this function returns NULL.
   198  */
   199 extern DECLSPEC const char *SDLCALL SDL_HapticName(int device_index);
   200 
   201 /*
   202  * Opens a Haptic device for usage - the index passed as an
   203  * argument refers to the N'th Haptic device on this system.
   204  *
   205  * This function returns a Haptic device identifier, or Null
   206  * if an error occurred.
   207  */
   208 extern DECLSPEC SDL_Haptic * SDL_HapticOpen(int device_index);
   209 
   210 /* 
   211  * Closes a Haptic device previously opened with SDL_HapticOpen.
   212  */
   213 extern DECLSPEC void SDL_HapticClose(SDL_Haptic * haptic);
   214 
   215 /*
   216  * Returns the number of effects a haptic device can store.
   217  */
   218 extern DECLSPEC int SDL_HapticNumEffects(SDL_Haptic * haptic);
   219 
   220 /*
   221  * Returns the supported effects.  Individual effects can be queried by
   222  * bitwise operators.
   223  *
   224  * Example:  (SDL_HapticQueryEffects(haptic) & SDL_HAPTIC_CONSTANT)
   225  */
   226 extern DECLSPEC unsigned int SDL_HapticQueryEffects(SDL_Haptic * haptic);
   227 
   228 /*
   229  * Checks to see if effect is supported by haptic.
   230  *
   231  * Returns SDL_TRUE if effect is supported, SDL_FALSE if it isn't and -1
   232  * on error.
   233  */
   234 extern DECLSPEC int SDL_HapticEffectSupported(SDL_Haptic * haptic, SDL_HapticEffect * effect);
   235 
   236 /*
   237  * Creates a new haptic effect on the device.
   238  *
   239  * Returns the id of the effect on success, -1 on failure.
   240  */
   241 extern DECLSPEC int SDL_HapticNewEffect(SDL_Haptic * haptic, SDL_HapticEffect * effect);
   242 
   243 /*
   244  * Runs the haptic effect on it's assosciated haptic device.
   245  *
   246  * Returns 0 on success or -1 on failure.
   247  */
   248 extern DECLSPEC int SDL_HapticRunEffect(SDL_Haptic * haptic, int effect);
   249 
   250 /*
   251  * Stops the haptic effect on it's assosciated haptic device.
   252  *
   253  * Returns 0 on success or -1 on failure.
   254  */
   255 extern DECLSPEC int SDL_HapticStopEffect(SDL_Haptic * haptic, int effect);
   256 
   257 /*
   258  * Destroys a haptic effect on the device.  This will stop the effect if it's
   259  * running.
   260  */
   261 extern DECLSPEC void SDL_HapticDestroyEffect(SDL_Haptic * haptic, int effect);
   262 
   263 /*
   264  * Sets the global gain of the device.  Gain should be between 0 and 100.
   265  *
   266  * Returns 0 on success or -1 on failure.
   267  */
   268 extern DECLSPEC int SDL_HapticSetGain(SDL_Haptic * haptic, int gain);
   269 
   270 /*
   271  * Sets the global autocenter of the device.  Autocenter should be between
   272  * 0 and 100.  Setting it to 0 will disable autocentering.
   273  *
   274  * Returns 0 on success or -1 on failure.
   275  */
   276 extern DECLSPEC int SDL_HapticSetAutocenter(SDL_Haptic * haptic, int autocenter);
   277 
   278 
   279 /* Ends C function definitions when using C++ */
   280 #ifdef __cplusplus
   281 /* *INDENT-OFF* */
   282 }
   283 /* *INDENT-ON* */
   284 #endif
   285 #include "close_code.h"
   286 
   287 #endif /* _SDL_haptic_h */
   288 
   289 /* vi: set ts=4 sw=4 expandtab: */
   290 
   291