Commit 265b219e3e78a1e5864aefb8876d2c0a77c7fc79

Sam Lantinga 2014-11-29T11:51:13

Fixed bug 2766 - Haptic coding bugs and fixes for Linux FF: periodic.phase handled as time instead of angle; + direction clarification Elias Vanderstuyft Remove the dependency of the calculation of Linux "phase" on "period", currently the "phase" parameter is interpreted as a time shift, instead of a phase shift. The Linux input documentation is not clear about the exact units of the "phase" parameter (see http://lxr.free-electrons.com/source/include/uapi/linux/input.h?v=3.17#L1075 ), but we're about to standardize the 'phase shift' interpretation into the Linux input documentation, since this will ease the job of a driver to recalculate the effect's state when the user dynamically updates the "period" parameter.

diff --git a/src/haptic/linux/SDL_syshaptic.c b/src/haptic/linux/SDL_syshaptic.c
index f75f7b8..bab3ddb 100644
--- a/src/haptic/linux/SDL_syshaptic.c
+++ b/src/haptic/linux/SDL_syshaptic.c
@@ -729,7 +729,6 @@ SDL_SYS_ToDirection(Uint16 *dest, SDL_HapticDirection * src)
 static int
 SDL_SYS_ToFFEffect(struct ff_effect *dest, SDL_HapticEffect * src)
 {
-    Uint32 tmp;
     SDL_HapticConstant *constant;
     SDL_HapticPeriodic *periodic;
     SDL_HapticCondition *condition;
@@ -807,9 +806,8 @@ SDL_SYS_ToFFEffect(struct ff_effect *dest, SDL_HapticEffect * src)
         dest->u.periodic.period = CLAMP(periodic->period);
         dest->u.periodic.magnitude = periodic->magnitude;
         dest->u.periodic.offset = periodic->offset;
-        /* Phase is calculated based of offset from period and then clamped. */
-        tmp = ((periodic->phase % 36000) * dest->u.periodic.period) / 36000;
-        dest->u.periodic.phase = CLAMP(tmp);
+        /* Linux phase is defined in interval "[0x0000, 0x10000[", corresponds with "[0deg, 360deg[" phase shift. */
+        dest->u.periodic.phase = ((Uint32)periodic->phase * 0x10000U) / 36000;
 
         /* Envelope */
         dest->u.periodic.envelope.attack_length =