diff options
author | Kevin O'Connor <kevin@koconnor.net> | 2016-09-19 13:18:55 -0400 |
---|---|---|
committer | Kevin O'Connor <kevin@koconnor.net> | 2016-09-22 11:15:17 -0400 |
commit | a7b81dc05cebc593ac4be2012142fbca9180e199 (patch) | |
tree | 0f3f4cc8591d2a59350fb5cee3bb58dd689ef6c3 /klippy/toolhead.py | |
parent | 0824d3231975428429141dbd06cd6b04a4a74e14 (diff) | |
download | kutter-a7b81dc05cebc593ac4be2012142fbca9180e199.tar.gz kutter-a7b81dc05cebc593ac4be2012142fbca9180e199.tar.xz kutter-a7b81dc05cebc593ac4be2012142fbca9180e199.zip |
toolhead: Force a firmware shutdown on an unhandled exception
Check for unhandled exceptions and force the MCU to shutdown in that
case.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'klippy/toolhead.py')
-rw-r--r-- | klippy/toolhead.py | 48 |
1 files changed, 29 insertions, 19 deletions
diff --git a/klippy/toolhead.py b/klippy/toolhead.py index 8c389d19..54dae025 100644 --- a/klippy/toolhead.py +++ b/klippy/toolhead.py @@ -85,6 +85,9 @@ class MoveQueue: self.queue = [] self.prev_junction_max = 0. self.junction_flush = 0. + def reset(self): + del self.queue[:] + self.prev_junction_max = self.junction_flush = 0. def flush(self, lazy=False): can_flush = not lazy flush_count = len(self.queue) @@ -186,26 +189,30 @@ class ToolHead: eventtime, self.print_time) return buffer_time > self.buffer_time_high def flush_handler(self, eventtime): - if not self.print_time: - self.move_queue.flush() + try: if not self.print_time: - if eventtime >= self.motor_off_time: - self.motor_off() - self.reset_print_time() - self.motor_off_time = self.reactor.NEVER - return self.motor_off_time - print_time = self.print_time - buffer_time = self.printer.mcu.get_print_buffer_time( - eventtime, print_time) - if buffer_time > self.buffer_time_low: - return eventtime + buffer_time - self.buffer_time_low - self.move_queue.flush() - if print_time != self.print_time: - self.print_time_stall += 1 - self.dwell(self.buffer_time_low + STALL_TIME) - return self.reactor.NOW - self.reset_print_time() - return self.motor_off_time + self.move_queue.flush() + if not self.print_time: + if eventtime >= self.motor_off_time: + self.motor_off() + self.reset_print_time() + self.motor_off_time = self.reactor.NEVER + return self.motor_off_time + print_time = self.print_time + buffer_time = self.printer.mcu.get_print_buffer_time( + eventtime, print_time) + if buffer_time > self.buffer_time_low: + return eventtime + buffer_time - self.buffer_time_low + self.move_queue.flush() + if print_time != self.print_time: + self.print_time_stall += 1 + self.dwell(self.buffer_time_low + STALL_TIME) + return self.reactor.NOW + self.reset_print_time() + return self.motor_off_time + except: + logging.exception("Exception in flush_handler") + self.force_shutdown() def stats(self, eventtime): buffer_time = 0. if self.print_time: @@ -273,3 +280,6 @@ class ToolHead: self.extruder.motor_off(last_move_time) self.dwell(STALL_TIME) logging.debug('; Max time of %f' % (last_move_time,)) + def force_shutdown(self): + self.printer.mcu.force_shutdown() + self.move_queue.reset() |