Added configurable pause triggers to be able to react to custom firmware messages with pausing/unpausing/pause toggling

master
Gina Häußge 2013-07-08 18:01:10 +02:00
parent 8dcbb620bb
commit c33c32410b
3 changed files with 40 additions and 1 deletions

View File

@ -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):

View File

@ -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

View File

@ -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")