Skip to content

Commit

Permalink
new style
Browse files Browse the repository at this point in the history
  • Loading branch information
bwnance committed Nov 11, 2023
1 parent 68bae20 commit 9ecfe73
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
22 changes: 16 additions & 6 deletions klippy/extras/heaters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
16 changes: 15 additions & 1 deletion klippy/gcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 9ecfe73

Please sign in to comment.