2012-01-02 23:46:50 +00:00
|
|
|
#
|
|
|
|
# allows you to control the roketlauncher via the rem0te l0dable
|
|
|
|
# documented this in the wiki:
|
|
|
|
# - http://r0ket.badge.events.ccc.de/r0ketlauncher#launch0r
|
|
|
|
#
|
|
|
|
import r0ketrem0te.game
|
2011-12-28 12:08:28 +00:00
|
|
|
import time
|
2012-01-02 23:46:50 +00:00
|
|
|
import hid
|
|
|
|
|
|
|
|
class Launch0r:
|
|
|
|
def __init__(self):
|
|
|
|
self.rem0te = r0ketrem0te.game.Game('/dev/cu.usbmodem411', "Launch0r", 83, 87, [ord(x) for x in 'REM0T'], 1, False)
|
2011-12-28 12:08:28 +00:00
|
|
|
self.rem0te.registerPlayerCallback(self.playercallback)
|
2012-01-02 23:46:50 +00:00
|
|
|
self.player = Rem0tePlayer(self.rem0te)
|
|
|
|
|
2011-12-28 12:08:28 +00:00
|
|
|
def playercallback(self, action, player):
|
2012-01-02 23:46:50 +00:00
|
|
|
if action == 'added':
|
|
|
|
if self.player == None:
|
|
|
|
self.player.player = player
|
|
|
|
elif action == 'removed':
|
2011-12-28 12:08:28 +00:00
|
|
|
self.player = None
|
2012-01-02 23:46:50 +00:00
|
|
|
|
|
|
|
def run(self):
|
2011-12-28 12:08:28 +00:00
|
|
|
self.player.launcher = hid.device(0x0a81, 0x0701)
|
2012-01-02 23:46:50 +00:00
|
|
|
self.player.launcher.set_nonblocking(1)
|
2011-12-28 12:08:28 +00:00
|
|
|
|
2012-01-02 23:46:50 +00:00
|
|
|
class Rem0tePlayer(object):
|
|
|
|
def __init__(self, rem0te):
|
|
|
|
self.rem0te = rem0te
|
|
|
|
self.rem0te.bridge.registerCallback(self.receivedPacket)
|
2011-12-28 12:08:28 +00:00
|
|
|
self.player = None
|
2012-01-02 23:46:50 +00:00
|
|
|
self.launcher = None
|
|
|
|
|
2011-12-28 12:08:28 +00:00
|
|
|
def receivedPacket(self, packet):
|
|
|
|
if packet.button == 0:#off
|
|
|
|
self.launcher.write([0x20, 0, 0])
|
|
|
|
if packet.button == 4:#left
|
|
|
|
self.launcher.write([0x04, 0, 0])
|
2012-01-02 23:46:50 +00:00
|
|
|
if packet.button == 8:#right
|
2011-12-28 12:08:28 +00:00
|
|
|
self.launcher.write([0x08, 0, 0])
|
2012-01-02 23:46:50 +00:00
|
|
|
if packet.button == 1:#up
|
2011-12-28 12:08:28 +00:00
|
|
|
self.launcher.write([0x02, 0, 0])
|
2012-01-02 23:46:50 +00:00
|
|
|
if packet.button == 2:#down
|
2011-12-28 12:08:28 +00:00
|
|
|
self.launcher.write([0x01, 0, 0])
|
2012-01-02 23:46:50 +00:00
|
|
|
if packet.button == 16:#fire
|
2011-12-28 12:08:28 +00:00
|
|
|
self.launcher.write([0x10, 0, 0])
|
2012-01-02 23:46:50 +00:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
launch0r = Launch0r()
|
|
|
|
launch0r.run()
|