aboutsummaryrefslogtreecommitdiffstats
path: root/klippy/extras
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2019-01-08 09:15:40 -0500
committerKevin O'Connor <kevin@koconnor.net>2019-01-08 10:59:43 -0500
commitfb7fe282c80854ba06defa1cb4b49f1c9942f450 (patch)
treefcc3098dd798ddd75d75ea854b0c1f4d6dae6b60 /klippy/extras
parentb2d5a8e65bfb4d5c9250a8cfb72e0b1923c8355d (diff)
downloadkutter-fb7fe282c80854ba06defa1cb4b49f1c9942f450.tar.gz
kutter-fb7fe282c80854ba06defa1cb4b49f1c9942f450.tar.xz
kutter-fb7fe282c80854ba06defa1cb4b49f1c9942f450.zip
klippy: Convert printer_state("shutdown") to an event handler
Convert all users of the printer_state("shutdown") handler to register a "klippy:shutdown" event handler instead. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'klippy/extras')
-rw-r--r--klippy/extras/verify_heater.py5
-rw-r--r--klippy/extras/virtual_sdcard.py5
2 files changed, 7 insertions, 3 deletions
diff --git a/klippy/extras/verify_heater.py b/klippy/extras/verify_heater.py
index 7ac4d920..378a8b94 100644
--- a/klippy/extras/verify_heater.py
+++ b/klippy/extras/verify_heater.py
@@ -13,6 +13,8 @@ for the parameters that control this check.
class HeaterCheck:
def __init__(self, config):
self.printer = config.get_printer()
+ self.printer.register_event_handler("klippy:shutdown",
+ self.handle_shutdown)
self.heater_name = config.get_name().split()[1]
self.heater = None
self.hysteresis = config.getfloat('hysteresis', 5., minval=0.)
@@ -38,7 +40,8 @@ class HeaterCheck:
reactor = self.printer.get_reactor()
self.check_timer = reactor.register_timer(self.check_event,
reactor.NOW)
- elif state == 'shutdown' and self.check_timer is not None:
+ def handle_shutdown(self):
+ if self.check_timer is not None:
reactor = self.printer.get_reactor()
reactor.update_timer(self.check_timer, reactor.NEVER)
def check_event(self, eventtime):
diff --git a/klippy/extras/virtual_sdcard.py b/klippy/extras/virtual_sdcard.py
index 1a0fc2a8..e99e7cf4 100644
--- a/klippy/extras/virtual_sdcard.py
+++ b/klippy/extras/virtual_sdcard.py
@@ -8,6 +8,7 @@ import os, logging
class VirtualSD:
def __init__(self, config):
printer = config.get_printer()
+ printer.register_event_handler("klippy:shutdown", self.handle_shutdown)
# sdcard state
sd = config.get('path')
self.sdcard_dirname = os.path.normpath(os.path.expanduser(sd))
@@ -24,8 +25,8 @@ class VirtualSD:
self.gcode.register_command(cmd, getattr(self, 'cmd_' + cmd))
for cmd in ['M28', 'M29', 'M30']:
self.gcode.register_command(cmd, self.cmd_error)
- def printer_state(self, state):
- if state == 'shutdown' and self.work_timer is not None:
+ def handle_shutdown(self):
+ if self.work_timer is not None:
self.must_pause_work = True
try:
readpos = max(self.file_position - 1024, 0)