#!/usr/bin/python2 from engine import engine from power_sensor import power_sensor from time import sleep, time from datetime import datetime from getopt import getopt from sys import argv eng = engine(13, 19) ps = power_sensor(1, 0x40) def run_engine(direction): if direction in ("u", "up"): eng.run_up() elif direction in ("d", "down"): eng.run_down() else: return log = open("power.log", "w") try: while True: power = ps.power_mw() ts = datetime.fromtimestamp(time()).microsecond log.write(str(ts) + " ms " + str(power) + " mW") log.write(str(ts) + " ms " + str(power) + " mW") log.write(str(ts) + " ms " + str(power) + " mW") print str(ts) + " ms " + str(power) + " mW" except KeyboardInterrupt: eng.stop() log.close() def print_help(): print "help screen..." def main(argv): dir_list = ["u", "up", "d", "down"] options, remainder = getopt(argv, "hd:", ["help", "direction="]) for opt, args in options: if opt in ("-h", "--help"): print_help() elif opt in ("-d", "--direction"): if args in dir_list: run_engine(args) else: print_help() if __name__ == "__main__": main(argv[1:])