Improve SD print detection
This commit is contained in:
1 parent
cb8ce62ec4
commit
5a60af9d13
2 files changed
+37
-56
No files matched your search
@@ -134,7 +134,17 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback):
|
||||
eventManager().subscribe(Events.METADATA_ANALYSIS_FINISHED, self._on_event_MetadataAnalysisFinished)
|
||||
eventManager().subscribe(Events.METADATA_STATISTICS_UPDATED, self._on_event_MetadataStatisticsUpdated)
|
||||
|
||||
def _create_estimator(self, job_type):
|
||||
def _create_estimator(self, job_type=None):
|
||||
if job_type is None:
|
||||
with self._selectedFileMutex:
|
||||
if self._selectedFile is None:
|
||||
return
|
||||
|
||||
if self._selectedFile["sd"]:
|
||||
job_type = "sdcard"
|
||||
else:
|
||||
job_type = "local"
|
||||
|
||||
self._estimator = self._estimator_factory(job_type)
|
||||
|
||||
#~~ handling of PrinterCallbacks
|
||||
@@ -490,16 +500,6 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback):
|
||||
if self._comm is None or not self._comm.isOperational() or self._comm.isPrinting():
|
||||
return
|
||||
|
||||
with self._selectedFileMutex:
|
||||
if self._selectedFile is None:
|
||||
return
|
||||
|
||||
if self._selectedFile["sd"]:
|
||||
job_type = "sdcard"
|
||||
else:
|
||||
job_type = "local"
|
||||
|
||||
self._create_estimator(job_type)
|
||||
self._fileManager.delete_recovery_data()
|
||||
|
||||
self._lastProgressReport = None
|
||||
@@ -749,7 +749,7 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback):
|
||||
cleanedPrintTime = self._comm.getCleanedPrintTime()
|
||||
|
||||
printTimeLeft = printTimeLeftOrigin = None
|
||||
if progress is not None:
|
||||
if progress is not None and self._estimator is not None:
|
||||
progress_int = int(progress * 100)
|
||||
if self._lastProgressReport != progress_int:
|
||||
self._lastProgressReport = progress_int
|
||||
@@ -1034,11 +1034,14 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback):
|
||||
self._setJobData(full_path, size, sd, user=user)
|
||||
self._stateMonitor.set_state(self._dict(text=self.get_state_string(), flags=self._getStateFlags()))
|
||||
|
||||
self._create_estimator()
|
||||
|
||||
if self._printAfterSelect:
|
||||
self._printAfterSelect = False
|
||||
self.start_print(pos=self._posAfterSelect, user=user)
|
||||
|
||||
def on_comm_print_job_started(self, suppress_script=False):
|
||||
self._stateMonitor.trigger_progress_update()
|
||||
payload = self._payload_for_print_job_event()
|
||||
if payload:
|
||||
eventManager().fire(Events.PRINT_STARTED, payload)
|
||||
|
||||
+22
-44
@@ -1011,11 +1011,6 @@ class MachineCom(object):
|
||||
self._callback.on_comm_print_job_started()
|
||||
|
||||
if self.isSdFileSelected():
|
||||
interval = self._timeout_intervals.get("sdStatus", 1.0)
|
||||
if interval <= 0:
|
||||
interval = 1.0
|
||||
self._sd_status_timer = RepeatedTimer(interval, self._poll_sd_status, run_first=True)
|
||||
|
||||
if not external_sd:
|
||||
# make sure to ignore the "file selected" later on, otherwise we'll reset our progress data
|
||||
self._ignore_select = True
|
||||
@@ -1031,15 +1026,9 @@ class MachineCom(object):
|
||||
else:
|
||||
self._currentFile.pos = 0
|
||||
|
||||
def start_polling():
|
||||
self._sd_status_timer.start()
|
||||
|
||||
self.sendCommand("M24",
|
||||
on_sent=start_polling,
|
||||
part_of_job=True,
|
||||
tags=tags | {"trigger:comm.start_print",})
|
||||
else:
|
||||
self._sd_status_timer.start()
|
||||
else:
|
||||
if pos is not None and isinstance(pos, int) and pos > 0:
|
||||
self._currentFile.seek(pos)
|
||||
@@ -1154,6 +1143,7 @@ class MachineCom(object):
|
||||
elif check_timer:
|
||||
return
|
||||
|
||||
self._currentFile.done = True
|
||||
self._recordFilePosition()
|
||||
self._callback.on_comm_print_job_cancelled()
|
||||
|
||||
@@ -1204,11 +1194,6 @@ class MachineCom(object):
|
||||
self.sendCommand("M25", part_of_job=True, tags=tags | {"trigger:comm.cancel",}) # pause print
|
||||
self.sendCommand("M27", part_of_job=True, tags=tags | {"trigger:comm.cancel",}) # get current byte position in file
|
||||
self.sendCommand("M26 S0", part_of_job=True, tags=tags | {"trigger:comm.cancel",}) # reset position in file to byte 0
|
||||
if self._sd_status_timer is not None:
|
||||
try:
|
||||
self._sd_status_timer.cancel()
|
||||
except:
|
||||
pass
|
||||
|
||||
if self._log_position_on_cancel and not disable_log_position:
|
||||
self.sendCommand("M400",
|
||||
@@ -1884,17 +1869,19 @@ class MachineCom(object):
|
||||
total = int(match.group("total"))
|
||||
|
||||
if self.isSdPrinting() and current == total == 0:
|
||||
# apparently not SD printing - newer Marlin reports it like that for some reason
|
||||
# apparently not SD printing - some Marlin versions report it like that for some reason
|
||||
self.cancelPrint(external_sd=True)
|
||||
|
||||
elif self.isSdFileSelected():
|
||||
if not self.isSdPrinting() and current != total:
|
||||
if not self.isSdPrinting() and current != total and current > 0:
|
||||
self.startPrint(external_sd=True)
|
||||
|
||||
self._currentFile.pos = current
|
||||
if self._currentFile.size == 0:
|
||||
self._currentFile.size = total
|
||||
self._callback.on_comm_progress()
|
||||
|
||||
if not self._currentFile.done:
|
||||
self._callback.on_comm_progress()
|
||||
|
||||
elif 'Not SD printing' in line and self.isSdFileSelected() and self.isPrinting() and not self.isFinishing():
|
||||
# something went wrong, printer is reporting that we actually are not printing right now...
|
||||
@@ -1910,9 +1897,7 @@ class MachineCom(object):
|
||||
size = 0
|
||||
user = None
|
||||
|
||||
expected = False
|
||||
if self._sdFileToSelect:
|
||||
expected = True
|
||||
name = self._sdFileToSelect
|
||||
user = self._sdFileToSelectUser
|
||||
|
||||
@@ -1920,12 +1905,6 @@ class MachineCom(object):
|
||||
self._sdFileToSelectUser = None
|
||||
|
||||
self._currentFile = PrintingSdFileInformation(name, size, user=user)
|
||||
|
||||
if not expected:
|
||||
# It doesn't look like we expected this, so it might be that someone just started a print
|
||||
# job from SD via the printer's controller. Let's query the printing status and see if that's
|
||||
# indeed the case and if so switch states accordingly
|
||||
self.sendCommand("M27", tags={"trigger:unexpected_file_open"})
|
||||
elif 'File selected' in line:
|
||||
if self._ignore_select:
|
||||
self._ignore_select = False
|
||||
@@ -1944,12 +1923,6 @@ class MachineCom(object):
|
||||
self._currentFile.done = True
|
||||
self._currentFile.pos = 0
|
||||
|
||||
if self._sd_status_timer is not None:
|
||||
try:
|
||||
self._sd_status_timer.cancel()
|
||||
except:
|
||||
pass
|
||||
|
||||
self.sendCommand("M400", part_of_job=True)
|
||||
self._callback.on_comm_print_job_done()
|
||||
def finalize():
|
||||
@@ -2266,7 +2239,7 @@ class MachineCom(object):
|
||||
command or heating, no poll will be done.
|
||||
"""
|
||||
|
||||
if self.isOperational() and not self._sdstatus_autoreporting and not self._connection_closing and self.isSdPrinting() and not self._long_running_command and not self._dwelling_until and not self._heating:
|
||||
if self.isOperational() and not self._sdstatus_autoreporting and not self._connection_closing and self.isSdFileSelected() and not self._long_running_command and not self._dwelling_until and not self._heating:
|
||||
self.sendCommand("M27", cmd_type="sd_status_poll", tags={"trigger:comm.poll_sd_status"})
|
||||
|
||||
def _set_autoreport_temperature_interval(self, interval=None):
|
||||
@@ -2295,9 +2268,12 @@ class MachineCom(object):
|
||||
|
||||
def _onConnected(self):
|
||||
self._serial.timeout = settings().getFloat(["serial", "timeout", "communication"])
|
||||
self._temperature_timer = RepeatedTimer(self._getTemperatureTimerInterval, self._poll_temperature, run_first=True)
|
||||
self._temperature_timer = RepeatedTimer(self._get_temperature_timer_interval, self._poll_temperature, run_first=True)
|
||||
self._temperature_timer.start()
|
||||
|
||||
self._sd_status_timer = RepeatedTimer(self._get_sd_status_timer_interval, self._poll_sd_status, run_first=True)
|
||||
self._sd_status_timer.start()
|
||||
|
||||
self._changeState(self.STATE_OPERATIONAL)
|
||||
|
||||
self.resetLineNumbers(tags={"trigger:comm.on_connected",})
|
||||
@@ -2334,7 +2310,7 @@ class MachineCom(object):
|
||||
if self._busy_protocol_detected:
|
||||
self._set_busy_protocol_interval()
|
||||
|
||||
def _getTemperatureTimerInterval(self):
|
||||
def _get_temperature_timer_interval(self):
|
||||
busy_default = 4.0
|
||||
target_default = 2.0
|
||||
|
||||
@@ -2358,6 +2334,12 @@ class MachineCom(object):
|
||||
|
||||
return get("temperature", busy_default)
|
||||
|
||||
def _get_sd_status_timer_interval(self):
|
||||
interval = self._timeout_intervals.get("sdStatus", 1.0)
|
||||
if interval <= 0:
|
||||
interval = 1.0
|
||||
return interval
|
||||
|
||||
def _send_from_command_queue(self):
|
||||
# We loop here to make sure that if we do NOT send the first command
|
||||
# from the queue, we'll send the second (if there is one). We do not
|
||||
@@ -3635,6 +3617,10 @@ class PrintingFileInformation(object):
|
||||
def done(self):
|
||||
return self._done
|
||||
|
||||
@done.setter
|
||||
def done(self, value):
|
||||
self._done = value
|
||||
|
||||
class PrintingSdFileInformation(PrintingFileInformation):
|
||||
"""
|
||||
Encapsulates information regarding an ongoing print from SD.
|
||||
@@ -3649,14 +3635,6 @@ class PrintingSdFileInformation(PrintingFileInformation):
|
||||
def getFileLocation(self):
|
||||
return FileDestinations.SDCARD
|
||||
|
||||
@property
|
||||
def done(self):
|
||||
return self._done
|
||||
|
||||
@done.setter
|
||||
def done(self, value):
|
||||
self._done = value
|
||||
|
||||
@property
|
||||
def size(self):
|
||||
return self._size
|
||||
|
||||
Reference in new issue
Block a user