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

Added ability to turn on/off LED. #9

Merged
merged 1 commit into from
Jan 17, 2013
Merged
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
10 changes: 10 additions & 0 deletions retaliation.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,11 @@
COMMAND_SETS = {
"will" : (
("zero", 0), # Zero/Park to know point (bottom-left)
("led", 1), # Turn the LED on
("right", 3250),
("up", 540),
("fire", 4), # Fire a full barrage of 4 missiles
("led", 0), # Turn the LED back off
("zero", 0), # Park after use for next time
),
"tom" : (
Expand Down Expand Up @@ -166,6 +168,7 @@ def usage():
print " fire - fire <value> times (between 1-4)"
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 ""
print " <command_set_name> - run/test a defined COMMAND_SET"
print " e.g. run:"
Expand Down Expand Up @@ -195,6 +198,8 @@ def setup_usb():
def send_cmd(cmd):
DEVICE.ctrl_transfer(0x21, 0x09, 0, 0, [0x02, cmd, 0x00,0x00,0x00,0x00,0x00,0x00])

def led(cmd):
DEVICE.ctrl_transfer(0x21, 0x09, 0, 0, [0x03, cmd, 0x00,0x00,0x00,0x00,0x00,0x00])

def send_move(cmd, duration_ms):
send_cmd(cmd)
Expand All @@ -218,6 +223,11 @@ def run_command(command, value):
send_move(LEFT, 8000)
elif command == "pause" or command == "sleep":
time.sleep(value / 1000.0)
elif command == "led":
if value == 0:
led(0x00)
else:
led(0x01)
elif command == "fire" or command == "shoot":
if value < 1 or value > 4:
value = 1
Expand Down