Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Added query functions for haptic devices.
- Loading branch information
Showing
with
52 additions
and
1 deletion.
-
+13
−0
include/SDL_haptic.h
-
+37
−0
src/haptic/SDL_haptic.c
-
+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) { |
|
|