Commit 22c25826 authored by Guillaume Seguin's avatar Guillaume Seguin

Add LightGcode implementation which stores as little as possible

parent 817d4a9d
This diff is collapsed.
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
# along with Printrun. If not, see <http://www.gnu.org/licenses/>. # along with Printrun. If not, see <http://www.gnu.org/licenses/>.
from libc.stdlib cimport malloc, free from libc.stdlib cimport malloc, free
from libc.stdint cimport uint32_t from libc.stdint cimport uint8_t, uint32_t
from libc.string cimport strlen, strncpy from libc.string cimport strlen, strncpy
cdef char* copy_string(object value): cdef char* copy_string(object value):
...@@ -26,23 +26,23 @@ cdef char* copy_string(object value): ...@@ -26,23 +26,23 @@ cdef char* copy_string(object value):
return array return array
cdef enum BitPos: cdef enum BitPos:
pos_x = 1 << 0 pos_raw = 1 << 0
pos_y = 1 << 1 pos_command = 1 << 1
pos_z = 1 << 2 pos_is_move = 1 << 2
pos_e = 1 << 3 pos_x = 1 << 3
pos_f = 1 << 4 pos_y = 1 << 4
pos_i = 1 << 5 pos_z = 1 << 5
pos_j = 1 << 6 pos_e = 1 << 6
pos_is_move = 1 << 7 pos_f = 1 << 7
pos_relative = 1 << 8 pos_i = 1 << 8
pos_relative_e = 1 << 9 pos_j = 1 << 9
pos_extruding = 1 << 10 pos_relative = 1 << 10
pos_current_x = 1 << 11 pos_relative_e = 1 << 11
pos_current_y = 1 << 12 pos_extruding = 1 << 12
pos_current_z = 1 << 13 pos_current_x = 1 << 13
pos_current_tool = 1 << 14 pos_current_y = 1 << 14
pos_raw = 1 << 15 pos_current_z = 1 << 15
pos_command = 1 << 16 pos_current_tool = 1 << 16
pos_gcview_end_vertex = 1 << 17 pos_gcview_end_vertex = 1 << 17
# WARNING: don't use bits 24 to 31 as we store current_tool there # WARNING: don't use bits 24 to 31 as we store current_tool there
...@@ -208,3 +208,49 @@ cdef class GLine: ...@@ -208,3 +208,49 @@ cdef class GLine:
# if self._command != NULL: free(self._command) # if self._command != NULL: free(self._command)
self._command = copy_string(value) self._command = copy_string(value)
self._status = set_has_var(self._status, pos_command) self._status = set_has_var(self._status, pos_command)
cdef class GLightLine:
cdef char* _raw
cdef char* _command
cdef uint8_t _status
__slots__ = ()
def __cinit__(self):
self._status = 0
self._raw = NULL
self._command = NULL
def __init__(self, line):
self.raw = line
def __dealloc__(self):
if self._raw != NULL: free(self._raw)
if self._command != NULL: free(self._command)
property raw:
def __get__(self):
if has_var(self._status, pos_raw): return self._raw
else: return None
def __set__(self, value):
# WARNING: memory leak could happen here, as we don't do the following :
# if self._raw != NULL: free(self._raw)
self._raw = copy_string(value)
self._status = set_has_var(self._status, pos_raw)
property command:
def __get__(self):
if has_var(self._status, pos_command): return self._command
else: return None
def __set__(self, value):
# WARNING: memory leak could happen here, as we don't do the following :
# if self._command != NULL: free(self._command)
self._command = copy_string(value)
self._status = set_has_var(self._status, pos_command)
property is_move:
def __get__(self):
if has_var(self._status, pos_is_move): return True
else: return False
def __set__(self, value):
if value: self._status = set_has_var(self._status, pos_is_move)
else: self._status = unset_has_var(self._status, pos_is_move)
...@@ -1143,7 +1143,7 @@ class pronsole(cmd.Cmd): ...@@ -1143,7 +1143,7 @@ class pronsole(cmd.Cmd):
def load_gcode(self, filename, layer_callback = None, gcode = None): def load_gcode(self, filename, layer_callback = None, gcode = None):
if gcode is None: if gcode is None:
self.fgcode = gcoder.GCode(deferred = True) self.fgcode = gcoder.LightGCode(deferred = True)
else: else:
self.fgcode = gcode self.fgcode = gcode
self.fgcode.prepare(open(filename, "rU"), self.fgcode.prepare(open(filename, "rU"),
......
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