Fixed bug 2766 - Haptic coding bugs and fixes for Linux FF: periodic.phase handled as time instead of angle; + direction clarification
authorSam Lantinga <slouken@libsdl.org>
Sat, 29 Nov 2014 11:51:13 -0800
changeset 9251198989b162d3
parent 9250 50fb32b7f2bd
child 9252 a11e8f6d82d1
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.
src/haptic/linux/SDL_syshaptic.c
     1.1 --- a/src/haptic/linux/SDL_syshaptic.c	Sat Nov 29 11:49:58 2014 -0800
     1.2 +++ b/src/haptic/linux/SDL_syshaptic.c	Sat Nov 29 11:51:13 2014 -0800
     1.3 @@ -729,7 +729,6 @@
     1.4  static int
     1.5  SDL_SYS_ToFFEffect(struct ff_effect *dest, SDL_HapticEffect * src)
     1.6  {
     1.7 -    Uint32 tmp;
     1.8      SDL_HapticConstant *constant;
     1.9      SDL_HapticPeriodic *periodic;
    1.10      SDL_HapticCondition *condition;
    1.11 @@ -807,9 +806,8 @@
    1.12          dest->u.periodic.period = CLAMP(periodic->period);
    1.13          dest->u.periodic.magnitude = periodic->magnitude;
    1.14          dest->u.periodic.offset = periodic->offset;
    1.15 -        /* Phase is calculated based of offset from period and then clamped. */
    1.16 -        tmp = ((periodic->phase % 36000) * dest->u.periodic.period) / 36000;
    1.17 -        dest->u.periodic.phase = CLAMP(tmp);
    1.18 +        /* Linux phase is defined in interval "[0x0000, 0x10000[", corresponds with "[0deg, 360deg[" phase shift. */
    1.19 +        dest->u.periodic.phase = ((Uint32)periodic->phase * 0x10000U) / 36000;
    1.20  
    1.21          /* Envelope */
    1.22          dest->u.periodic.envelope.attack_length =