Created
November 5, 2019 18:44
-
-
Save WhiteMagic/ff636574b45a12480fd0bd6f1a92740e to your computer and use it in GitHub Desktop.
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 time | |
import gremlin | |
from gremlin.user_plugin import * | |
mode = ModeVariable("Mode", "The mode in which to use this mapping") | |
axis = PhysicalInputVariable( | |
"Input axis", | |
"Input axis", | |
[gremlin.common.InputType.JoystickAxis] | |
) | |
inc_out = VirtualInputVariable( | |
"Increment output button", | |
"Increment output button", | |
[gremlin.common.InputType.JoystickButton] | |
) | |
dec_out = VirtualInputVariable( | |
"Decrement output button", | |
"Decrement output button", | |
[gremlin.common.InputType.JoystickButton] | |
) | |
step_size = FloatVariable( | |
"Amount of change per step", | |
"Amount of change per step", | |
0.05, | |
0.0, | |
1.0 | |
) | |
# Decorators for the two physical axes | |
decorator = axis.create_decorator(mode.value) | |
# Storage for axis values | |
g_last_value = 0.0 | |
# Increment macro | |
inc_macro = gremlin.macro.Macro() | |
inc_macro.exclusive = True | |
inc_macro.add_action(gremlin.macro.VJoyAction( | |
inc_out.vjoy_id, | |
gremlin.common.InputType.JoystickButton, | |
inc_out.input_id, | |
True | |
)) | |
inc_macro.add_action(gremlin.macro.PauseAction(0.05)) | |
inc_macro.add_action(gremlin.macro.VJoyAction( | |
inc_out.vjoy_id, | |
gremlin.common.InputType.JoystickButton, | |
inc_out.input_id, | |
False | |
)) | |
# Decrement macro | |
dec_macro = gremlin.macro.Macro() | |
dec_macro.exclusive = True | |
dec_macro.add_action(gremlin.macro.VJoyAction( | |
dec_out.vjoy_id, | |
gremlin.common.InputType.JoystickButton, | |
dec_out.input_id, | |
True | |
)) | |
dec_macro.add_action(gremlin.macro.PauseAction(0.05)) | |
dec_macro.add_action(gremlin.macro.VJoyAction( | |
dec_out.vjoy_id, | |
gremlin.common.InputType.JoystickButton, | |
dec_out.input_id, | |
False | |
)) | |
@decorator.axis(axis.input_id) | |
def axis1(event, vjoy): | |
global g_last_value | |
delta = event.value - g_last_value | |
if abs(delta) > step_size.value: | |
g_last_value = event.value | |
if delta > 0: | |
gremlin.macro.MacroManager().queue_macro(inc_macro) | |
else: | |
gremlin.macro.MacroManager().queue_macro(dec_macro) |
You probably can use the ideas from this other module which implements a basic average filter https://gist.github.com/WhiteMagic/2a6d774afe35784f21f8ff2092cffa12
Thanks! I'll try
…On Wed, Mar 10, 2021 at 9:01 AM WhiteMagic ***@***.***> wrote:
***@***.**** commented on this gist.
------------------------------
You probably can use the ideas from this other module which implements a
basic average filter
https://gist.github.com/WhiteMagic/2a6d774afe35784f21f8ff2092cffa12
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<https://gist.github.com/ff636574b45a12480fd0bd6f1a92740e#gistcomment-3660501>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACBNJBQDWYYA3SXUIL2HZYLTC6QXJANCNFSM4Y35CTMA>
.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is there a way to take an average position of an axis over a period of time? I'm trying to eliminate jitter in an axis (without using a deadzone.