tinygo icon indicating copy to clipboard operation
tinygo copied to clipboard

Joystick axes reduced by 2 for values of >2 in range -32767..32767 on Windows

Open andrewfstratton opened this issue 11 months ago • 1 comments

Using: Rpi Pico/Badger 2040/Wavshare RP2040 Zero - joystick, USB HID - setup is:

  • code sample at https://github.com/andrewfstratton/pico_vgamepad/blob/862d0a71e1f6425f8ebe92e671970e06f03c7081/main.go
  • flash with tinygo flash -target=waveshare-rp2040-zero main.go or change device to pico/badger2040
  • open USB Game Controllers
    • choose device -> Properties -> Settings Tab -> Calibrate
    • Choose Next>>Next (Axis Calibration)
    • Check the Display Raw Data option
    • This shows X Axis and Y Axis (starting at 0)
  • then run tinygo monitor to type commands into the command line

Here is the behaviour:

  • Typing X-32767 shows correctly as X Axis -32767
    • Raw data correctly shows X Axis -32767
    • Command line:
X-32767
Message: X-32767  Axis: 0  send: -32767  State:Axis0Value: -32767
  • Typing X0 and X1 and X2 also work fine

  • Typing X3 incorrectly is shown as 1:

    • Raw data incorrectly shows X Axis 1
    • Command line shows correct values
X3
Message: X3  Axis: 0  send: 3  State:Axis0Value: 3
  • Typing X4 (and upwards) shows raw Windows data as 2 below the expected value:
    • Raw data incorrectly shows X Axis 2 upwards
    • Command line shows correct values
X4
Message: X4  Axis: 0  send: 4  State:Axis0Value: 4
  • Typing X32767 is incorrect:
    • Raw data incorrectly shows X Axis 32765
    • Command line shows correct values
X32767
Message: X32767  Axis: 0  send: 32767  State:Axis0Value: 32767

This has the same, incorrect, behaviour for other axis

Note: I have checked the joystick package Max/Min In/Out conversion and that seems to work fine (I copied the code into Go playground and tried it for the same values).

I think the issue is further down, possibly in tinyusb itself.

I have tried it on another PC (win 10) and got the same error above - the 0.99994 value for 32767.

I did try this on MacOS and Android - but neither recognised the Pico - so I couldn't get any results there...

I may have made some stupid mistake in my code - which I can't see - but I do think there is some issue there that most users wouldn't see but is incorrect since the axis cannot reach their maximum limit.

andrewfstratton avatar Mar 18 '24 17:03 andrewfstratton

I have update the issue with further clarification when I discovered that the error happens for values of >2 for an axis range of -32767..32767

andrewfstratton avatar Mar 21 '24 11:03 andrewfstratton