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

Commit

Permalink
Added SDL_HapticGetEffectStatus().
Browse files Browse the repository at this point in the history
More comments.
  • Loading branch information
bobbens committed Jul 3, 2008
1 parent 37febab commit 1ee2ff1
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 17 deletions.
45 changes: 28 additions & 17 deletions include/SDL_haptic.h
Expand Up @@ -46,22 +46,25 @@ struct _SDL_Haptic;
typedef struct _SDL_Haptic SDL_Haptic;


/* Different effects that can be generated */
#define SDL_HAPTIC_CONSTANT (1<<0)
#define SDL_HAPTIC_SINE (1<<1)
#define SDL_HAPTIC_SQUARE (1<<2)
#define SDL_HAPTIC_TRIANGLE (1<<3)
#define SDL_HAPTIC_SAWTOOTHUP (1<<4)
#define SDL_HAPTIC_SAWTOOTHDOWN (1<<5)
#define SDL_HAPTIC_RAMP (1<<6)
#define SDL_HAPTIC_SPRING (1<<7)
#define SDL_HAPTIC_FRICTION (1<<8)
#define SDL_HAPTIC_DAMPER (1<<9)
#define SDL_HAPTIC_INERTIA (1<<10)
#define SDL_HAPTIC_CUSTOM (1<<11)
/*
* Different haptic features a device can have.
*/
#define SDL_HAPTIC_CONSTANT (1<<0) /* Constant effect supported */
#define SDL_HAPTIC_SINE (1<<1) /* Sine wave effect supported */
#define SDL_HAPTIC_SQUARE (1<<2) /* Square wave effect supported */
#define SDL_HAPTIC_TRIANGLE (1<<3) /* Triangle wave effect supported */
#define SDL_HAPTIC_SAWTOOTHUP (1<<4) /* Sawtoothup wave effect supported */
#define SDL_HAPTIC_SAWTOOTHDOWN (1<<5) /* Sawtoothdown wave effect supported */
#define SDL_HAPTIC_RAMP (1<<6) /* Ramp effect supported */
#define SDL_HAPTIC_SPRING (1<<7) /* Spring effect supported - uses axes position */
#define SDL_HAPTIC_DAMPER (1<<8) /* Damper effect supported - uses axes velocity */
#define SDL_HAPTIC_INERTIA (1<<9) /* Inertia effect supported - uses axes acceleration */
#define SDL_HAPTIC_FRICTION (1<<10) /* Friction effect supported - uses axes movement */
#define SDL_HAPTIC_CUSTOM (1<<11) /* Custom effect is supported */
/* These last two are features the device has, not effects */
#define SDL_HAPTIC_GAIN (1<<12)
#define SDL_HAPTIC_AUTOCENTER (1<<13)
#define SDL_HAPTIC_GAIN (1<<12) /* Device can set global gain */
#define SDL_HAPTIC_AUTOCENTER (1<<13) /* Device can set autocenter */
#define SDL_HAPTIC_STATUS (1<<14) /* Device can be queried for effect status */


/*
Expand Down Expand Up @@ -166,8 +169,8 @@ typedef struct SDL_HapticRamp {
Uint16 interval;

/* Ramp */
Sint16 start;
Sint16 end;
Sint16 start; /* Beginning strength level. */
Sint16 end; /* Ending strength level. */

/* Envelope */
Uint16 attack_length;
Expand Down Expand Up @@ -287,6 +290,14 @@ extern DECLSPEC int SDL_HapticStopEffect(SDL_Haptic * haptic, int effect);
*/
extern DECLSPEC void SDL_HapticDestroyEffect(SDL_Haptic * haptic, int effect);

/*
* Gets the status of the current effect on the haptic device.
*
* Returns 0 if it isn't playing, SDL_HAPTIC_PLAYING if it is playing
* or -1 on failure.
*/
extern DECLSPEC int SDL_HapticGetEffectStatus(SDL_Haptic *haptic, int effect);

/*
* Sets the global gain of the device. Gain should be between 0 and 100.
*
Expand Down
18 changes: 18 additions & 0 deletions src/haptic/SDL_haptic.c
Expand Up @@ -437,6 +437,24 @@ SDL_HapticDestroyEffect(SDL_Haptic * haptic, int effect)
SDL_SYS_HapticDestroyEffect(haptic, &haptic->effects[effect]);
}

/*
* Gets the status of a haptic effect.
*/
int
SDL_HapticGetEffectStatus(SDL_Haptic *haptic, int effect)
{
if (!ValidHaptic(&haptic) || !ValidEffect(haptic,effect)) {
return -1;
}

if ((haptic->supported & SDL_HAPTIC_STATUS) == 0) {
SDL_SetError("Haptic device does not support status queries.");
return -1;
}

return SDL_SYS_HapticGetEffectStatus(haptic, &haptic->effects[effect]);
}

/*
* Sets the global gain of the device.
*/
Expand Down
9 changes: 9 additions & 0 deletions src/haptic/SDL_syshaptic.h
Expand Up @@ -144,6 +144,15 @@ extern int SDL_SYS_HapticStopEffect(SDL_Haptic * haptic,
extern void SDL_SYS_HapticDestroyEffect(SDL_Haptic * haptic,
struct haptic_effect * effect);

/*
* Queries the device for the status of effect.
*
* Returns 0 if device is stopped, >0 if device is playing and
* -1 on error.
*/
extern int SDL_SYS_HapticGetEffectStatus(SDL_Haptic * haptic,
struct haptic_effect * effect);

/*
* Sets the global gain of the haptic device.
*
Expand Down
7 changes: 7 additions & 0 deletions src/haptic/dummy/SDL_syshaptic.c
Expand Up @@ -132,6 +132,13 @@ SDL_SYS_HapticDestroyEffect(SDL_Haptic * haptic, struct haptic_effect * effect)
}


int SDL_SYS_HapticGetEffectStatus(SDL_Haptic * haptic, struct haptic_effect * effect)
{
SDL_SetError("Logic error: No Haptic devices available.");
return -1;
}


int
SDL_SYS_HapticSetGain(SDL_Haptic * haptic, int gain)
{
Expand Down
25 changes: 25 additions & 0 deletions src/haptic/linux/SDL_syshaptic.c
Expand Up @@ -611,6 +611,31 @@ SDL_SYS_HapticDestroyEffect(SDL_Haptic * haptic, struct haptic_effect * effect)
}


/*
* Gets the status of a haptic effect.
*/
int
SDL_SYS_HapticGetEffectStatus(SDL_Haptic * haptic, struct haptic_effect * effect)
{
#if 0 /* Not supported atm. */
struct input_event ie;

ie.type = EV_FF;
ie.type = EV_FF_STATUS;
ie.code = effect->hweffect->effect.id;

if (write(haptic->hwdata->fd, &ie, sizeof(ie)) < 0) {
SDL_SetError("Error getting haptic device status.");
return -1;
}

return 0;
#endif

return -1;
}


/*
* Sets the gain.
*/
Expand Down

0 comments on commit 1ee2ff1

Please sign in to comment.