Commit 360b4f60 authored by fsantini's avatar fsantini

Pause code working;

implemented the @pause gcode host command (and a small framework for host commands)
parent 00f1306f
......@@ -76,6 +76,7 @@ class GCodeAnalyzer():
return m.group(1)
def Analyze(self, gcode):
gcode = gcode[:gcode.find(";")] # remove comments
code_g = self.findCode(gcode, "G")
code_m = self.findCode(gcode, "M")
# we have a g_code
......
......@@ -30,6 +30,10 @@ class Line(object):
self.imperial = False
self.relative = False
#ignore host commands
if "@" in self.raw:
self.raw = ""
if ";" in self.raw:
self.raw = self.raw.split(";")[0]
......
......@@ -73,6 +73,7 @@ class printcore():
self.analyzer = GCodeAnalyzer()
self.xy_feedrate = None
self.z_feedrate = None
self.pronterface = None
def disconnect(self):
"""Disconnects from printer and pauses the print
......@@ -223,23 +224,45 @@ class printcore():
self.print_thread.start()
return True
# run a simple script if it exists, no multithreading
def runSmallScript(self, filename):
if filename == None: return
f = None
try:
f = open(filename)
except:
pass
if f != None:
for i in f:
l = i.replace("\n", "")
l = l[:l.find(";")] #remove comment
self.send_now(l)
f.close()
def pause(self):
"""Pauses the print, saving the current position.
"""
self.paused = True
self.printing = False
self.print_thread.join()
# try joining the print thread: enclose it in try/except because we might be calling it from the thread itself
try:
self.print_thread.join()
except: pass
self.print_thread = None
# saves the status
self.pauseX = analyzer.x-analyzer.xOffset;
self.pauseY = analyzer.y-analyzer.yOffset;
self.pauseZ = analyzer.z-analyzer.zOffset;
self.pauseE = analyzer.e-analyzer.eOffset;
self.pauseF = analyzer.f;
self.pauseRelative = analyzer.relative;
self.pauseX = self.analyzer.x-self.analyzer.xOffset;
self.pauseY = self.analyzer.y-self.analyzer.yOffset;
self.pauseZ = self.analyzer.z-self.analyzer.zOffset;
self.pauseE = self.analyzer.e-self.analyzer.eOffset;
self.pauseF = self.analyzer.f;
self.pauseRelative = self.analyzer.relative;
def resume(self):
"""Resumes a paused print.
......@@ -247,20 +270,20 @@ class printcore():
if self.paused:
#restores the status
self.send("G90") # go to absolute coordinates
self.send_now("G90") # go to absolute coordinates
xyFeedString = ""
zFeedString = ""
if self.xy_feedrate != None: xyFeedString = " F" + str(self.xy_feedrate)
if self.z_feedrate != None: zFeedString = " F" + str(self.z_feedrate)
self.send("G1 X" + str(self.pauseX) + " Y" + str(self.pauseY) + xyFeedString)
self.send("G1 Z" + str(self.pauseZ) + zFeedString)
self.send("G92 E" + str(self.pauseE))
self.send_now("G1 X" + str(self.pauseX) + " Y" + str(self.pauseY) + xyFeedString)
self.send_now("G1 Z" + str(self.pauseZ) + zFeedString)
self.send_now("G92 E" + str(self.pauseE))
if self.pauseRelative: self.send("G91") # go back to relative if needed
if self.pauseRelative: self.send_now("G91") # go back to relative if needed
#reset old feed rate
self.send("G1 F" + str(self.pauseF))
self.send_now("G1 F" + str(self.pauseF))
self.paused = False
self.printing = True
......@@ -324,6 +347,14 @@ class printcore():
try: self.endcb()
except: pass
#now only "pause" is implemented as host command
def processHostCommand(self, command):
if command == "@pause":
if self.pronterface != None:
self.pronterface.pause(None)
else:
self.pause()
def _sendnext(self):
if not self.printer:
return
......@@ -344,6 +375,13 @@ class printcore():
return
if self.printing and self.queueindex < len(self.mainqueue):
tline = self.mainqueue[self.queueindex]
#check for host command
if tline.startswith("@"):
#it is a host command: pop it from the list
self.mainqueue.pop(self.queueindex)
self.processHostCommand(tline)
return
tline = tline.split(";")[0]
if len(tline) > 0:
self._send(tline, self.lineno, True)
......
......@@ -85,7 +85,7 @@ class Tee(object):
class PronterWindow(MainWindow, pronsole.pronsole):
def __init__(self, filename = None, size = winsize):
pronsole.pronsole.__init__(self)
self.settings.build_dimensions = '200x200x100+0+0+0' #default build dimensions are 200x200x100 with 0, 0, 0 in the corner of the bed
self.settings.build_dimensions = '200x200x100+0+0+0+0+0+0' #default build dimensions are 200x200x100 with 0, 0, 0 in the corner of the bed
self.settings.last_bed_temperature = 0.0
self.settings.last_file_path = ""
self.settings.last_temperature = 0.0
......@@ -93,7 +93,11 @@ class PronterWindow(MainWindow, pronsole.pronsole):
self.settings.preview_grid_step1 = 10.
self.settings.preview_grid_step2 = 50.
self.settings.bgcolor = "#FFFFFF"
self.helpdict["build_dimensions"] = _("Dimensions of Build Platform\n & optional offset of origin\n\nExamples:\n XXXxYYY\n XXX,YYY,ZZZ\n XXXxYYYxZZZ+OffX+OffY+OffZ")
self.pauseScript = "pause.gcode"
self.endScript = "end.gcode"
self.helpdict["build_dimensions"] = _("Dimensions of Build Platform\n & optional offset of origin\n & optional switch position\n\nExamples:\n XXXxYYY\n XXX,YYY,ZZZ\n XXXxYYYxZZZ+OffX+OffY+OffZ\nXXXxYYYxZZZ+OffX+OffY+OffZ+HomeX+HomeY+HomeZ")
self.helpdict["last_bed_temperature"] = _("Last Set Temperature for the Heated Print Bed")
self.helpdict["last_file_path"] = _("Folder of last opened file")
self.helpdict["last_temperature"] = _("Last Temperature of the Hot End")
......@@ -130,20 +134,24 @@ class PronterWindow(MainWindow, pronsole.pronsole):
self.build_dimensions_list = self.get_build_dimensions(self.settings.build_dimensions)
#initialize the code analyzer with the correct sizes. There must be a more general way to do so
self.p.analyzer.maxX = self.build_dimensions_list[0];
self.p.analyzer.maxY = self.build_dimensions_list[1];
self.p.analyzer.maxZ = self.build_dimensions_list[2];
self.p.analyzer.homeX = self.build_dimensions_list[3];
self.p.analyzer.homeY = self.build_dimensions_list[4];
self.p.analyzer.homeZ = self.build_dimensions_list[5];
self.p.analyzer.maxX = self.build_dimensions_list[0] if self.build_dimensions_list[0] >= self.build_dimensions_list[6] else self.build_dimensions_list[6] # maximum x is maximum x if maximum X > home X, else it is home X
self.p.analyzer.maxY = self.build_dimensions_list[1] if self.build_dimensions_list[1] >= self.build_dimensions_list[7] else self.build_dimensions_list[7]
self.p.analyzer.maxZ = self.build_dimensions_list[2] if self.build_dimensions_list[2] >= self.build_dimensions_list[8] else self.build_dimensions_list[8]
self.p.analyzer.print_status()
self.p.analyzer.minX = self.build_dimensions_list[3]
self.p.analyzer.minY = self.build_dimensions_list[4]
self.p.analyzer.minZ = self.build_dimensions_list[5]
self.p.analyzer.homeX = self.build_dimensions_list[6]
self.p.analyzer.homeY = self.build_dimensions_list[7]
self.p.analyzer.homeZ = self.build_dimensions_list[8]
#set feedrates in printcore for pause/resume
self.p.xy_feedrate = self.settings.xy_feedrate
self.p.z_feedrate = self.settings.z_feedrate
#make printcore aware of me
self.p.pronterface = self
self.panel.SetBackgroundColour(self.settings.bgcolor)
customdict = {}
......@@ -215,6 +223,8 @@ class PronterWindow(MainWindow, pronsole.pronsole):
wx.CallAfter(self.pausebtn.Disable)
wx.CallAfter(self.printbtn.SetLabel, _("Print"))
self.p.runSmallScript(self.endScript)
param = self.settings.final_command
if not param:
return
......@@ -1405,7 +1415,9 @@ class PronterWindow(MainWindow, pronsole.pronsole):
#print "Not printing, cannot pause."
return
self.p.pause()
self.p.runSmallScript(self.pauseScript)
self.paused = True
#self.p.runSmallScript(self.pauseScript)
self.extra_print_time += int(time.time() - self.starttime)
wx.CallAfter(self.pausebtn.SetLabel, _("Resume"))
else:
......@@ -1544,9 +1556,12 @@ class PronterWindow(MainWindow, pronsole.pronsole):
"[^\d+-]*(\d+)?" + # Z build size
"[^\d+-]*([+-]\d+)?" + # X corner coordinate
"[^\d+-]*([+-]\d+)?" + # Y corner coordinate
"[^\d+-]*([+-]\d+)?" # Z corner coordinate
"[^\d+-]*([+-]\d+)?" + # Z corner coordinate
"[^\d+-]*([+-]\d+)?" + # X endstop
"[^\d+-]*([+-]\d+)?" + # Y endstop
"[^\d+-]*([+-]\d+)?" # Z endstop
,bdim).groups()
defaults = [200, 200, 100, 0, 0, 0]
defaults = [200, 200, 100, 0, 0, 0, 0, 0, 0]
bdl_float = [float(value) if value else defaults[i] for i, value in enumerate(bdl)]
return bdl_float
......
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