From c16eab212ee706ab8c0b52e3846e61030fc68606 Mon Sep 17 00:00:00 2001 From: Pedro Lamas Date: Sun, 15 May 2022 12:19:37 +0100 Subject: [PATCH] virtual_sdcard: Adds on_error_gcode Signed-off-by: Pedro Lamas --- docs/Config_Reference.md | 3 +++ klippy/extras/virtual_sdcard.py | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/docs/Config_Reference.md b/docs/Config_Reference.md index aecf4b9d..c5347394 100644 --- a/docs/Config_Reference.md +++ b/docs/Config_Reference.md @@ -1334,6 +1334,9 @@ path: # are not supported). One may point this to OctoPrint's upload # directory (generally ~/.octoprint/uploads/ ). This parameter must # be provided. +#on_error_gcode: +# A list of G-Code commands to execute when an error is reported. + ``` ### [sdcard_loop] diff --git a/klippy/extras/virtual_sdcard.py b/klippy/extras/virtual_sdcard.py index 397c6513..870c099f 100644 --- a/klippy/extras/virtual_sdcard.py +++ b/klippy/extras/virtual_sdcard.py @@ -23,6 +23,10 @@ class VirtualSD: self.must_pause_work = self.cmd_from_sd = False self.next_file_position = 0 self.work_timer = None + # Error handling + gcode_macro = printer.load_object(config, 'gcode_macro') + self.on_error_gcode = gcode_macro.load_template( + config, 'on_error_gcode', '') # Register commands self.gcode = printer.lookup_object('gcode') for cmd in ['M20', 'M21', 'M23', 'M24', 'M25', 'M26', 'M27']: @@ -258,6 +262,10 @@ class VirtualSD: self.gcode.run_script(line) except self.gcode.error as e: error_message = str(e) + try: + self.gcode.run_script(self.on_error_gcode.render()) + except: + logging.exception("virtual_sdcard on_error") break except: logging.exception("virtual_sdcard dispatch")