Skip to content

Instantly share code, notes, and snippets.

@WhiteMagic
Last active April 23, 2017 01:37
Show Gist options
  • Save WhiteMagic/488ac6bc2de02706d13a219d52e89b99 to your computer and use it in GitHub Desktop.
Save WhiteMagic/488ac6bc2de02706d13a219d52e89b99 to your computer and use it in GitHub Desktop.
import gremlin
# Device decorator
spacenavigator = gremlin.input_devices.JoystickDecorator(
"SpaceNavigator",
1828988614,
"Default"
)
# Store the last reported values of each axis for delta value computations
g_last_values = [0, 0, 0, 0, 0, 0, 0]
# Compute delta and set vjoy axis values
def process_event(axis_id, value, vjoy):
global g_last_values
delta = value - g_last_values[axis_id]
# If the delta is too large, due to overflow we simply ignore the event
if abs(delta) > 0.5:
return
# Limit the delta value to the range [-0.1, 0.1] as this is what the
# device seems to adhere to range wise
delta = min(0.1, max(-0.1, delta))
# Set the axis value, multiplying by 10 to get into the range [-1, 1]
# which is what normally is expected by Gremlin
vjoy[1].axis(axis_id).value = delta * 10.0
# Store the latest value for the next iteration
g_last_values[axis_id] = value
# Callbacks for the individual axis of the device
@spacenavigator.axis(1)
def axis1(event, vjoy):
process_event(1, event.value, vjoy)
@spacenavigator.axis(2)
def axis2(event, vjoy):
process_event(2, event.value, vjoy)
@spacenavigator.axis(3)
def axis3(event, vjoy):
process_event(3, event.value, vjoy)
@spacenavigator.axis(4)
def axis4(event, vjoy):
process_event(4, event.value, vjoy)
@spacenavigator.axis(5)
def axis5(event, vjoy):
process_event(5, event.value, vjoy)
@spacenavigator.axis(6)
def axis6(event, vjoy):
process_event(6, event.value, vjoy)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment