Created
April 5, 2014 02:44
-
-
Save bossjones/9986828 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import argparse | |
import serial | |
import os | |
import sys | |
import time | |
import subprocess | |
def dummy_meth(a): | |
""" | |
>>> dummy_meth('a') | |
'a' | |
""" | |
return a | |
if __name__ == "__main__": | |
# commands | |
command_master_list = { | |
"frizzytv": { | |
"up": "1,77E1D009,32", | |
"down": "1,77E1B009,32", | |
"left": "1,77E11009,32", | |
"right": "1,77E1E009,32", | |
"menu": "1,77E1BA09,32", | |
"pause": "1,77E12009,32", | |
"play": "1,77E17A09,32", | |
"circle button": "1,77E1BA09,32" # this too 77E12009 | |
}, | |
"appletv": { | |
"up": "1,77E1D030,32", | |
"down": "1,77E1B030,32", | |
"left": "1,77E11030,32", | |
"right": "1,77E1E030,32", | |
"menu": "1,77E14030,32", | |
"pause": "1,77E17A30,32", | |
"play": "1,77E17A30,32", | |
"circle button": "1,77E1BA30,32" | |
}, | |
"toshiba": { | |
"channel up": "1,2FDD827,32", | |
"channel down": "1,2FDF807,32", | |
"volume up": "1,2FD58A7,32", | |
"volume down": "1,2FD7887,32", | |
"mute": "1,2FD08F7,32", | |
"recall": "1,2FD38C7,32", | |
"input": "1,2FDF00F,32", | |
"select up": "1,2FD41BE,32", | |
"select down": "1,2FDC13E,32", | |
"select left": "1,2FDB847,32", | |
"select right": "1,2FD9867,32", | |
"select enter": "1,2FD916E,32", | |
"one": "1,2FD807F,32", | |
"two": "1,2FD40BF,32", | |
"three": "1,2FDC03F,32", | |
"four": "1,2FD20DF,32", | |
"five": "1,2FDA05F,32", | |
"six": "1,2FD609F,32", | |
"seven": "1,2FDE01F,32", | |
"eight": "1,2FD10EF,32", | |
"nine": "1,2FD906F,32", | |
"zero": "1,2FD00FF,32", | |
"power": "1,2FD48B7,32" | |
} | |
} | |
device_names = [] | |
for key,values in command_master_list.iteritems(): | |
device_names.append(key) | |
parser = argparse.ArgumentParser("CLI tool to control arduino IR signals.") | |
parser.add_argument("--doctest", | |
action = 'store_true', | |
help = "perform doc tests") | |
parser.add_argument("-v","--verbose", | |
action = 'store_true', | |
help = "be verbose in all things, go with god") | |
parser.add_argument("-V","--version", | |
action = 'store_true', | |
help = "show version") | |
parser.add_argument("-d","--device", | |
action="store", | |
choices=device_names, | |
help = "set device to one of several ( eg. frizzyTV )") | |
parser.add_argument("-c","--command", | |
action="store", | |
help = "Set command") | |
parser.add_argument("-t","--test", | |
action="store_true", | |
help = "Run serial port test suite") | |
parser.add_argument("-p","--port", | |
action="store", | |
help = "Set the serial port") | |
parser.version = __version__ | |
args = parser.parse_args() | |
if args.version: | |
show_usage = False | |
if args.verbose: | |
print __cvs_id__ | |
else: | |
print parser.version | |
if args.verbose: | |
print "\n[Options]" | |
print args | |
port = args.port if args.port else "/dev/tty.usbmodem1411" | |
if args.test: | |
os.system("python -m serial.tools.list_ports") | |
if args.device: | |
device = args.device.lower() | |
if device in command_master_list.keys(): | |
if args.verbose: | |
print "\n[Device]" | |
print command_master_list[device] | |
if args.command: | |
command = args.command.lower() | |
if command in command_master_list[device].keys(): | |
hex = command_master_list[device][command].lower() | |
if args.verbose: | |
print "\n[Hex]" | |
print hex | |
# create arduino object and connect to default port | |
try: | |
arduino = serial.Serial(port, baudrate=9600, timeout=5) | |
except Exception, e: | |
sys.exit("************************\nNo arduino is attached.\n Please note you will not be able to control any IR devices without it.\n************************") | |
# wait two seconds for arduino to initialize connection | |
time.sleep(2) | |
print "\n[port]" | |
print port | |
arduino.write(hex) | |
# wait two seconds after writing to arduino via serial | |
time.sleep(2) | |
print 'Sent:', hex | |
#print "\n[readline]" | |
#print arduino.readline() | |
arduino.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment