Skip to content

Instantly share code, notes, and snippets.

@Cleric-K
Last active March 12, 2018 20:29
Show Gist options
  • Save Cleric-K/3e3000f715976b02044178cdca780240 to your computer and use it in GitHub Desktop.
Save Cleric-K/3e3000f715976b02044178cdca780240 to your computer and use it in GitHub Desktop.
import msp, uinput, sys, time
if len(sys.argv) != 2:
print('Usage: {} SERIAL_DEVICE'.format(sys.argv[0]))
sys.exit(1)
m = msp.MultiWii(sys.argv[1])
m.ser.timeout = 100
events = (
uinput.BTN_JOYSTICK,
uinput.ABS_X + (-32767, 32767, 0, 0),
uinput.ABS_Y + (-32767, 32767, 0, 0),
uinput.ABS_Z + (-32767, 32767, 0, 0),
uinput.ABS_RX + (-32767, 32767, 0, 0),
)
with uinput.Device(events) as device:
print("working ...")
while True:
state = m.getData(m.RC)
print(state)
if state:
device.emit(uinput.ABS_X, (state['roll']-1500)*32767/500, syn=False)
device.emit(uinput.ABS_Y, (state['pitch']-1500)*32767/500, syn=False)
device.emit(uinput.ABS_Z, (state['throttle']-1500)*32767/500, syn=False)
device.emit(uinput.ABS_RX , (state['yaw']-1500)*32767/500)
import msp, uinput, sys, time
if len(sys.argv) != 2:
print('Usage: {} SERIAL_DEVICE'.format(sys.argv[0]))
sys.exit(1)
m = msp.MultiWii(sys.argv[1])
m.ser.timeout = 100
events = (
#uinput.BTN_JOYSTICK,
uinput.ABS_X + (-32767, 32767, 0, 0),
uinput.ABS_Y + (-32767, 32767, 0, 0),
uinput.ABS_THROTTLE + (-32767, 32767, 0, 0),
uinput.ABS_RUDDER + (-32767, 32767, 0, 0),
)
with uinput.Device(events) as device:
print("working ...")
while True:
state = m.getData(m.RC)
if state:
device.emit(uinput.ABS_X, (state['roll']-1500)*32767/500, syn=False)
device.emit(uinput.ABS_Y, (state['pitch']-1500)*32767/500, syn=False)
device.emit(uinput.ABS_THROTTLE, (state['throttle']-1500)*32767/500, syn=False)
device.emit(uinput.ABS_RUDDER, (state['yaw']-1500)*32767/500)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment