Haptic: Don't interpret a direction of polar 35999 as "unsupported type". (or linux-direction 0xFFFF) Thanks, Elias! Partially fixes Bugzilla #2686.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
diff --git a/src/haptic/linux/SDL_syshaptic.c b/src/haptic/linux/SDL_syshaptic.c
index 7598a56..fc8ab5f 100644
--- a/src/haptic/linux/SDL_syshaptic.c
+++ b/src/haptic/linux/SDL_syshaptic.c
@@ -652,15 +652,15 @@ SDL_SYS_ToButton(Uint16 button)
/*
- * Returns the ff_effect usable direction from a SDL_HapticDirection.
+ * Initializes the ff_effect usable direction from a SDL_HapticDirection.
*/
-static Uint16
-SDL_SYS_ToDirection(SDL_HapticDirection * dir)
+static int
+SDL_SYS_ToDirection(Uint16 *dest, SDL_HapticDirection * src)
{
Uint32 tmp;
float f; /* Ideally we'd use fixed point math instead of floats... */
- switch (dir->type) {
+ switch (src->type) {
case SDL_HAPTIC_POLAR:
/* Linux directions start from south.
(and range from 0 to 0xFFFF)
@@ -671,10 +671,11 @@ SDL_SYS_ToDirection(SDL_HapticDirection * dir)
180 deg -> 0x8000 (up)
270 deg -> 0xC000 (right)
*/
- tmp = (((18000 + dir->dir[0]) % 36000) * 0xFFFF) / 36000; /* convert to range [0,0xFFFF] */
- return (Uint16) tmp;
+ tmp = (((18000 + src->dir[0]) % 36000) * 0xFFFF) / 36000; /* convert to range [0,0xFFFF] */
+ *dest = (Uint16) tmp;
+ break;
- case SDL_HAPTIC_SPHERICAL:
+ case SDL_HAPTIC_SPHERICAL:
/*
We convert to polar, because that's the only supported direction on Linux.
The first value of a spherical direction is practically the same as a
@@ -683,12 +684,13 @@ SDL_SYS_ToDirection(SDL_HapticDirection * dir)
--> add 9000
--> finally add 18000 and convert to [0,0xFFFF] as in case SDL_HAPTIC_POLAR.
*/
- tmp = ((dir->dir[0]) + 9000) % 36000; /* Convert to polars */
+ tmp = ((src->dir[0]) + 9000) % 36000; /* Convert to polars */
tmp = (((18000 + tmp) % 36000) * 0xFFFF) / 36000; /* convert to range [0,0xFFFF] */
- return (Uint16) tmp;
+ *dest = (Uint16) tmp;
+ break;
case SDL_HAPTIC_CARTESIAN:
- f = atan2(dir->dir[1], dir->dir[0]);
+ f = atan2(src->dir[1], src->dir[0]);
/*
atan2 takes the parameters: Y-axis-value and X-axis-value (in that order)
- Y-axis-value is the second coordinate (from center to SOUTH)
@@ -701,10 +703,11 @@ SDL_SYS_ToDirection(SDL_HapticDirection * dir)
*/
tmp = (((int) (f * 18000. / M_PI)) + 45000) % 36000;
tmp = (((18000 + tmp) % 36000) * 0xFFFF) / 36000; /* convert to range [0,0xFFFF] */
- return (Uint16) tmp;
+ *dest = (Uint16) tmp;
+ break;
default:
- return (Uint16) SDL_SetError("Haptic: Unsupported direction type.");
+ return SDL_SetError("Haptic: Unsupported direction type.");
}
return 0;
@@ -735,8 +738,7 @@ SDL_SYS_ToFFEffect(struct ff_effect *dest, SDL_HapticEffect * src)
/* Header */
dest->type = FF_CONSTANT;
- dest->direction = SDL_SYS_ToDirection(&constant->direction);
- if (dest->direction == (Uint16) - 1)
+ if (SDL_SYS_ToDirection(&dest->direction, &constant->direction) == -1)
return -1;
/* Replay */
@@ -771,8 +773,7 @@ SDL_SYS_ToFFEffect(struct ff_effect *dest, SDL_HapticEffect * src)
/* Header */
dest->type = FF_PERIODIC;
- dest->direction = SDL_SYS_ToDirection(&periodic->direction);
- if (dest->direction == (Uint16) - 1)
+ if (SDL_SYS_ToDirection(&dest->direction, &periodic->direction) == -1)
return -1;
/* Replay */
@@ -868,8 +869,7 @@ SDL_SYS_ToFFEffect(struct ff_effect *dest, SDL_HapticEffect * src)
/* Header */
dest->type = FF_RAMP;
- dest->direction = SDL_SYS_ToDirection(&ramp->direction);
- if (dest->direction == (Uint16) - 1)
+ if (SDL_SYS_ToDirection(&dest->direction, &ramp->direction) == -1)
return -1;
/* Replay */