printer: refactor to simplify
This commit is contained in:
parent
5dcbcea292
commit
36b6ce3092
@ -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:]: {
|
||||||
|
@ -46,61 +46,56 @@ 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
|
||||||
|
section, _, name = x.partition(" ")
|
||||||
|
if name.startswith("_"):
|
||||||
|
continue
|
||||||
|
|
||||||
|
if section.startswith("extruder"):
|
||||||
self.tools.append(x)
|
self.tools.append(x)
|
||||||
self.tools = sorted(self.tools)
|
|
||||||
self.extrudercount += 1
|
self.extrudercount += 1
|
||||||
if x.startswith('extruder_stepper'):
|
if name.startswith("extruder_stepper"):
|
||||||
continue
|
continue
|
||||||
self.data[x] = {
|
self.data[x] = {"temperature": 0, "target": 0}
|
||||||
"temperature": 0,
|
elif section in (
|
||||||
"target": 0
|
"heater_bed",
|
||||||
}
|
"heater_generic",
|
||||||
if x == 'heater_bed' \
|
"temperature_sensor",
|
||||||
or x.startswith('heater_generic ') \
|
"temperature_fan"
|
||||||
or x.startswith('temperature_sensor ') \
|
):
|
||||||
or x.startswith('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
|
self.tempdevcount += 1
|
||||||
name = x.split()[1] if len(x.split()) > 1 else x
|
elif section in (
|
||||||
if not name.startswith("_"):
|
"fan",
|
||||||
self.tempdevcount += 1
|
"controller_fan",
|
||||||
if x == 'fan' \
|
"heater_fan",
|
||||||
or x.startswith('controller_fan ') \
|
"fan_generic"
|
||||||
or x.startswith('heater_fan ') \
|
):
|
||||||
or x.startswith('fan_generic '):
|
self.fancount += 1
|
||||||
# Support for hiding devices by name
|
elif section == "output_pin":
|
||||||
name = x.split()[1] if len(x.split()) > 1 else x
|
|
||||||
if not name.startswith("_"):
|
|
||||||
self.fancount += 1
|
|
||||||
if x.startswith('output_pin ') and not x.split()[1].startswith("_"):
|
|
||||||
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":
|
||||||
try:
|
self.process_bed_mesh(x)
|
||||||
r = self.config[x]
|
elif section in (
|
||||||
r['x_count'] = int(r['x_count'])
|
"led",
|
||||||
r['y_count'] = int(r['y_count'])
|
"neopixel",
|
||||||
r['max_x'] = float(r['max_x'])
|
"dotstar",
|
||||||
r['min_x'] = float(r['min_x'])
|
"pca9533",
|
||||||
r['max_y'] = float(r['max_y'])
|
"pca9632"
|
||||||
r['min_y'] = float(r['min_y'])
|
):
|
||||||
r['points'] = [[float(j.strip()) for j in i.split(",")] for i in r['points'].strip().split("\n")]
|
self.ledcount += 1
|
||||||
except KeyError:
|
|
||||||
logging.debug(f"Couldn't load mesh {x}: {self.config[x]}")
|
self.tools = sorted(self.tools)
|
||||||
if x.startswith('led') \
|
|
||||||
or x.startswith('neopixel ') \
|
self.log_counts(printer_info)
|
||||||
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)
|
self.process_update(data)
|
||||||
|
|
||||||
|
def log_counts(self, printer_info):
|
||||||
logging.info(f"Klipper version: {printer_info['software_version']}")
|
logging.info(f"Klipper version: {printer_info['software_version']}")
|
||||||
logging.info(f"# Extruders: {self.extrudercount}")
|
logging.info(f"# Extruders: {self.extrudercount}")
|
||||||
logging.info(f"# Temperature devices: {self.tempdevcount}")
|
logging.info(f"# Temperature devices: {self.tempdevcount}")
|
||||||
@ -109,6 +104,19 @@ class Printer:
|
|||||||
logging.info(f"# PWM tools: {self.pwm_tools_count}")
|
logging.info(f"# PWM tools: {self.pwm_tools_count}")
|
||||||
logging.info(f"# Leds: {self.ledcount}")
|
logging.info(f"# Leds: {self.ledcount}")
|
||||||
|
|
||||||
|
def process_bed_mesh(self, x):
|
||||||
|
try:
|
||||||
|
r = self.config[x]
|
||||||
|
r['x_count'] = int(r['x_count'])
|
||||||
|
r['y_count'] = int(r['y_count'])
|
||||||
|
r['max_x'] = float(r['max_x'])
|
||||||
|
r['min_x'] = float(r['min_x'])
|
||||||
|
r['max_y'] = float(r['max_y'])
|
||||||
|
r['min_y'] = float(r['min_y'])
|
||||||
|
r['points'] = [[float(j.strip()) for j in i.split(",")] for i in r['points'].strip().split("\n")]
|
||||||
|
except KeyError:
|
||||||
|
logging.debug(f"Couldn't load mesh {x}: {self.config[x]}")
|
||||||
|
|
||||||
def stop_tempstore_updates(self):
|
def stop_tempstore_updates(self):
|
||||||
if self.store_timeout is not None:
|
if self.store_timeout is not None:
|
||||||
GLib.source_remove(self.store_timeout)
|
GLib.source_remove(self.store_timeout)
|
||||||
@ -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()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user