printer: change how the tempstore is initialized and updated, to avoid unnecesary retries
This commit is contained in:
parent
051a53ec22
commit
3c911ba7c7
@ -38,12 +38,11 @@ class Printer:
|
|||||||
self.fancount = 0
|
self.fancount = 0
|
||||||
self.ledcount = 0
|
self.ledcount = 0
|
||||||
self.output_pin_count = 0
|
self.output_pin_count = 0
|
||||||
self.tempstore = {}
|
self.tempstore = None
|
||||||
if not self.store_timeout:
|
|
||||||
self.store_timeout = GLib.timeout_add_seconds(1, self._update_temp_store)
|
|
||||||
self.tempstore_size = 1200
|
self.tempstore_size = 1200
|
||||||
self.available_commands = {}
|
self.available_commands = {}
|
||||||
self.temp_devices = self.sensors = None
|
self.temp_devices = self.sensors = None
|
||||||
|
self.stop_tempstore_updates()
|
||||||
|
|
||||||
for x in self.config.keys():
|
for x in self.config.keys():
|
||||||
if x[:8] == "extruder":
|
if x[:8] == "extruder":
|
||||||
@ -106,6 +105,12 @@ class Printer:
|
|||||||
logging.info(f"# Output pins: {self.output_pin_count}")
|
logging.info(f"# Output pins: {self.output_pin_count}")
|
||||||
logging.info(f"# Leds: {self.ledcount}")
|
logging.info(f"# Leds: {self.ledcount}")
|
||||||
|
|
||||||
|
def stop_tempstore_updates(self):
|
||||||
|
logging.info("Stopping tempstore")
|
||||||
|
if self.store_timeout is not None:
|
||||||
|
GLib.source_remove(self.store_timeout)
|
||||||
|
self.store_timeout = None
|
||||||
|
|
||||||
def process_update(self, data):
|
def process_update(self, data):
|
||||||
if self.data is None:
|
if self.data is None:
|
||||||
return
|
return
|
||||||
@ -336,11 +341,10 @@ class Printer:
|
|||||||
return 0
|
return 0
|
||||||
|
|
||||||
def get_temp_store_devices(self):
|
def get_temp_store_devices(self):
|
||||||
if self.tempstore is not None:
|
return list(self.tempstore) if self.tempstore is not None else self.tempstore
|
||||||
return list(self.tempstore)
|
|
||||||
|
|
||||||
def device_has_target(self, device):
|
def device_has_target(self, device):
|
||||||
return "target" in self.devices[device] or (device in self.tempstore and "targets" in self.tempstore[device])
|
return "target" in self.devices[device]
|
||||||
|
|
||||||
def get_temp_store(self, device, section=False, results=0):
|
def get_temp_store(self, device, section=False, results=0):
|
||||||
if device not in self.tempstore:
|
if device not in self.tempstore:
|
||||||
@ -390,6 +394,8 @@ class Printer:
|
|||||||
for _ in range(1, self.tempstore_size - length):
|
for _ in range(1, self.tempstore_size - length):
|
||||||
self.tempstore[device][x].insert(0, 0)
|
self.tempstore[device][x].insert(0, 0)
|
||||||
logging.info(f"Temp store: {list(self.tempstore)}")
|
logging.info(f"Temp store: {list(self.tempstore)}")
|
||||||
|
if not self.store_timeout:
|
||||||
|
self.store_timeout = GLib.timeout_add_seconds(1, self._update_temp_store)
|
||||||
|
|
||||||
def config_section_exists(self, section):
|
def config_section_exists(self, section):
|
||||||
return section in self.get_config_section_list()
|
return section in self.get_config_section_list()
|
||||||
|
@ -67,10 +67,11 @@ class Panel(MenuPanel):
|
|||||||
if self.graph_update is not None:
|
if self.graph_update is not None:
|
||||||
GLib.source_remove(self.graph_update)
|
GLib.source_remove(self.graph_update)
|
||||||
self.graph_update = None
|
self.graph_update = None
|
||||||
self.graph_retry = 0
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def activate(self):
|
def activate(self):
|
||||||
|
if self._printer.tempstore is None:
|
||||||
|
self._screen.init_tempstore()
|
||||||
self.update_graph_visibility()
|
self.update_graph_visibility()
|
||||||
|
|
||||||
def deactivate(self):
|
def deactivate(self):
|
||||||
|
@ -186,6 +186,8 @@ class Panel(ScreenPanel):
|
|||||||
self.graph_update = None
|
self.graph_update = None
|
||||||
|
|
||||||
def activate(self):
|
def activate(self):
|
||||||
|
if self._printer.tempstore is None:
|
||||||
|
self._screen.init_tempstore()
|
||||||
self.update_graph_visibility()
|
self.update_graph_visibility()
|
||||||
|
|
||||||
def deactivate(self):
|
def deactivate(self):
|
||||||
|
@ -654,6 +654,7 @@ class KlipperScreen(Gtk.Window):
|
|||||||
self.show_panel("printer_select", _("Printer Select"), remove_all=True)
|
self.show_panel("printer_select", _("Printer Select"), remove_all=True)
|
||||||
|
|
||||||
def websocket_disconnected(self, msg):
|
def websocket_disconnected(self, msg):
|
||||||
|
logging.debug("### websocket_disconnected")
|
||||||
self.printer_initializing(msg, remove=True)
|
self.printer_initializing(msg, remove=True)
|
||||||
self.printer.state = "disconnected"
|
self.printer.state = "disconnected"
|
||||||
self.connecting = True
|
self.connecting = True
|
||||||
@ -663,6 +664,7 @@ class KlipperScreen(Gtk.Window):
|
|||||||
|
|
||||||
def state_disconnected(self):
|
def state_disconnected(self):
|
||||||
logging.debug("### Going to disconnected")
|
logging.debug("### Going to disconnected")
|
||||||
|
self.printer.stop_tempstore_updates()
|
||||||
self.close_screensaver()
|
self.close_screensaver()
|
||||||
self.initialized = False
|
self.initialized = False
|
||||||
self.reinit_count = 0
|
self.reinit_count = 0
|
||||||
@ -704,6 +706,7 @@ class KlipperScreen(Gtk.Window):
|
|||||||
|
|
||||||
def state_shutdown(self):
|
def state_shutdown(self):
|
||||||
self.close_screensaver()
|
self.close_screensaver()
|
||||||
|
self.printer.stop_tempstore_updates()
|
||||||
msg = self.printer.get_stat("webhooks", "state_message")
|
msg = self.printer.get_stat("webhooks", "state_message")
|
||||||
msg = msg if "ready" not in msg else ""
|
msg = msg if "ready" not in msg else ""
|
||||||
self.printer_initializing(_("Klipper has shutdown") + "\n\n" + msg, remove=True)
|
self.printer_initializing(_("Klipper has shutdown") + "\n\n" + msg, remove=True)
|
||||||
@ -977,8 +980,6 @@ class KlipperScreen(Gtk.Window):
|
|||||||
extra_items))
|
extra_items))
|
||||||
if data is False:
|
if data is False:
|
||||||
return self._init_printer("Error getting printer object data with extra items")
|
return self._init_printer("Error getting printer object data with extra items")
|
||||||
if len(self.printer.get_temp_devices()) > 0:
|
|
||||||
self.init_tempstore()
|
|
||||||
|
|
||||||
self.files.set_gcodes_path()
|
self.files.set_gcodes_path()
|
||||||
self.files.refresh_files()
|
self.files.refresh_files()
|
||||||
@ -992,6 +993,8 @@ class KlipperScreen(Gtk.Window):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
def init_tempstore(self):
|
def init_tempstore(self):
|
||||||
|
if len(self.printer.get_temp_devices()) == 0:
|
||||||
|
return
|
||||||
tempstore = self.apiclient.send_request("server/temperature_store")
|
tempstore = self.apiclient.send_request("server/temperature_store")
|
||||||
if tempstore and 'result' in tempstore and tempstore['result']:
|
if tempstore and 'result' in tempstore and tempstore['result']:
|
||||||
self.printer.init_temp_store(tempstore['result'])
|
self.printer.init_temp_store(tempstore['result'])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user