Skip to content

Instantly share code, notes, and snippets.

@WhiteMagic
Created June 23, 2021 21:34
Show Gist options
  • Save WhiteMagic/812289cb98733d445a2f3c972951ca06 to your computer and use it in GitHub Desktop.
Save WhiteMagic/812289cb98733d445a2f3c972951ca06 to your computer and use it in GitHub Desktop.
import gremlin
from gremlin.user_plugin import *
# Plugin variables
mode = ModeVariable("Mode", "Mode in which to use these settings")
phys_axis1 = PhysicalInputVariable(
"First physical axis",
"First physical axis",
[gremlin.common.InputType.JoystickAxis]
)
phys_axis2 = PhysicalInputVariable(
"Second physical axis",
"Second physical axis",
[gremlin.common.InputType.JoystickAxis]
)
virt_axis = VirtualInputVariable(
"vJoy output",
"Virtual output axis",
[gremlin.common.InputType.JoystickAxis]
)
threshold = FloatVariable(
"Activity threshold",
"Value above which an axis is considered as being used",
0.0,
0.0,
1.0
)
# Decorators for the two physical axes
dec_1 = phys_axis1.create_decorator(mode.value)
dec_2 = phys_axis2.create_decorator(mode.value)
# State variables
g_active_index = -1
g_last_value = [0.0, 0.0]
def update_vjoy(vjoy, index, value):
global g_active_index
global g_last_value
if g_active_index != index:
delta = abs(value - g_last_value[index])
if delta > threshold.value:
g_active_index = index
if g_active_index == index:
vjoy[virt_axis.vjoy_id].axis(virt_axis.input_id).value = value
g_last_value[index] = value
@dec_1.axis(phys_axis1.input_id)
def axis1_cb(event, vjoy):
update_vjoy(vjoy, 0, event.value)
@dec_2.axis(phys_axis2.input_id)
def axis2_cb(event, vjoy):
update_vjoy(vjoy, 1, event.value)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment