Introduced new function matchesGcode to properly test if a line contains a specific gcode
parent
7257714a8e
commit
d5a620f476
|
@ -2,6 +2,8 @@
|
||||||
__author__ = "Gina Häußge <osd@foosel.net>"
|
__author__ = "Gina Häußge <osd@foosel.net>"
|
||||||
__license__ = 'GNU Affero General Public License http://www.gnu.org/licenses/agpl.html'
|
__license__ = 'GNU Affero General Public License http://www.gnu.org/licenses/agpl.html'
|
||||||
|
|
||||||
|
import re
|
||||||
|
|
||||||
def getFormattedSize(num):
|
def getFormattedSize(num):
|
||||||
"""
|
"""
|
||||||
Taken from http://stackoverflow.com/questions/1094841/reusable-library-to-get-human-readable-version-of-file-size
|
Taken from http://stackoverflow.com/questions/1094841/reusable-library-to-get-human-readable-version-of-file-size
|
||||||
|
@ -38,4 +40,7 @@ def getClass(name):
|
||||||
m = __import__(module)
|
m = __import__(module)
|
||||||
for comp in parts[1:]:
|
for comp in parts[1:]:
|
||||||
m = getattr(m, comp)
|
m = getattr(m, comp)
|
||||||
return m
|
return m
|
||||||
|
|
||||||
|
def matchesGcode(line, gcode):
|
||||||
|
return re.search("^\s*%s\D" % gcode, line, re.I)
|
|
@ -16,6 +16,8 @@ import serial
|
||||||
from octoprint.util.avr_isp import stk500v2
|
from octoprint.util.avr_isp import stk500v2
|
||||||
from octoprint.util.avr_isp import ispBase
|
from octoprint.util.avr_isp import ispBase
|
||||||
|
|
||||||
|
from octoprint.util import matchesGcode
|
||||||
|
|
||||||
from octoprint.settings import settings
|
from octoprint.settings import settings
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -833,20 +835,20 @@ class MachineCom(object):
|
||||||
with self._sendingLock:
|
with self._sendingLock:
|
||||||
if self._serial is None:
|
if self._serial is None:
|
||||||
return
|
return
|
||||||
if 'M109' in cmd or 'M190' in cmd:
|
if matchesGcode(cmd, "M109") or matchesGcode(cmd, "M190"):
|
||||||
self._heatupWaitStartTime = time.time()
|
self._heatupWaitStartTime = time.time()
|
||||||
if 'M104' in cmd or 'M109' in cmd:
|
if matchesGcode(cmd, "M104") or matchesGcode(cmd, "M109"):
|
||||||
try:
|
try:
|
||||||
self._targetTemp = float(re.search('S([0-9]+)', cmd).group(1))
|
self._targetTemp = float(re.search('S([0-9]+)', cmd).group(1))
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
if 'M140' in cmd or 'M190' in cmd:
|
if matchesGcode(cmd, "M140") or matchesGcode(cmd, "M190"):
|
||||||
try:
|
try:
|
||||||
self._bedTargetTemp = float(re.search('S([0-9]+)', cmd).group(1))
|
self._bedTargetTemp = float(re.search('S([0-9]+)', cmd).group(1))
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if "M110" in cmd:
|
if matchesGcode(cmd, "M110"):
|
||||||
newLineNumber = None
|
newLineNumber = None
|
||||||
if " N" in cmd:
|
if " N" in cmd:
|
||||||
try:
|
try:
|
||||||
|
@ -926,12 +928,12 @@ class MachineCom(object):
|
||||||
self._printSection = line[1]
|
self._printSection = line[1]
|
||||||
line = line[0]
|
line = line[0]
|
||||||
try:
|
try:
|
||||||
if line == 'M0' or line == 'M1':
|
if matchesGcode(line, "M0") or matchesGcode(line, "M1"):
|
||||||
self.setPause(True)
|
self.setPause(True)
|
||||||
line = 'M105' #Don't send the M0 or M1 to the machine, as M0 and M1 are handled as an LCD menu pause.
|
line = "M105" # Don't send the M0 or M1 to the machine, as M0 and M1 are handled as an LCD menu pause.
|
||||||
if self._printSection in self._feedRateModifier:
|
if self._printSection in self._feedRateModifier:
|
||||||
line = re.sub('F([0-9]*)', lambda m: 'F' + str(int(int(m.group(1)) * self._feedRateModifier[self._printSection])), line)
|
line = re.sub('F([0-9]*)', lambda m: 'F' + str(int(int(m.group(1)) * self._feedRateModifier[self._printSection])), line)
|
||||||
if ('G0' in line or 'G1' in line) and 'Z' in line:
|
if (matchesGcode(line, "G0") or matchesGcode(line, "G1")) and 'Z' in line:
|
||||||
z = float(re.search('Z([0-9\.]*)', line).group(1))
|
z = float(re.search('Z([0-9\.]*)', line).group(1))
|
||||||
if self._currentZ != z:
|
if self._currentZ != z:
|
||||||
self._currentZ = z
|
self._currentZ = z
|
||||||
|
|
Loading…
Reference in New Issue