printer: refactor to simplify

This commit is contained in:
Alfredo Monclus 2024-05-25 01:20:35 -03:00
parent 5dcbcea292
commit 36b6ce3092
2 changed files with 56 additions and 48 deletions

View File

@ -92,7 +92,7 @@ class KlipperScreenConfig:
self.errors.append(msg) self.errors.append(msg)
printers = [i for i in self.config.sections() if i.startswith("printer ")] printers = [i for i in self.config.sections() if i.startswith("printer ")]
if len(printers) == 0: if not printers:
printers.append("Printer Printer") printers.append("Printer Printer")
self.printers = [ self.printers = [
{printer[8:]: { {printer[8:]: {

View File

@ -46,40 +46,65 @@ class Printer:
self.system_info.clear() self.system_info.clear()
for x in self.config.keys(): for x in self.config.keys():
if x[:8] == "extruder": # Support for hiding devices by name
self.tools.append(x) section, _, name = x.partition(" ")
self.tools = sorted(self.tools) if name.startswith("_"):
self.extrudercount += 1
if x.startswith('extruder_stepper'):
continue continue
self.data[x] = {
"temperature": 0, if section.startswith("extruder"):
"target": 0 self.tools.append(x)
} self.extrudercount += 1
if x == 'heater_bed' \ if name.startswith("extruder_stepper"):
or x.startswith('heater_generic ') \ continue
or x.startswith('temperature_sensor ') \ self.data[x] = {"temperature": 0, "target": 0}
or x.startswith('temperature_fan '): elif section in (
"heater_bed",
"heater_generic",
"temperature_sensor",
"temperature_fan"
):
self.data[x] = {"temperature": 0} self.data[x] = {"temperature": 0}
if not x.startswith('temperature_sensor '): if section != "temperature_sensor":
self.data[x]["target"] = 0 self.data[x]["target"] = 0
# Support for hiding devices by name
name = x.split()[1] if len(x.split()) > 1 else x
if not name.startswith("_"):
self.tempdevcount += 1 self.tempdevcount += 1
if x == 'fan' \ elif section in (
or x.startswith('controller_fan ') \ "fan",
or x.startswith('heater_fan ') \ "controller_fan",
or x.startswith('fan_generic '): "heater_fan",
# Support for hiding devices by name "fan_generic"
name = x.split()[1] if len(x.split()) > 1 else x ):
if not name.startswith("_"):
self.fancount += 1 self.fancount += 1
if x.startswith('output_pin ') and not x.split()[1].startswith("_"): elif section == "output_pin":
self.output_pin_count += 1 self.output_pin_count += 1
if x.startswith('pwm_tool ') and not x.split()[1].startswith("_"): elif section == "pwm_tool":
self.pwm_tools_count += 1 self.pwm_tools_count += 1
if x.startswith('bed_mesh '): elif section == "bed_mesh":
self.process_bed_mesh(x)
elif section in (
"led",
"neopixel",
"dotstar",
"pca9533",
"pca9632"
):
self.ledcount += 1
self.tools = sorted(self.tools)
self.log_counts(printer_info)
self.process_update(data)
def log_counts(self, printer_info):
logging.info(f"Klipper version: {printer_info['software_version']}")
logging.info(f"# Extruders: {self.extrudercount}")
logging.info(f"# Temperature devices: {self.tempdevcount}")
logging.info(f"# Fans: {self.fancount}")
logging.info(f"# Output pins: {self.output_pin_count}")
logging.info(f"# PWM tools: {self.pwm_tools_count}")
logging.info(f"# Leds: {self.ledcount}")
def process_bed_mesh(self, x):
try: try:
r = self.config[x] r = self.config[x]
r['x_count'] = int(r['x_count']) r['x_count'] = int(r['x_count'])
@ -91,23 +116,6 @@ class Printer:
r['points'] = [[float(j.strip()) for j in i.split(",")] for i in r['points'].strip().split("\n")] r['points'] = [[float(j.strip()) for j in i.split(",")] for i in r['points'].strip().split("\n")]
except KeyError: except KeyError:
logging.debug(f"Couldn't load mesh {x}: {self.config[x]}") logging.debug(f"Couldn't load mesh {x}: {self.config[x]}")
if x.startswith('led') \
or x.startswith('neopixel ') \
or x.startswith('dotstar ') \
or x.startswith('pca9533 ') \
or x.startswith('pca9632 '):
name = x.split()[1] if len(x.split()) > 1 else x
if not name.startswith("_"):
self.ledcount += 1
self.process_update(data)
logging.info(f"Klipper version: {printer_info['software_version']}")
logging.info(f"# Extruders: {self.extrudercount}")
logging.info(f"# Temperature devices: {self.tempdevcount}")
logging.info(f"# Fans: {self.fancount}")
logging.info(f"# Output pins: {self.output_pin_count}")
logging.info(f"# PWM tools: {self.pwm_tools_count}")
logging.info(f"# Leds: {self.ledcount}")
def stop_tempstore_updates(self): def stop_tempstore_updates(self):
if self.store_timeout is not None: if self.store_timeout is not None:
@ -259,7 +267,7 @@ class Printer:
"pwm_tools": {"count": self.pwm_tools_count}, "pwm_tools": {"count": self.pwm_tools_count},
"gcode_macros": {"count": len(self.get_gcode_macros()), "list": self.get_gcode_macros()}, "gcode_macros": {"count": len(self.get_gcode_macros()), "list": self.get_gcode_macros()},
"leds": {"count": self.ledcount}, "leds": {"count": self.ledcount},
"config_sections": [section for section in self.config.keys()], "config_sections": list(self.config.keys()),
} }
} }