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.06k stars 403 forks source link

Second hat not being shown in Linux #210

Open ThatGuy435 opened 3 years ago

ThatGuy435 commented 3 years ago

Description of Issue

Hat0 shows and behaves as expected, but Hat1 does not interact with the system at all - on Linux Kernel 5.4 and 5.12. Hat0+Hat1 both show up in Windows 10 and Linux kernel 4.15.

I've looked at the /dev/event/eventX and /dev/input/jsX devices with evtest, jstest, and a straight cat on the device output. One 4.15, it shows HAT1X (event 18) and HAT1Y (event 19) as expected, in 5.4+ it does not show at all and no activity is registered on the cat output.

Technical Details

Sketch File that Reproduces Issue

This is a stripped down sketch that doesn't use actual hardware, to avoid any potential hardware issues:

#include <Joystick.h>

Joystick_ Joystick(JOYSTICK_DEFAULT_REPORT_ID, 
  JOYSTICK_TYPE_GAMEPAD, 0,
  JOYSTICK_DEFAULT_HATSWITCH_COUNT,
  false, false, false, false, false, false,
  false, false, false, false, false);

void setup() {

  // Initialize Joystick Library
  Joystick.begin();
}

int hatIndex=0;

void loop() {
    if (hatIndex == 0) {
        Joystick.setHatSwitch(0,-1);
        Joystick.setHatSwitch(1,0);
        hatIndex = 1;
    } else if (hatIndex == 1) {
        Joystick.setHatSwitch(0,0);
        Joystick.setHatSwitch(1,90);
        hatIndex = 2;
    } else if (hatIndex == 2) {
        Joystick.setHatSwitch(0,90);
        Joystick.setHatSwitch(1,180);
        hatIndex = 3;
    } else if (hatIndex == 3) {
        Joystick.setHatSwitch(0,180);
        Joystick.setHatSwitch(1,270);
        hatIndex = 4;
    } else if (hatIndex == 4) {
        Joystick.setHatSwitch(0,270);
        Joystick.setHatSwitch(1,-1);
        hatIndex = 0;
    }
    delay(500);
}

Additional context

I am not actually sure if this is an issue in this library or something with how the Linux kernel handles joystick/gamepad/other USB HID devices, but I am not enough of a programmer to figure it out.

Is it possible that linux is interpreting the USB descriptor in a more literal or strict way than older kernels and/or Windows are, and something in this library could be tweaked to work as expected?

I also tested on Kubuntu 21.04, Pop!_OS 21.04, Manjaro with identical results across kernels 5.4 and 5.12-xanmod.

CDRXavier commented 2 years ago

I feel like it's a issue with the way Linux handles the joystick. Try your setup on your friend's Mac. If it work on Windows and Mac (and you can try your android phone via OTG cable, why not), it's likely Linux's fault.