Joystick hat support on Linux

Hello,

I’m using the controller of the Xbox (USB) on Linux 2.4.21 (latest SDL from
CVS), but I’m having trouble to make the digital pad be recognized as a
hat and not axes.

So I’ve had a look in the src/joystick/linux/SDL_sysjoystick.c file and it
seems that before kernel 2.4 and its “new unified input interface”, a
digital pad mapped to 2 axes.

As I’m using 2.4.21, the hat should be detected correctly ?

Still in SDL_sysjoystick.c, I’ve understood that a joystick is configured
with either JS_ConfigJoystick() or EV_ConfigJoystick() (old/new interface
?), depending on the result of this big instruction :

  (ioctl(fd, EVIOCGBIT(EV_KEY, sizeof(keybit)), keybit) >= 0) &&
  (ioctl(fd, EVIOCGBIT(EV_ABS, sizeof(absbit)), absbit) >= 0) &&
  (ioctl(fd, EVIOCGBIT(EV_REL, sizeof(relbit)), relbit) >= 0)

And I’ve checked, for my joystick, the above instructions returns FALSE.
So my question is : what does this instuction above check ? Does my joystick
driver has to be special to use the new interface (it has been coded based
on the other kernel’ drivers, so should be quite “standard” in its
structure/function calls) ?
Has anyone managed to get joystick hat support on Linux whatsoever ?

I know it’s not a very big deal and I could get along with the 2 axes and a
few hacks but, still, I’d like to understand :slight_smile:

Thanks a lot.

Damiano

Hello,

I’m using the controller of the Xbox (USB) on Linux 2.4.21 (latest SDL from
CVS), but I’m having trouble to make the digital pad be recognized as a
hat and not axes.

And you want that because… :slight_smile:

So I’ve had a look in the src/joystick/linux/SDL_sysjoystick.c file and it
seems that before kernel 2.4 and its “new unified input interface”, a
digital pad mapped to 2 axes.

Then stop using the event interface - don’t load the evdev module.

I disabled it because my joystick, a Saitek Cyborg 3D, needs better
calibration than the autocalibration provided by the jsdev module. The
evdev doesn’t provide calibration at all, its up to SDL to correct using
the same method as jsdev.

My axis go from -29000 to 20000 instead of -32767 to 32767. Using
jscal fixes the range but screws the rest point to -5000. So I made a
spreadsheet and combined the calibrated min and max with uncalibrated
centre and deadzone… Hmm, I need a better joystick - enough moaning.

…and I like my hat too.

As I’m using 2.4.21, the hat should be detected correctly ?

For the jsdev the analog joystick driver, names matching the
special_joystick table, or forcing with enviroment variable
SDL_LINUX_JOYSTICK. Eg;

export SDL_LINUX_JOYSTICK="‘JOYSTICK DEVICE NAME’ AXES HATS BALLS"
export SDL_LINUX_JOYSTICK="‘WingMan Extreme Digital 3D’ 4 1 0"

For evdev only USB devices that report their components correctly
have their hats mapped (I believe).

Still in SDL_sysjoystick.c, I’ve understood that a joystick is configured
with either JS_ConfigJoystick() or EV_ConfigJoystick() (old/new interface
?), depending on the result of this big instruction :

  (ioctl(fd, EVIOCGBIT(EV_KEY, sizeof(keybit)), keybit) >= 0) &&
  (ioctl(fd, EVIOCGBIT(EV_ABS, sizeof(absbit)), absbit) >= 0) &&
  (ioctl(fd, EVIOCGBIT(EV_REL, sizeof(relbit)), relbit) >= 0)

And I’ve checked, for my joystick, the above instructions returns FALSE.
So my question is : what does this instuction above check ? Does my joystick
driver has to be special to use the new interface (it has been coded based
on the other kernel’ drivers, so should be quite “standard” in its
structure/function calls) ?

It checks that the device (/dev/input/event*) is an evdev by testing the
ioctls which return -1 for invalid (?) and 0-X for the number of
buttons, absolute axis, and relative axis.

Has anyone managed to get joystick hat support on Linux whatsoever ?

Yes.

I know it’s not a very big deal and I could get along with the 2 axes and a
few hacks but, still, I’d like to understand :slight_smile:

Try disabling the evdev as above and setting the enviroment or adding
to the special_joystick table.

Thanks a lot.

Depends on knowing how the XBox controller is reported (normal USB
device?) with the digital pad being reported as a normal axis and not
a USB device hat or something like that.On Thu, 2003-07-17 at 10:42, Damiano wrote:


Alan.

“One must never be purposelessnessnesslessness.”
-------------- next part --------------
A non-text attachment was scrubbed…
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20030717/d0da3bc6/attachment.pgp

The hat problem with my joystick continues…

I’ve tried to play with the evdev.o and xpad.o module : when both are loaded
there’s a /dev/input/event0 that is created (in addition of the
/dev/input/js0). That means that the controller should work with the event
API !

Exporting SDL_LINUX_JOYSTICK doesn’t work either : the buttons still work
but not the axes/hat (although obviously “well” detected in number) and
don’t respond.

This is now a certitude : SDL falls back to JS_ConfigJoystick (and so don’t
use the event based API) because of the ioctl() calls which fails in
EV_IsJoystick() – the 3 returns -1.
But why, I’ve no idea…

Could someone have a look in the xpad driver ? It is not a very complicated
driver but I don’t know at all what’s missing in the driver (if there is
something missing).
It’s available at http://tinylink.com/?PW8AtdpF1E

I’ve even tried to add

set_bit(0, xpad->dev.evbit);
set_bit(EV_KEY, xpad->dev.evbit);
set_bit(EV_ABS, xpad->dev.evbit);

to the driver, reflecting the ioctl() calls but without success.

Thanks a lot.

Damiano

The hat problem with my joystick continues…

I’ve tried to play with the evdev.o and xpad.o module : when both are loaded
there’s a /dev/input/event0 that is created (in addition of the
/dev/input/js0). That means that the controller should work with the event
API !

You’re using devfs? Okay, what are the permissions on the created dev
files?

Exporting SDL_LINUX_JOYSTICK doesn’t work either : the buttons still work
but not the axes/hat (although obviously “well” detected in number) and
don’t respond.

This is now a certitude : SDL falls back to JS_ConfigJoystick (and so don’t
use the event based API) because of the ioctl() calls which fails in
EV_IsJoystick() – the 3 returns -1.
But why, I’ve no idea…

So the axes don’t even work when using jsdev, with evdev definitely not
loaded?

Does it work okay with jstest and evtest?

Could someone have a look in the xpad driver ? It is not a very complicated
driver but I don’t know at all what’s missing in the driver (if there is
something missing).
It’s available at http://tinylink.com/?PW8AtdpF1E

I’ll have a look but I’m not really a kernel hacker. Jsdev and evdev
are only interfaces to the input system so should both report axes.

I’ve even tried to add

set_bit(0, xpad->dev.evbit);
set_bit(EV_KEY, xpad->dev.evbit);
set_bit(EV_ABS, xpad->dev.evbit);

to the driver, reflecting the ioctl() calls but without success.

See above :-)On Sat, 2003-07-19 at 14:25, Damiano wrote:


Alan.

“One must never be purposelessnessnesslessness.”
-------------- next part --------------
A non-text attachment was scrubbed…
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20030719/014ad822/attachment.pgp

Hum… I’ve finally found where my problems came from : /dev/input/event0
was rw-rw---- and owned as root:root ! A little chmod o+r and everything was
detected correctly.
Apparently, as SDL didn’t have access to the event device, it fell back to
the old API.

Thanks a lot Alan, now Zsnes works nice :slight_smile: