21 #include "../SDL_internal.h"
25 #include "../joystick/SDL_joystick_c.h"
28 #if (defined(SDL_HAPTIC_DINPUT) && SDL_HAPTIC_DINPUT) || (defined(SDL_HAPTIC_XINPUT) && SDL_HAPTIC_XINPUT)
58 SDL_Haptic *hapticlist;
65 if (hapticlist ==
haptic) {
69 hapticlist = hapticlist->next;
75 SDL_SetError(
"Haptic: Invalid haptic device identifier");
99 SDL_SetError(
"Haptic: There are %d haptic devices available",
114 SDL_Haptic *hapticlist;
117 SDL_SetError(
"Haptic: There are %d haptic devices available",
128 if (device_index == hapticlist->index) {
133 hapticlist = hapticlist->next;
146 haptic->index = device_index;
175 SDL_Haptic *hapticlist;
179 SDL_SetError(
"Haptic: There are %d haptic devices available",
189 if (hapticlist->index == (
Uint8) device_index) {
193 hapticlist = hapticlist->next;
235 if (device_index < 0) {
275 SDL_Haptic *hapticlist;
279 SDL_SetError(
"Haptic: There are %d haptic devices available",
292 SDL_SetError(
"Haptic: Joystick isn't a haptic device.");
305 hapticlist = hapticlist->next;
319 SDL_SetError(
"Haptic: SDL_SYS_HapticOpenFromJoystick failed.");
341 SDL_Haptic *hapticlist;
342 SDL_Haptic *hapticlistprev;
350 if (--
haptic->ref_count > 0) {
364 hapticlistprev =
NULL;
369 if ( hapticlistprev )
372 hapticlistprev->next = hapticlist->next;
381 hapticlistprev = hapticlist;
382 hapticlist = hapticlist->next;
487 return SDL_SetError(
"Haptic: Effect not supported by haptic device.");
506 return SDL_SetError(
"Haptic: Device has no free space left.");
515 if ((effect < 0) || (effect >=
haptic->neffects)) {
534 if (
data->type !=
haptic->effects[effect].effect.type) {
535 return SDL_SetError(
"Haptic: Updating effect type is illegal.");
598 if (
haptic->effects[effect].hweffect ==
NULL) {
616 return SDL_SetError(
"Haptic: Device does not support status queries.");
629 int real_gain, max_gain;
636 return SDL_SetError(
"Haptic: Device does not support setting gain.");
639 if ((gain < 0) || (gain > 100)) {
640 return SDL_SetError(
"Haptic: Gain must be between 0 and 100.");
651 else if (max_gain > 100)
655 real_gain = (gain * max_gain) / 100;
678 return SDL_SetError(
"Haptic: Device does not support setting autocenter.");
681 if ((autocenter < 0) || (autocenter > 100)) {
682 return SDL_SetError(
"Haptic: Autocenter must be between 0 and 100.");
703 return SDL_SetError(
"Haptic: Device does not support setting pausing.");
766 if (
haptic->rumble_id >= 0) {
789 if (
haptic->rumble_id >= 0) {
808 if (
haptic->rumble_id < 0) {
809 return SDL_SetError(
"Haptic: Rumble effect not initialized on haptic device");
813 if (strength > 1.0f) {
815 }
else if (strength < 0.0f) {
818 magnitude = (
Sint16)(32767.0f*strength);
820 efx = &
haptic->rumble_effect;
828 SDL_assert(0 &&
"This should have been caught elsewhere");
848 if (
haptic->rumble_id < 0) {
849 return SDL_SetError(
"Haptic: Rumble effect not initialized on haptic device");
#define SDL_assert(condition)
#define SDL_OutOfMemory()
int SDL_HapticRumblePlay(SDL_Haptic *haptic, float strength, Uint32 length)
Runs simple rumble on a haptic device.
int SDL_HapticStopAll(SDL_Haptic *haptic)
Stops all the currently playing effects on a haptic device.
const char * SDL_HapticName(int device_index)
Get the implementation dependent name of a haptic device.
int SDL_HapticStopEffect(SDL_Haptic *haptic, int effect)
Stops the haptic effect on its associated haptic device.
int SDL_HapticSetAutocenter(SDL_Haptic *haptic, int autocenter)
Sets the global autocenter of the device.
int SDL_JoystickIsHaptic(SDL_Joystick *joystick)
Checks to see if a joystick has haptic features.
unsigned int SDL_HapticQuery(SDL_Haptic *haptic)
Gets the haptic device's supported features in bitwise manner.
int SDL_HapticPause(SDL_Haptic *haptic)
Pauses a haptic device.
int SDL_HapticNewEffect(SDL_Haptic *haptic, SDL_HapticEffect *effect)
Creates a new haptic effect on the device.
int SDL_HapticOpened(int device_index)
Checks if the haptic device at index has been opened.
int SDL_NumHaptics(void)
Count the number of haptic devices attached to the system.
int SDL_HapticRumbleInit(SDL_Haptic *haptic)
Initializes the haptic device for simple rumble playback.
int SDL_HapticSetGain(SDL_Haptic *haptic, int gain)
Sets the global gain of the device.
int SDL_HapticUnpause(SDL_Haptic *haptic)
Unpauses a haptic device.
void SDL_HapticClose(SDL_Haptic *haptic)
Closes a haptic device previously opened with SDL_HapticOpen().
static int ValidEffect(SDL_Haptic *haptic, int effect)
int SDL_HapticNumEffectsPlaying(SDL_Haptic *haptic)
Returns the number of effects a haptic device can play at the same time.
void SDL_HapticDestroyEffect(SDL_Haptic *haptic, int effect)
Destroys a haptic effect on the device.
int SDL_HapticRumbleSupported(SDL_Haptic *haptic)
Checks to see if rumble is supported on a haptic device.
int SDL_HapticIndex(SDL_Haptic *haptic)
Gets the index of a haptic device.
int SDL_HapticRunEffect(SDL_Haptic *haptic, int effect, Uint32 iterations)
Runs the haptic effect on its associated haptic device.
SDL_Haptic * SDL_HapticOpen(int device_index)
Opens a haptic device for use.
int SDL_HapticNumEffects(SDL_Haptic *haptic)
Returns the number of effects a haptic device can store.
int SDL_HapticNumAxes(SDL_Haptic *haptic)
Gets the number of haptic axes the device has.
static int ValidHaptic(SDL_Haptic *haptic)
int SDL_MouseIsHaptic(void)
Gets whether or not the current mouse has haptic capabilities.
int SDL_HapticGetEffectStatus(SDL_Haptic *haptic, int effect)
Gets the status of the current effect on the haptic device.
void SDL_HapticQuit(void)
int SDL_HapticEffectSupported(SDL_Haptic *haptic, SDL_HapticEffect *effect)
Checks to see if effect is supported by haptic.
int SDL_HapticRumbleStop(SDL_Haptic *haptic)
Stops the simple rumble on a haptic device.
int SDL_HapticUpdateEffect(SDL_Haptic *haptic, int effect, SDL_HapticEffect *data)
Updates the properties of an effect.
SDL_Haptic * SDL_HapticOpenFromMouse(void)
Tries to open a haptic device from the current mouse.
SDL_Haptic * SDL_HapticOpenFromJoystick(SDL_Joystick *joystick)
Opens a haptic device for use from a joystick device.
static SDL_Haptic * SDL_haptics
#define SDL_HAPTIC_AUTOCENTER
Device can set autocenter.
#define SDL_HAPTIC_GAIN
Device can set global gain.
#define SDL_HAPTIC_PAUSE
Device can be paused.
#define SDL_HAPTIC_SINE
Sine wave effect supported.
#define SDL_HAPTIC_STATUS
Device can be queried for effect status.
#define SDL_HAPTIC_LEFTRIGHT
Left/Right effect supported.
#define SDL_HAPTIC_CARTESIAN
Uses cartesian coordinates for the direction.
SDL_bool SDL_PrivateJoystickValid(SDL_Joystick *joystick)
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
GLuint GLsizei GLsizei * length
void SDL_SYS_HapticClose(SDL_Haptic *haptic)
int SDL_SYS_HapticStopEffect(SDL_Haptic *haptic, struct haptic_effect *effect)
int SDL_SYS_HapticPause(SDL_Haptic *haptic)
int SDL_SYS_HapticSetGain(SDL_Haptic *haptic, int gain)
const char * SDL_SYS_HapticName(int index)
void SDL_SYS_HapticQuit(void)
int SDL_SYS_JoystickSameHaptic(SDL_Haptic *haptic, SDL_Joystick *joystick)
int SDL_SYS_HapticMouse(void)
int SDL_SYS_HapticUnpause(SDL_Haptic *haptic)
int SDL_SYS_HapticSetAutocenter(SDL_Haptic *haptic, int autocenter)
int SDL_SYS_HapticUpdateEffect(SDL_Haptic *haptic, struct haptic_effect *effect, SDL_HapticEffect *data)
int SDL_SYS_HapticStopAll(SDL_Haptic *haptic)
int SDL_SYS_HapticNewEffect(SDL_Haptic *haptic, struct haptic_effect *effect, SDL_HapticEffect *base)
int SDL_SYS_NumHaptics(void)
void SDL_SYS_HapticDestroyEffect(SDL_Haptic *haptic, struct haptic_effect *effect)
int SDL_SYS_HapticRunEffect(SDL_Haptic *haptic, struct haptic_effect *effect, Uint32 iterations)
int SDL_SYS_HapticOpenFromJoystick(SDL_Haptic *haptic, SDL_Joystick *joystick)
int SDL_SYS_HapticOpen(SDL_Haptic *haptic)
int SDL_SYS_HapticGetEffectStatus(SDL_Haptic *haptic, struct haptic_effect *effect)
int SDL_SYS_HapticInit(void)
int SDL_SYS_JoystickIsHaptic(SDL_Joystick *joystick)
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
SDL_HapticDirection direction
static SDL_Haptic * haptic
static SDL_Joystick * joystick
The generic template for any haptic effect.
SDL_HapticLeftRight leftright
SDL_HapticPeriodic periodic