MHeironimus / ArduinoJoystickLibrary

An Arduino library that adds one or more joysticks to the list of HID devices an Arduino Leonardo or Arduino Micro can support.
GNU Lesser General Public License v3.0
2.1k stars 409 forks source link

HTML5 axis shows NAN or Infinity with GamepadExample in Chrome #142

Open helpme2k2 opened 4 years ago

helpme2k2 commented 4 years ago

Description of Issue

When I use the GamepadExample that comes with the library on my Lenoardo and test it against Firefox and Chrome (https://html5gamepad.com/), the two browsers produce different result. Firefox's axis reading are all correct but the axis reading from Chrome v81.0.4044.138 returns NaN (when it should be 0) and +/- infinity (when it should be +/-1).

I figured the above issue only appear if I use the constructor with customized number of axis and button like below,

Joystick_ Joystick(JOYSTICK_DEFAULT_REPORT_ID,JOYSTICK_TYPE_GAMEPAD,
  1, 0,                  // Button Count, Hat Switch Count
  true, true, false,     // X and Y, but no Z Axis
  false, false, false,   // No Rx, Ry, or Rz
  false, false,          // No rudder or throttle
  false, false, false);  // No accelerator, brake, or steering

If I use
Joystick_ Joystick; or even Joystick_ Joystick(JOYSTICK_DEFAULT_REPORT_ID,JOYSTICK_TYPE_GAMEPAD); Although there will be non-used axis and button, but the issue of NaN on Chrome is gone.

Technical Details

Sketch File that Reproduces Issue

GamepadExample from the joystick library 2.0.5

Sketch file goes here (if applicable)

Wiring Details

no wiring

Additional context

Add any other context about the problem here.

ghost commented 4 years ago

I don't know if you should be worried about the html5gamepad test; I have made a set of sim pedals that shows up in chrome with +/- infinity and does not show up at all in mozilla. Despite this, they work perfectly fine in Assetto Corsa.

A piece of software that correctly displays all inputs is one made by Leo Bodnar, called DiView.

http://www.leobodnar.com/shop/index.php?main_page=page&id=12

You should see the actual information sent by the microcontroller there.

Hope this helps