From c33c32410b0a524f0d6c25fbb6d0420bc69e38bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Mon, 8 Jul 2013 18:01:10 +0200 Subject: [PATCH] Added configurable pause triggers to be able to react to custom firmware messages with pausing/unpausing/pause toggling --- octoprint/settings.py | 28 +++++++++++++++++++++++++++- octoprint/util/comm.py | 10 ++++++++++ octoprint/util/virtual.py | 3 +++ 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/octoprint/settings.py b/octoprint/settings.py index 4429521a..d7979bda 100644 --- a/octoprint/settings.py +++ b/octoprint/settings.py @@ -73,7 +73,8 @@ default_settings = { "y": 6000, "z": 200, "e": 300 - } + }, + "pauseTriggers": [] }, "appearance": { "name": "", @@ -259,6 +260,31 @@ class Settings(object): else: return [] + def getPauseTriggers(self): + triggers = { + "enable": [], + "disable": [], + "toggle": [] + } + for trigger in self.get(["printerParameters", "pauseTriggers"]): + try: + regex = trigger["regex"] + type = trigger["type"] + if type in triggers.keys(): + # make sure regex is valid + re.compile(regex) + # add to type list + triggers[type].append(regex) + except: + # invalid regex or something like this, we'll just skip this entry + pass + + result = {} + for type in triggers.keys(): + if len(triggers[type]) > 0: + result[type] = re.compile("|".join(map(lambda x: "(%s)" % x, triggers[type]))) + return result + #~~ setter def set(self, path, value, force=False): diff --git a/octoprint/util/comm.py b/octoprint/util/comm.py index 184fe4ec..ea8d8ab0 100644 --- a/octoprint/util/comm.py +++ b/octoprint/util/comm.py @@ -439,6 +439,7 @@ class MachineCom(object): def _monitor(self): feedbackControls = settings().getFeedbackControls() + pauseTriggers = settings().getPauseTriggers() #Open the serial port. if self._port == 'AUTO': @@ -602,6 +603,15 @@ class MachineCom(object): # ignored on purpose pass + ##~~ Parsing for pause triggers + if pauseTriggers: + if "enable" in pauseTriggers.keys() and pauseTriggers["enable"].search(line) is not None: + self.setPause(True) + elif "disable" in pauseTriggers.keys() and pauseTriggers["disable"].search(line) is not None: + self.setPause(False) + elif "toggle" in pauseTriggers.keys() and pauseTriggers["toggle"].search(line) is not None: + self.setPause(not self.isPaused()) + if "ok" in line and heatingUp: heatingUp = False diff --git a/octoprint/util/virtual.py b/octoprint/util/virtual.py index 613ea887..cf699f6c 100644 --- a/octoprint/util/virtual.py +++ b/octoprint/util/virtual.py @@ -113,6 +113,9 @@ class VirtualPrinter(): elif "M114" in data: # send dummy position report self.readList.append("ok C: X:10.00 Y:3.20 Z:5.20 E:1.24") + elif "M117" in data: + # we'll just use this to echo a message, to allow playing around with pause triggers + self.readList.append("ok %s" % re.search("M117\s+(.*)", data).group(1)) elif "M999" in data: # mirror Marlin behaviour self.readList.append("Resend: 1")