diff --git a/klippy/extras/print_stats.py b/klippy/extras/print_stats.py index 9ff9ca1f..7d6dd718 100644 --- a/klippy/extras/print_stats.py +++ b/klippy/extras/print_stats.py @@ -31,19 +31,31 @@ class PrintStats: # Reset last e-position gc_status = self.gcode.get_status(curtime) self.last_epos = gc_status['last_epos'] + self.state = "printing" + self.error_message = "" def note_pause(self): if self.last_pause_time is None: curtime = self.reactor.monotonic() self.last_pause_time = curtime # update filament usage self._update_filament_usage(curtime) + if self.state != "error": + self.state = "paused" + def note_error(self, message): + self.state = "error" + self.error_message = message + def note_complete(self): + self.state = "complete" + eventtime = self.reactor.monotonic() + self.total_duration = eventtime - self.print_start_time + self.print_start_time = None def reset(self): - self.filename = "" + self.filename = self.error_message = "" + self.state = "standby" self.prev_pause_duration = self.last_epos = 0. - self.filament_used = 0. + self.filament_used = self.total_duration = 0. self.print_start_time = self.last_pause_time = None def get_status(self, eventtime): - total_duration = 0. time_paused = self.prev_pause_duration if self.print_start_time is not None: if self.last_pause_time is not None: @@ -52,12 +64,14 @@ class PrintStats: else: # Accumulate filament if not paused self._update_filament_usage(eventtime) - total_duration = eventtime - self.print_start_time + self.total_duration = eventtime - self.print_start_time return { 'filename': self.filename, - 'total_duration': total_duration, - 'print_duration': total_duration - time_paused, - 'filament_used': self.filament_used + 'total_duration': self.total_duration, + 'print_duration': self.total_duration - time_paused, + 'filament_used': self.filament_used, + 'state': self.state, + 'message': self.error_message } def load_config(config): diff --git a/klippy/extras/virtual_sdcard.py b/klippy/extras/virtual_sdcard.py index a2de1327..7ab58654 100644 --- a/klippy/extras/virtual_sdcard.py +++ b/klippy/extras/virtual_sdcard.py @@ -231,6 +231,7 @@ class VirtualSD: try: self.gcode.run_script(lines[-1]) except self.gcode.error as e: + self.print_stats.note_error(str(e)) break except: logging.exception("virtual_sdcard dispatch") @@ -243,7 +244,7 @@ class VirtualSD: if self.current_file is not None: self.print_stats.note_pause() else: - self._reset_file() + self.print_stats.note_complete() return self.reactor.NEVER def load_config(config):