aboutsummaryrefslogtreecommitdiffstats
path: root/klippy/klippy.py
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2024-06-15 12:13:35 -0400
committerKevin O'Connor <kevin@koconnor.net>2024-06-21 15:32:30 -0400
commit4ac283cc0e198ad64aad8f321e4f158065828397 (patch)
treea777d0477d750dac3ff08964c5abf902666d5bce /klippy/klippy.py
parenta19d64febdbaa7d5ec0a0912bb65c6547c370ec3 (diff)
downloadkutter-4ac283cc0e198ad64aad8f321e4f158065828397.tar.gz
kutter-4ac283cc0e198ad64aad8f321e4f158065828397.tar.xz
kutter-4ac283cc0e198ad64aad8f321e4f158065828397.zip
error_mcu: Move shutdown error message formatting to new error_mcu.py module
Create a new module to help format verbose mcu error messages. Move the shutdown message formatting to this module. This moves the error formatting out of the background thread and out of the critical shutdown code path. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'klippy/klippy.py')
-rw-r--r--klippy/klippy.py25
1 files changed, 13 insertions, 12 deletions
diff --git a/klippy/klippy.py b/klippy/klippy.py
index 097cff99..5574063d 100644
--- a/klippy/klippy.py
+++ b/klippy/klippy.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python2
# Main code for host side printer firmware
#
-# Copyright (C) 2016-2020 Kevin O'Connor <kevin@koconnor.net>
+# Copyright (C) 2016-2024 Kevin O'Connor <kevin@koconnor.net>
#
# This file may be distributed under the terms of the GNU GPLv3 license.
import sys, os, gc, optparse, logging, time, collections, importlib
@@ -40,13 +40,6 @@ config, and restart the host software.
Error configuring printer
"""
-message_shutdown = """
-Once the underlying issue is corrected, use the
-"FIRMWARE_RESTART" command to reset the firmware, reload the
-config, and restart the host software.
-Printer is shutdown
-"""
-
class Printer:
config_error = configfile.error
command_error = gcode.CommandError
@@ -85,6 +78,13 @@ class Printer:
if (msg != message_ready
and self.start_args.get('debuginput') is not None):
self.request_exit('error_exit')
+ def update_error_msg(self, oldmsg, newmsg):
+ if (self.state_message != oldmsg
+ or self.state_message in (message_ready, message_startup)
+ or newmsg in (message_ready, message_startup)):
+ return
+ self.state_message = newmsg
+ logging.error(newmsg)
def add_object(self, name, obj):
if name in self.objects:
raise self.config_error(
@@ -241,12 +241,12 @@ class Printer:
logging.info(info)
if self.bglogger is not None:
self.bglogger.set_rollover_info(name, info)
- def invoke_shutdown(self, msg):
+ def invoke_shutdown(self, msg, details={}):
if self.in_shutdown_state:
return
logging.error("Transition to shutdown state: %s", msg)
self.in_shutdown_state = True
- self._set_state("%s%s" % (msg, message_shutdown))
+ self._set_state(msg)
for cb in self.event_handlers.get("klippy:shutdown", []):
try:
cb()
@@ -254,9 +254,10 @@ class Printer:
logging.exception("Exception during shutdown handler")
logging.info("Reactor garbage collection: %s",
self.reactor.get_gc_stats())
- def invoke_async_shutdown(self, msg):
+ self.send_event("klippy:notify_mcu_shutdown", msg, details)
+ def invoke_async_shutdown(self, msg, details):
self.reactor.register_async_callback(
- (lambda e: self.invoke_shutdown(msg)))
+ (lambda e: self.invoke_shutdown(msg, details)))
def register_event_handler(self, event, callback):
self.event_handlers.setdefault(event, []).append(callback)
def send_event(self, event, *params):