Joysticks under linux

Hello,

Under linux, when using the ‘js’ devices, I get the number of analog
inputs reported correctly, however when I use the ‘event’ devices, hats
are ignored.

Searching through the sources I found they are explicitly ignored
(SDL_sysjoystick.c, lines 419 - 423)

Is there any reason for this?

This is true at least on SDL 1.2.6

Thanks!
Drirr

Searching through the sources I found they are explicitly ignored
(SDL_sysjoystick.c, lines 419 - 423)

We don’t handle hats in that loop, since it’s just to configure the
axes…we handle them in the loop right below it. (line 449, etc).

What joystick and interface (usb? gameport? serial?) and kernel are you
using? Are you sure the kernel is reporting them as hats and not axes
when using the event interface? Perhaps the kernel’s not reporting them
at all in that case?

It may be a bug in SDL, but it might not be in this instance, too.

–ryan.

Hi,

I’m using kernel 2.4.22 and an adapted xbox pad connected throgh USB
with a driver from the xbox-linux project, but I’m on a PC.

I did some more testing. It seems SDL does actually find them, it was
just I was expecting it to behave the same whether it was though a 'js’
or ‘event’ device and I thought hats went sometimes undetected, sorry.

When I load joydev, SDL reports 10 buttons and 14 axes, which is good
-but not ‘correct’-. However when I use evdev, I get 10 buttons, 6 axes
and 4 hats reported from SDL. Which is ‘correct’ in the sense that
that’s what the pad driver reports.

I prefer how SDL behaves when using the ‘js’ driver, because when the
hats (which physically are analog buttons) are reported as axes I can
get their abolute position, not just a bitfield of positions.

The reason the driver maps the buttons to hats, I guess, is the lack of
more meaningful identifiers (in linux/input.h)

Is there a way of having the same behavior through ‘js’ and 'event’
devices? Or, perhaps, is there a way to get the analog value of the hats
from within SDL?

Thanks
DrirrOn Fri, 2003-12-26 at 06:37, Ryan C. Gordon wrote:

Searching through the sources I found they are explicitly ignored
(SDL_sysjoystick.c, lines 419 - 423)

We don’t handle hats in that loop, since it’s just to configure the
axes…we handle them in the loop right below it. (line 449, etc).

What joystick and interface (usb? gameport? serial?) and kernel are you
using? Are you sure the kernel is reporting them as hats and not axes
when using the event interface? Perhaps the kernel’s not reporting them
at all in that case?

It may be a bug in SDL, but it might not be in this instance, too.

–ryan.

Is there a way of having the same behavior through ‘js’ and 'event’
devices? Or, perhaps, is there a way to get the analog value of the hats
from within SDL?

I don’t think we can fix this at the SDL level if the kernel is handing
us absolute values. Then again, I don’t know much about the kernel
interface, so there might be a way to coerce it to do so.

I would ask the linux-xbox crew to add a module option that lets you
make the hat look like a relative and not absolute axis, though.

–ryan.

I don’t think we can fix this at the SDL level if the kernel is handing
us absolute values. Then again, I don’t know much about the kernel
interface, so there might be a way to coerce it to do so.

For the kernel, hats and axes are the same thing, absolute analog
inputs. Tweaking SDL a bit by making it not treat hats differently while
using event queues, I can, at least in my case, have a uniform behavior
with event queues and js devices.

What is the advantage of not handling hats as analog inputs and
discarding the value? Why not just treat all absolute analog inputs as
axes?

DrirrOn Sat, 2003-12-27 at 09:34, Ryan C. Gordon wrote:

Ok, after not receiving a follow-up to my post I think I’ll just have to
live with the joystick hat handling as is, right? It’s just sometimes
I’d like to know the reasons behind design decisions which, IMHO, can be
improved. Of course, it is very likely I just missed something here.

Drirr.On Sat, 2003-12-27 at 12:01, Miston Drirr wrote:

On Sat, 2003-12-27 at 09:34, Ryan C. Gordon wrote:

I don’t think we can fix this at the SDL level if the kernel is handing
us absolute values. Then again, I don’t know much about the kernel
interface, so there might be a way to coerce it to do so.

For the kernel, hats and axes are the same thing, absolute analog
inputs. Tweaking SDL a bit by making it not treat hats differently while
using event queues, I can, at least in my case, have a uniform behavior
with event queues and js devices.

What is the advantage of not handling hats as analog inputs and
discarding the value? Why not just treat all absolute analog inputs as
axes?

Ok, after not receiving a follow-up to my post I think I’ll just have to
live with the joystick hat handling as is, right? It’s just sometimes
I’d like to know the reasons behind design decisions which, IMHO, can be
improved. Of course, it is very likely I just missed something here.

The design decision was made after noticing that several APIs treat hats
separately, and that games use hats in a different way from true analog
axes. The bug here is that your joystick isn’t handled consistently.

If you look at the code in SDL_sysjoystick.c, you’ll notice that the hats
are ignored in the first pass, and then a second pass is made to detect the
hats. Try enabling DEBUG_INPUT_EVENTS and see what is being printed.

See ya!
-Sam Lantinga, Software Engineer, Blizzard Entertainment

Hi,

I tried defining DEBUG_INPUT_EVENTS, and indeed, they get recognised and
treated like hats.

It’s just there’s no way under SDL to get the absolute position of hats,
if available.

If I do a patch to allow the user to choose whether to map hats to axes,
would it be welcome?

For OSes where the analog value is availabe, it would behave like a
regular analog axis. For the rest it would return -32768, 0 or 32768.

Perhaps through a function like: void SDL_JoystickRemapHats(int do_map);
or a flag to SDL_Init. Of course, it would default to the present
behavior if nothing is specified.

DrirrOn Sat, 2004-01-03 at 02:49, Sam Lantinga wrote:

Ok, after not receiving a follow-up to my post I think I’ll just have to
live with the joystick hat handling as is, right? It’s just sometimes
I’d like to know the reasons behind design decisions which, IMHO, can be
improved. Of course, it is very likely I just missed something here.

The design decision was made after noticing that several APIs treat hats
separately, and that games use hats in a different way from true analog
axes. The bug here is that your joystick isn’t handled consistently.

If you look at the code in SDL_sysjoystick.c, you’ll notice that the hats
are ignored in the first pass, and then a second pass is made to detect the
hats. Try enabling DEBUG_INPUT_EVENTS and see what is being printed.

It’s just there’s no way under SDL to get the absolute position of hats,
if available.

If you are using Linux (and the subject line is a bit of a giveaway)
with joydev and not evdev then you can just the environment variable;

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

Which would remap the hat on the Wingman to an axis.

It’s just there’s no way under SDL to get the absolute position of
hats,

Not a solution for evdev, but how many joystick hats actually return
full useful analog hat information? Well, except yours :-)On Mon, 2004-01-05 at 14:39, Miston Drirr wrote:


Alan.

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

Hi,

Well, I really have no idea if any other joystick out there returns any
useful analog hat info. But certainly under linux the kernel can handle
it and at least in this particualr case, the joystick and the driver
too, it’s only SDL which doesn’t. The kernel actually has many other
analog inputs besides hats and axes (rudder, throttle, wheel, gas,
brake, pressure, etc…) I don’t know whether any driver actually use
them though, but SDL would treat them already as axes.

What I’m proposing is optionally handling hats as axes, and not
discarding the analog value. I’m pretty sure this can be done without
breaking backward compatibility.

DrirrOn Mon, 2004-01-05 at 21:10, Alan Swanson wrote:

On Mon, 2004-01-05 at 14:39, Miston Drirr wrote:

It’s just there’s no way under SDL to get the absolute position of hats,
if available.

If you are using Linux (and the subject line is a bit of a giveaway)
with joydev and not evdev then you can just the environment variable;

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

Which would remap the hat on the Wingman to an axis.

It’s just there’s no way under SDL to get the absolute position of
hats,

Not a solution for evdev, but how many joystick hats actually return
full useful analog hat information? Well, except yours :slight_smile: