diff options
Diffstat (limited to 'klippy/extras/ds18b20.py')
-rw-r--r-- | klippy/extras/ds18b20.py | 43 |
1 files changed, 26 insertions, 17 deletions
diff --git a/klippy/extras/ds18b20.py b/klippy/extras/ds18b20.py index 37b30104..e9c52fde 100644 --- a/klippy/extras/ds18b20.py +++ b/klippy/extras/ds18b20.py @@ -12,6 +12,7 @@ DS18_REPORT_TIME = 3.0 DS18_MIN_REPORT_TIME = 1.0 DS18_MAX_CONSECUTIVE_ERRORS = 4 + class DS18B20: def __init__(self, config): self.printer = config.get_printer() @@ -20,40 +21,47 @@ class DS18B20: self.temp = self.min_temp = self.max_temp = 0.0 self._report_clock = 0 self.report_time = config.getfloat( - 'ds18_report_time', - DS18_REPORT_TIME, - minval=DS18_MIN_REPORT_TIME + "ds18_report_time", DS18_REPORT_TIME, minval=DS18_MIN_REPORT_TIME ) - self._mcu = mcu.get_printer_mcu(self.printer, config.get('sensor_mcu')) + self._mcu = mcu.get_printer_mcu(self.printer, config.get("sensor_mcu")) self.oid = self._mcu.create_oid() - self._mcu.register_response(self._handle_ds18b20_response, - "ds18b20_result", self.oid) + self._mcu.register_response( + self._handle_ds18b20_response, "ds18b20_result", self.oid + ) self._mcu.register_config_callback(self._build_config) def _build_config(self): sid = "".join(["%02x" % (x,) for x in self.sensor_id]) self._mcu.add_config_cmd( "config_ds18b20 oid=%d serial=%s max_error_count=%d" - % (self.oid, sid, DS18_MAX_CONSECUTIVE_ERRORS)) + % (self.oid, sid, DS18_MAX_CONSECUTIVE_ERRORS) + ) clock = self._mcu.get_query_slot(self.oid) self._report_clock = self._mcu.seconds_to_clock(self.report_time) - self._mcu.add_config_cmd("query_ds18b20 oid=%d clock=%u rest_ticks=%u" - " min_value=%d max_value=%d" % ( - self.oid, clock, self._report_clock, - self.min_temp * 1000, self.max_temp * 1000), is_init=True) + self._mcu.add_config_cmd( + "query_ds18b20 oid=%d clock=%u rest_ticks=%u" + " min_value=%d max_value=%d" + % ( + self.oid, + clock, + self._report_clock, + self.min_temp * 1000, + self.max_temp * 1000, + ), + is_init=True, + ) def _handle_ds18b20_response(self, params): - temp = params['value'] / 1000.0 + temp = params["value"] / 1000.0 if params["fault"]: - logging.info("ds18b20 reports fault %d (temp=%0.1f)", - params["fault"], temp) + logging.info("ds18b20 reports fault %d (temp=%0.1f)", params["fault"], temp) return - next_clock = self._mcu.clock32_to_clock64(params['next_clock']) + next_clock = self._mcu.clock32_to_clock64(params["next_clock"]) last_read_clock = next_clock - self._report_clock - last_read_time = self._mcu.clock_to_print_time(last_read_clock) + last_read_time = self._mcu.clock_to_print_time(last_read_clock) self._callback(last_read_time, temp) def setup_minmax(self, min_temp, max_temp): @@ -71,9 +79,10 @@ class DS18B20: def get_status(self, eventtime): return { - 'temperature': round(self.temp, 2), + "temperature": round(self.temp, 2), } + def load_config(config): # Register sensor pheaters = config.get_printer().load_object(config, "heaters") |