include/SDL_haptic.h
author Edgar Simo <bobbens@gmail.com>
Tue, 01 Jul 2008 09:22:22 +0000
branchgsoc2008_force_feedback
changeset 2480 b883974445fc
parent 2478 4fd783e0f34b
child 2481 5d0ea4576f20
permissions -rw-r--r--
Some more error reporting.
Added periodic effect.
Confirmed it works.
bobbens@2472
     1
/*
bobbens@2472
     2
    SDL - Simple DirectMedia Layer
bobbens@2472
     3
    Copyright (C) 2008 Edgar Simo
bobbens@2472
     4
bobbens@2472
     5
    This library is free software; you can redistribute it and/or
bobbens@2472
     6
    modify it under the terms of the GNU Lesser General Public
bobbens@2472
     7
    License as published by the Free Software Foundation; either
bobbens@2472
     8
    version 2.1 of the License, or (at your option) any later version.
bobbens@2472
     9
bobbens@2472
    10
    This library is distributed in the hope that it will be useful,
bobbens@2472
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
bobbens@2472
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
bobbens@2472
    13
    Lesser General Public License for more details.
bobbens@2472
    14
bobbens@2472
    15
    You should have received a copy of the GNU Lesser General Public
bobbens@2472
    16
    License along with this library; if not, write to the Free Software
bobbens@2472
    17
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
bobbens@2472
    18
bobbens@2472
    19
    Sam Lantinga
bobbens@2472
    20
    slouken@libsdl.org
bobbens@2472
    21
*/
bobbens@2472
    22
bobbens@2472
    23
/**
bobbens@2472
    24
 * \file SDL_haptic.h
bobbens@2472
    25
 *
bobbens@2472
    26
 * Include file for SDL haptic subsystem
bobbens@2472
    27
 */
bobbens@2472
    28
bobbens@2472
    29
#ifndef _SDL_haptic_h
bobbens@2472
    30
#define _SDL_haptic_h
bobbens@2472
    31
bobbens@2472
    32
#include "SDL_stdinc.h"
bobbens@2472
    33
#include "SDL_error.h"
bobbens@2472
    34
bobbens@2472
    35
#include "begin_code.h"
bobbens@2472
    36
/* Set up for C function definitions, even when using C++ */
bobbens@2472
    37
#ifdef __cplusplus
bobbens@2472
    38
/* *INDENT-OFF* */
bobbens@2472
    39
extern "C" {
bobbens@2472
    40
   /* *INDENT-ON* */                                                         
bobbens@2472
    41
#endif
bobbens@2472
    42
bobbens@2472
    43
/* The haptic structure used to identify an SDL haptic */
bobbens@2472
    44
struct _SDL_Haptic;                                                     
bobbens@2472
    45
typedef struct _SDL_Haptic SDL_Haptic;
bobbens@2472
    46
bobbens@2472
    47
bobbens@2472
    48
/* Different effects that can be generated */
bobbens@2472
    49
#define SDL_HAPTIC_CONSTANT   (1<<0)
bobbens@2472
    50
#define SDL_HAPTIC_PERIODIC   (1<<1)
bobbens@2472
    51
#define SDL_HAPTIC_RAMP       (1<<2)
bobbens@2472
    52
#define SDL_HAPTIC_SPRING     (1<<3)
bobbens@2472
    53
#define SDL_HAPTIC_FRICTION   (1<<4)
bobbens@2472
    54
#define SDL_HAPTIC_DAMPER     (1<<5)
bobbens@2472
    55
#define SDL_HAPTIC_RUMBLE     (1<<6)
bobbens@2472
    56
#define SDL_HAPTIC_INERTIA    (1<<7)
bobbens@2472
    57
#define SDL_HAPTIC_GAIN       (1<<8)
bobbens@2472
    58
#define SDL_HAPTIC_AUTOCENTER (1<<9)
bobbens@2472
    59
bobbens@2477
    60
typedef struct SDL_HapticConstant {
bobbens@2477
    61
   /* Header */
bobbens@2477
    62
   Uint16 type;
bobbens@2480
    63
   Uint16 direction;
bobbens@2480
    64
bobbens@2480
    65
   /* Replay */
bobbens@2477
    66
   Uint16 length;
bobbens@2477
    67
   Uint16 delay;
bobbens@2480
    68
bobbens@2480
    69
   /* Trigger */
bobbens@2480
    70
   Uint16 button;
bobbens@2480
    71
   Uint16 interval;
bobbens@2480
    72
bobbens@2480
    73
   /* Constant */
bobbens@2480
    74
   Sint16 level;
bobbens@2480
    75
bobbens@2480
    76
   /* Envelope */
bobbens@2480
    77
   Uint16 attack_length;
bobbens@2480
    78
   Uint16 attack_level;
bobbens@2480
    79
   Uint16 fade_length;
bobbens@2480
    80
   Uint16 fade_level;
bobbens@2480
    81
} SDL_HapticConstant;
bobbens@2480
    82
typedef struct SDL_HapticPeriodic {
bobbens@2480
    83
   /* Header */
bobbens@2480
    84
   Uint16 type;
bobbens@2477
    85
   Uint16 direction;
bobbens@2480
    86
bobbens@2480
    87
   /* Replay */
bobbens@2480
    88
   Uint16 length;
bobbens@2480
    89
   Uint16 delay;
bobbens@2480
    90
bobbens@2480
    91
   /* Trigger */
bobbens@2480
    92
   Uint16 button;
bobbens@2480
    93
   Uint16 interval;
bobbens@2480
    94
bobbens@2480
    95
   /* Periodic */
bobbens@2480
    96
   Uint16 waveform;
bobbens@2480
    97
   Uint16 period;
bobbens@2480
    98
   Sint16 magnitude;
bobbens@2480
    99
   Sint16 offset;
bobbens@2480
   100
   Uint16 phase;
bobbens@2480
   101
bobbens@2480
   102
   /* Envelope */
bobbens@2480
   103
   Uint16 attack_length;
bobbens@2480
   104
   Uint16 attack_level;
bobbens@2480
   105
   Uint16 fade_length;
bobbens@2480
   106
   Uint16 fade_level;
bobbens@2480
   107
} SDL_HapticPeriodic;
bobbens@2477
   108
bobbens@2477
   109
typedef union SDL_HapticEffect {
bobbens@2477
   110
   /* Common for all force feedback effects */
bobbens@2477
   111
   Uint16 type; /* Effect type */
bobbens@2477
   112
   SDL_HapticConstant constant; /* Constant effect */
bobbens@2480
   113
   SDL_HapticPeriodic periodic; /* Periodic effect */
bobbens@2477
   114
} SDL_HapticEffect;
bobbens@2477
   115
bobbens@2472
   116
bobbens@2472
   117
/* Function prototypes */
bobbens@2472
   118
/*
bobbens@2472
   119
 * Count the number of joysticks attached to the system
bobbens@2472
   120
 */
bobbens@2472
   121
extern DECLSPEC int SDLCALL SDL_NumHaptics(void);
bobbens@2472
   122
bobbens@2472
   123
/*
bobbens@2476
   124
 * Get the implementation dependent name of a Haptic device.
bobbens@2472
   125
 * This can be called before any joysticks are opened.
bobbens@2472
   126
 * If no name can be found, this function returns NULL.
bobbens@2472
   127
 */
bobbens@2472
   128
extern DECLSPEC const char *SDLCALL SDL_HapticName(int device_index);
bobbens@2472
   129
bobbens@2476
   130
/*
bobbens@2476
   131
 * Opens a Haptic device for usage - the index passed as an
bobbens@2476
   132
 * argument refers to the N'th Haptic device on this system.
bobbens@2476
   133
 *
bobbens@2476
   134
 * This function returns a Haptic device identifier, or Null
bobbens@2476
   135
 * if an error occurred.
bobbens@2476
   136
 */
bobbens@2476
   137
extern DECLSPEC SDL_Haptic * SDL_HapticOpen(int device_index);
bobbens@2476
   138
bobbens@2476
   139
/* 
bobbens@2476
   140
 * Closes a Haptic device previously opened with SDL_HapticOpen.
bobbens@2476
   141
 */
bobbens@2476
   142
extern DECLSPEC void SDL_HapticClose(SDL_Haptic * haptic);
bobbens@2476
   143
bobbens@2477
   144
/*
bobbens@2478
   145
 * Returns the number of effects a haptic device can store.
bobbens@2478
   146
 */
bobbens@2478
   147
extern DECLSPEC int SDL_HapticNumEffects(SDL_Haptic * haptic);
bobbens@2478
   148
bobbens@2478
   149
/*
bobbens@2478
   150
 * Returns the supported effects.  Individual effects can be queried by
bobbens@2478
   151
 * bitwise operators.
bobbens@2478
   152
 *
bobbens@2478
   153
 * Example:  (SDL_HapticQueryEffects(haptic) & SDL_HAPTIC_CONSTANT)
bobbens@2478
   154
 */
bobbens@2478
   155
extern DECLSPEC unsigned int SDL_HapticQueryEffects(SDL_Haptic * haptic);
bobbens@2478
   156
bobbens@2478
   157
/*
bobbens@2477
   158
 * Creates a new haptic effect on the device.
bobbens@2477
   159
 */
bobbens@2477
   160
extern DECLSPEC int SDL_HapticNewEffect(SDL_Haptic * haptic, SDL_HapticEffect * effect);
bobbens@2477
   161
bobbens@2477
   162
/*
bobbens@2477
   163
 * Runs the haptic effect on it's assosciated haptic device.
bobbens@2477
   164
 */
bobbens@2477
   165
extern DECLSPEC int SDL_HapticRunEffect(SDL_Haptic * haptic, int effect);
bobbens@2477
   166
bobbens@2477
   167
/*
bobbens@2477
   168
 * Destroys a haptic effect on the device.
bobbens@2477
   169
 */
bobbens@2477
   170
extern DECLSPEC void SDL_HapticDestroyEffect(SDL_Haptic * haptic, int effect);
bobbens@2477
   171
bobbens@2472
   172
bobbens@2472
   173
/* Ends C function definitions when using C++ */
bobbens@2472
   174
#ifdef __cplusplus
bobbens@2472
   175
/* *INDENT-OFF* */
bobbens@2472
   176
}
bobbens@2472
   177
/* *INDENT-ON* */
bobbens@2472
   178
#endif
bobbens@2472
   179
#include "close_code.h"
bobbens@2472
   180
bobbens@2472
   181
#endif /* _SDL_haptic_h */
bobbens@2472
   182
bobbens@2472
   183
/* vi: set ts=4 sw=4 expandtab: */
bobbens@2472
   184
bobbens@2472
   185