diff options
author | Arksine <arksine.code@gmail.com> | 2020-07-29 06:14:02 -0400 |
---|---|---|
committer | KevinOConnor <kevin@koconnor.net> | 2020-08-05 13:46:24 -0400 |
commit | af39a209f34674c8fb0fb8bcc474dfbd2d09d326 (patch) | |
tree | 4fe481179b7f18eb9a9768fb611e88c57eab3f96 /klippy/extras/virtual_sdcard.py | |
parent | 10987003b09a5b88fa0d7cbfff76ffa2f857b445 (diff) | |
download | kutter-af39a209f34674c8fb0fb8bcc474dfbd2d09d326.tar.gz kutter-af39a209f34674c8fb0fb8bcc474dfbd2d09d326.tar.xz kutter-af39a209f34674c8fb0fb8bcc474dfbd2d09d326.zip |
virtual_sdcard: add SDCARD_RESET_FILE gcode
This allows the user to close a currently loaded file and reset the virtual_sdcard's state.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Diffstat (limited to 'klippy/extras/virtual_sdcard.py')
-rw-r--r-- | klippy/extras/virtual_sdcard.py | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/klippy/extras/virtual_sdcard.py b/klippy/extras/virtual_sdcard.py index d5312536..b08cdd18 100644 --- a/klippy/extras/virtual_sdcard.py +++ b/klippy/extras/virtual_sdcard.py @@ -25,6 +25,9 @@ class VirtualSD: self.gcode.register_command(cmd, getattr(self, 'cmd_' + cmd)) for cmd in ['M28', 'M29', 'M30']: self.gcode.register_command(cmd, self.cmd_error) + self.gcode.register_command( + "SDCARD_RESET_FILE", self.cmd_SDCARD_RESET_FILE, + desc=self.cmd_SDCARD_RESET_FILE_help) def handle_shutdown(self): if self.work_timer is not None: self.must_pause_work = True @@ -69,6 +72,19 @@ class VirtualSD: # G-Code commands def cmd_error(self, gcmd): raise gcmd.error("SD write not supported") + def _reset_file(self): + if self.current_file is not None: + self.do_pause() + self.current_file.close() + self.current_file = None + self.file_position = self.file_size = 0. + cmd_SDCARD_RESET_FILE_help = "Clears a loaded SD File. Stops the print "\ + "if necessary" + def cmd_SDCARD_RESET_FILE(self, gcmd): + if self.cmd_from_sd: + raise gcmd.error( + "SDCARD_RESET_FILE cannot be run from the sdcard") + self._reset_file() def cmd_M20(self, gcmd): # List SD card files = self.get_file_list() |