Linux Joysticks and Gamepads

From Elite Wiki
Revision as of 05:25, 14 July 2025 by Mcarans (talk | contribs)
PS3 Controller.jpeg

Overview

Generally speaking, Linux is quite good with joystick and gamepad detection and support, but sometimes things can go wrong. Failing to detect a joystick at all is fairly uncommon, and most reported problems revolve around button detection/assignment, and/or axis range. This article provides information on setting up game controllers so that they work well in Oolite Linux.

Calibrating a Joystick or Gamepad

Although Oolite provides options to set up dead zones, a full calibration within the game is not possible. The best way to calibrate game controllers on Linux is using a utility such as [jstest-gtk] which will probably be present in your distribution's Software Manager. Launch the jstest-gtk gui (it will probably be located in the System Menu) and, underneath the name of your joystick, it will list the device details, such as "Device:/dev/input/js0". Keep a record of this device information.

After calibrating and before closing the gui, execute the following command to store the calibration information:

sudo jscal-store /dev/input/js0

Ensure you use the device information you recorded earlier.

Button Detection & Axis Range Problems

For unknown reasons, it appears that sometimes SDL (Simple DirectMedia Layer) (which is used by Oolite) takes raw input from the evdev device drivers, instead of using the correct joystick device. If this happens, then the calibration will be ignored. By adding the appropriate environment variable to either the /etc/environment file, or the .bashrc startup script, you can force SDL to use the "real" joystick driver for input.

Officially speaking, /etc/environment is the correct place for system-wide environment variables. To add the environment variable to the /etc/environment file, as root, open /etc/environment in your text editor, add the following (on a new line) to the file, and save:

SDL_JOYSTICK_DEVICE="/dev/input/js0"

Again, use the device information you recorded earlier.

For the change to 'take', you then need to log out and back in again. Rebooting is unnecessary.

If you prefer changing the .bashrc startup script instead, you should add the above line to .bashrc in your Home folder. As the dot in front of the filename indicates, this is a hidden file, so you may need to set the view in your file browser to "Show Hidden Files" before it will become visible. Once done, save the file and log out, then back in.

Using Saved Calibration

The calibration will be forgotten after rebooting, so to ensure the saved calibration is used, make a bash script called for example run_oolite with:

#!/bin/bash
jscal-restore /dev/input/js0
cd ${1%/*}
$1

Make that script executable and then you can run Oolite assuming run_oolite"" is in your path, using:

run_oolite PATH_TO_OOLITE

PATH_TO_OOLITE can be something like /home/USERNAME/GNUstep/Applications/Oolite/oolite

If you are using the [Oolite Starter] then replace PATH_TO_OOLITE with PATH_TO_OOLITE_STARTER (which may look something like: /opt/oolitestarter-innocuous/bin/OoliteStarter_innocuous)

Mapping Axes and Buttons to Keyboard Key Presses

Sometimes it is desirable to have an axis act more like a keyboard key press, for example to increase and decrease speed. This can be achieved with the utility [AntiMicroX], a graphical program used to map gamepad keys to keyboard, mouse, scripts and macros. More information on keyboard controls can be found [here]. Once you have set up AntiMicroX the way you want, you can use your configuration by modifying the run_oolite script described earlier:

#!/bin/bash
jscal-restore /dev/input/js0
antimicrox --tray &
cd ${1%/*}
$1

Other problems

Should you require further guidance in creating or editing the above files, or the methods given above fail to resolve, or don't address your particular problem, please don't hesitate to post a thread detailing the issue, and your attempts to fix it, to the Oolite-Linux forum. The forum has several Linux gurus available, who would be more than happy to assist.

Links