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 <ayufan@ayufan.eu>
This commit is contained in:
Kamil Trzcinski 2021-06-08 17:33:35 +00:00 committed by KevinOConnor
parent 478f26cab6
commit f1091a484b
3 changed files with 18 additions and 6 deletions

View File

@ -329,7 +329,9 @@ The following information is available in the
- `is_active`: Returns True if a print from file is currently active. - `is_active`: Returns True if a print from file is currently active.
- `progress`: An estimate of the current print progress (based of file - `progress`: An estimate of the current print progress (based of file
size and file position). 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_position`: The current position (in bytes) of an active print.
- `file_size`: The file size (in bytes) of currently loaded file.
# webhooks # webhooks

View File

@ -165,7 +165,7 @@ name: SD Card
[menu __main __sdcard __start] [menu __main __sdcard __start]
type: command 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 name: Start printing
gcode: M24 gcode: M24

View File

@ -79,12 +79,22 @@ class VirtualSD:
logging.exception("virtual_sdcard get_file_list") logging.exception("virtual_sdcard get_file_list")
raise self.gcode.error("Unable to get file list") raise self.gcode.error("Unable to get file list")
def get_status(self, eventtime): 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: if self.file_size:
progress = float(self.file_position) / self.file_size return float(self.file_position) / self.file_size
is_active = self.is_active() else:
return {'progress': progress, 'is_active': is_active, return 0.
'file_position': self.file_position}
def is_active(self): def is_active(self):
return self.work_timer is not None return self.work_timer is not None
def do_pause(self): def do_pause(self):