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.
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.
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.
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).
Created attachment 241342 [details] Derive axis from rotational HID parameters Updated to not hard-code any HID hat switch.
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.
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(-)
I've committed your patch, thanks a lot Stephen!