Skip to content

Instantly share code, notes, and snippets.

@WhiteMagic
Created May 22, 2018 11:43
Show Gist options
  • Save WhiteMagic/c3928f421ad363f1b5f935c544126660 to your computer and use it in GitHub Desktop.
Save WhiteMagic/c3928f421ad363f1b5f935c544126660 to your computer and use it in GitHub Desktop.
import gremlin
device1 = gremlin.input_devices.JoystickDecorator(
"T.16000M",
72331530,
"Default"
)
device2 = gremlin.input_devices.JoystickDecorator(
"Joystick - HOTAS Warthog",
72287234,
"Default"
)
# Axis index of the two physical sticks
d1_axis_id = 1
d2_axis_id = 2
# vJoy axis definition
vjoy_device_id = 1
vjoy_axis_id = 1
# Storage for the physical axis values, these values are between -1 and 1
d1_axis_value = 0.0
d2_axis_value = 0.0
def update_vjoy(vjoy):
"""Updates the vJoy device with the sum of the two axis.
This ensures that the sum gets clamped between -1 and 1 as any value
outside that range is invalid.
:param vjoy vjoy device to use when setting the values
"""
vjoy[vjoy_device_id].axis(vjoy_axis_id).value = \
gremlin.util.clamp(d1_axis_value + d2_axis_value, -1.0, 1.0)
@device1.axis(d1_axis_id)
def d1_change(event, vjoy):
"""Stores the value of the first device's physical axis.
:param event joystick axis event
:param vjoy vjoy device handle
"""
global d1_axis_value
d1_axis_value = event.value
update_vjoy(vjoy)
@device2.axis(d2_axis_id)
def d2_change(event, vjoy):
"""Stores the value of the second device's physical axis.
:param event joystick axis event
:param vjoy vjoy device handle
"""
global d2_axis_value
d2_axis_value = event.value
update_vjoy(vjoy)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment