Removed obsolete GcodeLoader in printer module
parent
48f5a44bc5
commit
a7eb5f6493
|
@ -568,83 +568,6 @@ class Printer():
|
||||||
def isLoading(self):
|
def isLoading(self):
|
||||||
return self._gcodeLoader is not None
|
return self._gcodeLoader is not None
|
||||||
|
|
||||||
class GcodeLoader(threading.Thread):
|
|
||||||
"""
|
|
||||||
The GcodeLoader takes care of loading a gcode-File from disk and parsing it into a gcode object in a separate
|
|
||||||
thread while constantly notifying interested listeners about the current progress.
|
|
||||||
The progress is returned as a float value between 0 and 1 which is to be interpreted as the percentage of completion.
|
|
||||||
"""
|
|
||||||
|
|
||||||
def __init__(self, filename, progressCallback, loadedCallback):
|
|
||||||
threading.Thread.__init__(self)
|
|
||||||
|
|
||||||
self._progressCallback = progressCallback
|
|
||||||
self._loadedCallback = loadedCallback
|
|
||||||
|
|
||||||
self._filename = filename
|
|
||||||
self._gcodeList = None
|
|
||||||
|
|
||||||
def run(self):
|
|
||||||
#Send an initial M110 to reset the line counter to zero.
|
|
||||||
prevLineType = lineType = "CUSTOM"
|
|
||||||
gcodeList = ["M110 N0"]
|
|
||||||
filesize = os.stat(self._filename).st_size
|
|
||||||
with open(self._filename, "r") as file:
|
|
||||||
for line in file:
|
|
||||||
if line.startswith(";TYPE:"):
|
|
||||||
lineType = line[6:].strip()
|
|
||||||
if ";" in line:
|
|
||||||
line = line[0:line.find(";")]
|
|
||||||
line = line.strip()
|
|
||||||
if len(line) > 0:
|
|
||||||
if prevLineType != lineType:
|
|
||||||
gcodeList.append((line, lineType, ))
|
|
||||||
else:
|
|
||||||
gcodeList.append(line)
|
|
||||||
prevLineType = lineType
|
|
||||||
self._onLoadingProgress(float(file.tell()) / float(filesize))
|
|
||||||
|
|
||||||
self._gcodeList = gcodeList
|
|
||||||
self._loadedCallback(self._filename, self._gcodeList)
|
|
||||||
|
|
||||||
def _onLoadingProgress(self, progress):
|
|
||||||
self._progressCallback(self._filename, progress, "loading")
|
|
||||||
|
|
||||||
def _onParsingProgress(self, progress):
|
|
||||||
self._progressCallback(self._filename, progress, "parsing")
|
|
||||||
|
|
||||||
class SdFileStreamer(threading.Thread):
|
|
||||||
def __init__(self, comm, filename, file, progressCallback, finishCallback):
|
|
||||||
threading.Thread.__init__(self)
|
|
||||||
|
|
||||||
self._comm = comm
|
|
||||||
self._filename = filename
|
|
||||||
self._file = file
|
|
||||||
self._progressCallback = progressCallback
|
|
||||||
self._finishCallback = finishCallback
|
|
||||||
|
|
||||||
def run(self):
|
|
||||||
if self._comm.isBusy():
|
|
||||||
return
|
|
||||||
|
|
||||||
name = self._filename[:self._filename.rfind(".")]
|
|
||||||
sdFilename = name[:8].lower() + ".gco"
|
|
||||||
try:
|
|
||||||
size = os.stat(self._file).st_size
|
|
||||||
with open(self._file, "r") as f:
|
|
||||||
self._comm.startSdFileTransfer(sdFilename)
|
|
||||||
for line in f:
|
|
||||||
if ";" in line:
|
|
||||||
line = line[0:line.find(";")]
|
|
||||||
line = line.strip()
|
|
||||||
if len(line) > 0:
|
|
||||||
self._comm.sendCommand(line)
|
|
||||||
time.sleep(0.001) # do not send too fast
|
|
||||||
self._progressCallback(sdFilename, float(f.tell()) / float(size))
|
|
||||||
finally:
|
|
||||||
self._comm.endSdFileTransfer(sdFilename)
|
|
||||||
self._finishCallback(sdFilename)
|
|
||||||
|
|
||||||
class StateMonitor(object):
|
class StateMonitor(object):
|
||||||
def __init__(self, ratelimit, updateCallback, addTemperatureCallback, addLogCallback, addMessageCallback):
|
def __init__(self, ratelimit, updateCallback, addTemperatureCallback, addLogCallback, addMessageCallback):
|
||||||
self._ratelimit = ratelimit
|
self._ratelimit = ratelimit
|
||||||
|
|
Loading…
Reference in New Issue