ArduinoJoystickLibrary icon indicating copy to clipboard operation
ArduinoJoystickLibrary copied to clipboard

Second hat not being shown in Linux

Open ThatGuy435 opened this issue 3 years ago • 1 comments

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

  • Board: SparkFun Pro Micro
  • Host OS:
    • Not working correctly: kernel 5.4 (Linux Mint 20.1), kernel 5.12 (Linux Mint 20.1, XanMod stable)
    • Working correctly: Windows 10, kernel 4.15 (Kubuntu 18.04)
  • Arduino IDE 1.8.15

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.

ThatGuy435 avatar Jul 02 '21 05:07 ThatGuy435

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.

CDRXavier avatar Aug 19 '21 17:08 CDRXavier