Skip to content

uhat, using your joystick's hat switch in Linux flight simulators

So I have this fun hobby for a while already, flying.. I have around 50 hours logged by now in the US + Ireland, which means I can more or less land safely now, on my own. In fact I had my first solo in October last year which was an absolutely amazing experience. But sometimes weather just doesn't work with me here in Ireland (either too windy or too cloudy) and instead I go "flying" with X-Plane on my machine at home.

Now X-Plane is a pretty neat simulator, and as long as you use it with a real yoke/stick and not keyboard/mouse, it seems like a useful way to practice. But there's one way in which a flight simulation projected on a single screen, no matter its size, just doesn't beat sitting in a cockpit: the inability to look around in any direction by, you know, just turning your head. Instead, joysticks often have this hat switch on the top to look around. Unfortunately in Linux, the joystick driver gets told that the hat switch is a mini-joystick that the user can move up/down, left/right. Instead of just representing it as four separate buttons (which is what they really are anyway, hardware-wise). X-Plane and apparently other flight simulators can't use this, they need buttons.

This week I wrote uhat to solve this problem. It'll listen to joystick events and if you move the hat switch axes, it will generate button events on a separate virtual joystick device. There's a similar tool called jhat, which generates keyboard events instead, but I never really liked the idea of my joystick pretending to be a keyboard and hoped there were a better way to do this. A week ago I found my answer in uinput. It's poorly documented, but fortunately very simple to figure out. It looks like uinput is just a fairly 1:1 translation of the input subsystem kernel interface into a character device.

It works like a charm for me, with the udev rule I don't even have to think about it, udev will just start it for me when I plug in my joystick. Hugely enjoying X-Plane 10 again. :-D

Trackbacks

No Trackbacks

Comments

Display comments as Linear | Threaded

Rolf on :

You legend! Thanks for making things better for Linux users everywhere.

Wilmer on :

Cool, it's working well for you? Haven't had much feedback to this so far, so I'm happy to hear that!

DMZ on :

Hi Wilmer,

I have a ch products eclipse yoke and saitek rudder pedals. I'm running slackware linux 14.0 x64, and installed X-Plane 9 & 10.
In X-Plane 9, the yoke and pedals work flawlessly; but in X-Plane 10, they don't show up at all. Can you give me an example of or explain what you mean by the udev rule?

Thanks.

Also, if you would like to use your head to look around the cockpit without the joystick or keyboard, check out TrackIR 5 (http://www.naturalpoint.com)

Wilmer on :

The udev rules I'm talking about are just to make the hat switch work and are included in the uhat tarball.

The problem with recent versions of X-Plane 10 is that it uses raw input devices instead of joystick devices, and those aren't user-readable by default. It's a FAQ, see the X-Plane forums.

Add Comment