2016-12-23 12:06:02 +00:00
|
|
|
'''
|
|
|
|
Created on Dec 23, 2016
|
|
|
|
|
|
|
|
@author: klaehn
|
|
|
|
'''
|
|
|
|
import sys
|
2016-12-23 12:18:28 +00:00
|
|
|
from time import sleep
|
2017-01-07 12:23:28 +00:00
|
|
|
from datetime import datetime as dt
|
2016-12-23 12:06:02 +00:00
|
|
|
|
|
|
|
from data_buffer import DataBuffer
|
|
|
|
from gate.gate_handler import GateHandler
|
|
|
|
from power_sensor import PowerSensor
|
|
|
|
|
|
|
|
POWER_SENSOR_I2C_BUS = 1
|
|
|
|
POWER_SENSOR_I2C_ADDRESS = 0x40
|
|
|
|
|
|
|
|
CONSECUTIVE_POWER_READS = 1000
|
|
|
|
|
|
|
|
MAX_ENGINE_POWER = {"up":330, "down":290}
|
|
|
|
|
|
|
|
def main(argv):
|
|
|
|
gate_handler = GateHandler()
|
|
|
|
power_sensor = PowerSensor(POWER_SENSOR_I2C_BUS, POWER_SENSOR_I2C_ADDRESS)
|
|
|
|
power_data = DataBuffer(CONSECUTIVE_POWER_READS)
|
|
|
|
gate_handler.open()
|
|
|
|
try:
|
|
|
|
while True:
|
|
|
|
power_data.push(power_sensor.power_mw())
|
|
|
|
average = power_data.average()
|
2017-01-07 12:23:28 +00:00
|
|
|
print str(dt.now()) + " avg pwr: " + str(average) + " mW"
|
2016-12-23 12:06:02 +00:00
|
|
|
if average != None:
|
|
|
|
if average > MAX_ENGINE_POWER["up"]:
|
2016-12-23 12:18:28 +00:00
|
|
|
gate_handler.close()
|
2017-01-07 12:23:28 +00:00
|
|
|
sleep(5)
|
2016-12-23 12:06:02 +00:00
|
|
|
gate_handler.stop()
|
|
|
|
print "Gate successfully opened"
|
|
|
|
return 0
|
|
|
|
|
|
|
|
except KeyboardInterrupt:
|
2017-01-07 12:23:28 +00:00
|
|
|
gate_handler.stop()
|
2016-12-23 12:06:02 +00:00
|
|
|
print "Closing procedure interrupted."
|
|
|
|
return 1
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
sys.exit(main(sys.argv[1:]))
|