diff --git a/docs/events/index.rst b/docs/events/index.rst index 1054ba2c2..7fa5e733e 100644 --- a/docs/events/index.rst +++ b/docs/events/index.rst @@ -606,6 +606,32 @@ ToolChange .. versionadded:: 1.3.5 +CommandSuppressed + A command was suppressed by OctoPrint due to according configuration and will not be + sent to the printer. + + Payload: + + * ``command``: the command that was suppressed + * ``message``: a message containing an explanation of the command suppression + * ``severity``: a severity level, either ``warn`` or ``info`` - ``warn`` indicates + that the command was suppressed probably due to a misconfiguration either inside + OctoPrint or the firmware and that it should be investigated by the user + + .. versionadded:: 1.5.0 + +InvalidToolReported + The firmware reported a tool as invalid upon trying to select it. It has thus been marked + as invalid and further attempts to select said tool will result in the tool command + to get suppressed (and ``SuppressedCommand`` to be generated). + + Payload: + + * ``tool``: the tool number that was reported as invalid by the firmware + * ``fallback``: the tool number that OctoPrint will revert to + + .. versionadded:: 1.5.0 + .. _sec-events-available_events-timelapses: Timelapses diff --git a/src/octoprint/events.py b/src/octoprint/events.py index 2adf17db6..fd4847181 100644 --- a/src/octoprint/events.py +++ b/src/octoprint/events.py @@ -104,6 +104,8 @@ class Events(object): FIRMWARE_DATA = "FirmwareData" TOOL_CHANGE = "ToolChange" REGISTERED_MESSAGE_RECEIVED = "RegisteredMessageReceived" + COMMAND_SUPPRESSED = "CommandSuppressed" + INVALID_TOOL_REPORTED = "InvalidToolReported" # Timelapse CAPTURE_START = "CaptureStart" diff --git a/src/octoprint/server/api/settings.py b/src/octoprint/server/api/settings.py index c0f14c044..b029e5378 100644 --- a/src/octoprint/server/api/settings.py +++ b/src/octoprint/server/api/settings.py @@ -218,6 +218,7 @@ def getSettings(): "blockWhileDwelling": s.getBoolean(["serial", "blockWhileDwelling"]), "useParityWorkaround": s.get(["serial", "useParityWorkaround"]), "sanityCheckTools": s.getBoolean(["serial", "sanityCheckTools"]), + "notifySuppressedCommands": s.get(["serial", "notifySuppressedCommands"]), "sendM112OnError": s.getBoolean(["serial", "sendM112OnError"]), "disableSdPrintingDetection": s.getBoolean( ["serial", "disableSdPrintingDetection"] @@ -797,6 +798,10 @@ def _saveSettings(data): s.setBoolean( ["serial", "sanityCheckTools"], data["serial"]["sanityCheckTools"] ) + if "notifySuppressedCommands" in data["serial"]: + value = data["serial"]["notifySuppressedCommands"] + if value in ("info", "warn", "never"): + s.set(["serial", "notifySuppressedCommands"], value) if "sendM112OnError" in data["serial"]: s.setBoolean(["serial", "sendM112OnError"], data["serial"]["sendM112OnError"]) if "disableSdPrintingDetection" in data["serial"]: diff --git a/src/octoprint/settings.py b/src/octoprint/settings.py index 8ec943063..cd27d1cfd 100644 --- a/src/octoprint/settings.py +++ b/src/octoprint/settings.py @@ -161,6 +161,7 @@ default_settings = { "disableSdPrintingDetection": False, "ackMax": 1, "sanityCheckTools": True, + "notifySuppressedCommands": "warn", "capabilities": { "autoreport_temp": True, "autoreport_sdstatus": True, diff --git a/src/octoprint/static/js/app/viewmodels/terminal.js b/src/octoprint/static/js/app/viewmodels/terminal.js index dbb8ec1f8..69b4ae2a8 100644 --- a/src/octoprint/static/js/app/viewmodels/terminal.js +++ b/src/octoprint/static/js/app/viewmodels/terminal.js @@ -509,6 +509,54 @@ $(function () { self.onBrowserTabVisibilityChange = function (status) { self.updateOutput(); }; + + self.onEventCommandSuppressed = function (payload) { + var setting = self.settings.settings.serial.notifySuppressedCommands(); + + if ( + setting === "never" || + (setting === "warn" && payload.severity === "info") + ) { + return; + } + + var severity = payload.severity; + if (severity === "warn") { + severity = "error"; + } else if (severity === "info") { + severity = "warn"; + } + + var text = + "

" + + gettext( + "The command %(command)s was not sent " + + "to the printer:" + ) + + "

%(message)s

"; + + new PNotify({ + title: gettext("Suppressed command"), + text: _.sprintf(text, payload), + type: severity, + hide: false + }); + }; + + self.onEventInvalidToolReported = function (payload) { + new PNotify({ + title: gettext("Invalid tool reported"), + text: _.sprintf( + gettext( + "Your printer reported tool T%(tool)d as invalid, " + + "reverting back to T%(fallback)d" + ), + payload + ), + type: "error", + hide: false + }); + }; } OCTOPRINT_VIEWMODELS.push({ diff --git a/src/octoprint/templates/dialogs/settings/serialconnection.jinja2 b/src/octoprint/templates/dialogs/settings/serialconnection.jinja2 index 191535c45..e8e6717c5 100644 --- a/src/octoprint/templates/dialogs/settings/serialconnection.jinja2 +++ b/src/octoprint/templates/dialogs/settings/serialconnection.jinja2 @@ -500,6 +500,20 @@ {{ _('If enabled, OctoPrint will not send tool commands to your printer that exceed the number of extruders configured in the active printer profile, or for which the firmware has reported an "invalid extruder" error. Only uncheck this if OctoPrint or your firmware mistakingly mark valid tools as invalid and be sure to investigate the reason for that, it might be a misconfiguration you need to correct for proper operation.') }} +
+ +
+ + + +
+
diff --git a/src/octoprint/util/comm.py b/src/octoprint/util/comm.py index a3fefd879..b2a952192 100644 --- a/src/octoprint/util/comm.py +++ b/src/octoprint/util/comm.py @@ -2683,11 +2683,16 @@ class MachineCom(object): 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 - ) + message = "T{} reported as invalid, reverting to T{}".format( + invalid_tool, fallback_tool ) + self._log("Warn: " + message) + self._logger.warning(message) + eventManager().fire( + Events.INVALID_TOOL_REPORTED, + {"tool": invalid_tool, "fallback": fallback_tool}, + ) + self._knownInvalidTools.add(invalid_tool) # we actually do send a T command here instead of just settings self._currentTool just in case @@ -4684,9 +4689,19 @@ class MachineCom(object): new_tool = int(toolMatch.group("value")) if not self._validate_tool(new_tool): - self._log( + message = ( "Not queuing T{}, that tool doesn't exist according to the printer profile or " - "was reported as invalid by the firmware".format(new_tool) + "was reported as invalid by the firmware. Make sure your " + "printer profile is set up correctly.".format(new_tool) + ) + self._log("Warn: " + message) + eventManager().fire( + Events.COMMAND_SUPPRESSED, + { + "command": cmd, + "message": message, + "severity": "warn", + }, ) return (None,) @@ -4718,9 +4733,21 @@ class MachineCom(object): if toolMatch: new_tool = int(toolMatch.group("value")) if not self._validate_tool(new_tool): - self._log( - "Not sending T{}, that tool doesn't exist according to the printer profile or " - "was reported as invalid by the firmware".format(new_tool) + message = ( + "Not sending T{}, that tool doesn't exist according to " + "the printer profile or was reported as invalid by the " + "firmware. Make sure your printer profile is set up " + "correctly.".format(new_tool) + ) + self._log("Warn: " + message) + self._logger.warning(message) + eventManager().fire( + Events.COMMAND_SUPPRESSED, + { + "command": cmd, + "message": message, + "severity": "warn", + }, ) return (None,) @@ -4798,8 +4825,16 @@ class MachineCom(object): self, cmd, cmd_type=None, gcode=None, subcode=None, *args, **kwargs ): if not self._printerProfileManager.get_current_or_default()["heatedBed"]: - self._log( - 'Warn: Not sending "{}", printer profile has no heated bed'.format(cmd) + message = ( + 'Not sending "{}", printer profile has no heated bed. Either ' + "configure a heated bed or remove bed commands from your " + "GCODE.".format(cmd) + ) + self._log("Warn: " + message) + self._logger.warning(message) + eventManager().fire( + Events.COMMAND_SUPPRESSED, + {"command": cmd, "message": message, "severity": "warn"}, ) return (None,) # Don't send bed commands if we don't have a heated bed @@ -4809,10 +4844,16 @@ class MachineCom(object): self, cmd, cmd_type=None, gcode=None, subcode=None, *args, **kwargs ): if not self._printerProfileManager.get_current_or_default()["heatedChamber"]: - self._log( - 'Warn: Not sending "{}", printer profile has no heated chamber'.format( - cmd - ) + message = ( + 'Not sending "{}", printer profile has no heated chamber. Either ' + "configure a heated chamber or remove chamber commands from your " + "GCODE.".format(cmd) + ) + self._log("Warn: " + message) + self._logger.warning(message) + eventManager().fire( + Events.COMMAND_SUPPRESSED, + {"command": cmd, "message": message, "severity": "warn"}, ) return ( None, @@ -5136,10 +5177,18 @@ class MachineCom(object): 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 - ) + message = "Not sending {} to printer, it's configured as a blocked command".format( + gcode + ) + self._log("Info: " + message) + self._logger.info(message) + eventManager().fire( + Events.COMMAND_SUPPRESSED, + { + "command": cmd, + "message": message, + "severity": "warn", + }, ) return (None,)