2019-02-25 22:17:05 +03:00
|
|
|
# Support generic temperature sensors
|
|
|
|
#
|
|
|
|
# Copyright (C) 2019 Kevin O'Connor <kevin@koconnor.net>
|
|
|
|
#
|
|
|
|
# This file may be distributed under the terms of the GNU GPLv3 license.
|
|
|
|
|
2020-02-27 19:31:51 +03:00
|
|
|
KELVIN_TO_CELSIUS = -273.15
|
2019-02-25 22:17:05 +03:00
|
|
|
|
|
|
|
class PrinterSensorGeneric:
|
|
|
|
def __init__(self, config):
|
|
|
|
self.printer = config.get_printer()
|
2020-05-05 21:10:30 +03:00
|
|
|
pheaters = self.printer.load_object(config, 'heaters')
|
2020-04-25 20:27:41 +03:00
|
|
|
self.sensor = pheaters.setup_sensor(config)
|
2020-02-27 19:31:51 +03:00
|
|
|
self.min_temp = config.getfloat('min_temp', KELVIN_TO_CELSIUS,
|
|
|
|
minval=KELVIN_TO_CELSIUS)
|
2019-02-25 22:17:05 +03:00
|
|
|
self.max_temp = config.getfloat('max_temp', 99999999.9,
|
|
|
|
above=self.min_temp)
|
|
|
|
self.sensor.setup_minmax(self.min_temp, self.max_temp)
|
|
|
|
self.sensor.setup_callback(self.temperature_callback)
|
2020-04-25 20:27:41 +03:00
|
|
|
pheaters.register_sensor(config, self)
|
2019-02-25 22:17:05 +03:00
|
|
|
self.last_temp = 0.
|
2020-08-01 18:23:50 +03:00
|
|
|
self.measured_min = 99999999.
|
|
|
|
self.measured_max = 0.
|
2019-02-25 22:17:05 +03:00
|
|
|
def temperature_callback(self, read_time, temp):
|
|
|
|
self.last_temp = temp
|
2020-08-01 18:23:50 +03:00
|
|
|
if temp:
|
|
|
|
self.measured_min = min(self.measured_min, temp)
|
|
|
|
self.measured_max = max(self.measured_max, temp)
|
2019-02-25 22:17:05 +03:00
|
|
|
def get_temp(self, eventtime):
|
|
|
|
return self.last_temp, 0.
|
2019-12-13 17:13:36 +03:00
|
|
|
def get_status(self, eventtime):
|
2020-08-01 18:23:50 +03:00
|
|
|
return {
|
|
|
|
'temperature': self.last_temp,
|
|
|
|
'measured_min_temp': self.measured_min,
|
|
|
|
'measured_max_temp': self.measured_max
|
|
|
|
}
|
2019-02-25 22:17:05 +03:00
|
|
|
|
|
|
|
def load_config_prefix(config):
|
|
|
|
return PrinterSensorGeneric(config)
|