We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 2701

Summary: Haptic coding bugs and fixes for Windows and Mac OS: wrong handling of negative periodic magnitude
Product: SDL Reporter: Elias Vanderstuyft <Elias.vds>
Component: hapticAssignee: Ryan C. Gordon <icculus>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: major    
Priority: P2 CC: Elias.vds
Version: HG 2.1   
Hardware: x86_64   
OS: All   
Attachments: Fix some typos about angle units in the Haptic API doc
A negative periodic magnitude doesn't exist in Windows' and MacOS' FF APIs
Effect0_Sine.png
Effect1_SawtoothUp.png
Effect2_Constant.png
Effect7_Ramp.png

Description Elias Vanderstuyft 2014-08-23 20:59:44 UTC
This is something funny, a feature of the Linux FF API that doesn't exist in Windows' and MacOS' FF APIs:
    a negative periodic magnitude.
The periodic magnitude parameter of the SDL Haptic API is based on the Linux FF API, so it means they are not directly compatible:
    'dwMagnitude' is a 'DWORD', which is unsigned.

First I fixed some typos about angle units in the Haptic API doc (first patch: "vanilla-rev1.diff").

Then I created a patch to solve the problem by adding 180 degrees phase shift when the magnitude is negative (second patch: "rev1-rev2.diff").
WARNING: this patch is UNTESTED (as is the compilation), since I don't have the necessary access to a Windows or MacOS machine. Please verify this patch before applying it!

Both patches are based on yesterday's hg snapshot: SDL-2.0.3-9108

In the second patch you can see I also edited "testhaptic.c" to test the patch's changes:
To a user, the direction of the force of "Effect0 - Sine" should remain the same before and after this patch, since a negative magnitude combined with a 180 degrees phase shift will cancel out and become a positive magnitude combined with a zero degrees phase shift.

Finally, I included some images to graphically visualize exactly how the force output of "testhaptic" should be:
    "Effect0_Sine.png"
    "Effect1_SawtoothUp.png"
    "Effect2_Constant.png"
    "Effect7_Ramp.png"
I should note here that the forces and directions are defined in the Linux FF sense: the direction in which the force is applied by the joystick; *not* the direction where the force comes from!
Comment 1 Elias Vanderstuyft 2014-08-23 21:01:13 UTC
Created attachment 1841 [details]
Fix some typos about angle units in the Haptic API doc
Comment 2 Elias Vanderstuyft 2014-08-23 21:04:42 UTC
Created attachment 1842 [details]
A negative periodic magnitude doesn't exist in Windows' and MacOS' FF APIs

The periodic magnitude parameter of the SDL Haptic API is based on the Linux FF API, so it means they are not directly compatible:
    'dwMagnitude' is a 'DWORD', which is unsigned.

WARNING: this patch is UNTESTED (as is the compilation)
Comment 3 Elias Vanderstuyft 2014-08-23 21:06:26 UTC
Created attachment 1843 [details]
Effect0_Sine.png

testhaptic.c: effect[0]: Sine

The forces and directions are defined in the Linux FF sense: the direction in which the force is applied by the joystick; *not* the direction where the force comes from!
Comment 4 Elias Vanderstuyft 2014-08-23 21:06:55 UTC
Created attachment 1844 [details]
Effect1_SawtoothUp.png

testhaptic.c: effect[1]: SawtoothUp

The forces and directions are defined in the Linux FF sense: the direction in which the force is applied by the joystick; *not* the direction where the force comes from!
Comment 5 Elias Vanderstuyft 2014-08-23 21:07:20 UTC
Created attachment 1845 [details]
Effect2_Constant.png

testhaptic.c: effect[2]: Constant

The forces and directions are defined in the Linux FF sense: the direction in which the force is applied by the joystick; *not* the direction where the force comes from!
Comment 6 Elias Vanderstuyft 2014-08-23 21:07:45 UTC
Created attachment 1846 [details]
Effect7_Ramp.png

testhaptic.c: effect[7]: Ramp

The forces and directions are defined in the Linux FF sense: the direction in which the force is applied by the joystick; *not* the direction where the force comes from!
Comment 7 Ryan C. Gordon 2014-09-17 18:52:17 UTC
These patches are in revision control now, thanks!

    https://hg.libsdl.org/SDL/rev/dbef1f283c3f
    https://hg.libsdl.org/SDL/rev/6bf589c8d549

--ryan.