Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow movement with arrow keys #14

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions retaliation.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@
import json
import urllib2
import base64
import tty
import termios

import usb.core
import usb.util
Expand Down Expand Up @@ -170,13 +172,23 @@ def usage():
print " zero - park at zero position (bottom-left)"
print " pause - pause <value> milliseconds"
print " led - turn the led on or of (1 or 0)"
print " aim - control with the arrow keys, enter to fire"
print ""
print " <command_set_name> - run/test a defined COMMAND_SET"
print " e.g. run:"
print " retaliation.py 'chris'"
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
Expand Down Expand Up @@ -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

Expand Down