Skip to content

Instantly share code, notes, and snippets.

@shteou
Created March 23, 2025 00:23
Show Gist options
  • Select an option

  • Save shteou/54092bc042843d7efa1964b2b3d8ae1b to your computer and use it in GitHub Desktop.

Select an option

Save shteou/54092bc042843d7efa1964b2b3d8ae1b to your computer and use it in GitHub Desktop.
Stew's script to work around his broken y axis
from evdev import ecodes, uinput, AbsInfo, InputDevice
# This script works around a broken y axis for my Thrustmaster Cougar throttle.
# The y axis reads off center, this works around it by scaling the reported value around an offset
# It's not perfect, but it makes the joystick usable at least.
# The script works by grabbing exclusive access to the real device and proxying its events
# to a new virtual device, applying value fixes to the appropriate events
# The ID of my broken 20 year old Thrustmaster Cougar
input_device = InputDevice('/dev/input/by-id/usb-Thrustmaster_Thrustmaster_HOTAS_Cougar-event-joystick')
# Take exclusive access of the input
input_device.grab()
# TODO: Copy vendor info and give a better name
output_device = uinput.UInput.from_device(input_device)
# Account for the y axis offset which reads ~47830 when centered
def fix_dodgy_y_axis(value: int) -> int:
if not (0 <= value <= 65536):
raise ValueError("Input must be between 0 and 65536")
return int(value / 47830 * 32768) if value <= 47830 else int(32768 + (value - 47831) / (65536 - 47831) * 32768)
# Proxy every event
for event in input_device.read_loop():
# Handle ABS events produced by joystick axes
if event.type == ecodes.EV_ABS:
# Fix my dodgy y axis
if event.code == ecodes.ABS_Y:
event.value = fix_dodgy_y_axis(event.value)
output_device.write_event(event)
output_device.syn()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment