virtual_sdcard: Use new GCodeCommand wrappers
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
48ebb6959d
commit
b0d9a82718
|
@ -67,33 +67,33 @@ class VirtualSD:
|
||||||
while self.work_timer is not None and not self.cmd_from_sd:
|
while self.work_timer is not None and not self.cmd_from_sd:
|
||||||
self.reactor.pause(self.reactor.monotonic() + .001)
|
self.reactor.pause(self.reactor.monotonic() + .001)
|
||||||
# G-Code commands
|
# G-Code commands
|
||||||
def cmd_error(self, params):
|
def cmd_error(self, gcmd):
|
||||||
raise self.gcode.error("SD write not supported")
|
raise gcmd.error("SD write not supported")
|
||||||
def cmd_M20(self, params):
|
def cmd_M20(self, gcmd):
|
||||||
# List SD card
|
# List SD card
|
||||||
files = self.get_file_list()
|
files = self.get_file_list()
|
||||||
self.gcode.respond_raw("Begin file list")
|
gcmd.respond_raw("Begin file list")
|
||||||
for fname, fsize in files:
|
for fname, fsize in files:
|
||||||
self.gcode.respond_raw("%s %d" % (fname, fsize))
|
gcmd.respond_raw("%s %d" % (fname, fsize))
|
||||||
self.gcode.respond_raw("End file list")
|
gcmd.respond_raw("End file list")
|
||||||
def cmd_M21(self, params):
|
def cmd_M21(self, gcmd):
|
||||||
# Initialize SD card
|
# Initialize SD card
|
||||||
self.gcode.respond_raw("SD card ok")
|
gcmd.respond_raw("SD card ok")
|
||||||
def cmd_M23(self, params):
|
def cmd_M23(self, gcmd):
|
||||||
# Select SD file
|
# Select SD file
|
||||||
if self.work_timer is not None:
|
if self.work_timer is not None:
|
||||||
raise self.gcode.error("SD busy")
|
raise gcmd.error("SD busy")
|
||||||
if self.current_file is not None:
|
if self.current_file is not None:
|
||||||
self.current_file.close()
|
self.current_file.close()
|
||||||
self.current_file = None
|
self.current_file = None
|
||||||
self.file_position = self.file_size = 0
|
self.file_position = self.file_size = 0
|
||||||
try:
|
try:
|
||||||
orig = params['#original']
|
orig = gcmd.get_commandline()
|
||||||
filename = orig[orig.find("M23") + 4:].split()[0].strip()
|
filename = orig[orig.find("M23") + 4:].split()[0].strip()
|
||||||
if '*' in filename:
|
if '*' in filename:
|
||||||
filename = filename[:filename.find('*')].strip()
|
filename = filename[:filename.find('*')].strip()
|
||||||
except:
|
except:
|
||||||
raise self.gcode.error("Unable to extract filename")
|
raise gcmd.error("Unable to extract filename")
|
||||||
if filename.startswith('/'):
|
if filename.startswith('/'):
|
||||||
filename = filename[1:]
|
filename = filename[1:]
|
||||||
files = self.get_file_list()
|
files = self.get_file_list()
|
||||||
|
@ -107,35 +107,35 @@ class VirtualSD:
|
||||||
f.seek(0)
|
f.seek(0)
|
||||||
except:
|
except:
|
||||||
logging.exception("virtual_sdcard file open")
|
logging.exception("virtual_sdcard file open")
|
||||||
raise self.gcode.error("Unable to open file")
|
raise gcmd.error("Unable to open file")
|
||||||
self.gcode.respond_raw("File opened:%s Size:%d" % (filename, fsize))
|
gcmd.respond_raw("File opened:%s Size:%d" % (filename, fsize))
|
||||||
self.gcode.respond_raw("File selected")
|
gcmd.respond_raw("File selected")
|
||||||
self.current_file = f
|
self.current_file = f
|
||||||
self.file_position = 0
|
self.file_position = 0
|
||||||
self.file_size = fsize
|
self.file_size = fsize
|
||||||
def cmd_M24(self, params):
|
def cmd_M24(self, gcmd):
|
||||||
# Start/resume SD print
|
# Start/resume SD print
|
||||||
if self.work_timer is not None:
|
if self.work_timer is not None:
|
||||||
raise self.gcode.error("SD busy")
|
raise gcmd.error("SD busy")
|
||||||
self.must_pause_work = False
|
self.must_pause_work = False
|
||||||
self.work_timer = self.reactor.register_timer(
|
self.work_timer = self.reactor.register_timer(
|
||||||
self.work_handler, self.reactor.NOW)
|
self.work_handler, self.reactor.NOW)
|
||||||
def cmd_M25(self, params):
|
def cmd_M25(self, gcmd):
|
||||||
# Pause SD print
|
# Pause SD print
|
||||||
self.do_pause()
|
self.do_pause()
|
||||||
def cmd_M26(self, params):
|
def cmd_M26(self, gcmd):
|
||||||
# Set SD position
|
# Set SD position
|
||||||
if self.work_timer is not None:
|
if self.work_timer is not None:
|
||||||
raise self.gcode.error("SD busy")
|
raise gcmd.error("SD busy")
|
||||||
pos = self.gcode.get_int('S', params, minval=0)
|
pos = gcmd.get_int('S', minval=0)
|
||||||
self.file_position = pos
|
self.file_position = pos
|
||||||
def cmd_M27(self, params):
|
def cmd_M27(self, gcmd):
|
||||||
# Report SD print status
|
# Report SD print status
|
||||||
if self.current_file is None:
|
if self.current_file is None:
|
||||||
self.gcode.respond_raw("Not SD printing.")
|
gcmd.respond_raw("Not SD printing.")
|
||||||
return
|
return
|
||||||
self.gcode.respond_raw("SD printing byte %d/%d" % (
|
gcmd.respond_raw("SD printing byte %d/%d"
|
||||||
self.file_position, self.file_size))
|
% (self.file_position, self.file_size))
|
||||||
# Background work timer
|
# Background work timer
|
||||||
def work_handler(self, eventtime):
|
def work_handler(self, eventtime):
|
||||||
logging.info("Starting SD card print (position %d)", self.file_position)
|
logging.info("Starting SD card print (position %d)", self.file_position)
|
||||||
|
|
Loading…
Reference in New Issue