src/haptic/SDL_haptic.c
changeset 2713 0906692aa6a4
child 3080 4094b4f1c3a1
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/haptic/SDL_haptic.c	Mon Aug 25 09:55:03 2008 +0000
     1.3 @@ -0,0 +1,698 @@
     1.4 +/*
     1.5 +    SDL - Simple DirectMedia Layer
     1.6 +    Copyright (C) 2008 Edgar Simo
     1.7 +
     1.8 +    This library is free software; you can redistribute it and/or
     1.9 +    modify it under the terms of the GNU Lesser General Public
    1.10 +    License as published by the Free Software Foundation; either
    1.11 +    version 2.1 of the License, or (at your option) any later version.
    1.12 +
    1.13 +    This library is distributed in the hope that it will be useful,
    1.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    1.16 +    Lesser General Public License for more details.
    1.17 +
    1.18 +    You should have received a copy of the GNU Lesser General Public
    1.19 +    License along with this library; if not, write to the Free Software
    1.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    1.21 +
    1.22 +    Sam Lantinga
    1.23 +    slouken@libsdl.org
    1.24 +*/
    1.25 +#include "SDL_config.h"
    1.26 +
    1.27 +#include "SDL_syshaptic.h"
    1.28 +#include "../joystick/SDL_joystick_c.h" /* For SDL_PrivateJoystickValid */
    1.29 +
    1.30 +
    1.31 +Uint8 SDL_numhaptics = 0;
    1.32 +SDL_Haptic **SDL_haptics = NULL;
    1.33 +
    1.34 +
    1.35 +/*
    1.36 + * Initializes the Haptic devices.
    1.37 + */
    1.38 +int
    1.39 +SDL_HapticInit(void)
    1.40 +{
    1.41 +    int arraylen;
    1.42 +    int status;
    1.43 +
    1.44 +    SDL_numhaptics = 0;
    1.45 +    status = SDL_SYS_HapticInit();
    1.46 +    if (status >= 0) {
    1.47 +        arraylen = (status + 1) * sizeof(*SDL_haptics);
    1.48 +        SDL_haptics = (SDL_Haptic **) SDL_malloc(arraylen);
    1.49 +        if (SDL_haptics == NULL) {      /* Out of memory. */
    1.50 +            SDL_numhaptics = 0;
    1.51 +        } else {
    1.52 +            SDL_memset(SDL_haptics, 0, arraylen);
    1.53 +            SDL_numhaptics = status;
    1.54 +        }
    1.55 +        status = 0;
    1.56 +    }
    1.57 +
    1.58 +    return status;
    1.59 +}
    1.60 +
    1.61 +
    1.62 +/*
    1.63 + * Checks to see if the haptic device is valid
    1.64 + */
    1.65 +static int
    1.66 +ValidHaptic(SDL_Haptic * haptic)
    1.67 +{
    1.68 +    int i;
    1.69 +    int valid;
    1.70 +
    1.71 +    valid = 0;
    1.72 +    for (i = 0; i < SDL_numhaptics; i++) {
    1.73 +        if (SDL_haptics[i] == haptic) {
    1.74 +            valid = 1;
    1.75 +            break;
    1.76 +        }
    1.77 +    }
    1.78 +
    1.79 +    return valid;
    1.80 +}
    1.81 +
    1.82 +
    1.83 +/*
    1.84 + * Returns the number of available devices.
    1.85 + */
    1.86 +int
    1.87 +SDL_NumHaptics(void)
    1.88 +{
    1.89 +    return SDL_numhaptics;
    1.90 +}
    1.91 +
    1.92 +
    1.93 +/*
    1.94 + * Gets the name of a Haptic device by index.
    1.95 + */
    1.96 +const char *
    1.97 +SDL_HapticName(int device_index)
    1.98 +{
    1.99 +    if ((device_index < 0) || (device_index >= SDL_numhaptics)) {
   1.100 +        SDL_SetError("Haptic: There are %d haptic devices available",
   1.101 +                     SDL_numhaptics);
   1.102 +        return NULL;
   1.103 +    }
   1.104 +    return SDL_SYS_HapticName(device_index);
   1.105 +}
   1.106 +
   1.107 +
   1.108 +/*
   1.109 + * Opens a Haptic device.
   1.110 + */
   1.111 +SDL_Haptic *
   1.112 +SDL_HapticOpen(int device_index)
   1.113 +{
   1.114 +    int i;
   1.115 +    SDL_Haptic *haptic;
   1.116 +
   1.117 +    if ((device_index < 0) || (device_index >= SDL_numhaptics)) {
   1.118 +        SDL_SetError("Haptic: There are %d haptic devices available",
   1.119 +                     SDL_numhaptics);
   1.120 +        return NULL;
   1.121 +    }
   1.122 +
   1.123 +    /* If the haptic is already open, return it */
   1.124 +    for (i = 0; SDL_haptics[i]; i++) {
   1.125 +        if (device_index == SDL_haptics[i]->index) {
   1.126 +            haptic = SDL_haptics[i];
   1.127 +            ++haptic->ref_count;
   1.128 +            return haptic;
   1.129 +        }
   1.130 +    }
   1.131 +
   1.132 +    /* Create the haptic device */
   1.133 +    haptic = (SDL_Haptic *) SDL_malloc((sizeof *haptic));
   1.134 +    if (haptic == NULL) {
   1.135 +        SDL_OutOfMemory();
   1.136 +        return NULL;
   1.137 +    }
   1.138 +
   1.139 +    /* Initialize the haptic device */
   1.140 +    SDL_memset(haptic, 0, (sizeof *haptic));
   1.141 +    haptic->index = device_index;
   1.142 +    if (SDL_SYS_HapticOpen(haptic) < 0) {
   1.143 +        SDL_free(haptic);
   1.144 +        return NULL;
   1.145 +    }
   1.146 +
   1.147 +    /* Disable autocenter and set gain to max. */
   1.148 +    if (haptic->supported & SDL_HAPTIC_GAIN)
   1.149 +        SDL_HapticSetGain(haptic, 100);
   1.150 +    if (haptic->supported & SDL_HAPTIC_AUTOCENTER)
   1.151 +        SDL_HapticSetAutocenter(haptic, 0);
   1.152 +
   1.153 +    /* Add haptic to list */
   1.154 +    ++haptic->ref_count;
   1.155 +    for (i = 0; SDL_haptics[i]; i++)
   1.156 +        /* Skip to next haptic */ ;
   1.157 +    SDL_haptics[i] = haptic;
   1.158 +
   1.159 +    return haptic;
   1.160 +}
   1.161 +
   1.162 +
   1.163 +/*
   1.164 + * Returns 1 if the device has been opened.
   1.165 + */
   1.166 +int
   1.167 +SDL_HapticOpened(int device_index)
   1.168 +{
   1.169 +    int i, opened;
   1.170 +
   1.171 +    opened = 0;
   1.172 +    for (i = 0; SDL_haptics[i]; i++) {
   1.173 +        if (SDL_haptics[i]->index == (Uint8) device_index) {
   1.174 +            opened = 1;
   1.175 +            break;
   1.176 +        }
   1.177 +    }
   1.178 +    return opened;
   1.179 +}
   1.180 +
   1.181 +
   1.182 +/*
   1.183 + * Returns the index to a haptic device.
   1.184 + */
   1.185 +int
   1.186 +SDL_HapticIndex(SDL_Haptic * haptic)
   1.187 +{
   1.188 +    if (!ValidHaptic(haptic)) {
   1.189 +        return -1;
   1.190 +    }
   1.191 +
   1.192 +    return haptic->index;
   1.193 +}
   1.194 +
   1.195 +
   1.196 +/*
   1.197 + * Returns SDL_TRUE if mouse is haptic, SDL_FALSE if it isn't.
   1.198 + */
   1.199 +int
   1.200 +SDL_MouseIsHaptic(void)
   1.201 +{
   1.202 +    if (SDL_SYS_HapticMouse() < 0)
   1.203 +        return SDL_FALSE;
   1.204 +    return SDL_TRUE;
   1.205 +}
   1.206 +
   1.207 +
   1.208 +/*
   1.209 + * Returns the haptic device if mouse is haptic or NULL elsewise.
   1.210 + */
   1.211 +SDL_Haptic *
   1.212 +SDL_HapticOpenFromMouse(void)
   1.213 +{
   1.214 +    int device_index;
   1.215 +
   1.216 +    device_index = SDL_SYS_HapticMouse();
   1.217 +
   1.218 +    if (device_index < 0) {
   1.219 +        SDL_SetError("Haptic: Mouse isn't a haptic device.");
   1.220 +        return NULL;
   1.221 +    }
   1.222 +
   1.223 +    return SDL_HapticOpen(device_index);
   1.224 +}
   1.225 +
   1.226 +
   1.227 +/*
   1.228 + * Returns SDL_TRUE if joystick has haptic features.
   1.229 + */
   1.230 +int
   1.231 +SDL_JoystickIsHaptic(SDL_Joystick * joystick)
   1.232 +{
   1.233 +    int ret;
   1.234 +
   1.235 +    /* Must be a valid joystick */
   1.236 +    if (!SDL_PrivateJoystickValid(&joystick)) {
   1.237 +        return -1;
   1.238 +    }
   1.239 +
   1.240 +    ret = SDL_SYS_JoystickIsHaptic(joystick);
   1.241 +
   1.242 +    if (ret > 0)
   1.243 +        return SDL_TRUE;
   1.244 +    else if (ret == 0)
   1.245 +        return SDL_FALSE;
   1.246 +    else
   1.247 +        return -1;
   1.248 +}
   1.249 +
   1.250 +
   1.251 +/*
   1.252 + * Opens a haptic device from a joystick.
   1.253 + */
   1.254 +SDL_Haptic *
   1.255 +SDL_HapticOpenFromJoystick(SDL_Joystick * joystick)
   1.256 +{
   1.257 +    int i;
   1.258 +    SDL_Haptic *haptic;
   1.259 +
   1.260 +    /* Must be a valid joystick */
   1.261 +    if (!SDL_PrivateJoystickValid(&joystick)) {
   1.262 +        return NULL;
   1.263 +    }
   1.264 +
   1.265 +    /* Joystick must be haptic */
   1.266 +    if (SDL_SYS_JoystickIsHaptic(joystick) <= 0) {
   1.267 +        return NULL;
   1.268 +    }
   1.269 +
   1.270 +    /* Check to see if joystick's haptic is already open */
   1.271 +    for (i = 0; SDL_haptics[i]; i++) {
   1.272 +        if (SDL_SYS_JoystickSameHaptic(SDL_haptics[i], joystick)) {
   1.273 +            haptic = SDL_haptics[i];
   1.274 +            ++haptic->ref_count;
   1.275 +            return haptic;
   1.276 +        }
   1.277 +    }
   1.278 +
   1.279 +    /* Create the haptic device */
   1.280 +    haptic = (SDL_Haptic *) SDL_malloc((sizeof *haptic));
   1.281 +    if (haptic == NULL) {
   1.282 +        SDL_OutOfMemory();
   1.283 +        return NULL;
   1.284 +    }
   1.285 +
   1.286 +    /* Initialize the haptic device */
   1.287 +    SDL_memset(haptic, 0, sizeof(SDL_Haptic));
   1.288 +    if (SDL_SYS_HapticOpenFromJoystick(haptic, joystick) < 0) {
   1.289 +        SDL_free(haptic);
   1.290 +        return NULL;
   1.291 +    }
   1.292 +
   1.293 +    /* Add haptic to list */
   1.294 +    ++haptic->ref_count;
   1.295 +    for (i = 0; SDL_haptics[i]; i++)
   1.296 +        /* Skip to next haptic */ ;
   1.297 +    SDL_haptics[i] = haptic;
   1.298 +
   1.299 +    return haptic;
   1.300 +}
   1.301 +
   1.302 +
   1.303 +/*
   1.304 + * Closes a SDL_Haptic device.
   1.305 + */
   1.306 +void
   1.307 +SDL_HapticClose(SDL_Haptic * haptic)
   1.308 +{
   1.309 +    int i;
   1.310 +
   1.311 +    /* Must be valid */
   1.312 +    if (!ValidHaptic(haptic)) {
   1.313 +        return;
   1.314 +    }
   1.315 +
   1.316 +    /* Check if it's still in use */
   1.317 +    if (--haptic->ref_count < 0) {
   1.318 +        return;
   1.319 +    }
   1.320 +
   1.321 +    /* Close it, properly removing effects if needed */
   1.322 +    for (i = 0; i < haptic->neffects; i++) {
   1.323 +        if (haptic->effects[i].hweffect != NULL) {
   1.324 +            SDL_HapticDestroyEffect(haptic, i);
   1.325 +        }
   1.326 +    }
   1.327 +    SDL_SYS_HapticClose(haptic);
   1.328 +
   1.329 +    /* Remove from the list */
   1.330 +    for (i = 0; SDL_haptics[i]; ++i) {
   1.331 +        if (haptic == SDL_haptics[i]) {
   1.332 +            SDL_haptics[i] = NULL;
   1.333 +            SDL_memcpy(&SDL_haptics[i], &SDL_haptics[i + 1],
   1.334 +                       (SDL_numhaptics - i) * sizeof(haptic));
   1.335 +            break;
   1.336 +        }
   1.337 +    }
   1.338 +
   1.339 +    /* Free */
   1.340 +    SDL_free(haptic);
   1.341 +}
   1.342 +
   1.343 +/*
   1.344 + * Cleans up after the subsystem.
   1.345 + */
   1.346 +void
   1.347 +SDL_HapticQuit(void)
   1.348 +{
   1.349 +    SDL_SYS_HapticQuit();
   1.350 +    if (SDL_haptics != NULL) {
   1.351 +        SDL_free(SDL_haptics);
   1.352 +        SDL_haptics = NULL;
   1.353 +    }
   1.354 +    SDL_numhaptics = 0;
   1.355 +}
   1.356 +
   1.357 +/*
   1.358 + * Returns the number of effects a haptic device has.
   1.359 + */
   1.360 +int
   1.361 +SDL_HapticNumEffects(SDL_Haptic * haptic)
   1.362 +{
   1.363 +    if (!ValidHaptic(haptic)) {
   1.364 +        return -1;
   1.365 +    }
   1.366 +
   1.367 +    return haptic->neffects;
   1.368 +}
   1.369 +
   1.370 +
   1.371 +/*
   1.372 + * Returns the number of effects a haptic device can play.
   1.373 + */
   1.374 +int
   1.375 +SDL_HapticNumEffectsPlaying(SDL_Haptic * haptic)
   1.376 +{
   1.377 +    if (!ValidHaptic(haptic)) {
   1.378 +        return -1;
   1.379 +    }
   1.380 +
   1.381 +    return haptic->nplaying;
   1.382 +}
   1.383 +
   1.384 +
   1.385 +/*
   1.386 + * Returns supported effects by the device.
   1.387 + */
   1.388 +unsigned int
   1.389 +SDL_HapticQuery(SDL_Haptic * haptic)
   1.390 +{
   1.391 +    if (!ValidHaptic(haptic)) {
   1.392 +        return -1;
   1.393 +    }
   1.394 +
   1.395 +    return haptic->supported;
   1.396 +}
   1.397 +
   1.398 +
   1.399 +/*
   1.400 + * Returns the number of axis on the device.
   1.401 + */
   1.402 +int
   1.403 +SDL_HapticNumAxes(SDL_Haptic * haptic)
   1.404 +{
   1.405 +    if (!ValidHaptic(haptic)) {
   1.406 +        return -1;
   1.407 +    }
   1.408 +
   1.409 +    return haptic->naxes;
   1.410 +}
   1.411 +
   1.412 +/*
   1.413 + * Checks to see if the device can support the effect.
   1.414 + */
   1.415 +int
   1.416 +SDL_HapticEffectSupported(SDL_Haptic * haptic, SDL_HapticEffect * effect)
   1.417 +{
   1.418 +    if (!ValidHaptic(haptic)) {
   1.419 +        return -1;
   1.420 +    }
   1.421 +
   1.422 +    if ((haptic->supported & effect->type) != 0)
   1.423 +        return SDL_TRUE;
   1.424 +    return SDL_FALSE;
   1.425 +}
   1.426 +
   1.427 +/*
   1.428 + * Creates a new haptic effect.
   1.429 + */
   1.430 +int
   1.431 +SDL_HapticNewEffect(SDL_Haptic * haptic, SDL_HapticEffect * effect)
   1.432 +{
   1.433 +    int i;
   1.434 +
   1.435 +    /* Check for device validity. */
   1.436 +    if (!ValidHaptic(haptic)) {
   1.437 +        return -1;
   1.438 +    }
   1.439 +
   1.440 +    /* Check to see if effect is supported */
   1.441 +    if (SDL_HapticEffectSupported(haptic, effect) == SDL_FALSE) {
   1.442 +        SDL_SetError("Haptic: Effect not supported by haptic device.");
   1.443 +        return -1;
   1.444 +    }
   1.445 +
   1.446 +    /* See if there's a free slot */
   1.447 +    for (i = 0; i < haptic->neffects; i++) {
   1.448 +        if (haptic->effects[i].hweffect == NULL) {
   1.449 +
   1.450 +            /* Now let the backend create the real effect */
   1.451 +            if (SDL_SYS_HapticNewEffect(haptic, &haptic->effects[i], effect)
   1.452 +                != 0) {
   1.453 +                return -1;      /* Backend failed to create effect */
   1.454 +            }
   1.455 +
   1.456 +            SDL_memcpy(&haptic->effects[i].effect, effect,
   1.457 +                       sizeof(SDL_HapticEffect));
   1.458 +            return i;
   1.459 +        }
   1.460 +    }
   1.461 +
   1.462 +    SDL_SetError("Haptic: Device has no free space left.");
   1.463 +    return -1;
   1.464 +}
   1.465 +
   1.466 +/*
   1.467 + * Checks to see if an effect is valid.
   1.468 + */
   1.469 +static int
   1.470 +ValidEffect(SDL_Haptic * haptic, int effect)
   1.471 +{
   1.472 +    if ((effect < 0) || (effect >= haptic->neffects)) {
   1.473 +        SDL_SetError("Haptic: Invalid effect identifier.");
   1.474 +        return 0;
   1.475 +    }
   1.476 +    return 1;
   1.477 +}
   1.478 +
   1.479 +/*
   1.480 + * Updates an effect.
   1.481 + */
   1.482 +int
   1.483 +SDL_HapticUpdateEffect(SDL_Haptic * haptic, int effect,
   1.484 +                       SDL_HapticEffect * data)
   1.485 +{
   1.486 +    if (!ValidHaptic(haptic) || !ValidEffect(haptic, effect)) {
   1.487 +        return -1;
   1.488 +    }
   1.489 +
   1.490 +    /* Can't change type dynamically. */
   1.491 +    if (data->type != haptic->effects[effect].effect.type) {
   1.492 +        SDL_SetError("Haptic: Updating effect type is illegal.");
   1.493 +        return -1;
   1.494 +    }
   1.495 +
   1.496 +    /* Updates the effect */
   1.497 +    if (SDL_SYS_HapticUpdateEffect(haptic, &haptic->effects[effect], data) <
   1.498 +        0) {
   1.499 +        return -1;
   1.500 +    }
   1.501 +
   1.502 +    SDL_memcpy(&haptic->effects[effect].effect, data,
   1.503 +               sizeof(SDL_HapticEffect));
   1.504 +    return 0;
   1.505 +}
   1.506 +
   1.507 +
   1.508 +/*
   1.509 + * Runs the haptic effect on the device.
   1.510 + */
   1.511 +int
   1.512 +SDL_HapticRunEffect(SDL_Haptic * haptic, int effect, Uint32 iterations)
   1.513 +{
   1.514 +    if (!ValidHaptic(haptic) || !ValidEffect(haptic, effect)) {
   1.515 +        return -1;
   1.516 +    }
   1.517 +
   1.518 +    /* Run the effect */
   1.519 +    if (SDL_SYS_HapticRunEffect(haptic, &haptic->effects[effect], iterations)
   1.520 +        < 0) {
   1.521 +        return -1;
   1.522 +    }
   1.523 +
   1.524 +    return 0;
   1.525 +}
   1.526 +
   1.527 +/*
   1.528 + * Stops the haptic effect on the device.
   1.529 + */
   1.530 +int
   1.531 +SDL_HapticStopEffect(SDL_Haptic * haptic, int effect)
   1.532 +{
   1.533 +    if (!ValidHaptic(haptic) || !ValidEffect(haptic, effect)) {
   1.534 +        return -1;
   1.535 +    }
   1.536 +
   1.537 +    /* Stop the effect */
   1.538 +    if (SDL_SYS_HapticStopEffect(haptic, &haptic->effects[effect]) < 0) {
   1.539 +        return -1;
   1.540 +    }
   1.541 +
   1.542 +    return 0;
   1.543 +}
   1.544 +
   1.545 +/*
   1.546 + * Gets rid of a haptic effect.
   1.547 + */
   1.548 +void
   1.549 +SDL_HapticDestroyEffect(SDL_Haptic * haptic, int effect)
   1.550 +{
   1.551 +    if (!ValidHaptic(haptic) || !ValidEffect(haptic, effect)) {
   1.552 +        return;
   1.553 +    }
   1.554 +
   1.555 +    /* Not allocated */
   1.556 +    if (haptic->effects[effect].hweffect == NULL) {
   1.557 +        return;
   1.558 +    }
   1.559 +
   1.560 +    SDL_SYS_HapticDestroyEffect(haptic, &haptic->effects[effect]);
   1.561 +}
   1.562 +
   1.563 +/*
   1.564 + * Gets the status of a haptic effect.
   1.565 + */
   1.566 +int
   1.567 +SDL_HapticGetEffectStatus(SDL_Haptic * haptic, int effect)
   1.568 +{
   1.569 +    if (!ValidHaptic(haptic) || !ValidEffect(haptic, effect)) {
   1.570 +        return -1;
   1.571 +    }
   1.572 +
   1.573 +    if ((haptic->supported & SDL_HAPTIC_STATUS) == 0) {
   1.574 +        SDL_SetError("Haptic: Device does not support status queries.");
   1.575 +        return -1;
   1.576 +    }
   1.577 +
   1.578 +    return SDL_SYS_HapticGetEffectStatus(haptic, &haptic->effects[effect]);
   1.579 +}
   1.580 +
   1.581 +/*
   1.582 + * Sets the global gain of the device.
   1.583 + */
   1.584 +int
   1.585 +SDL_HapticSetGain(SDL_Haptic * haptic, int gain)
   1.586 +{
   1.587 +    const char *env;
   1.588 +    int real_gain, max_gain;
   1.589 +
   1.590 +    if (!ValidHaptic(haptic)) {
   1.591 +        return -1;
   1.592 +    }
   1.593 +
   1.594 +    if ((haptic->supported & SDL_HAPTIC_GAIN) == 0) {
   1.595 +        SDL_SetError("Haptic: Device does not support setting gain.");
   1.596 +        return -1;
   1.597 +    }
   1.598 +
   1.599 +    if ((gain < 0) || (gain > 100)) {
   1.600 +        SDL_SetError("Haptic: Gain must be between 0 and 100.");
   1.601 +        return -1;
   1.602 +    }
   1.603 +
   1.604 +    /* We use the envvar to get the maximum gain. */
   1.605 +    env = SDL_getenv("SDL_HAPTIC_GAIN_MAX");
   1.606 +    if (env != NULL) {
   1.607 +        max_gain = SDL_atoi(env);
   1.608 +
   1.609 +        /* Check for sanity. */
   1.610 +        if (max_gain < 0)
   1.611 +            max_gain = 0;
   1.612 +        else if (max_gain > 100)
   1.613 +            max_gain = 100;
   1.614 +
   1.615 +        /* We'll scale it linearly with SDL_HAPTIC_GAIN_MAX */
   1.616 +        real_gain = (gain * max_gain) / 100;
   1.617 +    } else {
   1.618 +        real_gain = gain;
   1.619 +    }
   1.620 +
   1.621 +    if (SDL_SYS_HapticSetGain(haptic, real_gain) < 0) {
   1.622 +        return -1;
   1.623 +    }
   1.624 +
   1.625 +    return 0;
   1.626 +}
   1.627 +
   1.628 +/*
   1.629 + * Makes the device autocenter, 0 disables.
   1.630 + */
   1.631 +int
   1.632 +SDL_HapticSetAutocenter(SDL_Haptic * haptic, int autocenter)
   1.633 +{
   1.634 +    if (!ValidHaptic(haptic)) {
   1.635 +        return -1;
   1.636 +    }
   1.637 +
   1.638 +    if ((haptic->supported & SDL_HAPTIC_AUTOCENTER) == 0) {
   1.639 +        SDL_SetError("Haptic: Device does not support setting autocenter.");
   1.640 +        return -1;
   1.641 +    }
   1.642 +
   1.643 +    if ((autocenter < 0) || (autocenter > 100)) {
   1.644 +        SDL_SetError("Haptic: Autocenter must be between 0 and 100.");
   1.645 +        return -1;
   1.646 +    }
   1.647 +
   1.648 +    if (SDL_SYS_HapticSetAutocenter(haptic, autocenter) < 0) {
   1.649 +        return -1;
   1.650 +    }
   1.651 +
   1.652 +    return 0;
   1.653 +}
   1.654 +
   1.655 +/*
   1.656 + * Pauses the haptic device.
   1.657 + */
   1.658 +int
   1.659 +SDL_HapticPause(SDL_Haptic * haptic)
   1.660 +{
   1.661 +    if (!ValidHaptic(haptic)) {
   1.662 +        return -1;
   1.663 +    }
   1.664 +
   1.665 +    if ((haptic->supported & SDL_HAPTIC_PAUSE) == 0) {
   1.666 +        SDL_SetError("Haptic: Device does not support setting pausing.");
   1.667 +        return -1;
   1.668 +    }
   1.669 +
   1.670 +    return SDL_SYS_HapticPause(haptic);
   1.671 +}
   1.672 +
   1.673 +/*
   1.674 + * Unpauses the haptic device.
   1.675 + */
   1.676 +int
   1.677 +SDL_HapticUnpause(SDL_Haptic * haptic)
   1.678 +{
   1.679 +    if (!ValidHaptic(haptic)) {
   1.680 +        return -1;
   1.681 +    }
   1.682 +
   1.683 +    if ((haptic->supported & SDL_HAPTIC_PAUSE) == 0) {
   1.684 +        return 0;               /* Not going to be paused, so we pretend it's unpaused. */
   1.685 +    }
   1.686 +
   1.687 +    return SDL_SYS_HapticUnpause(haptic);
   1.688 +}
   1.689 +
   1.690 +/*
   1.691 + * Stops all the currently playing effects.
   1.692 + */
   1.693 +int
   1.694 +SDL_HapticStopAll(SDL_Haptic * haptic)
   1.695 +{
   1.696 +    if (!ValidHaptic(haptic)) {
   1.697 +        return -1;
   1.698 +    }
   1.699 +
   1.700 +    return SDL_SYS_HapticStopAll(haptic);
   1.701 +}