<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.freebsd.org/bugzilla/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.freebsd.org/bugzilla/"
          
          maintainer="bugmeister@FreeBSD.org"
>

    <bug>
          <bug_id>270676</bug_id>
          
          <creation_ts>2023-04-06 23:07:50 +0000</creation_ts>
          <short_desc>games/flightgear: Joystick hatmap incorrect</short_desc>
          <delta_ts>2023-04-12 10:59:11 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>Ports &amp; Packages</product>
          <component>Individual Port(s)</component>
          <version>Latest</version>
          <rep_platform>Any</rep_platform>
          <op_sys>Any</op_sys>
          <bug_status>Closed</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>---</priority>
          <bug_severity>Affects Only Me</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Stephen Hurd">shurd</reporter>
          <assigned_to name="Ganael LAPLANCHE">martymac</assigned_to>
          
          

      

      

      <flag name="maintainer-feedback"
          id="72803"
          type_id="3"
          status="?"
          setter="bugzilla"
          requestee="martymac"
    />

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1254069</commentid>
    <comment_count>0</comment_count>
      <attachid>241330</attachid>
    <who name="Stephen Hurd">shurd</who>
    <bug_when>2023-04-06 23:07:50 +0000</bug_when>
    <thetext>Created attachment 241330
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.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1254114</commentid>
    <comment_count>1</comment_count>
    <who name="Ganael LAPLANCHE">martymac</who>
    <bug_when>2023-04-07 10:09:08 +0000</bug_when>
    <thetext>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.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1254129</commentid>
    <comment_count>2</comment_count>
    <who name="Stephen Hurd">shurd</who>
    <bug_when>2023-04-07 14:03:43 +0000</bug_when>
    <thetext>I&apos;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&apos;t appear to be possible, but assuming they inverted both axis, it would make sense.

I&apos;ll try to hack up something that actually generates the map from the HID data this weekend.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1254132</commentid>
    <comment_count>3</comment_count>
    <who name="Stephen Hurd">shurd</who>
    <bug_when>2023-04-07 14:25:20 +0000</bug_when>
    <thetext>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&apos;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).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1254165</commentid>
    <comment_count>4</comment_count>
      <attachid>241342</attachid>
    <who name="Stephen Hurd">shurd</who>
    <bug_when>2023-04-07 21:00:34 +0000</bug_when>
    <thetext>Created attachment 241342
Derive axis from rotational HID parameters

Updated to not hard-code any HID hat switch.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1254166</commentid>
    <comment_count>5</comment_count>
    <who name="Stephen Hurd">shurd</who>
    <bug_when>2023-04-07 21:00:47 +0000</bug_when>
    <thetext>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&apos;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.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1254894</commentid>
    <comment_count>6</comment_count>
    <who name="">commit-hook</who>
    <bug_when>2023-04-12 10:58:31 +0000</bug_when>
    <thetext>A commit in branch main references this bug:

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

commit 17391201101f313c2c9049fea8e336acfee43d92
Author:     Stephen Hurd &lt;shurd@FreeBSD.org&gt;
AuthorDate: 2023-04-12 10:47:02 +0000
Commit:     Ganael LAPLANCHE &lt;martymac@FreeBSD.org&gt;
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&apos;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(-)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1254896</commentid>
    <comment_count>7</comment_count>
    <who name="Ganael LAPLANCHE">martymac</who>
    <bug_when>2023-04-12 10:59:11 +0000</bug_when>
    <thetext>I&apos;ve committed your patch, thanks a lot Stephen!</thetext>
  </long_desc>
      
          <attachment
              isobsolete="1"
              ispatch="0"
              isprivate="0"
          >
            <attachid>241330</attachid>
            <date>2023-04-06 23:07:50 +0000</date>
            <delta_ts>2023-04-07 21:00:34 +0000</delta_ts>
            <desc>Update patch file</desc>
            <filename>patch-3rdparty-joystick-jsBSD.cxx</filename>
            <type>text/plain</type>
            <size>614</size>
            <attacher name="Stephen Hurd">shurd</attacher>
            
              <data encoding="base64">LS0tIDNyZHBhcnR5L2pveXN0aWNrL2pzQlNELmN4eC5vcmlnCTIwMjMtMDQtMDYgMjI6NTQ6MzEg
VVRDCisrKyAzcmRwYXJ0eS9qb3lzdGljay9qc0JTRC5jeHgKQEAgLTUyLDYgKzUyLDcgQEAKICNp
bmNsdWRlIDxzeXMvcGFyYW0uaD4KICNpbmNsdWRlIDxmY250bC5oPgogCisjaW5jbHVkZSA8dW5p
c3RkLmg+CiAjaW5jbHVkZSA8c3RyaW5nLmg+CiAjaW5jbHVkZSA8ZXJybm8uaD4KICNpbmNsdWRl
IDxzeXMvaW9jdGwuaD4KQEAgLTg3LDggKzg4LDggQEAgZXh0ZXJuICJDIiB7CiAjZW5kaWYKICNl
bmRpZgogCi1zdGF0aWMgaW50IGhhdG1hcF94WzldID0geyAwLCAwLCAxLCAxLCAxLCAwLCAtMSwg
LTEsIC0xIH07Ci1zdGF0aWMgaW50IGhhdG1hcF95WzldID0geyAwLCAxLCAxLCAwLCAtMSwgLTEs
IC0xLCAwLCAxIH07CitzdGF0aWMgaW50IGhhdG1hcF94WzldID0geyAwLCAxLCAxLCAxLCAwLCAt
MSwgLTEsIC0xLCAwIH07CitzdGF0aWMgaW50IGhhdG1hcF95WzldID0geyAtMSwgLTEsIDAsIDEs
IDEsIDEsIDAsIC0xLCAwIH07CiBzdHJ1Y3Qgb3Nfc3BlY2lmaWNfcyB7CiAgIGNoYXIgICAgICAg
ICAgICAgZm5hbWUgWzEyOCBdOwogICBpbnQgICAgICAgICAgICAgIGZkOwo=
</data>

          </attachment>
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>241342</attachid>
            <date>2023-04-07 21:00:34 +0000</date>
            <delta_ts>2023-04-07 21:00:34 +0000</delta_ts>
            <desc>Derive axis from rotational HID parameters</desc>
            <filename>patch-3rdparty-joystick-jsBSD.cxx</filename>
            <type>text/plain</type>
            <size>2960</size>
            <attacher name="Stephen Hurd">shurd</attacher>
            
              <data encoding="base64">LS0tIDNyZHBhcnR5L2pveXN0aWNrL2pzQlNELmN4eC5vcmlnCTIwMjMtMDQtMDcgMTc6NTc6MTUg
VVRDCisrKyAzcmRwYXJ0eS9qb3lzdGljay9qc0JTRC5jeHgKQEAgLTUyLDYgKzUyLDcgQEAKICNp
bmNsdWRlIDxzeXMvcGFyYW0uaD4KICNpbmNsdWRlIDxmY250bC5oPgogCisjaW5jbHVkZSA8dW5p
c3RkLmg+CiAjaW5jbHVkZSA8c3RyaW5nLmg+CiAjaW5jbHVkZSA8ZXJybm8uaD4KICNpbmNsdWRl
IDxzeXMvaW9jdGwuaD4KQEAgLTE5OCw2ICsxOTksOCBAQCBzdGF0aWMgaW50IGpveV9pbml0aWFs
aXplX2hpZChzdHJ1Y3Qgb3Nfc3BlY2lmaWNfcyAqb3MKICAgICBpbnRlcmVzdGluZ19oaWQgPSBU
UlVFOwogICAgIGlmIChwYWdlID09IEhVUF9HRU5FUklDX0RFU0tUT1ApCiAgICAgeworICAgICAg
IGludCByYW5nZTsKKyAgICAgICBpbnQgbWF0Y2hlZDsKICAgICAgICBzd2l0Y2godXNhZ2UpIHsK
ICAgICAgICAgIGNhc2UgSFVHX1g6CiAgICAgICAgICBjYXNlIEhVR19SWDoKQEAgLTIyMSw2ICsy
MjQsNjUgQEAgc3RhdGljIGludCBqb3lfaW5pdGlhbGl6ZV9oaWQoc3RydWN0IG9zX3NwZWNpZmlj
X3MgKm9zCiAgICAgICAgICAgICAgKCpudW1fYXhlcykrKzsKICAgICAgICAgICAgICBvcy0+YXhl
c191c2FnZVsqbnVtX2F4ZXNdID0gdXNhZ2U7CiAgICAgICAgICAgICAgKCpudW1fYXhlcykrKzsK
KyAgICAgICAgICAgfQorICAgICAgICAgICByYW5nZSA9IGgubG9naWNhbF9tYXhpbXVtIC0gaC5s
b2dpY2FsX21pbmltdW0gKyAxOworICAgICAgICAgICBtYXRjaGVkID0gMDsKKyAgICAgICAgICAg
aWYgKCgoaC5sb2dpY2FsX21pbmltdW0gPT0gMCkgfHwgKGgubG9naWNhbF9taW5pbXVtID09IDEp
KSAmJiAoaC51bml0ID09IEhVTV9ERUdSRUUpICYmIChoLnVuaXRfZXhwb25lbnQgPT0gMCkgJiYg
KChyYW5nZSA9PSA0KSB8fCAocmFuZ2UgPT0gOCkpKSB7CisgICAgICAgICAgICAgaW50IHJlc29s
dXRpb24gPSAoaC5waHlzaWNhbF9tYXhpbXVtIC0gaC5waHlzaWNhbF9taW5pbXVtKSAvIChoLmxv
Z2ljYWxfbWF4aW11bSAtIGgubG9naWNhbF9taW5pbXVtKTsKKyAgICAgICAgICAgICBmb3IgKGlu
dCBpID0gaC5sb2dpY2FsX21pbmltdW07IGkgPD0gaC5sb2dpY2FsX21heGltdW07IGkrKykgewor
ICAgICAgICAgICAgICAgY29uc3QgaW50IGRlZ3JlZXMgPSAoaSAtIGgubG9naWNhbF9taW5pbXVt
KSAqIHJlc29sdXRpb24gKyBoLnBoeXNpY2FsX21pbmltdW07CisgICAgICAgICAgICAgICBzd2l0
Y2ggKGRlZ3JlZXMpIHsKKyAgICAgICAgICAgICAgICAgY2FzZSAwOgorICAgICAgICAgICAgICAg
ICAgIGhhdG1hcF94W2ldID0gMDsKKyAgICAgICAgICAgICAgICAgICBoYXRtYXBfeVtpXSA9IC0x
OworICAgICAgICAgICAgICAgICAgIG1hdGNoZWQrKzsKKyAgICAgICAgICAgICAgICAgICBicmVh
azsKKyAgICAgICAgICAgICAgICAgY2FzZSA0NToKKyAgICAgICAgICAgICAgICAgICBoYXRtYXBf
eFtpXSA9IDE7CisgICAgICAgICAgICAgICAgICAgaGF0bWFwX3lbaV0gPSAtMTsKKyAgICAgICAg
ICAgICAgICAgICBtYXRjaGVkKys7CisgICAgICAgICAgICAgICAgICAgYnJlYWs7CisgICAgICAg
ICAgICAgICAgIGNhc2UgOTA6CisgICAgICAgICAgICAgICAgICAgaGF0bWFwX3hbaV0gPSAxOwor
ICAgICAgICAgICAgICAgICAgIGhhdG1hcF95W2ldID0gMDsKKyAgICAgICAgICAgICAgICAgICBt
YXRjaGVkKys7CisgICAgICAgICAgICAgICAgICAgYnJlYWs7CisgICAgICAgICAgICAgICAgIGNh
c2UgMTM1OgorICAgICAgICAgICAgICAgICAgIGhhdG1hcF94W2ldID0gMTsKKyAgICAgICAgICAg
ICAgICAgICBoYXRtYXBfeVtpXSA9IDE7CisgICAgICAgICAgICAgICAgICAgbWF0Y2hlZCsrOwor
ICAgICAgICAgICAgICAgICAgIGJyZWFrOworICAgICAgICAgICAgICAgICBjYXNlIDE4MDoKKyAg
ICAgICAgICAgICAgICAgICBoYXRtYXBfeFtpXSA9IDA7CisgICAgICAgICAgICAgICAgICAgaGF0
bWFwX3lbaV0gPSAxOworICAgICAgICAgICAgICAgICAgIG1hdGNoZWQrKzsKKyAgICAgICAgICAg
ICAgICAgICBicmVhazsKKyAgICAgICAgICAgICAgICAgY2FzZSAyMjU6CisgICAgICAgICAgICAg
ICAgICAgaGF0bWFwX3hbaV0gPSAtMTsKKyAgICAgICAgICAgICAgICAgICBoYXRtYXBfeVtpXSA9
IDE7CisgICAgICAgICAgICAgICAgICAgbWF0Y2hlZCsrOworICAgICAgICAgICAgICAgICAgIGJy
ZWFrOworICAgICAgICAgICAgICAgICBjYXNlIDI3MDoKKyAgICAgICAgICAgICAgICAgICBoYXRt
YXBfeFtpXSA9IC0xOworICAgICAgICAgICAgICAgICAgIGhhdG1hcF95W2ldID0gMDsKKyAgICAg
ICAgICAgICAgICAgICBtYXRjaGVkKys7CisgICAgICAgICAgICAgICAgICAgYnJlYWs7CisgICAg
ICAgICAgICAgICAgIGNhc2UgMzE1OgorICAgICAgICAgICAgICAgICAgIGhhdG1hcF94W2ldID0g
LTE7CisgICAgICAgICAgICAgICAgICAgaGF0bWFwX3lbaV0gPSAtMTsKKyAgICAgICAgICAgICAg
ICAgICBtYXRjaGVkKys7CisgICAgICAgICAgICAgICAgICAgYnJlYWs7CisgICAgICAgICAgICAg
ICB9CisgICAgICAgICAgICAgfQorICAgICAgICAgICAgIGlmIChtYXRjaGVkID09IHJhbmdlKSB7
CisgICAgICAgICAgICAgICBpZiAoaC5sb2dpY2FsX21pbmltdW0gPT0gMCkgeworICAgICAgICAg
ICAgICAgICBoYXRtYXBfeFtoLmxvZ2ljYWxfbWF4aW11bSArIDFdID0gMDsKKyAgICAgICAgICAg
ICAgICAgaGF0bWFwX3lbaC5sb2dpY2FsX21heGltdW0gKyAxXSA9IDA7CisgICAgICAgICAgICAg
ICB9IGVsc2UgeworICAgICAgICAgICAgICAgICBoYXRtYXBfeFswXSA9IDA7CisgICAgICAgICAg
ICAgICAgIGhhdG1hcF95WzBdID0gMDsKKyAgICAgICAgICAgICAgIH0KKyAgICAgICAgICAgICB9
CiAgICAgICAgICAgIH0KICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICBkZWZhdWx0Ogo=
</data>

          </attachment>
      

    </bug>

</bugzilla>