aa146b15e5
Signed-off-by: Thomas Klaehn <thomas.klaehn@u-blox.com>
45 lines
1.1 KiB
Python
45 lines
1.1 KiB
Python
'''
|
|
Created on Dec 23, 2016
|
|
|
|
@author: klaehn
|
|
'''
|
|
import sys
|
|
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":290}
|
|
|
|
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.up()
|
|
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["up"]:
|
|
__engine.stop()
|
|
# print "Gate successfully opened"
|
|
return 0
|
|
|
|
except KeyboardInterrupt:
|
|
__engine.stop()
|
|
print "Closing procedure interrupted."
|
|
return 1
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main(sys.argv[1:]))
|