src/haptic/SDL_haptic.c
author Edgar Simo <bobbens@gmail.com>
Tue, 08 Jul 2008 19:35:10 +0000
branchgsoc2008_force_feedback
changeset 2506 ba8e99fe92c1
parent 2505 abfcba0f3bd1
child 2507 8ef1d0f4d0c1
permissions -rw-r--r--
Added SDL_HapticOpened().
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
#include "SDL_config.h"
bobbens@2472
    23
bobbens@2472
    24
#include "SDL_syshaptic.h"
bobbens@2489
    25
#include "../joystick/SDL_joystick_c.h" /* For SDL_PrivateJoystickValid */
bobbens@2472
    26
bobbens@2472
    27
bobbens@2472
    28
static Uint8 SDL_numhaptics = 0;
bobbens@2472
    29
SDL_Haptic **SDL_haptics = NULL;
bobbens@2472
    30
static SDL_Haptic *default_haptic = NULL;
bobbens@2472
    31
bobbens@2472
    32
bobbens@2472
    33
/*
bobbens@2472
    34
 * Initializes the Haptic devices.
bobbens@2472
    35
 */
bobbens@2472
    36
int
bobbens@2472
    37
SDL_HapticInit(void)
bobbens@2472
    38
{  
bobbens@2472
    39
   int arraylen;
bobbens@2472
    40
   int status;
bobbens@2472
    41
bobbens@2472
    42
   SDL_numhaptics = 0;
bobbens@2472
    43
   status = SDL_SYS_HapticInit();
bobbens@2472
    44
   if (status >= 0) {
bobbens@2472
    45
      arraylen = (status + 1) * sizeof(*SDL_haptics);
bobbens@2472
    46
      SDL_haptics = (SDL_Haptic **) SDL_malloc(arraylen);
bobbens@2472
    47
      if (SDL_haptics == NULL) {
bobbens@2472
    48
         SDL_numhaptics = 0;
bobbens@2472
    49
      } else {
bobbens@2472
    50
         SDL_memset(SDL_haptics, 0, arraylen);
bobbens@2472
    51
         SDL_numhaptics = status;
bobbens@2472
    52
      }
bobbens@2472
    53
      status = 0;
bobbens@2472
    54
   }
bobbens@2472
    55
   default_haptic = NULL;
bobbens@2472
    56
bobbens@2472
    57
   return status;
bobbens@2472
    58
}
bobbens@2472
    59
bobbens@2472
    60
bobbens@2472
    61
/*
bobbens@2505
    62
 * Checks to see if the haptic device is valid
bobbens@2505
    63
 */
bobbens@2505
    64
static int
bobbens@2505
    65
ValidHaptic(SDL_Haptic ** haptic)
bobbens@2505
    66
{
bobbens@2505
    67
   int valid;
bobbens@2505
    68
   
bobbens@2505
    69
   if (*haptic == NULL) {
bobbens@2505
    70
      SDL_SetError("Haptic device hasn't been opened yet");
bobbens@2505
    71
      valid = 0;
bobbens@2505
    72
   } else {
bobbens@2505
    73
      valid = 1;
bobbens@2505
    74
   }
bobbens@2505
    75
   return valid;
bobbens@2505
    76
}
bobbens@2505
    77
bobbens@2505
    78
bobbens@2505
    79
/*
bobbens@2472
    80
 * Returns the number of available devices.
bobbens@2472
    81
 */
bobbens@2472
    82
int
bobbens@2472
    83
SDL_NumHaptics(void)
bobbens@2472
    84
{
bobbens@2472
    85
   return SDL_numhaptics;
bobbens@2472
    86
}
bobbens@2472
    87
bobbens@2472
    88
bobbens@2472
    89
/*
bobbens@2472
    90
 * Gets the name of a Haptic device by index.
bobbens@2472
    91
 */
bobbens@2472
    92
const char *
bobbens@2472
    93
SDL_HapticName(int device_index)
bobbens@2472
    94
{
bobbens@2472
    95
   if ((device_index < 0) || (device_index >= SDL_numhaptics)) {
bobbens@2472
    96
      SDL_SetError("There are %d haptic devices available", SDL_numhaptics);
bobbens@2472
    97
      return NULL;
bobbens@2472
    98
   }
bobbens@2472
    99
   return SDL_SYS_HapticName(device_index);
bobbens@2472
   100
}
bobbens@2472
   101
bobbens@2472
   102
bobbens@2472
   103
/*
bobbens@2475
   104
 * Opens a Haptic device.
bobbens@2472
   105
 */
bobbens@2472
   106
SDL_Haptic *
bobbens@2472
   107
SDL_HapticOpen(int device_index)
bobbens@2472
   108
{
bobbens@2472
   109
   int i;
bobbens@2472
   110
   SDL_Haptic *haptic;
bobbens@2472
   111
bobbens@2472
   112
   if ((device_index < 0) || (device_index >= SDL_numhaptics)) {
bobbens@2472
   113
      SDL_SetError("There are %d haptic devices available", SDL_numhaptics);
bobbens@2472
   114
      return NULL;
bobbens@2472
   115
   }
bobbens@2472
   116
bobbens@2472
   117
   /* If the haptic is already open, return it */
bobbens@2477
   118
   for (i=0; SDL_haptics[i]; i++) {             
bobbens@2472
   119
      if (device_index == SDL_haptics[i]->index) {
bobbens@2472
   120
         haptic = SDL_haptics[i];
bobbens@2472
   121
         ++haptic->ref_count;
bobbens@2472
   122
         return haptic;
bobbens@2472
   123
      }
bobbens@2472
   124
   }
bobbens@2472
   125
bobbens@2477
   126
   /* Create the haptic device */
bobbens@2472
   127
   haptic = (SDL_Haptic *) SDL_malloc((sizeof *haptic));
bobbens@2477
   128
   if (haptic == NULL) {
bobbens@2477
   129
      SDL_OutOfMemory();
bobbens@2477
   130
      return NULL;
bobbens@2472
   131
   }
bobbens@2477
   132
bobbens@2477
   133
   /* Initialize the haptic device */
bobbens@2477
   134
   SDL_memset(haptic, 0, (sizeof *haptic));
bobbens@2477
   135
   haptic->index = device_index;
bobbens@2477
   136
   if (SDL_SYS_HapticOpen(haptic) < 0) {
bobbens@2477
   137
      SDL_free(haptic);
bobbens@2477
   138
      return NULL;
bobbens@2472
   139
   }
bobbens@2477
   140
bobbens@2477
   141
   /* Add haptic to list */
bobbens@2477
   142
   ++haptic->ref_count;
bobbens@2490
   143
   for (i=0; SDL_haptics[i]; i++)
bobbens@2477
   144
      /* Skip to next haptic */ ;
bobbens@2477
   145
   SDL_haptics[i] = haptic;
bobbens@2477
   146
bobbens@2472
   147
   return haptic;
bobbens@2472
   148
}
bobbens@2474
   149
bobbens@2474
   150
bobbens@2475
   151
/*
bobbens@2506
   152
 * Returns 1 if the device has been opened.
bobbens@2506
   153
 */
bobbens@2506
   154
int
bobbens@2506
   155
SDL_HapticOpened(int device_index)
bobbens@2506
   156
{
bobbens@2506
   157
   int i, opened;
bobbens@2506
   158
bobbens@2506
   159
   opened = 0;
bobbens@2506
   160
   for (i=0; SDL_haptics[i]; i++) {
bobbens@2506
   161
      if (SDL_haptics[i]->index == (Uint8) device_index) {
bobbens@2506
   162
         opened = 1;
bobbens@2506
   163
         break;
bobbens@2506
   164
      }
bobbens@2506
   165
   }
bobbens@2506
   166
   return opened;
bobbens@2506
   167
}
bobbens@2506
   168
bobbens@2506
   169
bobbens@2506
   170
/*
bobbens@2505
   171
 * Returns the index to a haptic device.
bobbens@2505
   172
 */
bobbens@2505
   173
int
bobbens@2505
   174
SDL_HapticIndex(SDL_Haptic * haptic)
bobbens@2505
   175
{
bobbens@2505
   176
   if (!ValidHaptic(&haptic)) {
bobbens@2505
   177
      return -1;
bobbens@2505
   178
   }
bobbens@2505
   179
bobbens@2505
   180
   return haptic->index;
bobbens@2505
   181
}
bobbens@2505
   182
bobbens@2505
   183
bobbens@2505
   184
/*
bobbens@2489
   185
 * Returns SDL_TRUE if joystick has haptic features.
bobbens@2489
   186
 */
bobbens@2489
   187
int
bobbens@2489
   188
SDL_JoystickIsHaptic(SDL_Joystick * joystick)
bobbens@2489
   189
{
bobbens@2489
   190
   int ret;
bobbens@2489
   191
bobbens@2490
   192
   /* Must be a valid joystick */
bobbens@2489
   193
   if (!SDL_PrivateJoystickValid(&joystick)) {
bobbens@2489
   194
      return -1;
bobbens@2489
   195
   }
bobbens@2489
   196
bobbens@2489
   197
   ret = SDL_SYS_JoystickIsHaptic(joystick);
bobbens@2489
   198
bobbens@2489
   199
   if (ret > 0) return SDL_TRUE;
bobbens@2489
   200
   else if (ret == 0) return SDL_FALSE;
bobbens@2489
   201
   else return -1;
bobbens@2489
   202
}
bobbens@2489
   203
bobbens@2489
   204
bobbens@2489
   205
/*
bobbens@2489
   206
 * Opens a haptic device from a joystick.
bobbens@2489
   207
 */
bobbens@2489
   208
SDL_Haptic *
bobbens@2489
   209
SDL_HapticOpenFromJoystick(SDL_Joystick * joystick)
bobbens@2489
   210
{
bobbens@2490
   211
   int i;
bobbens@2490
   212
   SDL_Haptic *haptic;
bobbens@2490
   213
bobbens@2490
   214
   /* Must be a valid joystick */
bobbens@2489
   215
   if (!SDL_PrivateJoystickValid(&joystick)) {
bobbens@2490
   216
      return NULL;
bobbens@2489
   217
   }
bobbens@2490
   218
bobbens@2490
   219
   /* Joystick must be haptic */
bobbens@2490
   220
   if (SDL_SYS_JoystickIsHaptic(joystick) <= 0) {
bobbens@2490
   221
      return NULL;
bobbens@2490
   222
   }
bobbens@2490
   223
bobbens@2490
   224
   /* Check to see if joystick's haptic is already open */
bobbens@2490
   225
   for (i=0; SDL_haptics[i]; i++) {
bobbens@2491
   226
      if (SDL_SYS_JoystickSameHaptic(SDL_haptics[i],joystick)) {
bobbens@2490
   227
         haptic = SDL_haptics[i];
bobbens@2490
   228
         ++haptic->ref_count;
bobbens@2490
   229
         return haptic;
bobbens@2490
   230
      }
bobbens@2490
   231
   }
bobbens@2490
   232
bobbens@2490
   233
   /* Create the haptic device */
bobbens@2490
   234
   haptic = (SDL_Haptic *) SDL_malloc((sizeof *haptic));
bobbens@2490
   235
   if (haptic == NULL) {
bobbens@2490
   236
      SDL_OutOfMemory();
bobbens@2490
   237
      return NULL;
bobbens@2490
   238
   }
bobbens@2490
   239
bobbens@2490
   240
   /* Initialize the haptic device */
bobbens@2490
   241
   SDL_memset(haptic, 0, (sizeof *haptic));
bobbens@2490
   242
   if (SDL_SYS_HapticOpenFromJoystick(haptic,joystick) < 0) {
bobbens@2490
   243
      SDL_free(haptic);
bobbens@2490
   244
      return NULL;
bobbens@2490
   245
   }
bobbens@2490
   246
bobbens@2490
   247
   /* Add haptic to list */
bobbens@2490
   248
   ++haptic->ref_count;
bobbens@2490
   249
   for (i=0; SDL_haptics[i]; i++)
bobbens@2490
   250
      /* Skip to next haptic */ ;
bobbens@2490
   251
   SDL_haptics[i] = haptic;
bobbens@2490
   252
bobbens@2490
   253
   return haptic;
bobbens@2489
   254
}
bobbens@2489
   255
bobbens@2489
   256
bobbens@2489
   257
/*
bobbens@2475
   258
 * Closes a SDL_Haptic device.
bobbens@2475
   259
 */
bobbens@2475
   260
void
bobbens@2475
   261
SDL_HapticClose(SDL_Haptic * haptic)
bobbens@2475
   262
{
bobbens@2476
   263
   int i;
bobbens@2476
   264
bobbens@2476
   265
   /* Must be valid */
bobbens@2476
   266
   if (!ValidHaptic(&haptic)) {
bobbens@2476
   267
      return;
bobbens@2476
   268
   }
bobbens@2476
   269
bobbens@2476
   270
   /* Check if it's still in use */
bobbens@2476
   271
   if (--haptic->ref_count < 0) {
bobbens@2476
   272
      return;
bobbens@2476
   273
   }
bobbens@2476
   274
bobbens@2480
   275
   /* Close it, properly removing effects if needed */
bobbens@2480
   276
   for (i=0; i<haptic->neffects; i++) {
bobbens@2480
   277
      if (haptic->effects[i].hweffect != NULL) {
bobbens@2480
   278
         SDL_HapticDestroyEffect(haptic,i);
bobbens@2480
   279
      }
bobbens@2480
   280
   }
bobbens@2476
   281
   SDL_SYS_HapticClose(haptic);
bobbens@2476
   282
bobbens@2476
   283
   /* Remove from the list */
bobbens@2476
   284
   for (i = 0; SDL_haptics[i]; ++i) {
bobbens@2476
   285
      if (haptic == SDL_haptics[i]) {
bobbens@2476
   286
         SDL_memcpy(&SDL_haptics[i], &SDL_haptics[i + 1],
bobbens@2476
   287
               (SDL_numhaptics - i) * sizeof(haptic));
bobbens@2476
   288
         break;
bobbens@2476
   289
      }
bobbens@2476
   290
   }
bobbens@2476
   291
bobbens@2476
   292
   /* Free */
bobbens@2476
   293
   SDL_free(haptic);
bobbens@2475
   294
}
bobbens@2475
   295
bobbens@2475
   296
/*
bobbens@2475
   297
 * Cleans up after the subsystem.
bobbens@2475
   298
 */
bobbens@2474
   299
void
bobbens@2474
   300
SDL_HapticQuit(void)
bobbens@2474
   301
{
bobbens@2474
   302
   SDL_numhaptics = 0;
bobbens@2474
   303
bobbens@2474
   304
   SDL_SYS_HapticQuit();
bobbens@2474
   305
   if (SDL_haptics != NULL) {
bobbens@2474
   306
      SDL_free(SDL_haptics);
bobbens@2474
   307
      SDL_haptics = NULL;
bobbens@2474
   308
   }
bobbens@2474
   309
}
bobbens@2477
   310
bobbens@2478
   311
/*
bobbens@2478
   312
 * Returns the number of effects a haptic device has.
bobbens@2478
   313
 */
bobbens@2478
   314
int
bobbens@2478
   315
SDL_HapticNumEffects(SDL_Haptic * haptic)
bobbens@2478
   316
{
bobbens@2478
   317
   if (!ValidHaptic(&haptic)) {
bobbens@2478
   318
      return -1;
bobbens@2478
   319
   }
bobbens@2478
   320
bobbens@2478
   321
   return haptic->neffects;
bobbens@2478
   322
}
bobbens@2478
   323
bobbens@2478
   324
/*
bobbens@2478
   325
 * Returns supported effects by the device.
bobbens@2478
   326
 */
bobbens@2478
   327
unsigned int
bobbens@2497
   328
SDL_HapticQuery(SDL_Haptic * haptic)
bobbens@2478
   329
{
bobbens@2478
   330
   if (!ValidHaptic(&haptic)) {
bobbens@2478
   331
      return -1;
bobbens@2478
   332
   }
bobbens@2478
   333
bobbens@2478
   334
   return haptic->supported;
bobbens@2478
   335
}
bobbens@2478
   336
bobbens@2486
   337
/*
bobbens@2486
   338
 * Checks to see if the device can support the effect.
bobbens@2486
   339
 */
bobbens@2478
   340
int
bobbens@2478
   341
SDL_HapticEffectSupported(SDL_Haptic * haptic, SDL_HapticEffect * effect)
bobbens@2478
   342
{
bobbens@2478
   343
   if (!ValidHaptic(&haptic)) {
bobbens@2478
   344
      return -1;
bobbens@2478
   345
   }
bobbens@2478
   346
bobbens@2478
   347
   if ((haptic->supported & effect->type) != 0)
bobbens@2478
   348
      return SDL_TRUE;
bobbens@2478
   349
   return SDL_FALSE;
bobbens@2478
   350
}
bobbens@2477
   351
bobbens@2477
   352
/*
bobbens@2477
   353
 * Creates a new haptic effect.
bobbens@2477
   354
 */
bobbens@2477
   355
int
bobbens@2477
   356
SDL_HapticNewEffect(SDL_Haptic * haptic, SDL_HapticEffect * effect)
bobbens@2477
   357
{
bobbens@2477
   358
   int i;
bobbens@2477
   359
bobbens@2477
   360
   /* Check for device validity. */
bobbens@2477
   361
   if (!ValidHaptic(&haptic)) {
bobbens@2477
   362
      return -1;
bobbens@2477
   363
   }
bobbens@2477
   364
bobbens@2480
   365
   /* Check to see if effect is supported */
bobbens@2480
   366
   if (SDL_HapticEffectSupported(haptic,effect)==SDL_FALSE) {
bobbens@2480
   367
      SDL_SetError("Haptic effect not supported by haptic device.");
bobbens@2480
   368
      return -1;
bobbens@2480
   369
   }
bobbens@2480
   370
bobbens@2477
   371
   /* See if there's a free slot */
bobbens@2477
   372
   for (i=0; i<haptic->neffects; i++) {
bobbens@2477
   373
      if (haptic->effects[i].hweffect == NULL) {
bobbens@2477
   374
bobbens@2477
   375
         /* Now let the backend create the real effect */
bobbens@2480
   376
         if (SDL_SYS_HapticNewEffect(haptic,&haptic->effects[i],effect) != 0) {
bobbens@2477
   377
            return -1; /* Backend failed to create effect */
bobbens@2477
   378
         }
bobbens@2477
   379
         return i;
bobbens@2477
   380
      }
bobbens@2477
   381
   }
bobbens@2477
   382
bobbens@2477
   383
   SDL_SetError("Haptic device has no free space left.");
bobbens@2477
   384
   return -1;
bobbens@2477
   385
}
bobbens@2477
   386
bobbens@2477
   387
/*
bobbens@2480
   388
 * Checks to see if an effect is valid.
bobbens@2480
   389
 */
bobbens@2480
   390
static int
bobbens@2480
   391
ValidEffect(SDL_Haptic * haptic, int effect)
bobbens@2480
   392
{
bobbens@2480
   393
   if ((effect < 0) || (effect >= haptic->neffects)) {
bobbens@2480
   394
      SDL_SetError("Invalid haptic effect identifier.");
bobbens@2480
   395
      return 0;
bobbens@2480
   396
   }
bobbens@2480
   397
   return 1;
bobbens@2480
   398
}
bobbens@2480
   399
bobbens@2480
   400
/*
bobbens@2488
   401
 * Updates an effect.
bobbens@2488
   402
 */
bobbens@2488
   403
int
bobbens@2488
   404
SDL_HapticUpdateEffect(SDL_Haptic * haptic, int effect, SDL_HapticEffect * data)
bobbens@2488
   405
{
bobbens@2488
   406
   if (!ValidHaptic(&haptic) || !ValidEffect(haptic,effect)) {
bobbens@2488
   407
      return -1;
bobbens@2488
   408
   }
bobbens@2488
   409
bobbens@2488
   410
   /* Updates the effect */
bobbens@2488
   411
   if (SDL_SYS_HapticUpdateEffect(haptic,&haptic->effects[effect],data) < 0) {
bobbens@2488
   412
      return -1;
bobbens@2488
   413
   }
bobbens@2488
   414
bobbens@2488
   415
   return 0;
bobbens@2488
   416
}
bobbens@2488
   417
bobbens@2488
   418
bobbens@2488
   419
/*
bobbens@2477
   420
 * Runs the haptic effect on the device.
bobbens@2477
   421
 */
bobbens@2477
   422
int
bobbens@2477
   423
SDL_HapticRunEffect(SDL_Haptic * haptic, int effect)
bobbens@2477
   424
{
bobbens@2480
   425
   if (!ValidHaptic(&haptic) || !ValidEffect(haptic,effect)) {
bobbens@2477
   426
      return -1;
bobbens@2477
   427
   }
bobbens@2479
   428
bobbens@2479
   429
   /* Run the effect */
bobbens@2479
   430
   if (SDL_SYS_HapticRunEffect(haptic,&haptic->effects[effect]) < 0) {
bobbens@2479
   431
      return -1;
bobbens@2479
   432
   }
bobbens@2479
   433
bobbens@2479
   434
   return 0;
bobbens@2477
   435
}
bobbens@2477
   436
bobbens@2477
   437
/*
bobbens@2485
   438
 * Stops the haptic effect on the device.
bobbens@2485
   439
 */
bobbens@2485
   440
int
bobbens@2485
   441
SDL_HapticStopEffect(SDL_Haptic * haptic, int effect)
bobbens@2485
   442
{
bobbens@2485
   443
   if (!ValidHaptic(&haptic) || !ValidEffect(haptic,effect)) {
bobbens@2485
   444
      return -1;
bobbens@2485
   445
   }
bobbens@2485
   446
bobbens@2485
   447
   /* Stop the effect */
bobbens@2485
   448
   if (SDL_SYS_HapticStopEffect(haptic,&haptic->effects[effect]) < 0) {
bobbens@2485
   449
      return -1;
bobbens@2485
   450
   }
bobbens@2485
   451
bobbens@2485
   452
   return 0;
bobbens@2485
   453
}
bobbens@2485
   454
bobbens@2485
   455
/*
bobbens@2477
   456
 * Gets rid of a haptic effect.
bobbens@2477
   457
 */
bobbens@2477
   458
void
bobbens@2477
   459
SDL_HapticDestroyEffect(SDL_Haptic * haptic, int effect)
bobbens@2477
   460
{
bobbens@2480
   461
   if (!ValidHaptic(&haptic) || !ValidEffect(haptic,effect)) {
bobbens@2477
   462
      return;
bobbens@2477
   463
   }
bobbens@2479
   464
bobbens@2479
   465
   /* Not allocated */
bobbens@2479
   466
   if (haptic->effects[effect].hweffect == NULL) {
bobbens@2479
   467
      return;
bobbens@2479
   468
   }
bobbens@2479
   469
bobbens@2479
   470
   SDL_SYS_HapticDestroyEffect(haptic, &haptic->effects[effect]);
bobbens@2477
   471
}
bobbens@2477
   472
bobbens@2483
   473
/*
bobbens@2495
   474
 * Gets the status of a haptic effect.
bobbens@2495
   475
 */
bobbens@2495
   476
int
bobbens@2495
   477
SDL_HapticGetEffectStatus(SDL_Haptic *haptic, int effect)
bobbens@2495
   478
{
bobbens@2495
   479
   if (!ValidHaptic(&haptic) || !ValidEffect(haptic,effect)) {
bobbens@2495
   480
      return -1;
bobbens@2495
   481
   }
bobbens@2495
   482
bobbens@2495
   483
   if ((haptic->supported & SDL_HAPTIC_STATUS) == 0) {
bobbens@2495
   484
      SDL_SetError("Haptic device does not support status queries.");
bobbens@2495
   485
      return -1;
bobbens@2495
   486
   }
bobbens@2495
   487
bobbens@2495
   488
   return SDL_SYS_HapticGetEffectStatus(haptic, &haptic->effects[effect]);
bobbens@2495
   489
}
bobbens@2495
   490
bobbens@2495
   491
/*
bobbens@2483
   492
 * Sets the global gain of the device.
bobbens@2483
   493
 */
bobbens@2483
   494
int
bobbens@2483
   495
SDL_HapticSetGain(SDL_Haptic * haptic, int gain )
bobbens@2483
   496
{
bobbens@2483
   497
   if (!ValidHaptic(&haptic)) {
bobbens@2483
   498
      return -1;
bobbens@2483
   499
   }
bobbens@2477
   500
bobbens@2484
   501
   if ((haptic->supported & SDL_HAPTIC_GAIN) == 0) {
bobbens@2484
   502
      SDL_SetError("Haptic device does not support setting gain.");
bobbens@2484
   503
      return -1;
bobbens@2484
   504
   }
bobbens@2484
   505
bobbens@2483
   506
   if ((gain < 0) || (gain > 100)) {
bobbens@2483
   507
      SDL_SetError("Haptic gain must be between 0 and 100.");
bobbens@2483
   508
      return -1;
bobbens@2483
   509
   }
bobbens@2483
   510
bobbens@2483
   511
   if (SDL_SYS_HapticSetGain(haptic,gain) < 0) {
bobbens@2483
   512
      return -1;
bobbens@2483
   513
   }
bobbens@2483
   514
bobbens@2483
   515
   return 0;
bobbens@2483
   516
}
bobbens@2483
   517
bobbens@2484
   518
/*
bobbens@2484
   519
 * Makes the device autocenter, 0 disables.
bobbens@2484
   520
 */
bobbens@2484
   521
int
bobbens@2484
   522
SDL_HapticSetAutocenter(SDL_Haptic * haptic, int autocenter )
bobbens@2484
   523
{
bobbens@2484
   524
   if (!ValidHaptic(&haptic)) {
bobbens@2484
   525
      return -1;
bobbens@2484
   526
   }
bobbens@2483
   527
bobbens@2484
   528
   if ((haptic->supported & SDL_HAPTIC_AUTOCENTER) == 0) {
bobbens@2484
   529
      SDL_SetError("Haptic device does not support setting autocenter.");
bobbens@2484
   530
      return -1;
bobbens@2484
   531
   }
bobbens@2484
   532
bobbens@2484
   533
   if ((autocenter < 0) || (autocenter > 100)) {
bobbens@2484
   534
      SDL_SetError("Haptic autocenter must be between 0 and 100.");
bobbens@2484
   535
      return -1;
bobbens@2484
   536
   }                                           
bobbens@2484
   537
bobbens@2484
   538
   if (SDL_SYS_HapticSetAutocenter(haptic,autocenter) < 0) {
bobbens@2484
   539
      return -1;
bobbens@2484
   540
   }
bobbens@2484
   541
bobbens@2484
   542
   return 0;
bobbens@2484
   543
}
bobbens@2484
   544
bobbens@2484
   545