Created
October 30, 2018 10:09
-
-
Save WhiteMagic/d5958cdbcb86c98e0764e5dc96e52f11 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 gremlin | |
| import math | |
| device = gremlin.input_devices.JoystickDecorator( | |
| "T.16000M", | |
| 72331530, | |
| "Default" | |
| ) | |
| # Physical axis settings | |
| x_axis_id = 1 | |
| y_axis_id = 2 | |
| # vJoy output settings | |
| vjoy_device_id = 1 | |
| vjoy_x_axis_id = 1 | |
| vjoy_y_axis_id = 2 | |
| # Deadzone values in [0, 1] | |
| deadzone_inner = 0.1 | |
| deadzone_outer = 0.9 | |
| # Storage of last known axis value | |
| x_axis_value = 0.0 | |
| y_axis_value = 0.0 | |
| def unit_direction(): | |
| length = math.sqrt(x_axis_value**2 + y_axis_value**2) | |
| return (x_axis_value / length, y_axis_value / length) | |
| def update_vjoy(vjoy): | |
| radius = math.sqrt(x_axis_value**2 + y_axis_value**2) | |
| radius = min(max(deadzone_inner, radius), deadzone_outer) | |
| ratio = (radius - deadzone_inner) / (deadzone_outer - deadzone_inner) | |
| direction = unit_direction() | |
| vjoy[vjoy_device_id].axis(vjoy_x_axis_id).value = direction[0] * ratio | |
| vjoy[vjoy_device_id].axis(vjoy_y_axis_id).value = direction[1] * ratio | |
| @device.axis(x_axis_id) | |
| def x_axis(event, vjoy): | |
| global x_axis_value | |
| x_axis_value = event.value | |
| update_vjoy(vjoy) | |
| @device.axis(y_axis_id) | |
| def y_axis(event, vjoy): | |
| global y_axis_value | |
| y_axis_value = event.value | |
| update_vjoy(vjoy) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment