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.
This commit is contained in:
Sam Lantinga 2014-11-29 11:51:13 -08:00
parent a5ce9c1113
commit 265b219e3e
1 changed files with 2 additions and 4 deletions

View File

@ -729,7 +729,6 @@ SDL_SYS_ToDirection(Uint16 *dest, SDL_HapticDirection * src)
static int static int
SDL_SYS_ToFFEffect(struct ff_effect *dest, SDL_HapticEffect * src) SDL_SYS_ToFFEffect(struct ff_effect *dest, SDL_HapticEffect * src)
{ {
Uint32 tmp;
SDL_HapticConstant *constant; SDL_HapticConstant *constant;
SDL_HapticPeriodic *periodic; SDL_HapticPeriodic *periodic;
SDL_HapticCondition *condition; 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.period = CLAMP(periodic->period);
dest->u.periodic.magnitude = periodic->magnitude; dest->u.periodic.magnitude = periodic->magnitude;
dest->u.periodic.offset = periodic->offset; dest->u.periodic.offset = periodic->offset;
/* Phase is calculated based of offset from period and then clamped. */ /* Linux phase is defined in interval "[0x0000, 0x10000[", corresponds with "[0deg, 360deg[" phase shift. */
tmp = ((periodic->phase % 36000) * dest->u.periodic.period) / 36000; dest->u.periodic.phase = ((Uint32)periodic->phase * 0x10000U) / 36000;
dest->u.periodic.phase = CLAMP(tmp);
/* Envelope */ /* Envelope */
dest->u.periodic.envelope.attack_length = dest->u.periodic.envelope.attack_length =