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

Commit

Permalink
Added query functions for haptic devices.
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbens committed Jun 30, 2008
1 parent 37aedc1 commit 62590a8
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
13 changes: 13 additions & 0 deletions include/SDL_haptic.h
Expand Up @@ -99,6 +99,19 @@ extern DECLSPEC SDL_Haptic * SDL_HapticOpen(int device_index);
*/
extern DECLSPEC void SDL_HapticClose(SDL_Haptic * haptic);

/*
* Returns the number of effects a haptic device can store.
*/
extern DECLSPEC int SDL_HapticNumEffects(SDL_Haptic * haptic);

/*
* Returns the supported effects. Individual effects can be queried by
* bitwise operators.
*
* Example: (SDL_HapticQueryEffects(haptic) & SDL_HAPTIC_CONSTANT)
*/
extern DECLSPEC unsigned int SDL_HapticQueryEffects(SDL_Haptic * haptic);

/*
* Creates a new haptic effect on the device.
*/
Expand Down
37 changes: 37 additions & 0 deletions src/haptic/SDL_haptic.c
Expand Up @@ -197,6 +197,43 @@ SDL_HapticQuit(void)
}
}

/*
* Returns the number of effects a haptic device has.
*/
int
SDL_HapticNumEffects(SDL_Haptic * haptic)
{
if (!ValidHaptic(&haptic)) {
return -1;
}

return haptic->neffects;
}

/*
* Returns supported effects by the device.
*/
unsigned int
SDL_HapticQueryEffects(SDL_Haptic * haptic)
{
if (!ValidHaptic(&haptic)) {
return -1;
}

return haptic->supported;
}

int
SDL_HapticEffectSupported(SDL_Haptic * haptic, SDL_HapticEffect * effect)
{
if (!ValidHaptic(&haptic)) {
return -1;
}

if ((haptic->supported & effect->type) != 0)
return SDL_TRUE;
return SDL_FALSE;
}

/*
* Creates a new haptic effect.
Expand Down
3 changes: 2 additions & 1 deletion src/haptic/linux/SDL_syshaptic.c
Expand Up @@ -207,8 +207,9 @@ SDL_SYS_HapticOpen(SDL_Haptic * haptic)
goto open_err;
}
SDL_memset(haptic->hwdata, 0, sizeof(*haptic->hwdata));
/* Set the hwdata */
/* Set the data */
haptic->hwdata->fd = fd;
haptic->supported = EV_IsHaptic(fd);

/* Set the effects */
if (ioctl(fd, EVIOCGEFFECTS, &haptic->neffects) < 0) {
Expand Down

0 comments on commit 62590a8

Please sign in to comment.