|
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) |
|
|