Indentation fixes, start pronterface modification

master
fsantini 2013-03-14 07:35:17 +01:00
parent b335a4cf77
commit 6cf08006c2
2 changed files with 154 additions and 130 deletions

View File

@ -58,6 +58,9 @@ class GCodeAnalyzer():
self.maxX = 150 self.maxX = 150
self.maxY = 150 self.maxY = 150
self.maxZ = 150 self.maxZ = 150
self.hasHomeX = False
self.hasHomeY = False
self.hasHomeZ = False
# find a code in a gstring line # find a code in a gstring line
@ -66,26 +69,29 @@ class GCodeAnalyzer():
m=re.match(pattern, gcode) m=re.match(pattern, gcode)
if m == None: if m == None:
return None return None
else else:
return m.group(1) return m.group(1)
def Analyze(self, gcode): def Analyze(self, gcode):
code_g = self.findCode(gcode, "G") code_g = self.findCode(gcode, "G")
code_m = self.findCode(gcode, "M") code_m = self.findCode(gcode, "M")
# we have a g_code # we have a g_code
if code_g != None: if code_g != None:
code_g = int(code_g) code_g = int(code_g)
#get movement codes #get movement codes
if code_g == 0 or code_g == 1 or code_g == 2 or code_g == 3: if code_g == 0 or code_g == 1 or code_g == 2 or code_g == 3:
self.lastX = self.x
self.lastY = self.y
self.lastZ = self.z
self.lastE = self.e
eChanged = false; eChanged = false;
code_f = self.findCode(gcode, "F") code_f = self.findCode(gcode, "F")
if code_f != None: if code_f != None:
self.f=float(code_f) self.f=float(code_f)
code_x = self.findCode(gcode, "X") code_x = self.findCode(gcode, "X")
code_y = self.findCode(gcode. "Y") code_y = self.findCode(gcode, "Y")
code_z = self.findCode(gcode, "Z") code_z = self.findCode(gcode, "Z")
code_e = self.findCode(gcode, "E") code_e = self.findCode(gcode, "E")
@ -115,8 +121,11 @@ class GCodeAnalyzer():
eChanged = True eChanged = True
self.e = self.eOffset + e self.e = self.eOffset + e
#Repetier has a bunch of limit-checking code here and time calculations: we are leaving them for now #Repetier has a bunch of limit-checking code here and time calculations: we are leaving them for now
elif code_g == 28 or code_g == 161: elif code_g == 28 or code_g == 161:
self.lastX = self.x
self.lastY = self.y
self.lastZ = self.z
self.lastE = self.e
code_x = self.findCode(gcode, "X") code_x = self.findCode(gcode, "X")
code_y = self.findCode(gcode, "Y") code_y = self.findCode(gcode, "Y")
code_z = self.findCode(gcode, "Z") code_z = self.findCode(gcode, "Z")
@ -124,30 +133,40 @@ class GCodeAnalyzer():
homeAll = False homeAll = False
if code_x == None and code_y == None and code_z == None: homeAll = True if code_x == None and code_y == None and code_z == None: homeAll = True
if code_x != None or homeAll: if code_x != None or homeAll:
self.hasHomeX = True
self.xOffset = 0 self.xOffset = 0
self.x = self.homeX self.x = self.homeX
if code_y != None or homeAll: if code_y != None or homeAll:
self.hasHomeY = True
self.yOffset = 0 self.yOffset = 0
self.y = self.homeY self.y = self.homeY
if code_z != None or homeAll: if code_z != None or homeAll:
self.hasHomeZ = True
self.zOffset = 0 self.zOffset = 0
self.z = self.homeZ self.z = self.homeZ
if code_e != None: if code_e != None:
self.eOffset = 0 self.eOffset = 0
self.e = 0 self.e = 0
elif code_g == 162: elif code_g == 162:
self.lastX = self.x
self.lastY = self.y
self.lastZ = self.z
self.lastE = self.e
code_x = self.findCode(gcode, "X") code_x = self.findCode(gcode, "X")
code_y = self.findCode(gcode, "Y") code_y = self.findCode(gcode, "Y")
code_z = self.findCode(gcode, "Z") code_z = self.findCode(gcode, "Z")
homeAll = False homeAll = False
if code_x == None and code_y == None and code_z == None: homeAll = True if code_x == None and code_y == None and code_z == None: homeAll = True
if code_x != None or homeAll: if code_x != None or homeAll:
self.hasHomeX = True
self.xOffset = 0 self.xOffset = 0
self.x = self.maxX self.x = self.maxX
if code_y != None or homeAll: if code_y != None or homeAll:
self.hasHomeY = True
self.yOffset = 0 self.yOffset = 0
self.y = self.maxY self.y = self.maxY
if code_z != None or homeAll: if code_z != None or homeAll:
self.hasHomeZ = True
self.zOffset = 0 self.zOffset = 0
self.z = self.maxZ self.z = self.maxZ
elif code_g == 90: self.relative = False elif code_g == 90: self.relative = False
@ -175,3 +194,4 @@ class GCodeAnalyzer():
if code_m == 82: self.eRelative = False if code_m == 82: self.eRelative = False
elif code_m == 83: self.eRelative = True elif code_m == 83: self.eRelative = True

View File

@ -20,6 +20,7 @@ from threading import Thread
from select import error as SelectError from select import error as SelectError
import time, getopt, sys import time, getopt, sys
import platform, os import platform, os
from GCodeAnalyzer import GCodeAnalyzer
def control_ttyhup(port, disable_hup): def control_ttyhup(port, disable_hup):
"""Controls the HUPCL""" """Controls the HUPCL"""
@ -70,6 +71,8 @@ class printcore():
if port is not None and baud is not None: if port is not None and baud is not None:
self.connect(port, baud) self.connect(port, baud)
self.analyzer = GCodeAnalyzer()
def disconnect(self): def disconnect(self):
"""Disconnects from printer and pauses the print """Disconnects from printer and pauses the print
""" """
@ -335,6 +338,7 @@ class printcore():
self.sentlines[lineno] = command self.sentlines[lineno] = command
if self.printer: if self.printer:
self.sent.append(command) self.sent.append(command)
self.analyzer.Analyze(command) # run the command through the analyzer
if self.loud: if self.loud:
print "SENT: ", command print "SENT: ", command
if self.sendcb: if self.sendcb: