Commit 6a130c7b authored by kliment's avatar kliment

Add upload functionality to pronsole

parent 3ca695da
......@@ -120,6 +120,8 @@ class printcore():
self.queueindex=0
self.resendfrom=-1
self._send("M110",-1, True)
if len(data)==0:
return True
self.clear=False
Thread(target=self._print).start()
return True
......
......@@ -3,6 +3,9 @@ import cmd, printcore, sys
import glob, os, time
def dosify(name):
return name.split(".")[0][:8]+".g"
class pronsole(cmd.Cmd):
def __init__(self):
......@@ -77,6 +80,9 @@ class pronsole(cmd.Cmd):
print "Disconnects from the printer"
def do_load(self,l):
if len(l)==0:
print "No file name given."
return
print "Loading file:"+l
if not(os.path.exists(l)):
print "File not found!"
......@@ -87,6 +93,8 @@ class pronsole(cmd.Cmd):
def complete_load(self, text, line, begidx, endidx):
s=line.split()
if len(s)>2:
return []
if (len(s)==1 and line[-1]==" ") or (len(s)==2 and line[-1]!=" "):
if len(s)>1:
return [i[len(s[1])-len(text):] for i in glob.glob(s[1]+"*/")+glob.glob(s[1]+"*.g*")]
......@@ -96,6 +104,65 @@ class pronsole(cmd.Cmd):
def help_load(self):
print "Loads a gcode file (with tab-completion)"
def do_upload(self,l):
if len(l)==0:
print "No file name given."
return
print "Loading file:"+l.split()[0]
if not(os.path.exists(l.split()[0])):
print "File not found!"
return
if not self.p.online:
print "Not connected to printer."
return
self.f=[i.replace("\n","") for i in open(l.split()[0])]
self.filename=l.split()[0]
print "Loaded ",l,", ",len(self.f)," lines."
tname=""
if len(l.split())>1:
tname=l.split()[1]
else:
print "please enter target name in 8.3 format."
return
print "Uploading as ",tname
print("Uploading "+self.filename)
self.p.send_now("M28 "+tname)
print("Press Ctrl-C to interrupt upload.")
self.p.startprint(self.f)
try:
sys.stdout.write("Progress: 00.0%")
sys.stdout.flush()
time.sleep(1)
while self.p.printing:
time.sleep(1)
sys.stdout.write("\b\b\b\b\b%04.1f%%" % (100*float(self.p.queueindex)/len(self.p.mainqueue),) )
sys.stdout.flush()
self.p.send_now("M29 "+tname)
self.p.startprint([])
print "\b\b\b\b\b100%. Upload completed. ",tname," should now be on the card."
return
except:
print "...interrupted!"
self.p.pause()
self.p.send_now("M29 "+tname)
self.p.startprint([])
print "A partial file named ",tname," may have been written to the sd card."
def complete_upload(self, text, line, begidx, endidx):
s=line.split()
if len(s)>2:
return []
if (len(s)==1 and line[-1]==" ") or (len(s)==2 and line[-1]!=" "):
if len(s)>1:
return [i[len(s[1])-len(text):] for i in glob.glob(s[1]+"*/")+glob.glob(s[1]+"*.g*")]
else:
return glob.glob("*/")+glob.glob("*.g*")
def help_upload(self):
print "Uploads a gcode file to the sd card"
def help_print(self):
if self.f is None:
print "Send a loaded gcode file to the printer. Load a file with the load command first."
......@@ -131,7 +198,7 @@ class pronsole(cmd.Cmd):
time.sleep(1)
sys.stdout.write("\b\b\b\b\b%04.1f%%" % (100*float(self.p.queueindex)/len(self.p.mainqueue),) )
sys.stdout.flush()
print "Print completed."
print "\b\b\b\b\b100%. Print completed."
return
except:
print "...interrupted!"
......@@ -139,7 +206,8 @@ class pronsole(cmd.Cmd):
self.p.pause()
print "Use the resume command to resume this print"
def help_resume(self):
print "Resumes a paused print."
def emptyline(self):
pass
......@@ -156,12 +224,24 @@ class pronsole(cmd.Cmd):
if(self.p and self.p.online):
print "SENDING:"+l
self.p.send_now(l)
else:
print "Printer is not online."
return
if(l[0]=='m' or l[0]=="g"):
if(self.p and self.p.online):
print "SENDING:"+l.upper()
self.p.send_now(l.upper())
else:
print "Printer is not online."
return
else:
cmd.Cmd.default(self,l)
def do_EOF(self,l):
print "Use ^C to exit."
def help_help(self):
self.do_help("")
interp=pronsole()
interp.cmdloop()
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