During the 1990s, as flight simulators began to gain popularity with PC gamers, several companies started producing dedicated flight simulation joysticks. One of the cool features of these sticks was the hat switch – a four direction digital mini joystick which was operated by the thumb (usually used to control the view direction). The problem faced in designing such a joystick was how to encode the hat positions given the shortage of pins in the standard 15 pin PC gameport. Essentially, the PC’s gameport has enough pins for two joysticks each with two axes and two buttons (pinout here). Many of these joysticks used three axes already (aileron, elevator and throttle), and all four buttons, which left very little to encode the hat on.
Reading the hat switch of a classic PC joysticks on a modern microprocessor/dev board such as the Teensy USB or Arduino is fairly easy – there are only two major solutions you need to support (depending on the type of stick you want to read).
Thrustmaster FCS method – encode the hat in the fourth axis
The Thrustmaster FCS was the first PC flight stick to include a hat switch.The Thrustmaster Top Gun stick works the same way (it is essentially a re-branded FCS).
Thrustmaster encodes the hat position on the second Y axis (pin 13 on the plug). Moving the hat switch in any direction sets a particular resistance which can be easily read on one of the analog pins of the Teensy USB or Arduino (use analogRead(), which will return a value from 0-1023). The following table defines buckets for each hat position (High and Low are the top and bottom values you can expect the pin 13 analogRead() to be):
CH Products Flightstick Pro method – encode the hat using button chords
The second method of encoding hat switch positions was defined by CH Products for their Flight Stick Pro. It was used by several other sticks, such as the Suncom F-15 SFS, and the Logitech Wingman Extreme.
In this design, moving the hat switch produces multiple button presses simultaneously (i.e. a chord). A side effect of this is that these joysticks do not support pressing more than one of the regular buttons together – doing so produces a ghosting effect where the lowest numbered button wins. For example, if you press buttons 1 and 3 simultaneously, only button 1 registers; and if you press buttons 2, 3 and 4 simultaneously, only button 2 registers. The following table shows the chords that are produced by pressing the hat switch in each direction (the absence of a defined chord means the hat is in the center position). You will need to intercept these chords to use in your project:
[…] « Reading hat switches on PC gameport joysticks […]