Commit 56ed3dad authored by Guillaume Seguin's avatar Guillaume Seguin

Don't parse S and P parameters for all glines as it's a minor parameter

Add a specific parser for these, which can be accessed as gcoder.S/P
parent 77888d9a
......@@ -20,14 +20,15 @@ import math
import datetime
from array import array
gcode_parsed_args = ["x", "y", "e", "f", "z", "p", "i", "j", "s"]
gcode_parsed_args = ["x", "y", "e", "f", "z", "i", "j"]
gcode_exp = re.compile("\([^\(\)]*\)|;.*|[/\*].*\n|[a-z][-+]?[0-9]*\.?[0-9]*")
m114_exp = re.compile("\([^\(\)]*\)|[/\*].*\n|[A-Z]:?[-+]?[0-9]*\.?[0-9]*")
specific_exp = "(?:\([^\(\)]*\))|(?:;.*)|(?:[/\*].*\n)|(%s[-+]?[0-9]*\.?[0-9]*)"
move_gcodes = ["G0", "G1", "G2", "G3"]
class PyLine(object):
__slots__ = ('x','y','z','e','f','i','j','s','p',
__slots__ = ('x','y','z','e','f','i','j',
'raw','split_raw',
'command','is_move',
'relative','relative_e',
......@@ -46,6 +47,18 @@ try:
except ImportError:
Line = PyLine
def find_specific_code(line, code):
exp = specific_exp % code
bits = [bit for bit in re.findall(exp, line.raw) if bit]
if not bits: return None
else: return float(bits[0][1:])
def S(line):
return find_specific_code(line, "S")
def P(line):
return find_specific_code(line, "P")
def split(line):
split_raw = gcode_exp.findall(line.raw.lower())
line.command = split_raw[0].upper() if not split_raw[0].startswith("n") else split_raw[1].upper()
......@@ -402,7 +415,7 @@ def main():
if len(sys.argv) < 2:
print "usage: %s filename.gcode" % sys.argv[0]
return
print "Line object size:", sys.getsizeof(Line("G0 X0"))
gcode = GCode(open(sys.argv[1]))
......
......@@ -36,8 +36,7 @@ cdef enum BitPos:
pos_f = 1 << 4
pos_i = 1 << 5
pos_j = 1 << 6
pos_s = 1 << 7
pos_p = 1 << 8
pos_is_move = 1 << 9
pos_relative = 1 << 10
pos_relative_e = 1 << 11
......@@ -63,7 +62,7 @@ cdef class GLine:
cdef char* _raw
cdef char* _command
cdef float _x, _y, _z, _e, _f, _i, _j, _s, _p
cdef float _x, _y, _z, _e, _f, _i, _j
cdef float _current_x, _current_y, _current_z
cdef uint32_t _gcview_end_vertex
cdef uint32_t _status
......@@ -132,20 +131,6 @@ cdef class GLine:
def __set__(self, value):
self._j = value
self._status = set_has_var(self._status, pos_j)
property s:
def __get__(self):
if has_var(self._status, pos_s): return self._s
else: return None
def __set__(self, value):
self._s = value
self._status = set_has_var(self._status, pos_s)
property p:
def __get__(self):
if has_var(self._status, pos_p): return self._p
else: return None
def __set__(self, value):
self._p = value
self._status = set_has_var(self._status, pos_p)
property is_move:
def __get__(self):
if has_var(self._status, pos_is_move): return True
......
......@@ -367,7 +367,7 @@ class PronterWindow(MainWindow, pronsole.pronsole):
def sentcb(self, line):
gline = gcoder.Line(line)
split_raw = gcoder.split_line(gline)
split_raw = gcoder.split(gline)
gcoder.parse_coordinates(gline, split_raw, imperial = False)
if gline.is_move:
if gline.z != None:
......@@ -378,14 +378,16 @@ class PronterWindow(MainWindow, pronsole.pronsole):
wx.CallAfter(self.gviz.setlayer, layer)
elif gline.command in ["M104", "M109"]:
gcoder.parse_coordinates(gline, split_raw, imperial = False, force = True)
if gline.s != None:
temp = gline.s
gline_s = gcoder.S(gline)
if gline_s != None:
temp = gline_s
if self.display_gauges: wx.CallAfter(self.hottgauge.SetTarget, temp)
if self.display_graph: wx.CallAfter(self.graph.SetExtruder0TargetTemperature, temp)
elif gline.command == "M140":
gline.parse_coordinates(gline, split_raw, imperial = False, force = True)
if gline.s != None:
temp = gline.s
gline_s = gcoder.S(gline)
if gline_s != None:
temp = gline_s
if self.display_gauges: wx.CallAfter(self.bedtgauge.SetTarget, temp)
if self.display_graph: wx.CallAfter(self.graph.SetBedTargetTemperature, temp)
else:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment