chiark / gitweb /
Add Z change reporting support, which fixes the timelaps movie recording. Add tempera...
authorDaid <daid303@gmail.com>
Fri, 7 Sep 2012 12:10:57 +0000 (14:10 +0200)
committerDaid <daid303@gmail.com>
Fri, 7 Sep 2012 12:10:57 +0000 (14:10 +0200)
Cura/gui/printWindow.py
Cura/util/machineCom.py

index 6f8a464ae5af770dfdd8d9aab7d66d90d909e6c7..a69e18e76a3d343488744027a189ed948abe97e2 100644 (file)
@@ -456,29 +456,12 @@ class printWindow(wx.Frame):
                        return False\r
                line = self.gcodeList[lineNr]\r
                try:\r
-                       if line == 'M0' or line == 'M1':\r
-                               self.OnPause(None)\r
-                               line = 'M105'\r
                        if ('M104' in line or 'M109' in line) and 'S' in line:\r
                                n = int(re.search('S([0-9]*)', line).group(1))\r
                                wx.CallAfter(self.temperatureSelect.SetValue, n)\r
                        if ('M140' in line or 'M190' in line) and 'S' in line:\r
                                n = int(re.search('S([0-9]*)', line).group(1))\r
                                wx.CallAfter(self.bedTemperatureSelect.SetValue, n)\r
-                       if self.typeList[lineNr] == 'WALL-OUTER':\r
-                               line = re.sub('F([0-9]*)', lambda m: 'F' + str(int(int(m.group(1)) * self.feedrateRatioOuterWall)), line)\r
-                       if self.typeList[lineNr] == 'WALL-INNER':\r
-                               line = re.sub('F([0-9]*)', lambda m: 'F' + str(int(int(m.group(1)) * self.feedrateRatioInnerWall)), line)\r
-                       if self.typeList[lineNr] == 'FILL':\r
-                               line = re.sub('F([0-9]*)', lambda m: 'F' + str(int(int(m.group(1)) * self.feedrateRatioFill)), line)\r
-                       if self.typeList[lineNr] == 'SUPPORT':\r
-                               line = re.sub('F([0-9]*)', lambda m: 'F' + str(int(int(m.group(1)) * self.feedrateRatioSupport)), line)\r
-                       if 'G1' in line and 'Z' in line:\r
-                               z = float(re.search('Z([0-9\.]*)', line).group(1))\r
-                               if self.cam != None and self.currentZ != z:\r
-                                       wx.CallAfter(self.cam.takeNewImage)\r
-                                       wx.CallAfter(self.camPage.Refresh)\r
-                               self.currentZ = z\r
                except:\r
                        print "Unexpected error:", sys.exc_info()\r
                checksum = reduce(lambda x,y:x^y, map(ord, "N%d%s" % (lineNr, line)))\r
@@ -500,6 +483,11 @@ class printWindow(wx.Frame):
        \r
        def mcProgress(self, lineNr):\r
                wx.CallAfter(self.UpdateProgress)\r
+       \r
+       def mcZChange(self, newZ):\r
+               if self.cam != None:\r
+                       wx.CallAfter(self.cam.takeNewImage)\r
+                       wx.CallAfter(self.camPage.Refresh)\r
 \r
 class temperatureGraph(wx.Panel):\r
        def __init__(self, parent):\r
index 836b863fa7236ec272e9122c9feec9adce99be10..43369a79fbe9fb5b4d2a2adb29cf33a33dd60204 100644 (file)
@@ -58,7 +58,7 @@ class VirtualPrinter():
                                pass
                if 'M105' in data:
                        self.readList.append("ok T:%.2f /%.2f B:%.2f /%.2f @:64\n" % (self.temp, self.targetTemp, self.bedTemp, self.bedTargetTemp))
-               else:
+               elif len(data.strip()) > 0:
                        self.readList.append("ok\n")
 
        def readline(self):
@@ -100,6 +100,9 @@ class MachineComPrintCallback(object):
        
        def mcProgress(self, lineNr):
                pass
+       
+       def mcZChange(self, newZ):
+               pass
 
 class MachineCom(object):
        STATE_NONE = 0
@@ -135,6 +138,7 @@ class MachineCom(object):
                self._commandQueue = queue.Queue()
                self._logQueue = queue.Queue(256)
                self._feedRateModifier = {}
+               self._currentZ = -1
                
                if port == 'AUTO':
                        programmer = stk500v2.Stk500v2()
@@ -225,7 +229,7 @@ class MachineCom(object):
                return self._bedTemp
        
        def _monitor(self):
-               self._timeoutTime = time.time() + 5
+               timeout = time.time() + 5
                while True:
                        line = self._readline()
                        if line == None:
@@ -250,7 +254,7 @@ class MachineCom(object):
                                self._callback.mcMessage(line)
 
                        if self._state == self.STATE_DETECT_BAUDRATE:
-                               if line == '' or time.time() > self._timeoutTime:
+                               if line == '' or time.time() > timeout:
                                        if len(self._baudrateDetectList) < 1:
                                                self._log("No more baudrates to test, and no suitable baudrate found.")
                                                self.close()
@@ -265,7 +269,7 @@ class MachineCom(object):
                                                        self._serial.timeout = 0.5
                                                        self._log("Trying baudrate: %d" % (baudrate))
                                                        self._baudrateDetectRetry = 5
-                                                       self._timeoutTime = time.time() + 5
+                                                       timeout = time.time() + 5
                                                        self._serial.write('\n')
                                                        self._sendCommand("M105")
                                                except:
@@ -278,18 +282,23 @@ class MachineCom(object):
                                        self._sendCommand("M105")
                                elif 'ok' in line:
                                        self._changeState(self.STATE_OPERATIONAL)
-                               if time.time() > self._timeoutTime:
+                               if time.time() > timeout:
                                        self.close()
                        elif self._state == self.STATE_OPERATIONAL:
                                #Request the temperature on comm timeout (every 2 seconds) when we are not printing.
                                if line == '':
                                        self._sendCommand("M105")
+                                       tempRequestTimeout = time.time() + 5
                        elif self._state == self.STATE_PRINTING:
-                               if line == '' and time.time() > self._timeoutTime:
+                               if line == '' and time.time() > timeout:
                                        self._log("Communication timeout during printing, forcing a line")
                                        line = 'ok'
+                               #Even when printing request the temperture every 5 seconds.
+                               if time.time() > tempRequestTimeout:
+                                       self._commandQueue.put("M105")
+                                       tempRequestTimeout = time.time() + 5
                                if 'ok' in line:
-                                       self._timeoutTime = time.time() + 5
+                                       timeout = time.time() + 5
                                        if not self._commandQueue.empty():
                                                self._sendCommand(self._commandQueue.get())
                                        else:
@@ -365,6 +374,11 @@ class MachineCom(object):
                                line = 'M105'   #Don't send the M0 or M1 to the machine, as M0 and M1 are handled as an LCD menu pause.
                        if self._printSection in self._feedRateModifier:
                                line = re.sub('F([0-9]*)', lambda m: 'F' + str(int(int(m.group(1)) * self._feedRateModifier[self._printSection])), line)
+                       if ('G0' in line or 'G1' in line) and 'Z' in line:
+                               z = float(re.search('Z([0-9\.]*)', line).group(1))
+                               if self._currentZ != z:
+                                       self._currentZ = z
+                                       self._callback.mcZChange(z)
                except:
                        self._log("Unexpected error: %s" % (getExceptionString()))
                checksum = reduce(lambda x,y:x^y, map(ord, "N%d%s" % (self._gcodePos, line)))