diff options
author | Kevin O'Connor <kevin@koconnor.net> | 2017-10-12 15:15:14 -0400 |
---|---|---|
committer | Kevin O'Connor <kevin@koconnor.net> | 2017-10-12 16:28:53 -0400 |
commit | f8750b142f56ebb1b9dd25a2fdfb5b28d33de57d (patch) | |
tree | 608ad8cd061845f705406e684d704cecdb8bd3ea /klippy/mcu.py | |
parent | 3033b037893332b1175dfc1ed99bdeab50710e00 (diff) | |
download | kutter-f8750b142f56ebb1b9dd25a2fdfb5b28d33de57d.tar.gz kutter-f8750b142f56ebb1b9dd25a2fdfb5b28d33de57d.tar.xz kutter-f8750b142f56ebb1b9dd25a2fdfb5b28d33de57d.zip |
klippy: Rework shutdown handling
If an MCU signals a shutdown from the background thread, notify the
main thread and handle the shutdown there. Dispatch shutdown handling
from the main Printer() class instead of from the Toolhead class.
This simplifies the shutdown logic.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'klippy/mcu.py')
-rw-r--r-- | klippy/mcu.py | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/klippy/mcu.py b/klippy/mcu.py index 9d76e0fa..17e93e0b 100644 --- a/klippy/mcu.py +++ b/klippy/mcu.py @@ -472,7 +472,7 @@ class MCU: prefix = "MCU '%s' shutdown: " % (self._name,) if params['#name'] == 'is_shutdown': prefix = "Previous MCU '%s' shutdown: " % (self._name,) - self._printer.note_shutdown(prefix + msg + error_help(msg)) + self._printer.invoke_async_shutdown(prefix + msg + error_help(msg)) # Connection phase def _check_restart(self, reason): start_reason = self._printer.get_start_args().get("start_reason") @@ -723,11 +723,11 @@ class MCU: return offset, freq = self._clocksync.calibrate_clock(print_time, eventtime) self._ffi_lib.steppersync_set_time(self._steppersync, offset, freq) - if self._clocksync.is_active(eventtime): + if self._clocksync.is_active(eventtime) or self.is_fileoutput(): return logging.info("Timeout with MCU '%s' (eventtime=%f)", self._name, eventtime) - self._printer.note_mcu_error("Lost communication with MCU '%s'" % ( + self._printer.invoke_shutdown("Lost communication with MCU '%s'" % ( self._name,)) def stats(self, eventtime): msg = "%s: mcu_awake=%.03f mcu_task_avg=%.06f mcu_task_stddev=%.06f" % ( @@ -735,7 +735,9 @@ class MCU: self._mcu_tick_stddev) return ' '.join([msg, self._serial.stats(eventtime), self._clocksync.stats(eventtime)]) - def force_shutdown(self): + def do_shutdown(self): + if self._is_shutdown or self._emergency_stop_cmd is None: + return self.send(self._emergency_stop_cmd.encode()) def disconnect(self): self._serial.disconnect() |