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:
parent
478f26cab6
commit
f1091a484b
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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):
|
||||
|
|
Loading…
Reference in New Issue