From 38a321e175a4b5ef856f4b2e61e9bdc47cba1c9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Mon, 4 Mar 2019 17:29:00 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Add=20configurable=20list=20of=20bl?= =?UTF-8?q?ocked=20and=20pausing=20commands?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Instead of a boolean option to block sending of M0 *and* M1 and hardcoding them and M25 to pause an ongoing print, we now have two lists for blocked commands and pausing commands respectively. Blocked by default: M0 and M1. Pausing by default: M0, M1 and M25. Implements #2970 --- docs/configuration/config_yaml.rst | 13 ++++++++ src/octoprint/server/api/settings.py | 6 ++-- src/octoprint/settings.py | 23 ++++++++++++-- .../static/js/app/viewmodels/settings.js | 7 ++++- .../dialogs/settings/serialconnection.jinja2 | 16 +++++++--- src/octoprint/util/comm.py | 30 ++++++++----------- 6 files changed, 68 insertions(+), 27 deletions(-) diff --git a/docs/configuration/config_yaml.rst b/docs/configuration/config_yaml.rst index a95bac500..fd25a4d8c 100644 --- a/docs/configuration/config_yaml.rst +++ b/docs/configuration/config_yaml.rst @@ -810,6 +810,19 @@ Use the following settings to configure the serial connection to the printer: additionalBaudrates: - 123456 + # Commands which should not be sent to the printer, e.g. because they are known to block serial + # communication until physical interaction with the printer as is the case on most firmwares with + # the default M0 and M1. + blockedCommands: + - M0 + - M1 + + # Commands which should cause OctoPrint to pause any ongoing prints. + pausingCommands: + - M0 + - M1 + - M25 + # Commands which are known to take a long time to be acknowledged by the firmware. E.g. # homing, dwelling, auto leveling etc. Defaults to the below commands. longRunningCommands: diff --git a/src/octoprint/server/api/settings.py b/src/octoprint/server/api/settings.py index 4a27a4106..d1cd232a7 100644 --- a/src/octoprint/server/api/settings.py +++ b/src/octoprint/server/api/settings.py @@ -150,11 +150,12 @@ def getSettings(): "additionalBaudrates": s.get(["serial", "additionalBaudrates"]), "longRunningCommands": s.get(["serial", "longRunningCommands"]), "checksumRequiringCommands": s.get(["serial", "checksumRequiringCommands"]), + "blockedCommands": s.get(["serial", "blockedCommands"]), + "pausingCommands": s.get(["serial", "pausingCommands"]), "helloCommand": s.get(["serial", "helloCommand"]), "ignoreErrorsFromFirmware": s.getBoolean(["serial", "ignoreErrorsFromFirmware"]), "disconnectOnErrors": s.getBoolean(["serial", "disconnectOnErrors"]), "triggerOkForM29": s.getBoolean(["serial", "triggerOkForM29"]), - "blockM0M1": s.getBoolean(["serial", "blockM0M1"]), "logPositionOnPause": s.getBoolean(["serial", "logPositionOnPause"]), "logPositionOnCancel": s.getBoolean(["serial", "logPositionOnCancel"]), "abortHeatupOnCancel": s.getBoolean(["serial", "abortHeatupOnCancel"]), @@ -434,11 +435,12 @@ def _saveSettings(data): if "additionalBaudrates" in data["serial"] and isinstance(data["serial"]["additionalBaudrates"], (list, tuple)): s.set(["serial", "additionalBaudrates"], data["serial"]["additionalBaudrates"]) if "longRunningCommands" in data["serial"] and isinstance(data["serial"]["longRunningCommands"], (list, tuple)): s.set(["serial", "longRunningCommands"], data["serial"]["longRunningCommands"]) if "checksumRequiringCommands" in data["serial"] and isinstance(data["serial"]["checksumRequiringCommands"], (list, tuple)): s.set(["serial", "checksumRequiringCommands"], data["serial"]["checksumRequiringCommands"]) + if "blockedCommands" in data["serial"] and isinstance(data["serial"]["blockedCommands"], (list, tuple)): s.set(["serial", "blockedCommands"], data["serial"]["blockedCommands"]) + if "pausingCommands" in data["serial"] and isinstance(data["serial"]["pausingCommands"], (list, tuple)): s.set(["serial", "pausingCommands"], data["serial"]["pausingCommands"]) if "helloCommand" in data["serial"]: s.set(["serial", "helloCommand"], data["serial"]["helloCommand"]) if "ignoreErrorsFromFirmware" in data["serial"]: s.setBoolean(["serial", "ignoreErrorsFromFirmware"], data["serial"]["ignoreErrorsFromFirmware"]) if "disconnectOnErrors" in data["serial"]: s.setBoolean(["serial", "disconnectOnErrors"], data["serial"]["disconnectOnErrors"]) if "triggerOkForM29" in data["serial"]: s.setBoolean(["serial", "triggerOkForM29"], data["serial"]["triggerOkForM29"]) - if "blockM0M1" in data["serial"]: s.setBoolean(["serial", "blockM0M1"], data["serial"]["blockM0M1"]) if "supportResendsWithoutOk" in data["serial"]: value = data["serial"]["supportResendsWithoutOk"] if value in ("always", "detect", "never"): diff --git a/src/octoprint/settings.py b/src/octoprint/settings.py index 51ac62794..b448da7c5 100644 --- a/src/octoprint/settings.py +++ b/src/octoprint/settings.py @@ -113,6 +113,8 @@ default_settings = { "additionalPorts": [], "additionalBaudrates": [], "longRunningCommands": ["G4", "G28", "G29", "G30", "G32", "M400", "M226", "M600"], + "blockedCommands": ["M0", "M1"], + "pausingCommands": ["M0", "M1", "M25"], "checksumRequiringCommands": ["M110"], "helloCommand": "M110 N0", "disconnectOnErrors": True, @@ -149,8 +151,7 @@ default_settings = { }, # command specific flags - "triggerOkForM29": True, - "blockM0M1": True + "triggerOkForM29": True }, "server": { "host": None, @@ -957,7 +958,8 @@ class Settings(object): self._migrate_core_system_commands, self._migrate_serial_features, self._migrate_resend_without_ok, - self._migrate_string_temperature_profile_values + self._migrate_string_temperature_profile_values, + self._migrate_blocked_commands ) for migrate in migrators: @@ -1316,6 +1318,21 @@ class Settings(object): return True return False + def _migrate_blocked_commands(self, config): + if "serial" in config and "blockM0M1" in config["serial"]: + blockM0M1 = config["serial"]["blockM0M1"] + blockedCommands = config["serial"].get("blockedCommands", []) + if blockM0M1: + blockedCommands = set(blockedCommands) + blockedCommands.add("M0") + blockedCommands.add("M1") + config["serial"]["blockedCommands"] = sorted(blockedCommands) + else: + config["serial"]["blockedCommands"] = sorted([v for v in blockedCommands if v not in ("M0", "M1")]) + del config["serial"]["blockM0M1"] + return True + return False + def backup(self, suffix=None, path=None, ext=None, hidden=False): import shutil diff --git a/src/octoprint/static/js/app/viewmodels/settings.js b/src/octoprint/static/js/app/viewmodels/settings.js index 9bc9fd5ef..42eaf5bfd 100644 --- a/src/octoprint/static/js/app/viewmodels/settings.js +++ b/src/octoprint/static/js/app/viewmodels/settings.js @@ -169,10 +169,11 @@ $(function() { self.serial_additionalBaudrates = ko.observable(undefined); self.serial_longRunningCommands = ko.observable(undefined); self.serial_checksumRequiringCommands = ko.observable(undefined); + self.serial_blockedCommands = ko.observable(undefined); + self.serial_pausingCommands = ko.observable(undefined); self.serial_helloCommand = ko.observable(undefined); self.serial_serialErrorBehaviour = ko.observable("cancel"); self.serial_triggerOkForM29 = ko.observable(undefined); - self.serial_blockM0M1 = ko.observable(undefined); self.serial_waitForStart = ko.observable(undefined); self.serial_sendChecksum = ko.observable("print"); self.serial_sdRelativePath = ko.observable(undefined); @@ -778,6 +779,8 @@ $(function() { additionalBaudrates: function() { return _.map(splitTextToArray(self.serial_additionalBaudrates(), ",", true, function(item) { return !isNaN(parseInt(item)); }), function(item) { return parseInt(item); }) }, longRunningCommands: function() { return splitTextToArray(self.serial_longRunningCommands(), ",", true) }, checksumRequiringCommands: function() { return splitTextToArray(self.serial_checksumRequiringCommands(), ",", true) }, + blockedCommands: function() { return splitTextToArray(self.serial_blockedCommands(), ",", true) }, + pausingCommands: function() { return splitTextToArray(self.serial_pausingCommands(), ",", true) }, externalHeatupDetection: function() { return !self.serial_disableExternalHeatupDetection()}, alwaysSendChecksum: function() { return self.serial_sendChecksum() === "always"}, neverSendChecksum: function() { return self.serial_sendChecksum() === "never"}, @@ -914,6 +917,8 @@ $(function() { additionalBaudrates: function(value) { self.serial_additionalBaudrates(value.join(", "))}, longRunningCommands: function(value) { self.serial_longRunningCommands(value.join(", "))}, checksumRequiringCommands: function(value) { self.serial_checksumRequiringCommands(value.join(", "))}, + blockedCommands: function(value) { self.serial_blockedCommands(value.join(", "))}, + pausingCommands: function(value) { self.serial_pausingCommands(value.join(", "))}, externalHeatupDetection: function(value) { self.serial_disableExternalHeatupDetection(!value) }, alwaysSendChecksum: function(value) { if (value) { self.serial_sendChecksum("always")}}, neverSendChecksum: function(value) { if (value) { self.serial_sendChecksum("never")}}, diff --git a/src/octoprint/templates/dialogs/settings/serialconnection.jinja2 b/src/octoprint/templates/dialogs/settings/serialconnection.jinja2 index 663fef456..6eac21d49 100644 --- a/src/octoprint/templates/dialogs/settings/serialconnection.jinja2 +++ b/src/octoprint/templates/dialogs/settings/serialconnection.jinja2 @@ -329,11 +329,19 @@ {{ _('Try checking this if you run into connection timeouts due to your printer taking too long to respond to OctoPrint\'s handshake attempts on connect.') }} + +
+
- + + {{ _('Use this to specify commands that should never be sent to the printer. Just the G or M code, comma separated. Defaults to M0 and M1 since most firmware will block until a button on the controller has been pressed if it receives either of those two commands.') }} +
+
+
+ +
+ + {{ _('Use this to specify commands on which OctoPrint should pause the print job. Just the G or M code, comma separated. Defaults to M0, M1 and M25.') }}
diff --git a/src/octoprint/util/comm.py b/src/octoprint/util/comm.py index e90c49c7f..f2b13c8cc 100644 --- a/src/octoprint/util/comm.py +++ b/src/octoprint/util/comm.py @@ -425,7 +425,6 @@ class MachineCom(object): self._hello_command = settings().get(["serial", "helloCommand"]) self._trigger_ok_for_m29 = settings().getBoolean(["serial", "triggerOkForM29"]) - self._block_M0_M1 = settings().getBoolean(["serial", "blockM0M1"]) self._hello_command = settings().get(["serial", "helloCommand"]) @@ -483,6 +482,8 @@ class MachineCom(object): self._long_running_commands = settings().get(["serial", "longRunningCommands"]) self._checksum_requiring_commands = settings().get(["serial", "checksumRequiringCommands"]) + self._blocked_commands = settings().get(["serial", "blockedCommands"]) + self._pausing_commands = settings().get(["serial", "pausingCommands"]) self._clear_to_send = CountedEvent(name="comm.clear_to_send", minimum=None) self._send_queue = SendQueue() @@ -3432,22 +3433,6 @@ class MachineCom(object): except ValueError: pass - def _gcode_M0_queuing(self, cmd, cmd_type=None, gcode=None, subcode=None, *args, **kwargs): - self.setPause(True) - if self._block_M0_M1: - if self.isPrinting(): - self._log("Not sending {} to printer since it's known to block communication, only pausing".format(cmd)) - else: - self._log("Not sending {} to printer since it's known to block communication".format(cmd)) - return None, # Don't send the M0 or M1 to the machine, as M0 and M1 are handled as an LCD menu pause. - _gcode_M1_queuing = _gcode_M0_queuing - - def _gcode_M25_queuing(self, cmd, cmd_type=None, gcode=None, subcode=None, *args, **kwargs): - # M25 while not printing from SD will be handled as pause. This way it can be used as another marker - # for GCODE induced pausing. Send it to the printer anyway though. - if self.isPrinting() and not self.isSdPrinting(): - self.setPause(True) - def _gcode_M28_sent(self, cmd, cmd_type=None, gcode=None, subcode=None, *args, **kwargs): if not self.isStreaming(): self._log("Detected manual streaming. Disabling temperature polling. Finish writing with M29. Do NOT attempt to print while manually streaming!") @@ -3660,6 +3645,17 @@ class MachineCom(object): ##~~ command phase handlers + def _command_phase_queuing(self, cmd, cmd_type=None, gcode=None, subcode=None, *args, **kwargs): + if gcode is not None: + + if self.isPrinting() and gcode in self._pausing_commands: + self._logger.info("Pausing print job due to command {}".format(gcode)) + self.setPause(True) + + if gcode in self._blocked_commands: + self._logger.info("Not sending {} to printer, it's configured as a blocked command".format(gcode)) + return None, + def _command_phase_sending(self, cmd, cmd_type=None, gcode=None, subcode=None, *args, **kwargs): if gcode is not None and gcode in self._long_running_commands: self._long_running_command = True