Support action: commands sent from printer, for now only pause, resume and disconnect are supported, plus a new hook "octoprint.comm.protocol.action" to add handlers of custom actions via plugins.
Added "!!DEBUG:" command to virtual printer to be able to trigger such commands to be sent by it.
This commit is contained in:
parent
8998be66eb
commit
0737ee65bd
3 changed files with 38 additions and 0 deletions
|
|
@ -658,6 +658,9 @@ class Printer():
|
|||
def mcReceivedRegisteredMessage(self, command, output):
|
||||
self._sendFeedbackCommandOutput(command, output)
|
||||
|
||||
def mcForceDisconnect(self):
|
||||
self.disconnect()
|
||||
|
||||
#~~ sd file handling
|
||||
|
||||
def getSdFiles(self):
|
||||
|
|
|
|||
|
|
@ -161,6 +161,7 @@ class MachineCom(object):
|
|||
# hooks
|
||||
self._pluginManager = octoprint.plugin.plugin_manager()
|
||||
self._gcode_hooks = self._pluginManager.get_hooks("octoprint.comm.protocol.gcode")
|
||||
self._printer_action_hooks = self._pluginManager.get_hooks("octoprint.comm.protocol.action")
|
||||
|
||||
# SD status data
|
||||
self._sdAvailable = False
|
||||
|
|
@ -670,6 +671,27 @@ class MachineCom(object):
|
|||
if line.strip() is not "":
|
||||
self._timeout = getNewTimeout("communication")
|
||||
|
||||
##~~ debugging output handling
|
||||
if line.startswith("//"):
|
||||
debugging_output = line[2:].strip()
|
||||
if debugging_output.startswith("action:"):
|
||||
action_command = debugging_output[len("action:"):].strip()
|
||||
|
||||
if action_command == "pause":
|
||||
self._log("Pausing on request of the printer...")
|
||||
self.setPause(True)
|
||||
elif action_command == "resume":
|
||||
self._log("Resuming on request of the printer...")
|
||||
self.setPause(False)
|
||||
elif action_command == "disconnect":
|
||||
self._log("Disconnecting on request of the printer...")
|
||||
self._callback.mcForceDisconnect()
|
||||
else:
|
||||
for hook in self._printer_action_hooks:
|
||||
self._printer_action_hooks[hook](self, line, action_command)
|
||||
else:
|
||||
continue
|
||||
|
||||
##~~ Error handling
|
||||
line = self._handleErrors(line)
|
||||
|
||||
|
|
@ -1311,6 +1333,9 @@ class MachineComPrintCallback(object):
|
|||
def mcReceivedRegisteredMessage(self, command, message):
|
||||
pass
|
||||
|
||||
def mcForceDisconnect(self):
|
||||
pass
|
||||
|
||||
### Printing file information classes ##################################################################################
|
||||
|
||||
class PrintingFileInformation(object):
|
||||
|
|
|
|||
|
|
@ -227,6 +227,8 @@ class VirtualPrinter():
|
|||
self._relative = True
|
||||
elif "G92" in data:
|
||||
self._setPosition(data)
|
||||
elif data.startswith("!!DEBUG:"):
|
||||
self._debugTrigger(data[len("!!DEBUG:"):].strip())
|
||||
|
||||
elif data.startswith("G0") or data.startswith("G1") or data.startswith("G2") or data.startswith("G3") \
|
||||
or data.startswith("G28") or data.startswith("G29") or data.startswith("G30") \
|
||||
|
|
@ -237,6 +239,14 @@ class VirtualPrinter():
|
|||
if len(data.strip()) > 0:
|
||||
self._sendOk()
|
||||
|
||||
def _debugTrigger(self, data):
|
||||
if data == "action_pause":
|
||||
self.outgoing.put("// action:pause")
|
||||
elif data == "action_resume":
|
||||
self.outgoing.put("// action:resume")
|
||||
elif data == "action_disconnect":
|
||||
self.outgoing.put("// action:disconnect")
|
||||
|
||||
def _listSd(self):
|
||||
self.outgoing.put("Begin file list")
|
||||
if settings().getBoolean(["devel", "virtualPrinter", "extendedSdFileList"]):
|
||||
|
|
|
|||
Loading…
Reference in a new issue