add config parameters for controlling temperature
This commit is contained in:
+4
-3
@@ -26,7 +26,7 @@ class MAX31855(object):
|
||||
self.units = units
|
||||
self.data = None
|
||||
self.board = board
|
||||
self.noConnection = self.shortToGround = self.shortToVCC = False
|
||||
self.noConnection = self.shortToGround = self.shortToVCC = self.unknownError = False
|
||||
|
||||
# Initialize needed GPIO
|
||||
GPIO.setmode(self.board)
|
||||
@@ -74,9 +74,10 @@ class MAX31855(object):
|
||||
if anyErrors:
|
||||
self.noConnection = (data_32 & 0x00000001) != 0 # OC bit, D0
|
||||
self.shortToGround = (data_32 & 0x00000002) != 0 # SCG bit, D1
|
||||
self.shortToVCC = (data_32 & 0x00000004) != 0
|
||||
self.shortToVCC = (data_32 & 0x00000004) != 0 # SCV bit, D2
|
||||
self.unknownError = not (self.noConnection | self.shortToGround | self.shortToVCC) # Errk!
|
||||
else:
|
||||
self.noConnection = self.shortToGround = self.shortToVCC = False
|
||||
self.noConnection = self.shortToGround = self.shortToVCC = self.unknownError = False
|
||||
|
||||
def data_to_tc_temperature(self, data_32 = None):
|
||||
'''Takes an integer and returns a thermocouple temperature in celsius.'''
|
||||
|
||||
+22
-7
@@ -8,7 +8,6 @@ import config
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
TEMPERATURE_MOVING_AVERAGE_SAMPLES = 40
|
||||
|
||||
class Output(object):
|
||||
def __init__(self):
|
||||
@@ -124,15 +123,24 @@ class TempSensorReal(TempSensor):
|
||||
temps = []
|
||||
while True:
|
||||
temp = self.thermocouple.get()
|
||||
temps.append(temp)
|
||||
if len(temps) > TEMPERATURE_MOVING_AVERAGE_SAMPLES:
|
||||
del temps[0]
|
||||
|
||||
if len(temps):
|
||||
self.temperature = sum(temps) / len(temps)
|
||||
self.noConnection = self.thermocouple.noConnection
|
||||
self.shortToGround = self.thermocouple.shortToGround
|
||||
self.shortToVCC = self.thermocouple.shortToVCC
|
||||
self.unknownError = self.thermocouple.unknownError
|
||||
|
||||
is_bad_value = self.noConnection | self.unknownError
|
||||
if config.honour_theromocouple_short_errors:
|
||||
is_bad_value |= self.shortToGround | self.shortToVCC
|
||||
|
||||
if not is_bad_value:
|
||||
temps.append(temp)
|
||||
if len(temps) > config.temperature_average_samples:
|
||||
del temps[0]
|
||||
else:
|
||||
log.error(f"Problem reading temp N/C:{self.noConnection} GND:{self.shortToGround} VCC:{self.shortToVCC} ???:{self.unknownError}")
|
||||
|
||||
if len(temps):
|
||||
self.temperature = sum(temps) / len(temps)
|
||||
time.sleep(self.sleeptime)
|
||||
|
||||
class Oven(threading.Thread):
|
||||
@@ -167,6 +175,9 @@ class Oven(threading.Thread):
|
||||
if self.board.temp_sensor.shortToVCC:
|
||||
log.info("Refusing to start profile - thermocouple short to VCC")
|
||||
return
|
||||
if self.board.temp_sensor.unknownError:
|
||||
log.info("Refusing to start profile - thermocouple unknown error")
|
||||
return
|
||||
|
||||
log.info("Running schedule %s" % profile.name)
|
||||
self.profile = profile
|
||||
@@ -217,6 +228,10 @@ class Oven(threading.Thread):
|
||||
log.info("emergency!!! lost connection to thermocouple, shutting down")
|
||||
self.reset()
|
||||
|
||||
if self.board.temp_sensor.unknownError:
|
||||
log.info("emergency!!! unknown thermocouple error, shutting down")
|
||||
self.reset()
|
||||
|
||||
def reset_if_schedule_ended(self):
|
||||
if self.runtime > self.totaltime:
|
||||
log.info("schedule ended, shutting down")
|
||||
|
||||
Reference in New Issue
Block a user