ubuntusdl-2hidjoystickinput-devices

SDL2 does not see joystick, but OS does


I am using Ubuntu 18.0.4.4 LTS with a home-brew Arduino-based USB joystick attached.

The OS sees the device at both /dev/input/js0 and /dev/input/event5 and jstest works with it:

$ jstest /dev/input/js0 
Driver version is 2.1.0.
Joystick (Arduino LLC Arduino Micro) has 6 axes (X, Y, Z, Rx, Ry, Rz)
and 0 buttons ().
Testing ... (interrupt to exit)
Axes:  0:     0  1:     0  2:     0  3:     0  4:     0  5:     0 ^C

evtest also works, as root:

$ sudo evtest /dev/input/event5 
Input driver version is 1.0.1
Input device ID: bus 0x3 vendor 0x2341 product 0x8037 version 0x101
Input device name: "Arduino LLC Arduino Micro"
Supported events:
  Event type 0 (EV_SYN)
  Event type 3 (EV_ABS)
    Event code 0 (ABS_X)
      Value      0
      Min     -100
      Max      100
      Flat      12
    Event code 1 (ABS_Y)
      Value      0
      Min     -100
      Max      100
      Flat      12
    Event code 2 (ABS_Z)
      Value      0
      Min     -100
      Max      100
      Flat      12
    Event code 3 (ABS_RX)
      Value      0
      Min     -100
      Max      100
      Flat      12
    Event code 4 (ABS_RY)
      Value      0
      Min     -100
      Max      100
      Flat      12
    Event code 5 (ABS_RZ)
      Value      0
      Min     -100
      Max      100
      Flat      12

Yet, SDL2's SDL_NumJoysticks() always returns 0, despite initializing SDL2 with joystick and gamepad support:

        SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER | SDL_INIT_TIMER | SDL_INIT_AUDIO );

Why can't SDL2 not use a working /dev/input/js0 device on Ubuntu?


Solution

  • SDL2 uses /dev/input/event* device files to access joysticks/gamepads, so you need read (and in some cases write) permissions for that files. Most linux distros use special user group for that files, e.g. input group on debian or gentoo; check what's your permissions are and make your user member of appropriate group (and re-login after that).