Skip to content

Instantly share code, notes, and snippets.

@WhiteMagic
Created October 9, 2020 23:53
Show Gist options
  • Save WhiteMagic/377bd4d06d6a17edbcb03f0eadfe59b8 to your computer and use it in GitHub Desktop.
Save WhiteMagic/377bd4d06d6a17edbcb03f0eadfe59b8 to your computer and use it in GitHub Desktop.
Stepped trim control
import gremlin
from gremlin.user_plugin import *
mode = ModeVariable("Mode", "The mode in which to use this mapping")
vjoy_axis = VirtualInputVariable(
"Virtual output axis",
"The vJoy axis to apply trim settings to.",
[gremlin.common.InputType.JoystickAxis]
)
joy_axis = PhysicalInputVariable(
"Physical input axis",
"The physical input axis being trimmed",
[gremlin.common.InputType.JoystickAxis]
)
trim_dec = PhysicalInputVariable(
"Decrease trim",
"Button to decrease trim with",
[gremlin.common.InputType.JoystickButton]
)
trim_inc = PhysicalInputVariable(
"Increase trim",
"Button to increase trim with",
[gremlin.common.InputType.JoystickButton]
)
btn_reset = PhysicalInputVariable(
"Reset trim",
"Button to reset the trim setting",
[gremlin.common.InputType.JoystickButton]
)
step_size = FloatVariable(
"Amount of change per step",
"Amount of change per step",
0.05,
0.0,
1.0
)
# Current trim value applied to X and Y axis
g_trim_offset = 0.0
# Decorators
d_decrement = trim_dec.create_decorator(mode.value)
d_increment = trim_inc.create_decorator(mode.value)
d_reset = btn_reset.create_decorator(mode.value)
d_axis = joy_axis.create_decorator(mode.value)
def update_axis(vjoy, joy):
joy_value = joy[joy_axis.device_guid].axis(joy_axis.input_id).value
vjoy[vjoy_axis.vjoy_id].axis(vjoy_axis.input_id).value = joy_value + g_trim_offset
@d_reset.button(btn_reset.input_id)
def reset(event, vjoy, joy):
if event.is_pressed:
global g_trim_offset
g_trim_offset = 0
update_axis(vjoy, joy)
@d_decrement.button(trim_dec.input_id)
def decrement_trim(event, vjoy, joy):
if event.is_pressed:
global g_trim_offset
g_trim_offset = max(g_trim_offset - step_size.value, -1.0)
update_axis(vjoy, joy)
@d_increment.button(trim_inc.input_id)
def decrement_trim(event, vjoy, joy):
if event.is_pressed:
global g_trim_offset
g_trim_offset = min(g_trim_offset + step_size.value, 1.0)
update_axis(vjoy, joy)
@d_axis.axis(joy_axis.input_id)
def remap_axis(event, vjoy):
vjoy[vjoy_axis.vjoy_id].axis(vjoy_axis.input_id).value = event.value + g_trim_offset
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment