From 645208296495f8bbf259a4a80b9b3be86df25ada Mon Sep 17 00:00:00 2001 From: Sebastian Steuer Date: Sat, 30 Nov 2013 13:48:07 +0100 Subject: [PATCH] door state --- config.py.EXAMPLE | 1 + oven.py | 20 ++++++++++++++------ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/config.py.EXAMPLE b/config.py.EXAMPLE index 5deece1..60a5130 100644 --- a/config.py.EXAMPLE +++ b/config.py.EXAMPLE @@ -6,6 +6,7 @@ log_format = '%(asctime)s %(levelname)s %(name)s: %(message)s' gpio_heat = 11 gpio_cool = 10 gpio_air = 9 +gpio_door = 18 gpio_sensor_cs = 27 gpio_sensor_clock = 22 diff --git a/oven.py b/oven.py index 1bcb335..6174b15 100644 --- a/oven.py +++ b/oven.py @@ -10,10 +10,6 @@ except ImportError: log.warning("Could not initialize temperature sensor, using dummy values!") sensor_available = False -config.gpio_heat = 11 -config.gpio_cool = 10 -config.gpio_air = 9 - try: import RPi.GPIO as GPIO GPIO.setmode(GPIO.BCM) @@ -21,6 +17,7 @@ try: GPIO.setup(config.gpio_heat, GPIO.OUT) GPIO.setup(config.gpio_cool, GPIO.OUT) GPIO.setup(config.gpio_air, GPIO.OUT) + GPIO.setup(config.gpio_door, GPIO.IN) gpio_available = True except ImportError: @@ -45,6 +42,7 @@ class Oven (threading.Thread): self.runtime = 0 self.totaltime = 0 self.target = 0 + self.door = self.read_door() self.state = Oven.STATE_IDLE self.set_heat(False) self.set_cool(False) @@ -63,9 +61,11 @@ class Oven (threading.Thread): def run(self): while True: + self.door_open = self.read_door() + if self.state == Oven.STATE_RUNNING: self.runtime = (datetime.datetime.now() - self.start_time).total_seconds() - log.info("running at %.1f deg C (Target: %.1f) , heat %.2f, cool %.2f, air %.2f (%.1fs/%.0f)"%(self.temp_sensor.temperature,self.target,self.heat,self.cool,self.air,self.runtime,self.totaltime)) + log.info("running at %.1f deg C (Target: %.1f) , heat %.2f, cool %.2f, air %.2f, door %s (%.1fs/%.0f)"%(self.temp_sensor.temperature,self.target,self.heat,self.cool,self.air,self.door,self.runtime,self.totaltime)) self.target = self.profile.get_target_temperature(self.runtime) if self.profile.is_rising(self.runtime): @@ -120,9 +120,17 @@ class Oven (threading.Thread): 'heat': self.heat, 'cool': self.cool, 'air' : self.air, - 'totaltime': self.totaltime + 'totaltime': self.totaltime, + 'door': self.door } return state + + def read_door(self): + if gpio_available: + return "OPEN" if GPIO.input(gpio_door) else "CLOSED" + else: + return "UNKNOWN" + class TempSensor(threading.Thread): def __init__(self,oven):