Skip to content

Instantly share code, notes, and snippets.

@WhiteMagic
Created June 10, 2017 13:55
Show Gist options
  • Select an option

  • Save WhiteMagic/3e6efc06dd3321fcbb66868f687734d8 to your computer and use it in GitHub Desktop.

Select an option

Save WhiteMagic/3e6efc06dd3321fcbb66868f687734d8 to your computer and use it in GitHub Desktop.
import threading
import time
import gremlin
# Joystick decorator
t16000 = gremlin.input_devices.JoystickDecorator(
"T.16000M",
72331530,
"Default"
)
g_axis_increment = 0.0
g_axis_value = 0.0
g_axis_thread = None
def change_axis_value(vjoy):
global g_axis_increment, g_axis_value
while g_axis_increment is not None:
g_axis_value += g_axis_increment
if g_axis_value >= 1.0:
g_axis_value = 1.0
g_axis_increment = None
elif g_axis_value <= -1.0:
g_axis_value = -1.0
g_axis_increment = None
vjoy[1].axis(1).value = g_axis_value
gremlin.util.log(str(g_axis_value))
time.sleep(0.1)
@t16000.axis(2)
def axis2(event, vjoy):
global g_axis_increment, g_axis_thread, g_axis_value
dead_zone = 0.05
increment = 0.05
if abs(event.value) > dead_zone:
g_axis_increment = increment if event.value > 0 else -increment
if not g_axis_thread or not g_axis_thread.is_alive():
g_axis_thread = threading.Thread(target=lambda: change_axis_value(vjoy))
g_axis_thread.start()
else:
g_axis_increment = None
if g_axis_thread and g_axis_thread.is_alive():
g_axis_thread.join()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment