gcode: Allow handlers to be registered for all gcode output

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2020-08-04 14:45:21 -04:00
parent 8ed1696624
commit b66dd1a60f
1 changed files with 5 additions and 0 deletions

View File

@ -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")