# HG changeset patch # User Edgar Simo # Date 1214922069 0 # Node ID 666472fd4cb098f73a6a3df5b867e9a89764c435 # Parent 9d52368ebcf5d024fd7cb08b6151b996c75e9fff HapticSetGain checks to see if device supports it. Added HapticSetAutocenter(). diff -r 9d52368ebcf5 -r 666472fd4cb0 include/SDL_haptic.h --- a/include/SDL_haptic.h Tue Jul 01 14:09:53 2008 +0000 +++ b/include/SDL_haptic.h Tue Jul 01 14:21:09 2008 +0000 @@ -256,6 +256,14 @@ */ extern DECLSPEC int SDL_HapticSetGain(SDL_Haptic * haptic, int gain); +/* + * Sets the global autocenter of the device. Autocenter should be between + * 0 and 100. Setting it to 0 will disable autocentering. + * + * Returns 0 on success or -1 on failure. + */ +extern DECLSPEC int SDL_HapticSetAutocenter(SDL_Haptic * haptic, int autocenter); + /* Ends C function definitions when using C++ */ #ifdef __cplusplus diff -r 9d52368ebcf5 -r 666472fd4cb0 src/haptic/SDL_haptic.c --- a/src/haptic/SDL_haptic.c Tue Jul 01 14:09:53 2008 +0000 +++ b/src/haptic/SDL_haptic.c Tue Jul 01 14:21:09 2008 +0000 @@ -334,6 +334,11 @@ return -1; } + if ((haptic->supported & SDL_HAPTIC_GAIN) == 0) { + SDL_SetError("Haptic device does not support setting gain."); + return -1; + } + if ((gain < 0) || (gain > 100)) { SDL_SetError("Haptic gain must be between 0 and 100."); return -1; @@ -346,4 +351,31 @@ return 0; } +/* + * Makes the device autocenter, 0 disables. + */ +int +SDL_HapticSetAutocenter(SDL_Haptic * haptic, int autocenter ) +{ + if (!ValidHaptic(&haptic)) { + return -1; + } + if ((haptic->supported & SDL_HAPTIC_AUTOCENTER) == 0) { + SDL_SetError("Haptic device does not support setting autocenter."); + return -1; + } + + if ((autocenter < 0) || (autocenter > 100)) { + SDL_SetError("Haptic autocenter must be between 0 and 100."); + return -1; + } + + if (SDL_SYS_HapticSetAutocenter(haptic,autocenter) < 0) { + return -1; + } + + return 0; +} + + diff -r 9d52368ebcf5 -r 666472fd4cb0 src/haptic/SDL_syshaptic.h --- a/src/haptic/SDL_syshaptic.h Tue Jul 01 14:09:53 2008 +0000 +++ b/src/haptic/SDL_syshaptic.h Tue Jul 01 14:21:09 2008 +0000 @@ -59,5 +59,6 @@ extern void SDL_SYS_HapticDestroyEffect(SDL_Haptic * haptic, struct haptic_effect * effect); extern int SDL_SYS_HapticSetGain(SDL_Haptic * haptic, int gain); +extern int SDL_SYS_HapticSetAutocenter(SDL_Haptic * haptic, int autocenter); diff -r 9d52368ebcf5 -r 666472fd4cb0 src/haptic/linux/SDL_syshaptic.c --- a/src/haptic/linux/SDL_syshaptic.c Tue Jul 01 14:09:53 2008 +0000 +++ b/src/haptic/linux/SDL_syshaptic.c Tue Jul 01 14:21:09 2008 +0000 @@ -519,13 +519,36 @@ ie.type = EV_FF; ie.code = FF_GAIN; ie.value = (0xFFFFUL * gain) / 100; - printf("%d\n",ie.value); - if (write(haptic->hwdata->fd, &ie, sizeof(ie)) == -1) { + if (write(haptic->hwdata->fd, &ie, sizeof(ie)) < 0) { SDL_SetError("Error setting gain."); + return -1; } + return 0; } +/* + * Sets the autocentering. + */ +int +SDL_SYS_HapticSetAutocenter(SDL_Haptic * haptic, int autocenter) +{ + struct input_event ie; + + ie.type = EV_FF; + ie.code = FF_AUTOCENTER; + ie.value = (0xFFFFUL * autocenter) / 100; + + if (write(haptic->hwdata->fd, &ie, sizeof(ie)) < 0) { + SDL_SetError("Error setting autocenter."); + return -1; + } + + return 0; +} + + + #endif /* SDL_HAPTIC_LINUX */