Created
February 15, 2022 12:33
-
-
Save Ryuk47/ca5549c97f110e0cd01c973406190031 to your computer and use it in GitHub Desktop.
Moving Deadzone Filter Plugin for Joystick Gremlin
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 | |
from gremlin.user_plugin import * | |
mode = ModeVariable("Mode", "The mode in which to use this mapping") | |
virtual_axis = VirtualInputVariable( | |
"Virtual output axis", | |
"The vJoy axis to send the filtered output to.", | |
[gremlin.common.InputType.JoystickAxis] | |
) | |
physical_axis = PhysicalInputVariable( | |
"Physical input axis", | |
"The physical input axis being filtered.", | |
[gremlin.common.InputType.JoystickAxis] | |
) | |
deadzone = IntegerVariable( | |
"Deadzone size", | |
"Size of the deadzone around the cached value.", | |
5, | |
0, | |
100 | |
) | |
# Decorator for the physical axis | |
dec_physical_axis = physical_axis.create_decorator(mode.value) | |
# Global variables | |
# The cached physical input | |
g_cached_value = 0.0 | |
# The current input | |
g_current_value = 0.0 | |
g_vjoy = gremlin.joystick_handling.VJoyProxy() | |
def apply_deadzone(): | |
global g_current_value, g_cached_value | |
if(abs(g_current_value - g_cached_value) > deadzone.value/100): | |
g_cached_value = g_current_value | |
return g_cached_value | |
def update_vjoy(): | |
global g_vjoy | |
g_vjoy[virtual_axis.vjoy_id].axis(virtual_axis.input_id).value = apply_deadzone() | |
@dec_physical_axis.axis(physical_axis.input_id) | |
def axis_cb(event): | |
global g_current_value | |
g_current_value = event.value | |
update_vjoy() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For users experiencing ghosting/fluctuating/spinking/noisy axis inputs (as for example prevalent with the rotaries on the Saitek/Logitech X55/X56), this Joystick Gremlin user plugin implements a moving deadzone around the last input value of the filtered axis.
To use, add this plugin to Joystick Gremlin and create an instance of this plugin for any troubling input axis. Pay attention to NOT also remap the to be filteres axes to a virtual one, else the plugin will not work. To confirm the plugin working, set a high deadzone, enable Gremlin and observe the difference in axis inputs between the physical and virtual devices you configured.
For general Joystick Gremlin related questions and issues, please refer to the above linked repository.