Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

HapticSetGain checks to see if device supports it.

Added HapticSetAutocenter().
  • Loading branch information
bobbens committed Jul 1, 2008
1 parent 7e6f106 commit ce595d24b4200bbea51a74b751103a7b6a415bf8
Showing with 66 additions and 2 deletions.
  1. +8 −0 include/SDL_haptic.h
  2. +32 −0 src/haptic/SDL_haptic.c
  3. +1 −0 src/haptic/SDL_syshaptic.h
  4. +25 −2 src/haptic/linux/SDL_syshaptic.c
@@ -256,6 +256,14 @@ extern DECLSPEC void SDL_HapticDestroyEffect(SDL_Haptic * haptic, int effect);
*/
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
@@ -334,6 +334,11 @@ SDL_HapticSetGain(SDL_Haptic * haptic, int gain )
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 @@ SDL_HapticSetGain(SDL_Haptic * haptic, int gain )
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;
}


@@ -59,5 +59,6 @@ extern int SDL_SYS_HapticRunEffect(SDL_Haptic * haptic,
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);


@@ -519,13 +519,36 @@ SDL_SYS_HapticSetGain(SDL_Haptic * haptic, int gain)
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 */

0 comments on commit ce595d2

Please sign in to comment.