Bug 270676 - games/flightgear: Joystick hatmap incorrect
Summary: games/flightgear: Joystick hatmap incorrect
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: --- Affects Only Me
Assignee: Ganael LAPLANCHE
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-04-06 23:07 UTC by Stephen Hurd
Modified: 2023-04-12 10:59 UTC (History)
0 users

See Also:
bugzilla: maintainer-feedback? (martymac)


Attachments
Update patch file (614 bytes, text/plain)
2023-04-06 23:07 UTC, Stephen Hurd
no flags Details
Derive axis from rotational HID parameters (2.89 KB, patch)
2023-04-07 21:00 UTC, Stephen Hurd
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Stephen Hurd freebsd_committer freebsd_triage 2023-04-06 23:07:50 UTC
Created attachment 241330 [details]
Update patch file

On my Logitech Extreme 3D Pro, usbhidctl shows the hat starting at zero at top-centre, and incrementing clockwise with the middle value of 8.  This does not match the hatmap in the 3rdparty/joystick library.

The attached updated patch file fixes the hatmap so it works with my joystick.
Comment 1 Ganael LAPLANCHE freebsd_committer freebsd_triage 2023-04-07 10:09:08 UTC
Hello Stephen,

Thanks a lot for your patch.

I would like to avoid compatibility with other joysticks. Do you know how they would behave with your patch ?

I am surprised by the fact no one reported that issue yet (also, x11-toolkits/plib still uses the old mapping). If things are unsure, maybe we can make it an optional patch (disabled by default) ?

Cheers,

Ganael.
Comment 2 Stephen Hurd freebsd_committer freebsd_triage 2023-04-07 14:03:43 UTC
I've dug into it a bit more... it appears that hat switches are defined by HID as mapping logical values to degrees.  The old values appear to represent 0 as out of range, then south first with a counter-clockwise degrees, which doesn't appear to be possible, but assuming they inverted both axis, it would make sense.

I'll try to hack up something that actually generates the map from the HID data this weekend.
Comment 3 Stephen Hurd freebsd_committer freebsd_triage 2023-04-07 14:25:20 UTC
It appears that SDL hardcodes the values my patch use...

https://github.com/libsdl-org/SDL/blob/main/src/joystick/bsd/SDL_bsdjoystick.c#L596

(0-7 clockwise starting from North, 8 maps to centered)

I've sent an email to the contributor of the BSD hat support (patch adding hat support here: https://sourceforge.net/p/plib/code/1804/) asking him to validate (if he still runs FreeBSD and has a controller with a hat 20 years later).
Comment 4 Stephen Hurd freebsd_committer freebsd_triage 2023-04-07 21:00:34 UTC
Created attachment 241342 [details]
Derive axis from rotational HID parameters

Updated to not hard-code any HID hat switch.
Comment 5 Stephen Hurd freebsd_committer freebsd_triage 2023-04-07 21:00:47 UTC
Updated patch.  This one properly derives values from HID data (based on HID1.1 spec), and if the HID data is unexpected, falls back to the old values.

I suspect that the original code was designed around a HID hat with a logical minimum of 1, which made 0 the center-point, and the Y axis was inverted in the code.  If that's the case, this patch will invert the Y axis on his hat (which is easily fixed with a toggle box in FlightGear), and eventually the old values can go away.
Comment 6 commit-hook freebsd_committer freebsd_triage 2023-04-12 10:58:31 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/ports/commit/?id=17391201101f313c2c9049fea8e336acfee43d92

commit 17391201101f313c2c9049fea8e336acfee43d92
Author:     Stephen Hurd <shurd@FreeBSD.org>
AuthorDate: 2023-04-12 10:47:02 +0000
Commit:     Ganael LAPLANCHE <martymac@FreeBSD.org>
CommitDate: 2023-04-12 10:52:33 +0000

    games/flightgear: Improve joystick hat management

    Do not hardcode the hatmap but derive values from HID data (based on HID1.1
    spec), and if the HID data is unexpected, fall back to the old values.

    That patch fixes support for Logitech Extreme 3D Pro joystick's hat.

    PR:             270676
    Reported by:    shurd
    Tested by:      shurd

 games/flightgear/Makefile                          |  1 +
 .../files/patch-3rdparty-joystick-jsBSD.cxx        | 77 +++++++++++++++++++++-
 2 files changed, 77 insertions(+), 1 deletion(-)
Comment 7 Ganael LAPLANCHE freebsd_committer freebsd_triage 2023-04-12 10:59:11 UTC
I've committed your patch, thanks a lot Stephen!