Skip to content

Commit

Permalink
Relative axis mode fixes
Browse files Browse the repository at this point in the history
- small deltas on vjoy axis entries result in no change
- early thread termination due to holding an axis input steady
  • Loading branch information
WhiteMagic committed Apr 6, 2019
1 parent 886d398 commit 2387f3e
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions action_plugins/remap/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,16 +207,19 @@ def __init__(self, action):

self.needs_auto_release = self._check_for_auto_release(action)
self.thread_running = False
self.should_stop_thread = False
self.thread_last_update = time.time()
self.thread = None
self.axis_delta_value = 0.0
self.axis_value = 0.0

def process_event(self, event, value):
if self.input_type == InputType.JoystickAxis:
if self.axis_mode == "absolute":
joystick_handling.VJoyProxy()[self.vjoy_device_id] \
.axis(self.vjoy_input_id).value = value.current
else:
self.should_stop_thread = abs(event.value) < 0.05
self.axis_delta_value = \
value.current * (self.axis_scaling / 1000.0)
self.thread_last_update = time.time()
Expand All @@ -228,8 +231,6 @@ def process_event(self, event, value):
)
self.thread.start()



elif self.input_type == InputType.JoystickButton:
if event.event_type in [InputType.JoystickButton, InputType.Keyboard] \
and event.is_pressed \
Expand All @@ -241,6 +242,7 @@ def process_event(self, event, value):

joystick_handling.VJoyProxy()[self.vjoy_device_id] \
.button(self.vjoy_input_id).is_pressed = value.current

elif self.input_type == InputType.JoystickHat:
joystick_handling.VJoyProxy()[self.vjoy_device_id] \
.hat(self.vjoy_input_id).direction = value.current
Expand All @@ -249,18 +251,22 @@ def process_event(self, event, value):

def relative_axis_thread(self):
self.thread_running = True
vjoy_dev = joystick_handling.VJoyProxy()[self.vjoy_device_id]
self.axis_value = vjoy_dev.axis(self.vjoy_input_id).value
while self.thread_running:
cur_value = joystick_handling.VJoyProxy()[self.vjoy_device_id].axis(
self.vjoy_input_id).value
joystick_handling.VJoyProxy()[self.vjoy_device_id].axis(
self.vjoy_input_id).value = max(
-1.0,
min(1.0, cur_value+self.axis_delta_value)
)
try:
self.axis_value = max(
-1.0,
min(1.0, self.axis_value + self.axis_delta_value)
)
vjoy_dev.axis(self.vjoy_input_id).value = self.axis_value

if self.thread_last_update + 1.0 < time.time():
if self.should_stop_thread and \
self.thread_last_update + 1.0 < time.time():
self.thread_running = False
time.sleep(0.01)
except gremlin.error.VJoyError:
self.thread_running = False
time.sleep(0.01)

def _check_for_auto_release(self, action):
activation_condition = None
Expand Down

0 comments on commit 2387f3e

Please sign in to comment.