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

Added query functions for haptic devices.

  • Loading branch information
bobbens committed Jun 30, 2008
1 parent 37aedc1 commit 62590a89a5474abf7ea6d87fbb50823f308a96a0
Showing with 52 additions and 1 deletion.
  1. +13 −0 include/SDL_haptic.h
  2. +37 −0 src/haptic/SDL_haptic.c
  3. +2 −1 src/haptic/linux/SDL_syshaptic.c
@@ -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.
*/
@@ -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.
@@ -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) {

0 comments on commit 62590a8

Please sign in to comment.