Clean up the monitor command.
The monitor command now: * Has more pythonic code * Limits precision of progress elements (12.3% instead of 12.347812...%) * Uses a carriage return to have print progress replace the previous progress line. For example: Monitoring printer, use ^C to interrupt. Updating values every 5.000000 seconds. Print progress: 0.3% Previously, the line "Print progress: 0.3%" was "Print progress: 0.2%", etc.master
parent
92821f7e41
commit
3fb7a3e71c
26
pronsole.py
26
pronsole.py
|
@ -1118,6 +1118,9 @@ class pronsole(cmd.Cmd):
|
||||||
if not self.p.online:
|
if not self.p.online:
|
||||||
print "Printer is not online. Please connect first."
|
print "Printer is not online. Please connect first."
|
||||||
return
|
return
|
||||||
|
if not (self.p.printing or self.sdprinting):
|
||||||
|
print "Printer not printing. Please print something before monitoring."
|
||||||
|
return
|
||||||
print "Monitoring printer, use ^C to interrupt."
|
print "Monitoring printer, use ^C to interrupt."
|
||||||
if len(l):
|
if len(l):
|
||||||
try:
|
try:
|
||||||
|
@ -1126,22 +1129,27 @@ class pronsole(cmd.Cmd):
|
||||||
print "Invalid period given."
|
print "Invalid period given."
|
||||||
print "Updating values every %f seconds."%(interval,)
|
print "Updating values every %f seconds."%(interval,)
|
||||||
self.monitoring = 1
|
self.monitoring = 1
|
||||||
|
prev_msg_len = 0
|
||||||
try:
|
try:
|
||||||
while(1):
|
while True:
|
||||||
self.p.send_now("M105")
|
self.p.send_now("M105")
|
||||||
if(self.sdprinting):
|
if(self.sdprinting):
|
||||||
self.p.send_now("M27")
|
self.p.send_now("M27")
|
||||||
time.sleep(interval)
|
time.sleep(interval)
|
||||||
#print (self.tempreadings.replace("\r", "").replace("T", "Hotend").replace("B", "Bed").replace("\n", "").replace("ok ", ""))
|
#print (self.tempreadings.replace("\r", "").replace("T", "Hotend").replace("B", "Bed").replace("\n", "").replace("ok ", ""))
|
||||||
if(self.p.printing):
|
if self.p.printing:
|
||||||
print "Print progress: ", 100*float(self.p.queueindex)/len(self.p.mainqueue), "%"
|
preface = "Print progress: "
|
||||||
|
progress = 100*float(self.p.queueindex)/len(self.p.mainqueue)
|
||||||
if(self.sdprinting):
|
elif self.sdprinting:
|
||||||
print "SD print progress: ", self.percentdone, "%"
|
preface = "Print progress: "
|
||||||
|
progress = self.percentdone
|
||||||
except:
|
progress = int(progress*10)/10.0 #limit precision
|
||||||
|
prev_msg = preface + str(progress) + "%"
|
||||||
|
sys.stdout.write("\r" + prev_msg.ljust(prev_msg_len))
|
||||||
|
sys.stdout.flush()
|
||||||
|
prev_msg_len = len(prev_msg)
|
||||||
|
except KeyboardInterrupt:
|
||||||
print "Done monitoring."
|
print "Done monitoring."
|
||||||
pass
|
|
||||||
self.monitoring = 0
|
self.monitoring = 0
|
||||||
|
|
||||||
def help_monitor(self):
|
def help_monitor(self):
|
||||||
|
|
Loading…
Reference in New Issue