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;
316 SDL_SetError(
"Haptic: SDL_SYS_HapticOpenFromJoystick failed.");
338 SDL_Haptic *hapticlist;
339 SDL_Haptic *hapticlistprev;
347 if (--haptic->ref_count > 0) {
352 for (i = 0; i < haptic->neffects; i++) {
353 if (haptic->effects[i].hweffect !=
NULL) {
361 hapticlistprev =
NULL;
364 if (haptic == hapticlist)
366 if ( hapticlistprev )
369 hapticlistprev->next = hapticlist->next;
378 hapticlistprev = hapticlist;
379 hapticlist = hapticlist->next;
409 return haptic->neffects;
423 return haptic->nplaying;
437 return haptic->supported;
451 return haptic->naxes;
464 if ((haptic->supported & effect->
type) != 0)
484 return SDL_SetError(
"Haptic: Effect not supported by haptic device.");
488 for (i = 0; i < haptic->neffects; i++) {
489 if (haptic->effects[i].hweffect ==
NULL) {
497 SDL_memcpy(&haptic->effects[i].effect, effect,
503 return SDL_SetError(
"Haptic: Device has no free space left.");
512 if ((effect < 0) || (effect >= haptic->neffects)) {
531 if (data->
type != haptic->effects[effect].effect.type) {
532 return SDL_SetError(
"Haptic: Updating effect type is illegal.");
541 SDL_memcpy(&haptic->effects[effect].effect, data,
595 if (haptic->effects[effect].hweffect ==
NULL) {
613 return SDL_SetError(
"Haptic: Device does not support status queries.");
626 int real_gain, max_gain;
633 return SDL_SetError(
"Haptic: Device does not support setting gain.");
636 if ((gain < 0) || (gain > 100)) {
637 return SDL_SetError(
"Haptic: Gain must be between 0 and 100.");
648 else if (max_gain > 100)
652 real_gain = (gain * max_gain) / 100;
675 return SDL_SetError(
"Haptic: Device does not support setting autocenter.");
678 if ((autocenter < 0) || (autocenter > 100)) {
679 return SDL_SetError(
"Haptic: Autocenter must be between 0 and 100.");
700 return SDL_SetError(
"Haptic: Device does not support setting pausing.");
763 if (haptic->rumble_id >= 0) {
786 if (haptic->rumble_id >= 0) {
805 if (haptic->rumble_id < 0) {
806 return SDL_SetError(
"Haptic: Rumble effect not initialized on haptic device");
810 if (strength > 1.0
f) {
812 }
else if (strength < 0.0
f) {
815 magnitude = (
Sint16)(32767.0
f*strength);
817 efx = &haptic->rumble_effect;
825 SDL_assert(0 &&
"This should have been caught elsewhere");
845 if (haptic->rumble_id < 0) {
846 return SDL_SetError(
"Haptic: Rumble effect not initialized on haptic device");