src/haptic/SDL_haptic.c
author Edgar Simo <bobbens@gmail.com>
Tue, 08 Jul 2008 19:23:03 +0000
branchgsoc2008_force_feedback
changeset 2505 abfcba0f3bd1
parent 2497 0893fbf73b3d
child 2506 ba8e99fe92c1
permissions -rw-r--r--
Added SDL_HapticIndex.
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@2505
   152
 * Returns the index to a haptic device.
bobbens@2505
   153
 */
bobbens@2505
   154
int
bobbens@2505
   155
SDL_HapticIndex(SDL_Haptic * haptic)
bobbens@2505
   156
{
bobbens@2505
   157
   if (!ValidHaptic(&haptic)) {
bobbens@2505
   158
      return -1;
bobbens@2505
   159
   }
bobbens@2505
   160
bobbens@2505
   161
   return haptic->index;
bobbens@2505
   162
}
bobbens@2505
   163
bobbens@2505
   164
bobbens@2505
   165
/*
bobbens@2489
   166
 * Returns SDL_TRUE if joystick has haptic features.
bobbens@2489
   167
 */
bobbens@2489
   168
int
bobbens@2489
   169
SDL_JoystickIsHaptic(SDL_Joystick * joystick)
bobbens@2489
   170
{
bobbens@2489
   171
   int ret;
bobbens@2489
   172
bobbens@2490
   173
   /* Must be a valid joystick */
bobbens@2489
   174
   if (!SDL_PrivateJoystickValid(&joystick)) {
bobbens@2489
   175
      return -1;
bobbens@2489
   176
   }
bobbens@2489
   177
bobbens@2489
   178
   ret = SDL_SYS_JoystickIsHaptic(joystick);
bobbens@2489
   179
bobbens@2489
   180
   if (ret > 0) return SDL_TRUE;
bobbens@2489
   181
   else if (ret == 0) return SDL_FALSE;
bobbens@2489
   182
   else return -1;
bobbens@2489
   183
}
bobbens@2489
   184
bobbens@2489
   185
bobbens@2489
   186
/*
bobbens@2489
   187
 * Opens a haptic device from a joystick.
bobbens@2489
   188
 */
bobbens@2489
   189
SDL_Haptic *
bobbens@2489
   190
SDL_HapticOpenFromJoystick(SDL_Joystick * joystick)
bobbens@2489
   191
{
bobbens@2490
   192
   int i;
bobbens@2490
   193
   SDL_Haptic *haptic;
bobbens@2490
   194
bobbens@2490
   195
   /* Must be a valid joystick */
bobbens@2489
   196
   if (!SDL_PrivateJoystickValid(&joystick)) {
bobbens@2490
   197
      return NULL;
bobbens@2489
   198
   }
bobbens@2490
   199
bobbens@2490
   200
   /* Joystick must be haptic */
bobbens@2490
   201
   if (SDL_SYS_JoystickIsHaptic(joystick) <= 0) {
bobbens@2490
   202
      return NULL;
bobbens@2490
   203
   }
bobbens@2490
   204
bobbens@2490
   205
   /* Check to see if joystick's haptic is already open */
bobbens@2490
   206
   for (i=0; SDL_haptics[i]; i++) {
bobbens@2491
   207
      if (SDL_SYS_JoystickSameHaptic(SDL_haptics[i],joystick)) {
bobbens@2490
   208
         haptic = SDL_haptics[i];
bobbens@2490
   209
         ++haptic->ref_count;
bobbens@2490
   210
         return haptic;
bobbens@2490
   211
      }
bobbens@2490
   212
   }
bobbens@2490
   213
bobbens@2490
   214
   /* Create the haptic device */
bobbens@2490
   215
   haptic = (SDL_Haptic *) SDL_malloc((sizeof *haptic));
bobbens@2490
   216
   if (haptic == NULL) {
bobbens@2490
   217
      SDL_OutOfMemory();
bobbens@2490
   218
      return NULL;
bobbens@2490
   219
   }
bobbens@2490
   220
bobbens@2490
   221
   /* Initialize the haptic device */
bobbens@2490
   222
   SDL_memset(haptic, 0, (sizeof *haptic));
bobbens@2490
   223
   if (SDL_SYS_HapticOpenFromJoystick(haptic,joystick) < 0) {
bobbens@2490
   224
      SDL_free(haptic);
bobbens@2490
   225
      return NULL;
bobbens@2490
   226
   }
bobbens@2490
   227
bobbens@2490
   228
   /* Add haptic to list */
bobbens@2490
   229
   ++haptic->ref_count;
bobbens@2490
   230
   for (i=0; SDL_haptics[i]; i++)
bobbens@2490
   231
      /* Skip to next haptic */ ;
bobbens@2490
   232
   SDL_haptics[i] = haptic;
bobbens@2490
   233
bobbens@2490
   234
   return haptic;
bobbens@2489
   235
}
bobbens@2489
   236
bobbens@2489
   237
bobbens@2489
   238
/*
bobbens@2475
   239
 * Closes a SDL_Haptic device.
bobbens@2475
   240
 */
bobbens@2475
   241
void
bobbens@2475
   242
SDL_HapticClose(SDL_Haptic * haptic)
bobbens@2475
   243
{
bobbens@2476
   244
   int i;
bobbens@2476
   245
bobbens@2476
   246
   /* Must be valid */
bobbens@2476
   247
   if (!ValidHaptic(&haptic)) {
bobbens@2476
   248
      return;
bobbens@2476
   249
   }
bobbens@2476
   250
bobbens@2476
   251
   /* Check if it's still in use */
bobbens@2476
   252
   if (--haptic->ref_count < 0) {
bobbens@2476
   253
      return;
bobbens@2476
   254
   }
bobbens@2476
   255
bobbens@2480
   256
   /* Close it, properly removing effects if needed */
bobbens@2480
   257
   for (i=0; i<haptic->neffects; i++) {
bobbens@2480
   258
      if (haptic->effects[i].hweffect != NULL) {
bobbens@2480
   259
         SDL_HapticDestroyEffect(haptic,i);
bobbens@2480
   260
      }
bobbens@2480
   261
   }
bobbens@2476
   262
   SDL_SYS_HapticClose(haptic);
bobbens@2476
   263
bobbens@2476
   264
   /* Remove from the list */
bobbens@2476
   265
   for (i = 0; SDL_haptics[i]; ++i) {
bobbens@2476
   266
      if (haptic == SDL_haptics[i]) {
bobbens@2476
   267
         SDL_memcpy(&SDL_haptics[i], &SDL_haptics[i + 1],
bobbens@2476
   268
               (SDL_numhaptics - i) * sizeof(haptic));
bobbens@2476
   269
         break;
bobbens@2476
   270
      }
bobbens@2476
   271
   }
bobbens@2476
   272
bobbens@2476
   273
   /* Free */
bobbens@2476
   274
   SDL_free(haptic);
bobbens@2475
   275
}
bobbens@2475
   276
bobbens@2475
   277
/*
bobbens@2475
   278
 * Cleans up after the subsystem.
bobbens@2475
   279
 */
bobbens@2474
   280
void
bobbens@2474
   281
SDL_HapticQuit(void)
bobbens@2474
   282
{
bobbens@2474
   283
   SDL_numhaptics = 0;
bobbens@2474
   284
bobbens@2474
   285
   SDL_SYS_HapticQuit();
bobbens@2474
   286
   if (SDL_haptics != NULL) {
bobbens@2474
   287
      SDL_free(SDL_haptics);
bobbens@2474
   288
      SDL_haptics = NULL;
bobbens@2474
   289
   }
bobbens@2474
   290
}
bobbens@2477
   291
bobbens@2478
   292
/*
bobbens@2478
   293
 * Returns the number of effects a haptic device has.
bobbens@2478
   294
 */
bobbens@2478
   295
int
bobbens@2478
   296
SDL_HapticNumEffects(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->neffects;
bobbens@2478
   303
}
bobbens@2478
   304
bobbens@2478
   305
/*
bobbens@2478
   306
 * Returns supported effects by the device.
bobbens@2478
   307
 */
bobbens@2478
   308
unsigned int
bobbens@2497
   309
SDL_HapticQuery(SDL_Haptic * haptic)
bobbens@2478
   310
{
bobbens@2478
   311
   if (!ValidHaptic(&haptic)) {
bobbens@2478
   312
      return -1;
bobbens@2478
   313
   }
bobbens@2478
   314
bobbens@2478
   315
   return haptic->supported;
bobbens@2478
   316
}
bobbens@2478
   317
bobbens@2486
   318
/*
bobbens@2486
   319
 * Checks to see if the device can support the effect.
bobbens@2486
   320
 */
bobbens@2478
   321
int
bobbens@2478
   322
SDL_HapticEffectSupported(SDL_Haptic * haptic, SDL_HapticEffect * effect)
bobbens@2478
   323
{
bobbens@2478
   324
   if (!ValidHaptic(&haptic)) {
bobbens@2478
   325
      return -1;
bobbens@2478
   326
   }
bobbens@2478
   327
bobbens@2478
   328
   if ((haptic->supported & effect->type) != 0)
bobbens@2478
   329
      return SDL_TRUE;
bobbens@2478
   330
   return SDL_FALSE;
bobbens@2478
   331
}
bobbens@2477
   332
bobbens@2477
   333
/*
bobbens@2477
   334
 * Creates a new haptic effect.
bobbens@2477
   335
 */
bobbens@2477
   336
int
bobbens@2477
   337
SDL_HapticNewEffect(SDL_Haptic * haptic, SDL_HapticEffect * effect)
bobbens@2477
   338
{
bobbens@2477
   339
   int i;
bobbens@2477
   340
bobbens@2477
   341
   /* Check for device validity. */
bobbens@2477
   342
   if (!ValidHaptic(&haptic)) {
bobbens@2477
   343
      return -1;
bobbens@2477
   344
   }
bobbens@2477
   345
bobbens@2480
   346
   /* Check to see if effect is supported */
bobbens@2480
   347
   if (SDL_HapticEffectSupported(haptic,effect)==SDL_FALSE) {
bobbens@2480
   348
      SDL_SetError("Haptic effect not supported by haptic device.");
bobbens@2480
   349
      return -1;
bobbens@2480
   350
   }
bobbens@2480
   351
bobbens@2477
   352
   /* See if there's a free slot */
bobbens@2477
   353
   for (i=0; i<haptic->neffects; i++) {
bobbens@2477
   354
      if (haptic->effects[i].hweffect == NULL) {
bobbens@2477
   355
bobbens@2477
   356
         /* Now let the backend create the real effect */
bobbens@2480
   357
         if (SDL_SYS_HapticNewEffect(haptic,&haptic->effects[i],effect) != 0) {
bobbens@2477
   358
            return -1; /* Backend failed to create effect */
bobbens@2477
   359
         }
bobbens@2477
   360
         return i;
bobbens@2477
   361
      }
bobbens@2477
   362
   }
bobbens@2477
   363
bobbens@2477
   364
   SDL_SetError("Haptic device has no free space left.");
bobbens@2477
   365
   return -1;
bobbens@2477
   366
}
bobbens@2477
   367
bobbens@2477
   368
/*
bobbens@2480
   369
 * Checks to see if an effect is valid.
bobbens@2480
   370
 */
bobbens@2480
   371
static int
bobbens@2480
   372
ValidEffect(SDL_Haptic * haptic, int effect)
bobbens@2480
   373
{
bobbens@2480
   374
   if ((effect < 0) || (effect >= haptic->neffects)) {
bobbens@2480
   375
      SDL_SetError("Invalid haptic effect identifier.");
bobbens@2480
   376
      return 0;
bobbens@2480
   377
   }
bobbens@2480
   378
   return 1;
bobbens@2480
   379
}
bobbens@2480
   380
bobbens@2480
   381
/*
bobbens@2488
   382
 * Updates an effect.
bobbens@2488
   383
 */
bobbens@2488
   384
int
bobbens@2488
   385
SDL_HapticUpdateEffect(SDL_Haptic * haptic, int effect, SDL_HapticEffect * data)
bobbens@2488
   386
{
bobbens@2488
   387
   if (!ValidHaptic(&haptic) || !ValidEffect(haptic,effect)) {
bobbens@2488
   388
      return -1;
bobbens@2488
   389
   }
bobbens@2488
   390
bobbens@2488
   391
   /* Updates the effect */
bobbens@2488
   392
   if (SDL_SYS_HapticUpdateEffect(haptic,&haptic->effects[effect],data) < 0) {
bobbens@2488
   393
      return -1;
bobbens@2488
   394
   }
bobbens@2488
   395
bobbens@2488
   396
   return 0;
bobbens@2488
   397
}
bobbens@2488
   398
bobbens@2488
   399
bobbens@2488
   400
/*
bobbens@2477
   401
 * Runs the haptic effect on the device.
bobbens@2477
   402
 */
bobbens@2477
   403
int
bobbens@2477
   404
SDL_HapticRunEffect(SDL_Haptic * haptic, int effect)
bobbens@2477
   405
{
bobbens@2480
   406
   if (!ValidHaptic(&haptic) || !ValidEffect(haptic,effect)) {
bobbens@2477
   407
      return -1;
bobbens@2477
   408
   }
bobbens@2479
   409
bobbens@2479
   410
   /* Run the effect */
bobbens@2479
   411
   if (SDL_SYS_HapticRunEffect(haptic,&haptic->effects[effect]) < 0) {
bobbens@2479
   412
      return -1;
bobbens@2479
   413
   }
bobbens@2479
   414
bobbens@2479
   415
   return 0;
bobbens@2477
   416
}
bobbens@2477
   417
bobbens@2477
   418
/*
bobbens@2485
   419
 * Stops the haptic effect on the device.
bobbens@2485
   420
 */
bobbens@2485
   421
int
bobbens@2485
   422
SDL_HapticStopEffect(SDL_Haptic * haptic, int effect)
bobbens@2485
   423
{
bobbens@2485
   424
   if (!ValidHaptic(&haptic) || !ValidEffect(haptic,effect)) {
bobbens@2485
   425
      return -1;
bobbens@2485
   426
   }
bobbens@2485
   427
bobbens@2485
   428
   /* Stop the effect */
bobbens@2485
   429
   if (SDL_SYS_HapticStopEffect(haptic,&haptic->effects[effect]) < 0) {
bobbens@2485
   430
      return -1;
bobbens@2485
   431
   }
bobbens@2485
   432
bobbens@2485
   433
   return 0;
bobbens@2485
   434
}
bobbens@2485
   435
bobbens@2485
   436
/*
bobbens@2477
   437
 * Gets rid of a haptic effect.
bobbens@2477
   438
 */
bobbens@2477
   439
void
bobbens@2477
   440
SDL_HapticDestroyEffect(SDL_Haptic * haptic, int effect)
bobbens@2477
   441
{
bobbens@2480
   442
   if (!ValidHaptic(&haptic) || !ValidEffect(haptic,effect)) {
bobbens@2477
   443
      return;
bobbens@2477
   444
   }
bobbens@2479
   445
bobbens@2479
   446
   /* Not allocated */
bobbens@2479
   447
   if (haptic->effects[effect].hweffect == NULL) {
bobbens@2479
   448
      return;
bobbens@2479
   449
   }
bobbens@2479
   450
bobbens@2479
   451
   SDL_SYS_HapticDestroyEffect(haptic, &haptic->effects[effect]);
bobbens@2477
   452
}
bobbens@2477
   453
bobbens@2483
   454
/*
bobbens@2495
   455
 * Gets the status of a haptic effect.
bobbens@2495
   456
 */
bobbens@2495
   457
int
bobbens@2495
   458
SDL_HapticGetEffectStatus(SDL_Haptic *haptic, int effect)
bobbens@2495
   459
{
bobbens@2495
   460
   if (!ValidHaptic(&haptic) || !ValidEffect(haptic,effect)) {
bobbens@2495
   461
      return -1;
bobbens@2495
   462
   }
bobbens@2495
   463
bobbens@2495
   464
   if ((haptic->supported & SDL_HAPTIC_STATUS) == 0) {
bobbens@2495
   465
      SDL_SetError("Haptic device does not support status queries.");
bobbens@2495
   466
      return -1;
bobbens@2495
   467
   }
bobbens@2495
   468
bobbens@2495
   469
   return SDL_SYS_HapticGetEffectStatus(haptic, &haptic->effects[effect]);
bobbens@2495
   470
}
bobbens@2495
   471
bobbens@2495
   472
/*
bobbens@2483
   473
 * Sets the global gain of the device.
bobbens@2483
   474
 */
bobbens@2483
   475
int
bobbens@2483
   476
SDL_HapticSetGain(SDL_Haptic * haptic, int gain )
bobbens@2483
   477
{
bobbens@2483
   478
   if (!ValidHaptic(&haptic)) {
bobbens@2483
   479
      return -1;
bobbens@2483
   480
   }
bobbens@2477
   481
bobbens@2484
   482
   if ((haptic->supported & SDL_HAPTIC_GAIN) == 0) {
bobbens@2484
   483
      SDL_SetError("Haptic device does not support setting gain.");
bobbens@2484
   484
      return -1;
bobbens@2484
   485
   }
bobbens@2484
   486
bobbens@2483
   487
   if ((gain < 0) || (gain > 100)) {
bobbens@2483
   488
      SDL_SetError("Haptic gain must be between 0 and 100.");
bobbens@2483
   489
      return -1;
bobbens@2483
   490
   }
bobbens@2483
   491
bobbens@2483
   492
   if (SDL_SYS_HapticSetGain(haptic,gain) < 0) {
bobbens@2483
   493
      return -1;
bobbens@2483
   494
   }
bobbens@2483
   495
bobbens@2483
   496
   return 0;
bobbens@2483
   497
}
bobbens@2483
   498
bobbens@2484
   499
/*
bobbens@2484
   500
 * Makes the device autocenter, 0 disables.
bobbens@2484
   501
 */
bobbens@2484
   502
int
bobbens@2484
   503
SDL_HapticSetAutocenter(SDL_Haptic * haptic, int autocenter )
bobbens@2484
   504
{
bobbens@2484
   505
   if (!ValidHaptic(&haptic)) {
bobbens@2484
   506
      return -1;
bobbens@2484
   507
   }
bobbens@2483
   508
bobbens@2484
   509
   if ((haptic->supported & SDL_HAPTIC_AUTOCENTER) == 0) {
bobbens@2484
   510
      SDL_SetError("Haptic device does not support setting autocenter.");
bobbens@2484
   511
      return -1;
bobbens@2484
   512
   }
bobbens@2484
   513
bobbens@2484
   514
   if ((autocenter < 0) || (autocenter > 100)) {
bobbens@2484
   515
      SDL_SetError("Haptic autocenter must be between 0 and 100.");
bobbens@2484
   516
      return -1;
bobbens@2484
   517
   }                                           
bobbens@2484
   518
bobbens@2484
   519
   if (SDL_SYS_HapticSetAutocenter(haptic,autocenter) < 0) {
bobbens@2484
   520
      return -1;
bobbens@2484
   521
   }
bobbens@2484
   522
bobbens@2484
   523
   return 0;
bobbens@2484
   524
}
bobbens@2484
   525
bobbens@2484
   526