chickenhouse/source/close.py
Thomas Klaehn e541023bba ci: enable continuous integration
Signed-off-by: Thomas Klaehn <thomas.klaehn@u-blox.com>
2018-08-27 11:26:31 +02:00

46 lines
1.1 KiB
Python

'''
Created on Dec 23, 2016
@author: klaehn
'''
import sys
sys.path.append('source/')
import time
import data_buffer
import engine
import power_sensor
POWER_SENSOR_I2C_BUS = 1
POWER_SENSOR_I2C_ADDRESS = 0x40
CONSECUTIVE_POWER_READS = 1000
MAX_ENGINE_POWER = {"up":330, "down":280}
def main(argv):
__engine = engine.Engine(gpio_1=13, gpio_2=19)
__power_sensor = power_sensor.PowerSensor(POWER_SENSOR_I2C_BUS, POWER_SENSOR_I2C_ADDRESS)
__power_data = data_buffer.DataBuffer(CONSECUTIVE_POWER_READS)
__engine.down()
try:
while True:
rd = __power_sensor.power_mw()
__power_data.push(rd)
average = __power_data.average()
print str(time.time()) + " " + str(rd)
if average != None:
if average > MAX_ENGINE_POWER["down"]:
__engine.stop()
# print "Gate successfully closed"
return 0
except KeyboardInterrupt:
__engine.stop()
# print "Closing procedure interrupted."
return 1
if __name__ == "__main__":
sys.exit(main(sys.argv[1:]))