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