mirror of
https://github.com/dragonpilot/dragonpilot.git
synced 2026-07-09 06:52:05 +08:00
Joystick: learn axis min/max (#23377)
* Joystick: learn axis min/max * clean up updating max/min Co-authored-by: Willem Melching <willem.melching@gmail.com>
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user