✨ Add configurable list of blocked and pausing commands
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
This commit is contained in:
1 parent
32050c31ae
commit
38a321e175
6 files changed
+68
-27
No files matched your search
@@ -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:
|
||||
|
||||
@@ -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"):
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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")}},
|
||||
|
||||
@@ -329,11 +329,19 @@
|
||||
<span class="help-block">{{ _('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.') }}</span>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="control-group">
|
||||
<label class="control-label" for="settings-serialBlockedCommands">{{ _('Blocked commands') }}</label>
|
||||
<div class="controls">
|
||||
<label class="checkbox">
|
||||
<input type="checkbox" data-bind="checked: serial_blockM0M1" id="settings-serialBlockM0M1"> {{ _('Do not send <code>M0</code>/<code>M1</code> commands to the firmware, only pause') }}
|
||||
<span class="help-block">{{ _('Most firmware will block and wait for the user to press the button on the controller when an <code>M0</code> or <code>M1</code> is received. Due to that OctoPrint will normally not send those commands to the printer and only pause any ongoing prints. If you want OctoPrint to send those commands to your printer, uncheck this option.') }}</span>
|
||||
</label>
|
||||
<input type="text" class="input-block-level" id="settings-serialBlockedCommands" data-bind="value: serial_blockedCommands">
|
||||
<span class="help-inline">{{ _('Use this to specify commands that should never be sent to the printer. Just the G or M code, comma separated. Defaults to <code>M0</code> and <code>M1</code> since most firmware will block until a button on the controller has been pressed if it receives either of those two commands.') }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="control-group">
|
||||
<label class="control-label" for="settings-serialPausingCommands">{{ _('Pausing commands') }}</label>
|
||||
<div class="controls">
|
||||
<input type="text" class="input-block-level" id="settings-serialPausingCommands" data-bind="value: serial_pausingCommands">
|
||||
<span class="help-inline">{{ _('Use this to specify commands on which OctoPrint should pause the print job. Just the G or M code, comma separated. Defaults to <code>M0</code>, <code>M1</code> and <code>M25</code>.') }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
|
||||
+13
-17
@@ -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
|
||||
|
||||
Reference in new issue
Block a user