Add new states "resuming" and "finishing"
The later allows us to distinguish between a file having been streamed completely and the print job done script having streamed completely as well. Should fix #2547
This commit is contained in:
1 parent
9c89c4c999
commit
db81bf1e72
2 files changed
+64
-27
No files matched your search
@@ -615,6 +615,12 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback):
|
||||
def is_paused(self, *args, **kwargs):
|
||||
return self._comm is not None and self._comm.isPaused()
|
||||
|
||||
def is_resuming(self, *args, **kwargs):
|
||||
return self._comm is not None and self._comm.isResuming()
|
||||
|
||||
def is_finishing(self, *args, **kwargs):
|
||||
return self._comm is not None and self._comm.isFinishing()
|
||||
|
||||
def is_error(self, *args, **kwargs):
|
||||
return self._comm is not None and self._comm.isError()
|
||||
|
||||
@@ -904,6 +910,8 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback):
|
||||
printing=self.is_printing(),
|
||||
cancelling=self.is_cancelling(),
|
||||
pausing=self.is_pausing(),
|
||||
resuming=self.is_resuming(),
|
||||
finishing=self.is_finishing(),
|
||||
closedOrError=self.is_closed_or_error(),
|
||||
error=self.is_error(),
|
||||
paused=self.is_paused(),
|
||||
@@ -936,28 +944,29 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback):
|
||||
if self._comm is not None:
|
||||
state_string = self._comm.getStateString()
|
||||
|
||||
# forward relevant state changes to gcode manager
|
||||
if oldState == comm.MachineCom.STATE_PRINTING:
|
||||
with self._selectedFileMutex:
|
||||
if self._selectedFile is not None:
|
||||
if state == comm.MachineCom.STATE_CLOSED or state == comm.MachineCom.STATE_ERROR or state == comm.MachineCom.STATE_CLOSED_WITH_ERROR:
|
||||
payload = self._payload_for_print_job_event()
|
||||
if payload:
|
||||
payload["time"] = self._comm.getPrintTime()
|
||||
if oldState in (comm.MachineCom.STATE_PRINTING,):
|
||||
# if we were still printing and went into an error state, mark the print as failed
|
||||
if state in (comm.MachineCom.STATE_CLOSED, comm.MachineCom.STATE_ERROR, comm.MachineCom.STATE_CLOSED_WITH_ERROR):
|
||||
with self._selectedFileMutex:
|
||||
if self._selectedFile is not None:
|
||||
payload = self._payload_for_print_job_event()
|
||||
if payload:
|
||||
payload["time"] = self._comm.getPrintTime()
|
||||
|
||||
def finalize():
|
||||
self._fileManager.log_print(payload["origin"],
|
||||
payload["path"],
|
||||
time.time(),
|
||||
payload["time"],
|
||||
False,
|
||||
self._printerProfileManager.get_current_or_default()["id"])
|
||||
eventManager().fire(Events.PRINT_FAILED, payload)
|
||||
def finalize():
|
||||
self._fileManager.log_print(payload["origin"],
|
||||
payload["path"],
|
||||
time.time(),
|
||||
payload["time"],
|
||||
False,
|
||||
self._printerProfileManager.get_current_or_default()["id"])
|
||||
eventManager().fire(Events.PRINT_FAILED, payload)
|
||||
|
||||
thread = threading.Thread(target=finalize)
|
||||
thread.daemon = True
|
||||
thread.start()
|
||||
thread = threading.Thread(target=finalize)
|
||||
thread.daemon = True
|
||||
thread.start()
|
||||
self._analysisQueue.resume() # printing done, put those cpu cycles to good use
|
||||
|
||||
elif state == comm.MachineCom.STATE_PRINTING:
|
||||
self._analysisQueue.pause() # do not analyse files while printing
|
||||
|
||||
|
||||
@@ -338,6 +338,15 @@ class MachineCom(object):
|
||||
STATE_TRANSFERING_FILE = 11
|
||||
STATE_CANCELLING = 12
|
||||
STATE_PAUSING = 13
|
||||
STATE_RESUMING = 14
|
||||
STATE_FINISHING = 15
|
||||
|
||||
# be sure to add anything here that signifies an operational state
|
||||
OPERATIONAL_STATES = (STATE_PRINTING, STATE_OPERATIONAL, STATE_PAUSED, STATE_CANCELLING, STATE_PAUSING,
|
||||
STATE_RESUMING, STATE_FINISHING, STATE_TRANSFERING_FILE)
|
||||
|
||||
# be sure to add anything here that signifies a printing state
|
||||
PRINTING_STATES = (STATE_PRINTING, STATE_CANCELLING, STATE_PAUSING, STATE_RESUMING, STATE_FINISHING)
|
||||
|
||||
CAPABILITY_AUTOREPORT_TEMP = "AUTOREPORT_TEMP"
|
||||
CAPABILITY_AUTOREPORT_SD_STATUS = "AUTOREPORT_SD_STATUS"
|
||||
@@ -647,6 +656,10 @@ class MachineCom(object):
|
||||
return "Pausing"
|
||||
elif state == self.STATE_PAUSED:
|
||||
return "Paused"
|
||||
elif state == self.STATE_RESUMING:
|
||||
return "Resuming"
|
||||
elif state == self.STATE_FINISHING:
|
||||
return "Finishing"
|
||||
elif state == self.STATE_CLOSED:
|
||||
return "Offline"
|
||||
elif state == self.STATE_ERROR:
|
||||
@@ -667,11 +680,10 @@ class MachineCom(object):
|
||||
return self._state in (self.STATE_ERROR, self.STATE_CLOSED_WITH_ERROR)
|
||||
|
||||
def isOperational(self):
|
||||
return self._state in (self.STATE_OPERATIONAL, self.STATE_PRINTING, self.STATE_CANCELLING, self.STATE_PAUSING,
|
||||
self.STATE_PAUSED, self.STATE_TRANSFERING_FILE)
|
||||
return self._state in self.OPERATIONAL_STATES
|
||||
|
||||
def isPrinting(self):
|
||||
return self._state in (self.STATE_PRINTING, self.STATE_CANCELLING, self.STATE_PAUSING)
|
||||
return self._state in self.PRINTING_STATES
|
||||
|
||||
def isCancelling(self):
|
||||
return self._state == self.STATE_CANCELLING
|
||||
@@ -679,6 +691,12 @@ class MachineCom(object):
|
||||
def isPausing(self):
|
||||
return self._state == self.STATE_PAUSING
|
||||
|
||||
def isResuming(self):
|
||||
return self._state == self.STATE_RESUMING
|
||||
|
||||
def isFinishing(self):
|
||||
return self._state == self.STATE_FINISHING
|
||||
|
||||
def isSdPrinting(self):
|
||||
return self.isSdFileSelected() and self.isPrinting()
|
||||
|
||||
@@ -1199,7 +1217,10 @@ class MachineCom(object):
|
||||
if suppress_script is None:
|
||||
with self._suppress_scripts_mutex:
|
||||
suppress_script = "pause" in self._suppress_scripts
|
||||
self._suppress_scripts.remove("pause")
|
||||
try:
|
||||
self._suppress_scripts.remove("pause")
|
||||
except KeyError:
|
||||
pass
|
||||
|
||||
with self._pause_mutex:
|
||||
if self._pause_position_timer is not None:
|
||||
@@ -1231,8 +1252,9 @@ class MachineCom(object):
|
||||
self._pauseWaitTimeLost = self._pauseWaitTimeLost + (time.time() - self._pauseWaitStartTime)
|
||||
self._pauseWaitStartTime = None
|
||||
|
||||
self._changeState(self.STATE_PRINTING)
|
||||
self._changeState(self.STATE_RESUMING)
|
||||
self._callback.on_comm_print_job_resumed(suppress_script=not local_handling)
|
||||
self.sendCommand(SendQueueMarker(lambda: self._changeState(self.STATE_PRINTING)))
|
||||
|
||||
if self.isSdFileSelected():
|
||||
if local_handling:
|
||||
@@ -1908,13 +1930,18 @@ class MachineCom(object):
|
||||
# printer is reporting file finished printing
|
||||
self._currentFile.done = True
|
||||
self._currentFile.pos = 0
|
||||
self._callback.on_comm_print_job_done()
|
||||
self._changeState(self.STATE_OPERATIONAL)
|
||||
|
||||
if self._sd_status_timer is not None:
|
||||
try:
|
||||
self._sd_status_timer.cancel()
|
||||
except:
|
||||
pass
|
||||
|
||||
self._changeState(self.STATE_FINISHING)
|
||||
self._callback.on_comm_print_job_done()
|
||||
def finalize():
|
||||
self._changeState(self.STATE_OPERATIONAL)
|
||||
self.sendCommand(SendQueueMarker(finalize))
|
||||
elif 'Done saving file' in line:
|
||||
if self._trigger_ok_for_m29:
|
||||
# workaround for most versions of Marlin out in the wild
|
||||
@@ -2021,7 +2048,7 @@ class MachineCom(object):
|
||||
|
||||
self._finish_heatup()
|
||||
|
||||
if not self._state in (self.STATE_PRINTING, self.STATE_OPERATIONAL, self.STATE_PAUSED, self.STATE_CANCELLING, self.STATE_PAUSING):
|
||||
if not self._state in self.OPERATIONAL_STATES:
|
||||
return
|
||||
|
||||
# process queues ongoing resend requests and queues if we are operational
|
||||
@@ -2553,6 +2580,7 @@ class MachineCom(object):
|
||||
if isinstance(self._currentFile, StreamingGcodeFileInformation):
|
||||
self._finishFileTransfer()
|
||||
else:
|
||||
self._changeState(self.STATE_FINISHING)
|
||||
self._callback.on_comm_print_job_done()
|
||||
def finalize():
|
||||
self._changeState(self.STATE_OPERATIONAL)
|
||||
|
||||
Reference in new issue
Block a user