chickenhouse/engine_test.py

51 lines
1.1 KiB
Python
Raw Normal View History

2016-03-20 17:16:20 +00:00
#!/usr/bin/python2
from engine import engine
2016-04-07 04:50:41 +00:00
from power_sensor import power_sensor
from time import sleep, time
from datetime import datetime
from getopt import getopt
from sys import argv
2016-03-20 17:16:20 +00:00
eng = engine(13, 19)
2016-04-07 04:50:41 +00:00
ps = power_sensor(1, 0x40)
2016-03-20 17:16:20 +00:00
2016-04-07 04:50:41 +00:00
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:])