Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/4493 - Defer M20 commands until initial capability report is done #4577

Merged
merged 8 commits into from
Sep 28, 2022
Prev Previous commit
Next Next commit
Refactor to be more similar to _firmware_info implementation
  • Loading branch information
kForth committed Aug 2, 2022
commit 99f1bacefc19b08ad02201de744886b179922f6e
47 changes: 15 additions & 32 deletions src/octoprint/util/comm.py
Original file line number Diff line number Diff line change
Expand Up @@ -621,9 +621,12 @@ def __init__(

self._firmware_detection = settings().getBoolean(["serial", "firmwareDetection"])
self._firmware_info_received = False
self._firmware_capabilities_received = False
self._firmware_info = {}
self._firmware_capabilities = {}

self._defer_sd_refresh = settings().getBoolean(["serial", "waitToLoadSdFileList"])

self._temperature_autoreporting = False
self._sdstatus_autoreporting = False
self._pos_autoreporting = False
Expand Down Expand Up @@ -752,11 +755,6 @@ def __init__(
self._ignore_select = False
self._manualStreaming = False

# Capability report tracking
self._first_cap_report_pending = False
self._first_cap_report_started = False
self._refresh_sd_files_after_cap_report = False

self.last_temperature = TemperatureRecord()
self.pause_temperature = TemperatureRecord()
self.cancel_temperature = TemperatureRecord()
Expand Down Expand Up @@ -2008,12 +2006,8 @@ def refreshSdFiles(self, tags=None):
if not self.isOperational() or self.isBusy():
return

if (
settings().get(["serial", "waitToLoadSdFileList"])
and self._first_cap_report_pending
):
self._refresh_sd_files_after_cap_report = True
self._logger.info(
if self._defer_sd_refresh and not self._firmware_capabilities_received:
self._logger.debug(
"Deferring sd file refresh until capability report is processed"
)
return
Expand Down Expand Up @@ -2596,26 +2590,18 @@ def convert_line(line):
):
continue

# track the start and end of the first firmware capability reporting (from M115) so the sd card
# file list can be loaded afterwards for some printers
# wait for the end of the firmware capability report (M115) then notify plugins and refresh sd list if deferred
if (
settings().get(["serial", "waitToLoadSdFileList"])
and self._first_cap_report_pending
self._firmware_capabilities
and not self._firmware_capabilities_received
and not lower_line.startswith("cap:")
):
# capability report in progress
if lower_line.startswith("cap:"):
self._first_cap_report_started = True

# capability report done
elif self._first_cap_report_started:
self._first_cap_report_pending = False
self._first_cap_report_started = False

# refresh sd files now if it was deferred while waiting for report
if self._refresh_sd_files_after_cap_report:
self._refresh_sd_files_after_cap_report = False
self._logger.info("Performing deferred sd file refresh")
self.refreshSdFiles()
self._firmware_capabilities_received = True

if self._defer_sd_refresh:
# sd list was deferred, refresh it now
self._logger.debug("Performing deferred sd file refresh")
self.refreshSdFiles()

##~~ position report processing
if "X:" in line and "Y:" in line and "Z:" in line:
Expand Down Expand Up @@ -3667,9 +3653,6 @@ def _onConnected(self):
"trigger:comm.on_connected",
},
)
if settings().get(["serial", "waitToLoadSdFileList"]):
self._first_cap_report_pending = True
self._first_cap_report_started = False

if self._sdAvailable:
self.refreshSdFiles(tags={"trigger:comm.on_connected"})
Expand Down