From 258250131fd727b495f78e5dda5de0f9c6afdf7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Mon, 20 Apr 2020 16:52:29 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Allow=20disabling=20of=20tool=20san?= =?UTF-8?q?ity=20check?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Should work around rare cases where the firmware reports invalid tools that aren't invalid. Should usually not be needed, but there are enough people with broken configs out there that this might actually help people to stay running, as meh as it is. --- src/octoprint/server/api/settings.py | 2 ++ src/octoprint/settings.py | 1 + .../static/js/app/viewmodels/settings.js | 1 + .../dialogs/settings/serialconnection.jinja2 | 9 ++++++++ src/octoprint/util/comm.py | 22 +++++++++++++------ 5 files changed, 28 insertions(+), 7 deletions(-) diff --git a/src/octoprint/server/api/settings.py b/src/octoprint/server/api/settings.py index 76f7ab60e..752018d64 100644 --- a/src/octoprint/server/api/settings.py +++ b/src/octoprint/server/api/settings.py @@ -186,6 +186,7 @@ def getSettings(): "firmwareDetection": s.getBoolean(["serial", "firmwareDetection"]), "blockWhileDwelling": s.getBoolean(["serial", "blockWhileDwelling"]), "useParityWorkaround": s.get(["serial", "useParityWorkaround"]), + "sanityCheckTools": s.getBoolean(["serial", "sanityCheckTools"]), "sendM112OnError": s.getBoolean(["serial", "sendM112OnError"]), "disableSdPrintingDetection": s.getBoolean(["serial", "disableSdPrintingDetection"]), "ackMax": s.getInt(["serial", "ackMax"]), @@ -485,6 +486,7 @@ def _saveSettings(data): value = data["serial"]["useParityWorkaround"] if value in ("always", "detect", "never"): s.set(["serial", "useParityWorkaround"], value) + if "sanityCheckTools" in data["serial"]: s.setBoolean(["serial", "sanityCheckTools"], data["serial"]["sanityCheckTools"]) if "sendM112OnError" in data["serial"]: s.setBoolean(["serial", "sendM112OnError"], data["serial"]["sendM112OnError"]) if "disableSdPrintingDetection" in data["serial"]: s.setBoolean(["serial", "disableSdPrintingDetection"], data["serial"]["disableSdPrintingDetection"]) if "ackMax" in data["serial"]: s.setInt(["serial", "ackMax"], data["serial"]["ackMax"]) diff --git a/src/octoprint/settings.py b/src/octoprint/settings.py index 26459fc77..c8a96b97e 100644 --- a/src/octoprint/settings.py +++ b/src/octoprint/settings.py @@ -155,6 +155,7 @@ default_settings = { "sendM112OnError": True, "disableSdPrintingDetection": False, "ackMax": 1, + "sanityCheckTools": True, "capabilities": { "autoreport_temp": True, diff --git a/src/octoprint/static/js/app/viewmodels/settings.js b/src/octoprint/static/js/app/viewmodels/settings.js index 68d2ca354..dbf0fd79b 100644 --- a/src/octoprint/static/js/app/viewmodels/settings.js +++ b/src/octoprint/static/js/app/viewmodels/settings.js @@ -195,6 +195,7 @@ $(function() { self.serial_firmwareDetection = ko.observable(undefined); self.serial_blockWhileDwelling = ko.observable(undefined); self.serial_useParityWorkaround = ko.observable(undefined); + self.serial_sanityCheckTools = ko.observable(undefined); self.serial_supportResendsWithoutOk = ko.observable(undefined); self.serial_logPositionOnPause = ko.observable(undefined); self.serial_logPositionOnCancel = ko.observable(undefined); diff --git a/src/octoprint/templates/dialogs/settings/serialconnection.jinja2 b/src/octoprint/templates/dialogs/settings/serialconnection.jinja2 index 978fe2074..0a45dc0ae 100644 --- a/src/octoprint/templates/dialogs/settings/serialconnection.jinja2 +++ b/src/octoprint/templates/dialogs/settings/serialconnection.jinja2 @@ -466,6 +466,15 @@ +
+ {{ _('Sanity Checking') }} +
+ +
+
diff --git a/src/octoprint/util/comm.py b/src/octoprint/util/comm.py index ec1c4ed2b..1efa3372c 100644 --- a/src/octoprint/util/comm.py +++ b/src/octoprint/util/comm.py @@ -533,6 +533,7 @@ class MachineCom(object): self._blocked_commands = settings().get(["serial", "blockedCommands"]) self._pausing_commands = settings().get(["serial", "pausingCommands"]) self._emergency_commands = settings().get(["serial", "emergencyCommands"]) + self._sanity_check_tools = settings().getBoolean(["serial", "sanityCheckTools"]) self._ack_max = settings().getInt(["serial", "ackMax"]) self._clear_to_send = CountedEvent(name="comm.clear_to_send", minimum=None, maximum=self._ack_max) @@ -2045,13 +2046,18 @@ class MachineCom(object): invalid_tool = self._currentTool - # log to terminal and remember as invalid - self._log("T{} reported as invalid, reverting to T{}".format(invalid_tool, fallback_tool)) - self._knownInvalidTools.add(invalid_tool) + if self._sanity_check_tools: + # log to terminal and remember as invalid + self._log("T{} reported as invalid, reverting to T{}".format(invalid_tool, fallback_tool)) + self._knownInvalidTools.add(invalid_tool) - # we actually do send a T command here instead of just settings self._currentTool just in case - # we had any scripts or plugins modify stuff due to the prior tool change - self.sendCommand("T{}".format(fallback_tool), tags={"trigger:revert_invalid_tool",}) + # we actually do send a T command here instead of just settings self._currentTool just in case + # we had any scripts or plugins modify stuff due to the prior tool change + self.sendCommand("T{}".format(fallback_tool), tags={"trigger:revert_invalid_tool",}) + else: + # just log to terminal, user disabled sanity check + self._log("T{} reported as invalid by the firmware, but you've " + "disabled tool sanity checking, ignoring".format(invalid_tool)) ##~~ SD Card handling elif 'SD init fail' in line or 'volume.init failed' in line or 'openRoot failed' in line: @@ -3847,7 +3853,9 @@ class MachineCom(object): return None, def _validate_tool(self, tool): - return tool < self._printerProfileManager.get_current_or_default()["extruder"]["count"] and not tool in self._knownInvalidTools + return not self._sanity_check_tools \ + or (tool < self._printerProfileManager.get_current_or_default()["extruder"]["count"] + and not tool in self._knownInvalidTools) def _reset_position_timers(self): if self._cancel_position_timer: