Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Broke API by introducing iterations to SDL_HapticRunEffects().
Browse files Browse the repository at this point in the history
Fixed minor issues.
  • Loading branch information
bobbens committed Jul 10, 2008
1 parent 5b8704d commit 77cf877
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 11 deletions.
23 changes: 19 additions & 4 deletions include/SDL_haptic.h
Expand Up @@ -70,7 +70,7 @@
* effect_id = SDL_HapticNewEffect( haptic, &effect );
*
* // Test the effect
* SDL_HapticRunEffect( haptic, effect_id );
* SDL_HapticRunEffect( haptic, effect_id, 1 );
* SDL_Delay( 5000); // Wait for the effect to finish
*
* // We destroy the effect, although closing the device also does this
Expand Down Expand Up @@ -263,6 +263,19 @@ typedef struct _SDL_Haptic SDL_Haptic;
#define SDL_HAPTIC_CARTESIAN 1


/*
* Misc defines.
*/
/**
* \def SDL_HAPTIC_INFINITY
*
* \brief Used to play a device an infinite number of times.
*
* \sa SDL_HapticRunEffect
*/
#define SDL_HAPTIC_INFINITY -1


/**
* \struct SDL_HapticDirection
*
Expand Down Expand Up @@ -681,7 +694,7 @@ extern DECLSPEC int SDL_HapticIndex(SDL_Haptic * haptic);
*
* \sa SDL_HapticOpenFromMouse
*/
extern DECLSPEC SDL_MouseIsHaptic(void);
extern DECLSPEC int SDL_MouseIsHaptic(void);

/**
* \fn SDL_Haptic * SDL_HapticOpenFromMouse(void)
Expand Down Expand Up @@ -830,19 +843,21 @@ extern DECLSPEC int SDL_HapticNewEffect(SDL_Haptic * haptic, SDL_HapticEffect *
extern DECLSPEC int SDL_HapticUpdateEffect(SDL_Haptic * haptic, int effect, SDL_HapticEffect * data);

/**
* \fn int SDL_HapticRunEffect(SDL_Haptic * haptic, int effect)
* \fn int SDL_HapticRunEffect(SDL_Haptic * haptic, int effect, int iterations)
*
* \brief Runs the haptic effect on it's assosciated haptic device.
*
* \param haptic Haptic device to run the effect on.
* \param effect Identifier of the haptic effect to run.
* \param iterations Number of iterations to run the effect. Use
* SDL_HAPTIC_INFINITY for infinity.
* \return 0 on success or -1 on error.
*
* \sa SDL_HapticStopEffect
* \sa SDL_HapticDestroyEffect
* \sa SDL_HapticGetEffectStatus
*/
extern DECLSPEC int SDL_HapticRunEffect(SDL_Haptic * haptic, int effect);
extern DECLSPEC int SDL_HapticRunEffect(SDL_Haptic * haptic, int effect, int iterations);

/**
* \fn int SDL_HapticStopEffect(SDL_Haptic * haptic, int effect)
Expand Down
4 changes: 2 additions & 2 deletions src/haptic/SDL_haptic.c
Expand Up @@ -470,14 +470,14 @@ SDL_HapticUpdateEffect(SDL_Haptic * haptic, int effect, SDL_HapticEffect * data)
* Runs the haptic effect on the device.
*/
int
SDL_HapticRunEffect(SDL_Haptic * haptic, int effect)
SDL_HapticRunEffect(SDL_Haptic * haptic, int effect, int iterations)
{
if (!ValidHaptic(&haptic) || !ValidEffect(haptic,effect)) {
return -1;
}

/* Run the effect */
if (SDL_SYS_HapticRunEffect(haptic,&haptic->effects[effect]) < 0) {
if (SDL_SYS_HapticRunEffect(haptic,&haptic->effects[effect], iterations) < 0) {
return -1;
}

Expand Down
5 changes: 3 additions & 2 deletions src/haptic/SDL_syshaptic.h
Expand Up @@ -38,7 +38,7 @@ struct haptic_effect
};

/*
* The real SDL_Haptic event.
* The real SDL_Haptic struct.
*/
struct _SDL_Haptic
{
Expand Down Expand Up @@ -139,7 +139,8 @@ extern int SDL_SYS_HapticUpdateEffect(SDL_Haptic * haptic,
* Returns 0 on success, -1 on error.
*/
extern int SDL_SYS_HapticRunEffect(SDL_Haptic * haptic,
struct haptic_effect * effect);
struct haptic_effect * effect,
int iterations);

/*
* Stops the effect on the haptic device.
Expand Down
2 changes: 1 addition & 1 deletion src/haptic/dummy/SDL_syshaptic.c
Expand Up @@ -114,7 +114,7 @@ SDL_SYS_HapticUpdateEffect(SDL_Haptic * haptic,


int
SDL_SYS_HapticRunEffect(SDL_Haptic * haptic, struct haptic_effect * effect)
SDL_SYS_HapticRunEffect(SDL_Haptic * haptic, struct haptic_effect * effect, int iterations)
{
SDL_SetError("Logic error: No haptic devices available.");
return -1;
Expand Down
8 changes: 6 additions & 2 deletions src/haptic/linux/SDL_syshaptic.c
Expand Up @@ -36,6 +36,7 @@
#include <sys/stat.h>
#include <fcntl.h>
#include <linux/limits.h>
#include <limits.h> /* INT_MAX */
#include <string.h>
#include <errno.h>
#include <math.h>
Expand Down Expand Up @@ -672,14 +673,17 @@ int SDL_SYS_HapticUpdateEffect(SDL_Haptic * haptic,
* Runs an effect.
*/
int
SDL_SYS_HapticRunEffect(SDL_Haptic * haptic, struct haptic_effect * effect)
SDL_SYS_HapticRunEffect(SDL_Haptic * haptic, struct haptic_effect * effect, int iterations)
{
struct input_event run;

/* Prepare to run the effect */
run.type = EV_FF;
run.code = effect->hweffect->effect.id;
run.value = 1;
if (iterations == SDL_HAPTIC_INFINITY)
run.value = INT_MAX;
else
run.value = iterations;

if (write(haptic->hwdata->fd, (const void*) &run, sizeof(run)) < 0) {
SDL_SetError("Haptic: Unable to run the effect: %s", strerror(errno));
Expand Down

0 comments on commit 77cf877

Please sign in to comment.