aboutsummaryrefslogtreecommitdiffstats
path: root/klippy/gcode.py
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2018-01-19 22:49:27 -0500
committerKevin O'Connor <kevin@koconnor.net>2018-01-28 12:19:26 -0500
commitd3665699f168bc1b1413fa8dddba318d6adbdf87 (patch)
tree7fff975a7465983d8b19eed382c27f166c122450 /klippy/gcode.py
parent81013ba5c8638dd42932bd893e1b3115b1b98041 (diff)
downloadkutter-d3665699f168bc1b1413fa8dddba318d6adbdf87.tar.gz
kutter-d3665699f168bc1b1413fa8dddba318d6adbdf87.tar.xz
kutter-d3665699f168bc1b1413fa8dddba318d6adbdf87.zip
klippy: Support generic printer_state() and stats() callbacks
Instead of hardcoding which objects are called on state transitions, allow any "printer object" to be invoked if it has a printer_state() method. Convert connect, ready, shutdown, and disconnect callbacks to this mechanism. Similarly, allow all printer objects to provide a stats() callback. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'klippy/gcode.py')
-rw-r--r--klippy/gcode.py21
1 files changed, 12 insertions, 9 deletions
diff --git a/klippy/gcode.py b/klippy/gcode.py
index 261bbf22..c6d5e23d 100644
--- a/klippy/gcode.py
+++ b/klippy/gcode.py
@@ -68,7 +68,18 @@ class GCodeParser:
self.gcode_help[cmd] = desc
def stats(self, eventtime):
return "gcodein=%d" % (self.bytes_read,)
- def connect(self):
+ def printer_state(self, state):
+ if state == 'shutdown':
+ if not self.is_printer_ready:
+ return
+ self.is_printer_ready = False
+ self.gcode_handlers = self.base_gcode_handlers
+ self.dump_debug()
+ if self.is_fileinput:
+ self.printer.request_exit()
+ return
+ if state != 'ready':
+ return
self.is_printer_ready = True
self.gcode_handlers = self.ready_gcode_handlers
# Lookup printer components
@@ -85,14 +96,6 @@ class GCodeParser:
def reset_last_position(self):
if self.toolhead is not None:
self.last_position = self.toolhead.get_position()
- def do_shutdown(self):
- if not self.is_printer_ready:
- return
- self.is_printer_ready = False
- self.gcode_handlers = self.base_gcode_handlers
- self.dump_debug()
- if self.is_fileinput:
- self.printer.request_exit()
def motor_heater_off(self):
if self.toolhead is None:
return