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