From b66dd1a60f4e30a4e8636812cf9fb46b8f34f658 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Tue, 4 Aug 2020 14:45:21 -0400 Subject: [PATCH] gcode: Allow handlers to be registered for all gcode output Signed-off-by: Kevin O'Connor --- klippy/gcode.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/klippy/gcode.py b/klippy/gcode.py index 3428ce4f..1ef2f37f 100644 --- a/klippy/gcode.py +++ b/klippy/gcode.py @@ -105,6 +105,7 @@ class GCodeParser: # Command handling self.is_printer_ready = False self.mutex = self.reactor.mutex() + self.output_callbacks = [] self.base_gcode_handlers = self.gcode_handlers = {} self.ready_gcode_handlers = {} self.mux_commands = {} @@ -171,6 +172,8 @@ class GCodeParser: "mux command %s %s %s already registered (%s)" % ( cmd, key, value, prev_values)) prev_values[value] = func + def register_output_handler(self, cb): + self.output_callbacks.append(cb) def set_move_transform(self, transform, force=False): if self.move_transform is not None and not force: raise self.printer.config_error( @@ -390,6 +393,8 @@ class GCodeParser: return GCodeCommand(self, command, commandline, params, False) # Response handling def respond_raw(self, msg): + for cb in self.output_callbacks: + cb(msg) if self.pipe_is_active: try: os.write(self.fd, msg+"\n")