21 #include "../SDL_internal.h" 25 #include "../joystick/SDL_joystick_c.h" 55 SDL_Haptic *hapticlist;
62 if (hapticlist == haptic) {
66 hapticlist = hapticlist->next;
72 SDL_SetError(
"Haptic: Invalid haptic device identifier");
96 SDL_SetError(
"Haptic: There are %d haptic devices available",
111 SDL_Haptic *hapticlist;
114 SDL_SetError(
"Haptic: There are %d haptic devices available",
125 if (device_index == hapticlist->index) {
130 hapticlist = hapticlist->next;
134 haptic = (SDL_Haptic *)
SDL_malloc((
sizeof *haptic));
135 if (haptic ==
NULL) {
142 haptic->rumble_id = -1;
143 haptic->index = device_index;
172 SDL_Haptic *hapticlist;
176 SDL_SetError(
"Haptic: There are %d haptic devices available",
186 if (hapticlist->index == (
Uint8) device_index) {
190 hapticlist = hapticlist->next;
206 return haptic->index;
232 if (device_index < 0) {
272 SDL_Haptic *hapticlist;
276 SDL_SetError(
"Haptic: There are %d haptic devices available",
289 SDL_SetError(
"Haptic: Joystick isn't a haptic device.");
302 hapticlist = hapticlist->next;
306 haptic = (SDL_Haptic *)
SDL_malloc((
sizeof *haptic));
307 if (haptic ==
NULL) {
314 haptic->rumble_id = -1;
337 SDL_Haptic *hapticlist;
338 SDL_Haptic *hapticlistprev;
346 if (--haptic->ref_count > 0) {
351 for (i = 0; i < haptic->neffects; i++) {
352 if (haptic->effects[i].hweffect !=
NULL) {
360 hapticlistprev =
NULL;
363 if (haptic == hapticlist)
365 if ( hapticlistprev )
368 hapticlistprev->next = hapticlist->next;
377 hapticlistprev = hapticlist;
378 hapticlist = hapticlist->next;
406 return haptic->neffects;
420 return haptic->nplaying;
434 return haptic->supported;
448 return haptic->naxes;
461 if ((haptic->supported & effect->
type) != 0)
481 return SDL_SetError(
"Haptic: Effect not supported by haptic device.");
485 for (i = 0; i < haptic->neffects; i++) {
486 if (haptic->effects[i].hweffect ==
NULL) {
494 SDL_memcpy(&haptic->effects[i].effect, effect,
500 return SDL_SetError(
"Haptic: Device has no free space left.");
509 if ((effect < 0) || (effect >= haptic->neffects)) {
528 if (data->
type != haptic->effects[effect].effect.type) {
529 return SDL_SetError(
"Haptic: Updating effect type is illegal.");
538 SDL_memcpy(&haptic->effects[effect].effect, data,
592 if (haptic->effects[effect].hweffect ==
NULL) {
610 return SDL_SetError(
"Haptic: Device does not support status queries.");
623 int real_gain, max_gain;
630 return SDL_SetError(
"Haptic: Device does not support setting gain.");
633 if ((gain < 0) || (gain > 100)) {
634 return SDL_SetError(
"Haptic: Gain must be between 0 and 100.");
645 else if (max_gain > 100)
649 real_gain = (gain * max_gain) / 100;
672 return SDL_SetError(
"Haptic: Device does not support setting autocenter.");
675 if ((autocenter < 0) || (autocenter > 100)) {
676 return SDL_SetError(
"Haptic: Autocenter must be between 0 and 100.");
697 return SDL_SetError(
"Haptic: Device does not support setting pausing.");
760 if (haptic->rumble_id >= 0) {
782 if (haptic->rumble_id >= 0) {
801 if (haptic->rumble_id < 0) {
802 return SDL_SetError(
"Haptic: Rumble effect not initialized on haptic device");
806 if (strength > 1.0
f) {
808 }
else if (strength < 0.0
f) {
811 magnitude = (
Sint16)(32767.0
f*strength);
813 efx = &haptic->rumble_effect;
821 SDL_assert(0 &&
"This should have been caught elsewhere");
841 if (haptic->rumble_id < 0) {
842 return SDL_SetError(
"Haptic: Rumble effect not initialized on haptic device");
int SDL_SYS_HapticOpenFromJoystick(SDL_Haptic *haptic, SDL_Joystick *joystick)
int SDL_HapticRumbleStop(SDL_Haptic *haptic)
Stops the simple rumble on a haptic device.
int SDL_HapticStopAll(SDL_Haptic *haptic)
Stops all the currently playing effects on a haptic device.
int SDL_HapticUnpause(SDL_Haptic *haptic)
Unpauses a haptic device.
const char * SDL_HapticName(int device_index)
Get the implementation dependent name of a Haptic device.
int SDL_PrivateJoystickValid(SDL_Joystick *joystick)
int SDL_HapticRumbleInit(SDL_Haptic *haptic)
Initializes the haptic device for simple rumble playback.
void SDL_HapticQuit(void)
#define SDL_HAPTIC_AUTOCENTER
Device can set autocenter.
#define SDL_HAPTIC_GAIN
Device can set global gain.
int SDL_HapticRumbleSupported(SDL_Haptic *haptic)
Checks to see if rumble is supported on a haptic device.
int SDL_SYS_HapticOpen(SDL_Haptic *haptic)
int SDL_HapticGetEffectStatus(SDL_Haptic *haptic, int effect)
Gets the status of the current effect on the haptic device.
int SDL_SYS_HapticMouse(void)
int SDL_SYS_JoystickSameHaptic(SDL_Haptic *haptic, SDL_Joystick *joystick)
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
int SDL_SYS_HapticStopEffect(SDL_Haptic *haptic, struct haptic_effect *effect)
const char * SDL_SYS_HapticName(int index)
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_SYS_HapticUnpause(SDL_Haptic *haptic)
uint32_t Uint32
An unsigned 32-bit integer type.
SDL_Haptic * SDL_HapticOpen(int device_index)
Opens a Haptic device for usage.
#define SDL_HAPTIC_SINE
Sine wave effect supported.
int SDL_HapticNumEffectsPlaying(SDL_Haptic *haptic)
Returns the number of effects a haptic device can play at the same time.
int SDL_SYS_HapticGetEffectStatus(SDL_Haptic *haptic, struct haptic_effect *effect)
int SDL_HapticIndex(SDL_Haptic *haptic)
Gets the index of a haptic device.
int SDL_HapticEffectSupported(SDL_Haptic *haptic, SDL_HapticEffect *effect)
Checks to see if effect is supported by haptic.
The generic template for any haptic effect.
int SDL_SYS_HapticSetAutocenter(SDL_Haptic *haptic, int autocenter)
int SDL_JoystickIsHaptic(SDL_Joystick *joystick)
Checks to see if a joystick has haptic features.
int SDL_HapticSetGain(SDL_Haptic *haptic, int gain)
Sets the global gain of the device.
uint8_t Uint8
An unsigned 8-bit integer type.
int SDL_HapticRumblePlay(SDL_Haptic *haptic, float strength, Uint32 length)
Runs simple rumble on a haptic device.
int SDL_HapticRunEffect(SDL_Haptic *haptic, int effect, Uint32 iterations)
Runs the haptic effect on its associated haptic device.
int SDL_NumHaptics(void)
Count the number of haptic devices attached to the system.
static int ValidHaptic(SDL_Haptic *haptic)
#define SDL_HAPTIC_PAUSE
Device can be paused.
int SDL_SYS_HapticUpdateEffect(SDL_Haptic *haptic, struct haptic_effect *effect, SDL_HapticEffect *data)
int SDL_MouseIsHaptic(void)
Gets whether or not the current mouse has haptic capabilities.
int SDL_SYS_JoystickIsHaptic(SDL_Joystick *joystick)
int SDL_HapticSetAutocenter(SDL_Haptic *haptic, int autocenter)
Sets the global autocenter of the device.
void SDL_SYS_HapticDestroyEffect(SDL_Haptic *haptic, struct haptic_effect *effect)
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)
#define SDL_assert(condition)
#define SDL_OutOfMemory()
static SDL_Haptic * haptic
int SDL_SYS_HapticInit(void)
void SDL_SYS_HapticQuit(void)
#define SDL_HAPTIC_STATUS
Device can be queried for effect status.
void SDL_SYS_HapticClose(SDL_Haptic *haptic)
int SDL_SYS_HapticPause(SDL_Haptic *haptic)
SDL_HapticLeftRight leftright
int SDL_HapticNumAxes(SDL_Haptic *haptic)
Gets the number of haptic axes the device has.
int SDL_HapticNumEffects(SDL_Haptic *haptic)
Returns the number of effects a haptic device can store.
static int ValidEffect(SDL_Haptic *haptic, int effect)
void SDL_HapticDestroyEffect(SDL_Haptic *haptic, int effect)
Destroys a haptic effect on the device.
int SDL_SYS_HapticStopAll(SDL_Haptic *haptic)
int SDL_HapticUpdateEffect(SDL_Haptic *haptic, int effect, SDL_HapticEffect *data)
Updates the properties of an effect.
int SDL_SYS_HapticSetGain(SDL_Haptic *haptic, int gain)
unsigned int SDL_HapticQuery(SDL_Haptic *haptic)
Gets the haptic device's supported features in bitwise manner.
GLuint GLsizei GLsizei * length
#define SDL_HAPTIC_LEFTRIGHT
Left/Right effect supported.
int SDL_SYS_HapticRunEffect(SDL_Haptic *haptic, struct haptic_effect *effect, Uint32 iterations)
SDL_HapticPeriodic periodic
int SDL_HapticStopEffect(SDL_Haptic *haptic, int effect)
Stops the haptic effect on its associated haptic device.
void SDL_HapticClose(SDL_Haptic *haptic)
Closes a Haptic device previously opened with SDL_HapticOpen().
int16_t Sint16
A signed 16-bit integer type.
int SDL_HapticOpened(int device_index)
Checks if the haptic device at index has been opened.
int SDL_SYS_HapticNewEffect(SDL_Haptic *haptic, struct haptic_effect *effect, SDL_HapticEffect *base)
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 usage from a Joystick device.