diff --git a/tools/joystick/joystickd.py b/tools/joystick/joystickd.py index ba7b29df54..0e3269556a 100755 --- a/tools/joystick/joystickd.py +++ b/tools/joystick/joystickd.py @@ -34,7 +34,8 @@ class Keyboard: class Joystick: def __init__(self): - self.max_axis_value = 255 # tune based on your joystick, 0 to this + self.min_axis_value = 0 + self.max_axis_value = 255 self.cancel_button = 'BTN_TRIGGER' self.axes_values = {'ABS_Y': 0., 'ABS_RZ': 0.} # gb, steer @@ -45,7 +46,10 @@ class Joystick: if event[0] == self.cancel_button and event[1] == 0: # state 0 is falling edge self.cancel = True elif event[0] in self.axes_values: - norm = -interp(event[1], [0, self.max_axis_value], [-1., 1.]) + self.max_axis_value = max(event[1], self.max_axis_value) + self.min_axis_value = min(event[1], self.min_axis_value) + + norm = -interp(event[1], [self.min_axis_value, self.max_axis_value], [-1., 1.]) self.axes_values[event[0]] = norm if abs(norm) > 0.05 else 0. # center can be noisy, deadzone of 5% else: return False