Last active
November 19, 2017 00:45
-
-
Save WhiteMagic/e4d849cfb5e9ec2e52480ef7bf16f17d 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 math | |
import time | |
import gremlin | |
t16000 = gremlin.input_devices.JoystickDecorator( | |
"T.16000M", | |
72331530, | |
"Default" | |
) | |
g_last_axis_value = 0.0 | |
# Macros to send the throttle increase / decrease ccommands | |
increase = gremlin.macro.Macro() | |
increase.tap("-") | |
decrease = gremlin.macro.Macro() | |
decrease.tap("=") | |
@t16000.axis(4) | |
def fs2_throttle(event): | |
"""Sets the throttle to the desired value ensuring a consistent amount | |
of key presses are sent, i.e. one per 5% of change in an axis. | |
""" | |
global g_last_axis_value | |
cur_value = event.value | |
delta = cur_value - g_last_axis_value | |
count = math.floor(abs(delta) / 0.05) | |
action = increase if delta > 0 else decrease | |
if count > 0: | |
g_last_axis_value = cur_value | |
macro_manager = gremlin.macro.MacroManager() | |
for _ in range(count): | |
macro_manager.add_macro(action, None, event) | |
time.sleep(0.025) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment