Commit 211ce92b authored by D1plo1d's avatar D1plo1d

Merge branch 'experimental' of github.com:kliment/Printrun into experimental

parents 97355a82 07935b24
...@@ -152,7 +152,8 @@ class printcore(): ...@@ -152,7 +152,8 @@ class printcore():
print _("Could not connect to %s:%s:") % (hostname, port) print _("Could not connect to %s:%s:") % (hostname, port)
self.printer = None self.printer = None
self.printer_tcp = None self.printer_tcp = None
print _("Socket error %s: %s") % (e.errno, e.strerror) print _("Socket error %s:") % e.errno,
print e.strerror
return return
else: else:
disable_hup(self.port) disable_hup(self.port)
...@@ -225,18 +226,22 @@ class printcore(): ...@@ -225,18 +226,22 @@ class printcore():
# workaround cases where M105 was sent before printer Serial # workaround cases where M105 was sent before printer Serial
# was online an empty line means read timeout was reached, # was online an empty line means read timeout was reached,
# meaning no data was received thus we count those empty lines, # meaning no data was received thus we count those empty lines,
# and once we have seen 5 in a row, we just break and send a # and once we have seen 15 in a row, we just break and send a
# new M105 # new M105
if not line: empty_lines += 1 # 15 was chosen based on the fact that it gives enough time for
# Gen7 bootloader to time out, and that the non received M105
# issues should be quite rare so we can wait for a long time
# before resending
if not line:
empty_lines += 1
if empty_lines == 15: break
else: empty_lines = 0 else: empty_lines = 0
if empty_lines == 5: break if line.startswith(tuple(self.greetings)) or line.startswith('ok') or "T:" in line:
if line.startswith(tuple(self.greetings)) or line.startswith('ok'):
if self.onlinecb: if self.onlinecb:
try: self.onlinecb() try: self.onlinecb()
except: pass except: pass
self.online = True self.online = True
return return
time.sleep(0.25)
def _listen(self): def _listen(self):
"""This function acts on messages from the firmware """This function acts on messages from the firmware
...@@ -523,7 +528,7 @@ class printcore(): ...@@ -523,7 +528,7 @@ class printcore():
except: pass except: pass
try: try:
self.printer.write(str(command + "\n")) self.printer.write(str(command + "\n"))
self.printer.flush() if self.printer_tcp: self.printer.flush()
self.writefailures = 0 self.writefailures = 0
except socket.error as e: except socket.error as e:
print "Can't write to printer (disconnected?) (Socket error {0}): {1}".format(e.errno, e.strerror) print "Can't write to printer (disconnected?) (Socket error {0}): {1}".format(e.errno, e.strerror)
......
...@@ -31,8 +31,7 @@ move_gcodes = ["G0", "G1", "G2", "G3"] ...@@ -31,8 +31,7 @@ move_gcodes = ["G0", "G1", "G2", "G3"]
class PyLine(object): class PyLine(object):
__slots__ = ('x','y','z','e','f','i','j', __slots__ = ('x','y','z','e','f','i','j',
'raw','split_raw', 'raw', 'command', 'is_move',
'command','is_move',
'relative','relative_e', 'relative','relative_e',
'current_x', 'current_y', 'current_z', 'extruding', 'current_tool', 'current_x', 'current_y', 'current_z', 'extruding', 'current_tool',
'gcview_end_vertex') 'gcview_end_vertex')
......
...@@ -20,6 +20,15 @@ from math import log10, floor, ceil ...@@ -20,6 +20,15 @@ from math import log10, floor, ceil
from bufferedcanvas import * from bufferedcanvas import *
class GraphWindow(wx.Frame):
def __init__(self, root, size = (600, 600)):
wx.Frame.__init__(self, None, title = _("Temperature graph"), size = size)
panel = wx.Panel(self, -1)
vbox = wx.BoxSizer(wx.VERTICAL)
self.graph = Graph(panel, wx.ID_ANY, root)
vbox.Add(self.graph, 1, wx.EXPAND)
panel.SetSizer(vbox)
class Graph(BufferedCanvas): class Graph(BufferedCanvas):
'''A class to show a Graph with Pronterface.''' '''A class to show a Graph with Pronterface.'''
...@@ -52,6 +61,20 @@ class Graph(BufferedCanvas): ...@@ -52,6 +61,20 @@ class Graph(BufferedCanvas):
self.xbars = 6 # One bar per 10 second self.xbars = 6 # One bar per 10 second
self.xsteps = 60 # Covering 1 minute in the graph self.xsteps = 60 # Covering 1 minute in the graph
self.window = None
def showwin(self, event = None):
if not self.window:
self.window = GraphWindow(self.root)
self.window.Show()
if self.timer.IsRunning():
self.window.graph.StartPlotting(self.timer.Interval)
else:
self.window.Raise()
def __del__(self):
if self.window: self.window.Close()
def OnPaint(self, evt): def OnPaint(self, evt):
dc = wx.PaintDC(self) dc = wx.PaintDC(self)
gc = wx.GraphicsContext.Create(dc) gc = wx.GraphicsContext.Create(dc)
...@@ -197,6 +220,7 @@ class Graph(BufferedCanvas): ...@@ -197,6 +220,7 @@ class Graph(BufferedCanvas):
def SetBedTemperature(self, value): def SetBedTemperature(self, value):
self.bedtemps.pop() self.bedtemps.pop()
self.bedtemps.append(value) self.bedtemps.append(value)
if self.window: self.window.graph.SetBedTemperature(value)
def AddBedTemperature(self, value): def AddBedTemperature(self, value):
self.bedtemps.append(value) self.bedtemps.append(value)
...@@ -206,6 +230,7 @@ class Graph(BufferedCanvas): ...@@ -206,6 +230,7 @@ class Graph(BufferedCanvas):
def SetBedTargetTemperature(self, value): def SetBedTargetTemperature(self, value):
self.bedtargettemps.pop() self.bedtargettemps.pop()
self.bedtargettemps.append(value) self.bedtargettemps.append(value)
if self.window: self.window.graph.SetBedTargetTemperature(value)
def AddBedTargetTemperature(self, value): def AddBedTargetTemperature(self, value):
self.bedtargettemps.append(value) self.bedtargettemps.append(value)
...@@ -215,6 +240,7 @@ class Graph(BufferedCanvas): ...@@ -215,6 +240,7 @@ class Graph(BufferedCanvas):
def SetExtruder0Temperature(self, value): def SetExtruder0Temperature(self, value):
self.extruder0temps.pop() self.extruder0temps.pop()
self.extruder0temps.append(value) self.extruder0temps.append(value)
if self.window: self.window.graph.SetExtruder0Temperature(value)
def AddExtruder0Temperature(self, value): def AddExtruder0Temperature(self, value):
self.extruder0temps.append(value) self.extruder0temps.append(value)
...@@ -224,6 +250,7 @@ class Graph(BufferedCanvas): ...@@ -224,6 +250,7 @@ class Graph(BufferedCanvas):
def SetExtruder0TargetTemperature(self, value): def SetExtruder0TargetTemperature(self, value):
self.extruder0targettemps.pop() self.extruder0targettemps.pop()
self.extruder0targettemps.append(value) self.extruder0targettemps.append(value)
if self.window: self.window.graph.SetExtruder0TargetTemperature(value)
def AddExtruder0TargetTemperature(self, value): def AddExtruder0TargetTemperature(self, value):
self.extruder0targettemps.append(value) self.extruder0targettemps.append(value)
...@@ -233,6 +260,7 @@ class Graph(BufferedCanvas): ...@@ -233,6 +260,7 @@ class Graph(BufferedCanvas):
def SetExtruder1Temperature(self, value): def SetExtruder1Temperature(self, value):
self.extruder1temps.pop() self.extruder1temps.pop()
self.extruder1temps.append(value) self.extruder1temps.append(value)
if self.window: self.window.graph.SetExtruder1Temperature(value)
def AddExtruder1Temperature(self, value): def AddExtruder1Temperature(self, value):
self.extruder1temps.append(value) self.extruder1temps.append(value)
...@@ -242,6 +270,7 @@ class Graph(BufferedCanvas): ...@@ -242,6 +270,7 @@ class Graph(BufferedCanvas):
def SetExtruder1TargetTemperature(self, value): def SetExtruder1TargetTemperature(self, value):
self.extruder1targettemps.pop() self.extruder1targettemps.pop()
self.extruder1targettemps.append(value) self.extruder1targettemps.append(value)
if self.window: self.window.graph.SetExtruder1TargetTemperature(value)
def AddExtruder1TargetTemperature(self, value): def AddExtruder1TargetTemperature(self, value):
self.extruder1targettemps.append(value) self.extruder1targettemps.append(value)
...@@ -251,10 +280,12 @@ class Graph(BufferedCanvas): ...@@ -251,10 +280,12 @@ class Graph(BufferedCanvas):
def StartPlotting(self, time): def StartPlotting(self, time):
self.Refresh() self.Refresh()
self.timer.Start(time) self.timer.Start(time)
if self.window: self.window.graph.StartPlotting(time)
def StopPlotting(self): def StopPlotting(self):
self.timer.Stop() self.timer.Stop()
self.Refresh() self.Refresh()
if self.window: self.window.graph.StopPlotting()
def draw(self, dc, w, h): def draw(self, dc, w, h):
dc.SetBackground(wx.Brush(self.root.settings.bgcolor)) dc.SetBackground(wx.Brush(self.root.settings.bgcolor))
......
...@@ -171,6 +171,7 @@ def add_extra_controls(self, root, parentpanel, extra_buttons = None): ...@@ -171,6 +171,7 @@ def add_extra_controls(self, root, parentpanel, extra_buttons = None):
self.Add(root.graph, pos = (base_line + 5, 0), span = (3, 6)) self.Add(root.graph, pos = (base_line + 5, 0), span = (3, 6))
else: else:
self.Add(root.graph, pos = (base_line + 2, 5), span = (3, 1)) self.Add(root.graph, pos = (base_line + 2, 5), span = (3, 1))
root.graph.Bind(wx.EVT_LEFT_DOWN, root.graph.showwin)
if extra_buttons: if extra_buttons:
pos_mapping = { pos_mapping = {
......
...@@ -295,7 +295,7 @@ class GcodeModel(Model): ...@@ -295,7 +295,7 @@ class GcodeModel(Model):
def copy(self): def copy(self):
copy = GcodeModel() copy = GcodeModel()
for var in ["vertices", "colors", "max_layers", "num_layers_to_draw", "printed_until", "layer_stops"]: for var in ["vertices", "colors", "max_layers", "num_layers_to_draw", "printed_until", "layer_stops", "dims"]:
setattr(copy, var, getattr(self, var)) setattr(copy, var, getattr(self, var))
copy.loaded = True copy.loaded = True
copy.initialized = False copy.initialized = False
......
...@@ -539,6 +539,7 @@ class pronsole(cmd.Cmd): ...@@ -539,6 +539,7 @@ class pronsole(cmd.Cmd):
if ls.startswith('!'): if ls.startswith('!'):
return ws + ls[1:] + "\n" # python mode return ws + ls[1:] + "\n" # python mode
else: else:
ls = ls.replace('"','\\"') # need to escape double quotes
ret = ws + 'self.parseusercmd("'+ls+'".format(*arg))\n' # parametric command mode ret = ws + 'self.parseusercmd("'+ls+'".format(*arg))\n' # parametric command mode
return ret + ws + 'self.onecmd("'+ls+'".format(*arg))\n' return ret + ws + 'self.onecmd("'+ls+'".format(*arg))\n'
...@@ -576,7 +577,7 @@ class pronsole(cmd.Cmd): ...@@ -576,7 +577,7 @@ class pronsole(cmd.Cmd):
self.logError("Macro '"+macro_name+"' is not defined") self.logError("Macro '"+macro_name+"' is not defined")
def do_macro(self, args): def do_macro(self, args):
if args.strip()=="": if args.strip()=="":
self.print_topics("User-defined macros", self.macros.keys(), 15, 80) self.print_topics("User-defined macros", map(str,self.macros.keys()), 15, 80)
return return
arglist = args.split(None, 1) arglist = args.split(None, 1)
macro_name = arglist[0] macro_name = arglist[0]
...@@ -1430,7 +1431,10 @@ class pronsole(cmd.Cmd): ...@@ -1430,7 +1431,10 @@ class pronsole(cmd.Cmd):
self.processing_args = False self.processing_args = False
if args.filename: if args.filename:
filename = args.filename.decode(locale.getpreferredencoding()) filename = args.filename.decode(locale.getpreferredencoding())
self.do_load(filename) self.cmdline_filename_callback(filename)
def cmdline_filename_callback(self, filename):
self.do_load(filename)
def parse_cmdline(self, args): def parse_cmdline(self, args):
parser = argparse.ArgumentParser(description = 'Printrun 3D printer interface') parser = argparse.ArgumentParser(description = 'Printrun 3D printer interface')
......
...@@ -50,7 +50,7 @@ import pronsole ...@@ -50,7 +50,7 @@ import pronsole
from pronsole import dosify, wxSetting, HiddenSetting, StringSetting, SpinSetting, FloatSpinSetting, BooleanSetting, StaticTextSetting from pronsole import dosify, wxSetting, HiddenSetting, StringSetting, SpinSetting, FloatSpinSetting, BooleanSetting, StaticTextSetting
from printrun import gcoder from printrun import gcoder
tempreport_exp = re.compile("([TB]\d*):([-+]?\d*\.?\d*)(?: \/)?([-+]?\d*\.?\d*)") tempreport_exp = re.compile("([TB]\d*):([-+]?\d*\.?\d*)(?: ?\/)?([-+]?\d*\.?\d*)")
def parse_temperature_report(report): def parse_temperature_report(report):
matches = tempreport_exp.findall(report) matches = tempreport_exp.findall(report)
...@@ -1226,15 +1226,32 @@ class PronterWindow(MainWindow, pronsole.pronsole): ...@@ -1226,15 +1226,32 @@ class PronterWindow(MainWindow, pronsole.pronsole):
if "T0" in temps: if "T0" in temps:
hotend_temp = float(temps["T0"][0]) hotend_temp = float(temps["T0"][0])
else: else:
hotend_temp = float(temps["T"][0]) if "T" in temps else -1.0 hotend_temp = float(temps["T"][0]) if "T" in temps else None
if self.display_graph: wx.CallAfter(self.graph.SetExtruder0Temperature, hotend_temp) if hotend_temp is not None:
if self.display_gauges: wx.CallAfter(self.hottgauge.SetValue, hotend_temp) if self.display_graph: wx.CallAfter(self.graph.SetExtruder0Temperature, hotend_temp)
if self.display_gauges: wx.CallAfter(self.hottgauge.SetValue, hotend_temp)
setpoint = None
if "T0" in temps and temps["T0"][1]: setpoint = float(temps["T0"][1])
elif temps["T"][1]: setpoint = float(temps["T"][1])
if setpoint is not None:
if self.display_graph: wx.CallAfter(self.graph.SetExtruder0TargetTemperature, setpoint)
if self.display_gauges: wx.CallAfter(self.hottgauge.SetTarget, setpoint)
if "T1" in temps: if "T1" in temps:
hotend_temp = float(temps["T1"][0]) hotend_temp = float(temps["T1"][0])
if self.display_graph: wx.CallAfter(self.graph.SetExtruder1Temperature, hotend_temp) if self.display_graph: wx.CallAfter(self.graph.SetExtruder1Temperature, hotend_temp)
bed_temp = float(temps["B"][0]) if "B" in temps else -1.0 setpoint = temps["T1"][1]
if self.display_graph: wx.CallAfter(self.graph.SetBedTemperature, bed_temp) if setpoint and self.display_graph:
if self.display_gauges: wx.CallAfter(self.bedtgauge.SetValue, bed_temp) wx.CallAfter(self.graph.SetExtruder1TargetTemperature, float(setpoint))
bed_temp = float(temps["B"][0]) if "B" in temps else None
if bed_temp is not None:
if self.display_graph: wx.CallAfter(self.graph.SetBedTemperature, bed_temp)
if self.display_gauges: wx.CallAfter(self.bedtgauge.SetValue, bed_temp)
setpoint = temps["B"][1]
if setpoint:
setpoint = float(setpoint)
if self.display_graph: wx.CallAfter(self.graph.SetBedTargetTemperature, setpoint)
if self.display_gauges: wx.CallAfter(self.bedtgauge.SetTarget, setpoint)
except: except:
traceback.print_exc() traceback.print_exc()
...@@ -1469,6 +1486,11 @@ class PronterWindow(MainWindow, pronsole.pronsole): ...@@ -1469,6 +1486,11 @@ class PronterWindow(MainWindow, pronsole.pronsole):
threading.Thread(target = self.skein_func).start() threading.Thread(target = self.skein_func).start()
threading.Thread(target = self.skein_monitor).start() threading.Thread(target = self.skein_monitor).start()
def cmdline_filename_callback(self, filename):
# Do nothing when processing a filename from command line, as we'll
# handle it when everything has been prepared
self.filename = filename
def do_load(self,l): def do_load(self,l):
if hasattr(self, 'skeining'): if hasattr(self, 'skeining'):
self.loadfile(None, l) self.loadfile(None, l)
......
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