Last active
February 17, 2019 01:32
-
-
Save WhiteMagic/801631977c9bab278da587974386ccb8 to your computer and use it in GitHub Desktop.
Merge two axis
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import gremlin | |
# ---------- Edit between here ----------------------------- | |
# Definition of the first device | |
device_1 = gremlin.input_devices.JoystickDecorator( | |
"Joystick - HOTAS Warthog", | |
gremlin.common.DeviceIdentifier((72287234, 1) | |
"Default" | |
) | |
# Definition of the second device | |
device_2 = gremlin.input_devices.JoystickDecorator( | |
"T.16000M", | |
gremlin.common.DeviceIdentifier(72331530, 2) | |
"Default" | |
) | |
# ---------- and here -------------------------------------- | |
def sum_merge_axis(vjoy): | |
"""Merges two axis values by summing their values together. | |
The vJoy axis is set to A + B where A and B are the axis values of the | |
two devices. | |
:param vjoy the vjoy instance to use | |
""" | |
vjoy[1].axis(vjoy_axis_id).value = gremlin.util.clamp( | |
device_1_last_value + device_2_last_value, | |
-1.0, | |
1.0 | |
) | |
def max_merge_axis(vjoy): | |
"""Merges two axis values by using the maximum value of the two. | |
The vJoy axis is set to max(|A|, |B|) where A and B are the axis values of the | |
two devices and |A| and |B| are the absolute values of A and B respectively. | |
:param vjoy the vjoy instance to use | |
""" | |
value = device_1_last_value | |
if abs(device_2_last_value) > abs(device_1_last_value): | |
value = device_2_last_value | |
vjoy[1].axis(vjoy_axis_id).value = value | |
# ---------- Edit between here ----------------------------- | |
# ID of the first device's axis | |
device_1_axis_id = 1 | |
# ID of the second device's axis | |
device_2_axis_id = 1 | |
vjoy_axis_id = 1 | |
# Merge function to use, either sum_merge_axis or max_merge_axis | |
merge_axis = sum_merge_axis | |
# ---------- and here -------------------------------------- | |
# Storage for the current axis values | |
device_1_last_value = 0.0 | |
device_2_last_value = 0.0 | |
@device_1.axis(device_1_axis_id) | |
def device_1_axis(event, vjoy): | |
"""Callback for the first device.""" | |
global device_1_last_value | |
device_1_last_value = event.value | |
merge_axis(vjoy) | |
@device_2.axis(device_2_axis_id) | |
def device_2_axis(event, vjoy): | |
"""Callback for the second device.""" | |
global device_2_last_value | |
device_2_last_value = event.value | |
merge_axis(vjoy) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment