From 10c0176ea952a5678e317657eaa116a49024386b Mon Sep 17 00:00:00 2001 From: Brandon Nance Date: Wed, 11 Oct 2023 18:10:40 -0400 Subject: [PATCH] experimental --- klippy/extras/bed_mesh.py | 4 +++- klippy/extras/debug_options.py | 14 ++++++++++++++ klippy/extras/statistics.py | 4 ++-- klippy/klippy.py | 6 +++++- klippy/mcu.py | 19 +++++++++++-------- klippy/toolhead.py | 2 ++ 6 files changed, 37 insertions(+), 12 deletions(-) create mode 100644 klippy/extras/debug_options.py diff --git a/klippy/extras/bed_mesh.py b/klippy/extras/bed_mesh.py index 23e4ea4aa..4fd36bc9d 100644 --- a/klippy/extras/bed_mesh.py +++ b/klippy/extras/bed_mesh.py @@ -161,7 +161,9 @@ def __init__(self, config): def handle_connect(self): self.toolhead = self.printer.lookup_object("toolhead") - self.bmc.print_generated_points(logging.info) + self.debug_options = self.printer.lookup_object("debug_options") + if self.debug_options.log_bed_mesh_at_startup: + self.bmc.print_generated_points(logging.info) def set_mesh(self, mesh): if mesh is not None and self.fade_end != self.FADE_DISABLE: diff --git a/klippy/extras/debug_options.py b/klippy/extras/debug_options.py new file mode 100644 index 000000000..6d6723d50 --- /dev/null +++ b/klippy/extras/debug_options.py @@ -0,0 +1,14 @@ +class DebugOptions: + def __init__(self, config): + self.log_statistics = config.getboolean("log_statistics", True) + self.log_config_file_at_startup = config.getboolean( + "log_config_file_at_startup", True + ) + self.log_bed_mesh_at_startup = config.getboolean( + "log_bed_mesh_at_startup", True + ) + self.log_shutdown_info = config.getboolean("log_shutdown_info", True) + + +def load_config_prefix(config): + return DebugOptions(config) diff --git a/klippy/extras/statistics.py b/klippy/extras/statistics.py index 80c66bd26..cd035497c 100644 --- a/klippy/extras/statistics.py +++ b/klippy/extras/statistics.py @@ -61,8 +61,8 @@ def get_status(self, eventtime): class PrinterStats: def __init__(self, config): self.printer = config.get_printer() + self.debug_options = self.printer.lookup_object("debug_options") reactor = self.printer.get_reactor() - self.log_stats = config.getboolean("log_stats", True) self.stats_timer = reactor.register_timer(self.generate_stats) self.stats_cb = [] self.printer.register_event_handler("klippy:ready", self.handle_ready) @@ -79,7 +79,7 @@ def handle_ready(self): def generate_stats(self, eventtime): stats = [cb(eventtime) for cb in self.stats_cb] - if max([s[0] for s in stats]) and self.log_stats: + if max([s[0] for s in stats]) and self.debug_options.log_statistics: logging.info( "Stats %.1f: %s", eventtime, " ".join([s[1] for s in stats]) ) diff --git a/klippy/klippy.py b/klippy/klippy.py index 01f3d5450..5f6cb14ef 100644 --- a/klippy/klippy.py +++ b/klippy/klippy.py @@ -154,7 +154,11 @@ def load_object(self, config, section, default=configfile.sentinel): def _read_config(self): self.objects["configfile"] = pconfig = configfile.PrinterConfig(self) config = pconfig.read_main_config() - if self.bglogger is not None: + debug_options = self.load_object(config, "debug_options", None) + if ( + self.bglogger is not None + and debug_options.log_config_file_at_startup + ): pconfig.log_config(config) # Create printer components for m in [pins, mcu]: diff --git a/klippy/mcu.py b/klippy/mcu.py index 4ea583921..b5d3915f8 100644 --- a/klippy/mcu.py +++ b/klippy/mcu.py @@ -18,6 +18,7 @@ class error(Exception): # Command transmit helper classes ###################################################################### + # Class to retry sending of a query command until a given response is received class RetryAsyncCommand: TIMEOUT_TIME = 5.0 @@ -744,6 +745,7 @@ class MCU: def __init__(self, config, clocksync): self._printer = printer = config.get_printer() + self.debug_options = printer.lookup_object("debug_options") self._clocksync = clocksync self._reactor = printer.get_reactor() self._name = config.get_name() @@ -833,14 +835,15 @@ def _handle_shutdown(self, params): if clock is not None: self._shutdown_clock = self.clock32_to_clock64(clock) self._shutdown_msg = msg = params["static_string_id"] - logging.info( - "MCU '%s' %s: %s\n%s\n%s", - self._name, - params["#name"], - self._shutdown_msg, - self._clocksync.dump_debug(), - self._serial.dump_debug(), - ) + if self.debug_options.log_shutdown_info: + logging.info( + "MCU '%s' %s: %s\n%s\n%s", + self._name, + params["#name"], + self._shutdown_msg, + self._clocksync.dump_debug(), + self._serial.dump_debug(), + ) prefix = "MCU '%s' shutdown: " % (self._name,) if params["#name"] == "is_shutdown": prefix = "Previous MCU '%s' shutdown: " % (self._name,) diff --git a/klippy/toolhead.py b/klippy/toolhead.py index 58f4c2368..7f38a6969 100644 --- a/klippy/toolhead.py +++ b/klippy/toolhead.py @@ -11,6 +11,7 @@ # mm/second), _v2 is velocity squared (mm^2/s^2), _t is time (in # seconds), _r is ratio (scalar between 0.0 and 1.0) + # Class to track each move request class Move: def __init__(self, toolhead, start_pos, end_pos, speed): @@ -128,6 +129,7 @@ def set_junction(self, start_v2, cruise_v2, end_v2): LOOKAHEAD_FLUSH_TIME = 0.250 + # Class to track a list of pending move requests and to facilitate # "look-ahead" across moves to reduce acceleration between moves. class MoveQueue: