From f1091a484bfbf2cc5676e3a6fcd595172f123f67 Mon Sep 17 00:00:00 2001 From: Kamil Trzcinski Date: Tue, 8 Jun 2021 17:33:35 +0000 Subject: [PATCH] virtual_sdcard: add `file_path` and `file_size` to `status` This provides a comprehensive information if currently we have a file loaded. Signed-off-by: Kamil Trzcinski --- docs/Status_Reference.md | 2 ++ klippy/extras/display/menu.cfg | 2 +- klippy/extras/virtual_sdcard.py | 20 +++++++++++++++----- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/docs/Status_Reference.md b/docs/Status_Reference.md index 7442c170..da530e1b 100644 --- a/docs/Status_Reference.md +++ b/docs/Status_Reference.md @@ -329,7 +329,9 @@ The following information is available in the - `is_active`: Returns True if a print from file is currently active. - `progress`: An estimate of the current print progress (based of file size and file position). +- `file_path`: A full path to the file of currently loaded file. - `file_position`: The current position (in bytes) of an active print. +- `file_size`: The file size (in bytes) of currently loaded file. # webhooks diff --git a/klippy/extras/display/menu.cfg b/klippy/extras/display/menu.cfg index 594a16c4..213aea02 100644 --- a/klippy/extras/display/menu.cfg +++ b/klippy/extras/display/menu.cfg @@ -165,7 +165,7 @@ name: SD Card [menu __main __sdcard __start] type: command -enable: {('virtual_sdcard' in printer) and (printer.print_stats.state == "standby" or printer.print_stats.state == "error" or printer.print_stats.state == "complete")} +enable: {('virtual_sdcard' in printer) and printer.virtual_sdcard.file_path} name: Start printing gcode: M24 diff --git a/klippy/extras/virtual_sdcard.py b/klippy/extras/virtual_sdcard.py index 3cd77612..d61af0cf 100644 --- a/klippy/extras/virtual_sdcard.py +++ b/klippy/extras/virtual_sdcard.py @@ -79,12 +79,22 @@ class VirtualSD: logging.exception("virtual_sdcard get_file_list") raise self.gcode.error("Unable to get file list") def get_status(self, eventtime): - progress = 0. + return { + 'file_path': self.file_path(), + 'progress': self.progress(), + 'is_active': self.is_active(), + 'file_position': self.file_position, + 'file_size': self.file_size, + } + def file_path(self): + if self.current_file: + return self.current_file.name + return None + def progress(self): if self.file_size: - progress = float(self.file_position) / self.file_size - is_active = self.is_active() - return {'progress': progress, 'is_active': is_active, - 'file_position': self.file_position} + return float(self.file_position) / self.file_size + else: + return 0. def is_active(self): return self.work_timer is not None def do_pause(self):