Make SD prints work again
#mswa
This commit is contained in:
1 parent
93d77e6b25
commit
60d84b7d06
7 files changed
+79
-19
No files matched your search
@@ -279,6 +279,7 @@ class LocalFilePrintjob(StoragePrintjob):
|
||||
|
||||
if not line:
|
||||
self.process_job_done()
|
||||
return None
|
||||
processed = self.process_line(line)
|
||||
|
||||
self._read_lines += 1
|
||||
@@ -460,11 +461,9 @@ class SDFilePrintjob(StoragePrintjob, FileAwareProtocolListener):
|
||||
self._active = True
|
||||
self._last_pos = position
|
||||
|
||||
from octoprint.util import RepeatedTimer
|
||||
self._status_timer = RepeatedTimer(self._status_interval, self._query_status, condition=self._query_active)
|
||||
self._status_timer.start()
|
||||
self._protocol.start_file_print_status_monitor()
|
||||
|
||||
def on_protocol_file_status(self, protocol, pos, total, *args, **kwargs):
|
||||
def on_protocol_sd_status(self, protocol, pos, total, *args, **kwargs):
|
||||
self._last_pos = pos
|
||||
self._size = total
|
||||
self.process_job_progress()
|
||||
@@ -474,6 +473,7 @@ class SDFilePrintjob(StoragePrintjob, FileAwareProtocolListener):
|
||||
self.process_job_started()
|
||||
|
||||
def on_protocol_file_print_done(self, protocol, *args, **kwargs):
|
||||
self._protocol.stop_file_print_status_monitor()
|
||||
self.process_job_done()
|
||||
|
||||
def reset_job(self):
|
||||
@@ -481,12 +481,10 @@ class SDFilePrintjob(StoragePrintjob, FileAwareProtocolListener):
|
||||
self._last_pos = None
|
||||
self._size = None
|
||||
|
||||
def _query_status(self):
|
||||
if self._protocol.can_send():
|
||||
self._protocol.get_file_print_status()
|
||||
|
||||
def _query_active(self):
|
||||
return self._active
|
||||
def event_payload(self):
|
||||
payload = Printjob.event_payload(self)
|
||||
payload["size"] = self.size
|
||||
return payload
|
||||
|
||||
|
||||
class PrintjobListener(object):
|
||||
|
||||
@@ -331,6 +331,12 @@ class FileAwareProtocolMixin(object):
|
||||
def get_file_print_status(self):
|
||||
pass
|
||||
|
||||
def start_file_print_status_monitor(self):
|
||||
pass
|
||||
|
||||
def stop_file_print_status_monitor(self):
|
||||
pass
|
||||
|
||||
|
||||
class FileManagementProtocolMixin(FileAwareProtocolMixin):
|
||||
|
||||
|
||||
@@ -97,6 +97,7 @@ class ReprapGcodeProtocol(Protocol, ThreeDPrinterProtocolMixin, MotorControlProt
|
||||
temperature_interval_idle=5.0,
|
||||
temperature_interval_printing=5.0,
|
||||
temperature_interval_autoreport=2.0,
|
||||
sd_status_interval=2.0,
|
||||
sd_status_interval_autoreport=1.0,
|
||||
plugin_manager=None):
|
||||
super(ReprapGcodeProtocol, self).__init__()
|
||||
@@ -119,6 +120,7 @@ class ReprapGcodeProtocol(Protocol, ThreeDPrinterProtocolMixin, MotorControlProt
|
||||
temperature_idle=temperature_interval_idle,
|
||||
temperature_printing=temperature_interval_printing,
|
||||
temperature_autoreport=temperature_interval_autoreport,
|
||||
sd_status=sd_status_interval,
|
||||
sd_status_autoreport=sd_status_interval_autoreport
|
||||
)
|
||||
|
||||
@@ -507,6 +509,7 @@ class ReprapGcodeProtocol(Protocol, ThreeDPrinterProtocolMixin, MotorControlProt
|
||||
|
||||
def start_file_print(self, name, position=0, *args, **kwargs):
|
||||
tags = kwargs.get(b"tags", set()) | {"trigger:protocol.start_file_print"}
|
||||
|
||||
self._send_commands(self.flavor.command_sd_select_file(name),
|
||||
self.flavor.command_sd_set_pos(position),
|
||||
self.flavor.command_sd_start(),
|
||||
@@ -530,8 +533,28 @@ class ReprapGcodeProtocol(Protocol, ThreeDPrinterProtocolMixin, MotorControlProt
|
||||
def get_file_print_status(self, *args, **kwargs):
|
||||
self._send_commands(self.flavor.command_sd_status())
|
||||
|
||||
def start_file_print_status_monitor(self):
|
||||
if self._internal_flags["sd_status_autoreporting"]:
|
||||
return
|
||||
|
||||
from octoprint.util import RepeatedTimer
|
||||
|
||||
def poll_status():
|
||||
if self.can_send() and not self._internal_flags["sd_status_autoreporting"]:
|
||||
self.get_file_print_status()
|
||||
self._sd_status_poller = RepeatedTimer(self.interval["sd_status"],
|
||||
poll_status)
|
||||
self._sd_status_poller.start()
|
||||
|
||||
def stop_file_print_status_monitor(self):
|
||||
if self._sd_status_poller is not None:
|
||||
self._sd_status_poller.cancel()
|
||||
self._sd_status_poller = None
|
||||
|
||||
##~~
|
||||
|
||||
def can_send(self):
|
||||
return not self._internal_flags["long_running_command"] and not self._internal_flags["heating"]
|
||||
return self._is_operational() and not self._internal_flags["long_running_command"] and not self._internal_flags["heating"] and not self._internal_flags["dwelling_until"]
|
||||
|
||||
def send_commands(self, *commands, **kwargs):
|
||||
command_type = kwargs.get(b"command_type")
|
||||
|
||||
@@ -609,10 +609,13 @@ class FileManager(object):
|
||||
|
||||
def log_print(self, destination, path, timestamp, print_time, success, printer_profile):
|
||||
try:
|
||||
if success:
|
||||
self._storage(destination).add_history(path, dict(timestamp=timestamp, printTime=print_time, success=success, printerProfile=printer_profile))
|
||||
else:
|
||||
self._storage(destination).add_history(path, dict(timestamp=timestamp, success=success, printerProfile=printer_profile))
|
||||
try:
|
||||
if success:
|
||||
self._storage(destination).add_history(path, dict(timestamp=timestamp, printTime=print_time, success=success, printerProfile=printer_profile))
|
||||
else:
|
||||
self._storage(destination).add_history(path, dict(timestamp=timestamp, success=success, printerProfile=printer_profile))
|
||||
except NotImplementedError:
|
||||
pass
|
||||
eventManager().fire(Events.METADATA_STATISTICS_UPDATED, dict(storage=destination, path=path))
|
||||
except NoSuchStorage:
|
||||
# if there's no storage configured where to log the print, we'll just not log it
|
||||
|
||||
@@ -296,6 +296,33 @@ class Storage(object):
|
||||
"""
|
||||
raise NotImplementedError()
|
||||
|
||||
def add_history(self, path, data):
|
||||
"""
|
||||
Adds a history entry for the given ``path``.
|
||||
|
||||
:param path: path of the file for which to add the history entry
|
||||
:param data: history entry
|
||||
"""
|
||||
raise NotImplementedError()
|
||||
|
||||
def update_history(self, path, index, data):
|
||||
"""
|
||||
Updates the history entry for ``path`` at ``index``.
|
||||
|
||||
:param path: path of the file for which to update the history entry
|
||||
:param index: index
|
||||
:param data: history entry
|
||||
"""
|
||||
raise NotImplementedError()
|
||||
|
||||
def remove_history(self, path, index):
|
||||
"""
|
||||
Removes the history entry for ``path`` at ``index``.
|
||||
:param path: path of the file for which to remove the history entry
|
||||
:param index: index
|
||||
"""
|
||||
raise NotImplementedError()
|
||||
|
||||
def set_additional_metadata(self, path, key, data, overwrite=False, merge=False):
|
||||
"""
|
||||
Adds additional metadata to the metadata of ``path``. Metadata in ``data`` will be saved under ``key``.
|
||||
|
||||
@@ -487,7 +487,10 @@ class VirtualPrinter(object):
|
||||
|
||||
def _gcode_M26(self, data):
|
||||
if self._sdCardReady:
|
||||
pos = int(re.search("S([0-9]+)", data).group(1))
|
||||
match = re.search("S([0-9]+)", data)
|
||||
if not match:
|
||||
return
|
||||
pos = int(match.group(1))
|
||||
self._setSdPos(pos)
|
||||
|
||||
def _gcode_M27(self, data):
|
||||
|
||||
@@ -521,14 +521,14 @@ class Printer(PrinterInterface,
|
||||
@util.deprecated("select_file has been deprecated, use select_job instead",
|
||||
includedoc="Replaced by :func:`select_job`",
|
||||
since="1.4.0")
|
||||
def select_file(self, path, sd, printAfterSelect=False, pos=None, user=None):
|
||||
def select_file(self, path, sd, printAfterSelect=False, pos=None, user=None, **kwargs):
|
||||
if sd:
|
||||
storage = "sdcard"
|
||||
else:
|
||||
storage = "local"
|
||||
|
||||
job = self._file_manager.create_print_job(storage, path, user=user)
|
||||
self.select_job(job, start_printing=printAfterSelect, pos=pos)
|
||||
self.select_job(job, start_printing=printAfterSelect, pos=pos, **kwargs)
|
||||
|
||||
unselect_file = util.deprecated("unselect_file has been deprecated, use unselect_job instead",
|
||||
includedoc="Replaced by :func:`unselect_job`",
|
||||
@@ -549,7 +549,7 @@ class Printer(PrinterInterface,
|
||||
self._set_current_z(None)
|
||||
|
||||
self._protocol.process(self._job.job,
|
||||
position=pos,
|
||||
position=0 if pos is None else pos,
|
||||
tags=kwargs.get("tags", set()) | {"trigger:printer.start_print"})
|
||||
|
||||
def pause_print(self, *args, **kwargs):
|
||||
|
||||
Reference in new issue
Block a user