aboutsummaryrefslogtreecommitdiffstats
path: root/klippy/extras/display_status.py
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2020-03-03 17:13:29 -0500
committerKevin O'Connor <kevin@koconnor.net>2020-03-08 17:36:14 -0400
commit5acc1816242510ddfdde7eeb972a5ba70ce8a26e (patch)
treef1994bba40d276de5f85b074d3ab460d26b72c49 /klippy/extras/display_status.py
parent7fb7f0d331e8d2e11d3e829ac647a5c0c6b6d74b (diff)
downloadkutter-5acc1816242510ddfdde7eeb972a5ba70ce8a26e.tar.gz
kutter-5acc1816242510ddfdde7eeb972a5ba70ce8a26e.tar.xz
kutter-5acc1816242510ddfdde7eeb972a5ba70ce8a26e.zip
display_status: Separate out M73 and M117 handling to new module
Move M73 and M117 handling from display.py to a new display_status.py module. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'klippy/extras/display_status.py')
-rw-r--r--klippy/extras/display_status.py52
1 files changed, 52 insertions, 0 deletions
diff --git a/klippy/extras/display_status.py b/klippy/extras/display_status.py
new file mode 100644
index 00000000..ce2cece5
--- /dev/null
+++ b/klippy/extras/display_status.py
@@ -0,0 +1,52 @@
+# Module to handle M73 and M117 display status commands
+#
+# Copyright (C) 2018-2020 Kevin O'Connor <kevin@koconnor.net>
+# Copyright (C) 2018 Eric Callahan <arksine.code@gmail.com>
+#
+# This file may be distributed under the terms of the GNU GPLv3 license.
+
+M73_TIMEOUT = 5.
+
+class DisplayStatus:
+ def __init__(self, config):
+ self.printer = config.get_printer()
+ self.expire_progress = 0.
+ self.progress = self.message = None
+ # Register commands
+ gcode = self.printer.lookup_object('gcode')
+ gcode.register_command('M73', self.cmd_M73)
+ gcode.register_command('M117', self.cmd_M117)
+ def get_status(self, eventtime):
+ progress = self.progress
+ if progress is not None and eventtime > self.expire_progress:
+ idle_timeout = self.printer.lookup_object('idle_timeout')
+ idle_timeout_info = idle_timeout.get_status(eventtime)
+ if idle_timeout_info['state'] != "Printing":
+ self.progress = progress = None
+ if progress is None:
+ progress = 0.
+ sdcard = self.printer.lookup_object('virtual_sdcard', None)
+ if sdcard is not None:
+ progress = sdcard.get_status(eventtime)['progress']
+ return { 'progress': progress, 'message': self.message }
+ def cmd_M73(self, params):
+ gcode = self.printer.lookup_object('gcode')
+ progress = gcode.get_float('P', params, 0.) / 100.
+ self.progress = min(1., max(0., progress))
+ curtime = self.printer.get_reactor().monotonic()
+ self.expire_progress = curtime + M73_TIMEOUT
+ def cmd_M117(self, params):
+ msg = params['#original']
+ umsg = msg.upper()
+ if not umsg.startswith('M117'):
+ # Parse out additional info if M117 recd during a print
+ start = umsg.find('M117')
+ end = msg.rfind('*')
+ msg = msg[start:end]
+ if len(msg) > 5:
+ self.message = msg[5:]
+ else:
+ self.message = None
+
+def load_config(config):
+ return DisplayStatus(config)