From e1cb5bf30eb57f95554c33acb2848f17338ee5b4 Mon Sep 17 00:00:00 2001 From: Tim Date: Sun, 16 Feb 2014 08:19:27 +0000 Subject: [PATCH 1/2] allow movement with arrow keys --- retaliation.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/retaliation.py b/retaliation.py index 763c829..2fc4f68 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 @@ -177,6 +179,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 +265,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 From 3eaaeced07cc8ac3297ccb57881ae6ad3b3ebcae Mon Sep 17 00:00:00 2001 From: Tim Wright Date: Sat, 10 May 2014 13:21:08 +0100 Subject: [PATCH 2/2] update help --- retaliation.py | 1 + 1 file changed, 1 insertion(+) diff --git a/retaliation.py b/retaliation.py index 2fc4f68..5d1712d 100755 --- a/retaliation.py +++ b/retaliation.py @@ -172,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:"