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

Added SDL_HapticUpdateEffect().

  • Loading branch information
bobbens committed Jul 1, 2008
1 parent 4fdd153 commit b50f26e08618e22bd10f7ce4ab006f1e9be1329e
Showing with 68 additions and 2 deletions.
  1. +10 −0 include/SDL_haptic.h
  2. +19 −0 src/haptic/SDL_haptic.c
  3. +2 −0 src/haptic/SDL_syshaptic.h
  4. +37 −2 src/haptic/linux/SDL_syshaptic.c
@@ -240,6 +240,16 @@ extern DECLSPEC int SDL_HapticEffectSupported(SDL_Haptic * haptic, SDL_HapticEff
*/
extern DECLSPEC int SDL_HapticNewEffect(SDL_Haptic * haptic, SDL_HapticEffect * effect);

/*
* Uploads an effect. Can be used dynamically, although behaviour when
* dynamically changing direction may be strange. Specifically the effect
* may reupload itself and start playing from the start. You cannot change
* the type either when running UpdateEffect.
*
* Returns the id of the effect on success, -1 on failure.
*/
extern DECLSPEC int SDL_HapticUpdateEffect(SDL_Haptic * haptic, int effect, SDL_HapticEffect * data);

/*
* Runs the haptic effect on it's assosciated haptic device.
*
@@ -291,6 +291,25 @@ ValidEffect(SDL_Haptic * haptic, int effect)
return 1;
}

/*
* Updates an effect.
*/
int
SDL_HapticUpdateEffect(SDL_Haptic * haptic, int effect, SDL_HapticEffect * data)
{
if (!ValidHaptic(&haptic) || !ValidEffect(haptic,effect)) {
return -1;
}

/* Updates the effect */
if (SDL_SYS_HapticUpdateEffect(haptic,&haptic->effects[effect],data) < 0) {
return -1;
}

return 0;
}


/*
* Runs the haptic effect on the device.
*/
@@ -54,6 +54,8 @@ extern void SDL_SYS_HapticClose(SDL_Haptic * haptic);
extern void SDL_SYS_HapticQuit(void);
extern int SDL_SYS_HapticNewEffect(SDL_Haptic * haptic,
struct haptic_effect * effect, SDL_HapticEffect * base);
extern int SDL_SYS_HapticUpdateEffect(SDL_Haptic * haptic,
struct haptic_effect * effect, SDL_HapticEffect * data);
extern int SDL_SYS_HapticRunEffect(SDL_Haptic * haptic,
struct haptic_effect * effect);
extern int SDL_SYS_HapticStopEffect(SDL_Haptic * haptic,
@@ -456,17 +456,52 @@ SDL_SYS_HapticNewEffect(SDL_Haptic * haptic, struct haptic_effect * effect,
/* Prepare the ff_effect */
linux_effect = &effect->hweffect->effect;
if (SDL_SYS_ToFFEffect( linux_effect, base ) != 0) {
return -1;
goto new_effect_err;
}
linux_effect->id = -1; /* Have the kernel give it an id */

/* Upload the effect */
if (ioctl(haptic->hwdata->fd, EVIOCSFF, linux_effect) < 0) {
SDL_SetError("Error uploading effect to the haptic device.");
return -1;
goto new_effect_err;
}

return 0;

new_effect_err:
free(effect->hweffect);
effect->hweffect = NULL;
return -1;
}


/*
* Updates an effect.
*
* Note: Dynamically updating the direction can in some cases force
* the effect to restart and run once.
*/
int SDL_SYS_HapticUpdateEffect(SDL_Haptic * haptic,
struct haptic_effect * effect, SDL_HapticEffect * data)
{
struct ff_effect linux_effect;

/* Create the new effect */
if (SDL_SYS_ToFFEffect( &linux_effect, data ) != 0) {
return -1;
}
linux_effect.id = effect->hweffect->effect.id;

/* See if it can be uploaded. */
if (ioctl(haptic->hwdata->fd, EVIOCSFF, &linux_effect) < 0) {
SDL_SetError("Error updating the haptic effect.");
return -1;
}

/* Copy the new effect into memory. */
SDL_memcpy( &effect->hweffect->effect, &linux_effect, sizeof(struct ff_effect) );

return effect->hweffect->effect.id;
}


0 comments on commit b50f26e

Please sign in to comment.