diff --git a/klippy/extras/heaters.py b/klippy/extras/heaters.py index 7d8c9bef6..3c0a11bc8 100644 --- a/klippy/extras/heaters.py +++ b/klippy/extras/heaters.py @@ -388,14 +388,14 @@ def __init__(self, config): "gcode:request_restart", self.turn_off_all_heaters ) # Register commands - gcode = self.printer.lookup_object("gcode") - gcode.register_command( + self.gcode = self.printer.lookup_object("gcode") + self.gcode.register_command( "TURN_OFF_HEATERS", self.cmd_TURN_OFF_HEATERS, desc=self.cmd_TURN_OFF_HEATERS_help, ) - gcode.register_command("M105", self.cmd_M105, when_not_ready=True) - gcode.register_command( + self.gcode.register_command("M105", self.cmd_M105, when_not_ready=True) + self.gcode.register_command( "TEMPERATURE_WAIT", self.cmd_TEMPERATURE_WAIT, desc=self.cmd_TEMPERATURE_WAIT_help, @@ -513,7 +513,12 @@ def _wait_for_temperature(self, heater): gcode = self.printer.lookup_object("gcode") reactor = self.printer.get_reactor() eventtime = reactor.monotonic() - while not self.printer.is_shutdown() and heater.check_busy(eventtime): + initial_interrupt_counter = gcode.check_interrupt_counter() + while ( + not self.printer.is_shutdown() + and heater.check_busy(eventtime) + and initial_interrupt_counter == gcode.check_interrupt_counter() + ): print_time = toolhead.get_last_move_time() gcode.respond_raw(self._get_temp(eventtime)) eventtime = reactor.pause(eventtime + 1.0) @@ -546,7 +551,12 @@ def cmd_TEMPERATURE_WAIT(self, gcmd): toolhead = self.printer.lookup_object("toolhead") reactor = self.printer.get_reactor() eventtime = reactor.monotonic() - while not self.printer.is_shutdown(): + initial_interrupt_counter = self.gcode.check_interrupt_counter() + while ( + not self.printer.is_shutdown() + and initial_interrupt_counter + == self.gcode.check_interrupt_counter() + ): temp, target = sensor.get_temp(eventtime) if temp >= min_temp and temp <= max_temp: return diff --git a/klippy/gcode.py b/klippy/gcode.py index 2a8b316c8..608b5cb2f 100644 --- a/klippy/gcode.py +++ b/klippy/gcode.py @@ -153,6 +153,7 @@ def __init__(self, printer): self.ready_gcode_handlers = {} self.mux_commands = {} self.gcode_help = {} + self._interrupt_counter = 0 # Register commands needed before config file is loaded handlers = [ "M110", @@ -163,12 +164,19 @@ def __init__(self, printer): "ECHO", "STATUS", "HELP", + "INTERRUPT", ] for cmd in handlers: func = getattr(self, "cmd_" + cmd) desc = getattr(self, "cmd_" + cmd + "_help", None) self.register_command(cmd, func, True, desc) + def check_interrupt_counter(self): + return self._interrupt_counter + + def increment_interrupt_counter(self): + self._interrupt_counter += 1 + def is_traditional_gcode(self, cmd): # A "traditional" g-code command is a letter and followed by a number try: @@ -291,8 +299,11 @@ def run_script_from_command(self, script): self._process_commands(script.split("\n"), need_ack=False) def run_script(self, script): - with self.mutex: + if "INTERRUPT" in script: self._process_commands(script.split("\n"), need_ack=False) + else: + with self.mutex: + self._process_commands(script.split("\n"), need_ack=False) def get_mutex(self): return self.mutex @@ -460,6 +471,9 @@ def cmd_HELP(self, gcmd): cmdhelp.append("%-10s: %s" % (cmd, self.gcode_help[cmd])) gcmd.respond_info("\n".join(cmdhelp), log=False) + def cmd_INTERRUPT_HEATER(self, gcmd): + self.increment_interrupt_counter() + # Support reading gcode from a pseudo-tty interface class GCodeIO: