diff --git a/retaliation.py b/retaliation.py index 763c829..5d1712d 100755 --- a/retaliation.py +++ b/retaliation.py @@ -79,6 +79,8 @@ import json import urllib2 import base64 +import tty +import termios import usb.core import usb.util @@ -170,6 +172,7 @@ def usage(): print " zero - park at zero position (bottom-left)" print " pause - pause milliseconds" print " led - turn the led on or of (1 or 0)" + print " aim - control with the arrow keys, enter to fire" print "" print " - run/test a defined COMMAND_SET" print " e.g. run:" @@ -177,6 +180,15 @@ def usage(): print " to test targeting of chris as defined in your command set." print "" +def getchar(): + fd = sys.stdin.fileno() + old_settings = termios.tcgetattr(fd) + try: + tty.setraw(sys.stdin.fileno()) + ch = sys.stdin.read(1) + finally: + termios.tcsetattr(fd, termios.TCSADRAIN, old_settings) + return ch def setup_usb(): # Tested only with the Cheeky Dream Thunder @@ -254,6 +266,24 @@ def run_command(command, value): for i in range(value): send_cmd(FIRE) time.sleep(4.5) + elif command == "aim": + while True: + char = getchar() + if char == "A": + send_move(UP, 80) + elif char == "B": + send_move(DOWN, 80) + elif char == "D": + send_move(LEFT, 80) + elif char == "C": + send_move(RIGHT, 80) + elif char == chr(13): + send_cmd(FIRE) + time.sleep(4.5) + elif char == chr(4) or char == chr(3): + break + #else: + #print "got " + char + " hex " + '%02x' % ord(char) else: print "Error: Unknown command: '%s'" % command