Commit e77d3f08 authored by Guillaume Seguin's avatar Guillaume Seguin

Factorize pronsole and pronterface's recvcb

parent b6d9b575
......@@ -58,6 +58,10 @@ except:
tempreading_exp = re.compile("(^T:| T:)")
REPORT_NONE = 0
REPORT_POS = 1
REPORT_TEMP = 2
class Status(object):
def __init__(self):
......@@ -125,7 +129,11 @@ class pronsole(cmd.Cmd):
self.temps = {"pla": "185", "abs": "230", "off": "0"}
self.bedtemps = {"pla": "60", "abs": "110", "off": "0"}
self.percentdone = 0
self.posreport = ""
self.tempreadings = ""
self.userm114 = 0
self.userm105 = 0
self.m105_waitcycles = 0
self.macros = {}
self.history_file = "~/.pronsole-history"
self.rc_loaded = False
......@@ -1122,9 +1130,27 @@ class pronsole(cmd.Cmd):
self.log("Final command output:")
self.log(output.rstrip())
def recvcb(self, l):
if tempreading_exp.findall(l):
def recvcb_report(self, l):
isreport = REPORT_NONE
if "ok C:" in l or "Count" in l \
or ("X:" in l and len(gcoder.m114_exp.findall(l)) == 6):
self.posreport = l
if self.userm114 > 0:
self.userm114 -= 1
else:
isreport = REPORT_POS
if "ok T:" in l or tempreading_exp.findall(l):
self.tempreadings = l
if self.userm105 > 0:
self.userm105 -= 1
else:
self.m105_waitcycles = 0
isreport = REPORT_TEMP
return isreport
def recvcb(self, l):
report_type = self.recvcb_report(l)
if report_type == REPORT_TEMP:
self.status.update_tempreading(l)
tstring = l.rstrip()
if tstring != "ok" and not self.listing and not self.monitoring:
......
......@@ -62,6 +62,7 @@ from .excluder import Excluder
from .settings import wxSetting, HiddenSetting, StringSetting, SpinSetting, \
FloatSpinSetting, BooleanSetting, StaticTextSetting
from printrun import gcoder
from .pronsole import REPORT_NONE, REPORT_POS, REPORT_TEMP
tempreading_exp = re.compile("(^T:| T:)")
......@@ -145,10 +146,6 @@ class PronterWindow(MainWindow, pronsole.pronsole):
self.status_thread = None
self.capture_skip = {}
self.capture_skip_newline = False
self.tempreadings = ""
self.userm114 = 0
self.userm105 = 0
self.m105_waitcycles = 0
self.fgcode = None
self.excluder = None
self.slicep = None
......@@ -1675,8 +1672,8 @@ Printrun. If not, see <http://www.gnu.org/licenses/>."""
except:
traceback.print_exc()
def update_pos(self, l):
bits = gcoder.m114_exp.findall(l)
def update_pos(self):
bits = gcoder.m114_exp.findall(self.posreport)
x = None
y = None
z = None
......@@ -1693,24 +1690,13 @@ Printrun. If not, see <http://www.gnu.org/licenses/>."""
if z is not None: self.current_pos[2] = z
def recvcb(self, l):
isreport = False
if "ok C:" in l or "Count" in l \
or ("X:" in l and len(gcoder.m114_exp.findall(l)) == 6):
self.posreport = l
self.update_pos(l)
if self.userm114 > 0:
self.userm114 -= 1
else:
isreport = True
if "ok T:" in l or tempreading_exp.findall(l):
self.tempreadings = l
report_type = self.recvcb_report(l)
isreport = report_type != REPORT_NONE
if report_type == REPORT_POS:
self.update_pos()
elif report_type == REPORT_TEMP:
wx.CallAfter(self.tempdisp.SetLabel, self.tempreadings.strip().replace("ok ", ""))
self.update_tempdisplay()
if self.userm105 > 0:
self.userm105 -= 1
else:
self.m105_waitcycles = 0
isreport = True
tstring = l.rstrip()
if not self.p.loud and (tstring not in ["ok", "wait"] and not isreport):
wx.CallAfter(self.addtexttolog, tstring + "\n")
......
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