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

Bunch of pictures (and updated blog software)

Sigh. If a PHP coder says "The complete upgrade path is automatted and can be performed with a single mouse click.", don't believe him. I just spent almost an hour on a Serendipity upgrade. Maybe it works well if you have a dumbass FTP CGI-exec webhost, but I miss the good old days without "user friendly" installer scripts, where installing a webapp was a matter of unpacking a tarball and feeding a database dump to MySQL. Stuff just worked without having to give the webserver write permissions pretty much everywhere.

But now, after the hackish s9y upgrade I lost the old theme, random plugins broke and I had to reinstall + reconfigure them (after resolving some more permission issues), and the best part must be that the upgrade script does absolutely no error checking. After tons of error messages it says "upgrade successful". Fortunately it's also dumb and didn't mark the upgrade as successful, so I could retry the upgrade after fixing permissions. One day I'll just figure out how to move all this stuff to Blogger. :-/

Anyway, I promised pictures. Lots of stuff is now on Don't have very fast hosting for it yet, but I'll work that out later. Hilights are the pictures of my first flight lesson, and also pictures of my cool model airplane. Bought it in April (after mostly trashing my Super Cub and leaving it behind in Beilen), and got some cool in-flight pictures. I also bought a 37g camera especially designed for attaching to these planes, so soon I'll be spying on people in the park and around here in Dublin. :-P

Some pretty hiking pictures from this year's Mountain View trip are also there: Big Sur (under Monterey), Rancho San Antonio (just under Mountain View/Sunnyvale). In other news, I'm flying to New York on the 24th. Not sure if I'll make any pictures there since probably everything there has been photographed to death already.