chiark / gitweb /
Fix the speed rate modify in the printing interface.
authorDaid <daid303@gmail.com>
Fri, 7 Sep 2012 10:04:55 +0000 (12:04 +0200)
committerDaid <daid303@gmail.com>
Fri, 7 Sep 2012 10:04:55 +0000 (12:04 +0200)
Cura/gui/printWindow.py
Cura/util/gcodeInterpreter.py
Cura/util/machineCom.py

index b0f46f39fdd1f7d67c0b01938a158284ec3d5508..6f8a464ae5af770dfdd8d9aab7d66d90d909e6c7 100644 (file)
@@ -296,10 +296,14 @@ class printWindow(wx.Frame):
 \r
        def UpdateButtonStates(self):\r
                self.connectButton.Enable(self.machineCom == None or self.machineCom.isClosedOrError())\r
-               #self.loadButton.Enable(self.printIdx == None)\r
-               self.printButton.Enable(self.machineCom != None and self.machineCom.isOperational() and not (self.machineCom.isPrinting() or self.machineCome.isPaused()))\r
-               self.pauseButton.Enable(self.machineCom != None and (self.machineCom.isPrinting() or self.machineCome.isPaused()))\r
-               self.cancelButton.Enable(self.machineCom != None and (self.machineCom.isPrinting() or self.machineCome.isPaused()))\r
+               #self.loadButton.Enable(self.machineCom == None or not (self.machineCom.isPrinting() or self.machineCom.isPaused()))\r
+               self.printButton.Enable(self.machineCom != None and self.machineCom.isOperational() and not (self.machineCom.isPrinting() or self.machineCom.isPaused()))\r
+               self.pauseButton.Enable(self.machineCom != None and (self.machineCom.isPrinting() or self.machineCom.isPaused()))\r
+               if self.machineCom != None and self.machineCom.isPaused():\r
+                       self.pauseButton.SetLabel('Resume')\r
+               else:\r
+                       self.pauseButton.SetLabel('Pause')\r
+               self.cancelButton.Enable(self.machineCom != None and (self.machineCom.isPrinting() or self.machineCom.isPaused()))\r
                self.temperatureSelect.Enable(self.machineCom != None and self.machineCom.isOperational())\r
                self.bedTemperatureSelect.Enable(self.machineCom != None and self.machineCom.isOperational())\r
                self.directControlPanel.Enable(self.machineCom != None and self.machineCom.isOperational())\r
@@ -367,10 +371,8 @@ class printWindow(wx.Frame):
        def OnPause(self, e):\r
                if self.machineCom.isPaused():\r
                        self.machineCom.setPause(False)\r
-                       self.pauseButton.SetLabel('Pause')\r
                else:\r
                        self.machineCom.setPause(True)\r
-                       self.pauseButton.SetLabel('Resume')\r
        \r
        def OnClose(self, e):\r
                global printWindowHandle\r
@@ -386,10 +388,12 @@ class printWindow(wx.Frame):
                self.machineCom.sendCommand("M140 S%d" % (self.bedTemperatureSelect.GetValue()))\r
        \r
        def OnSpeedChange(self, e):\r
-               self.feedrateRatioOuterWall = self.outerWallSpeedSelect.GetValue() / 100.0\r
-               self.feedrateRatioInnerWall = self.innerWallSpeedSelect.GetValue() / 100.0\r
-               self.feedrateRatioFill = self.fillSpeedSelect.GetValue() / 100.0\r
-               self.feedrateRatioSupport = self.supportSpeedSelect.GetValue() / 100.0\r
+               if self.machineCom == None:\r
+                       return\r
+               self.machineCom.setFeedrateModifier('WALL-OUTER', self.outerWallSpeedSelect.GetValue() / 100.0)\r
+               self.machineCom.setFeedrateModifier('WALL-INNER', self.innerWallSpeedSelect.GetValue() / 100.0)\r
+               self.machineCom.setFeedrateModifier('FILL', self.fillSpeedSelect.GetValue() / 100.0)\r
+               self.machineCom.setFeedrateModifier('SUPPORT', self.supportSpeedSelect.GetValue() / 100.0)\r
        \r
        def AddTermLog(self, line):\r
                self.termLog.AppendText(unicode(line, 'utf-8', 'replace'))\r
@@ -422,9 +426,8 @@ class printWindow(wx.Frame):
                if self.machineCom != None and self.machineCom.isPrinting():\r
                        return\r
                #Send an initial M110 to reset the line counter to zero.\r
-               lineType = 'CUSTOM'\r
+               prevLineType = lineType = 'CUSTOM'\r
                gcodeList = ["M110"]\r
-               typeList = [lineType]\r
                for line in open(filename, 'r'):\r
                        if line.startswith(';TYPE:'):\r
                                lineType = line[6:].strip()\r
@@ -432,15 +435,17 @@ class printWindow(wx.Frame):
                                line = line[0:line.find(';')]\r
                        line = line.strip()\r
                        if len(line) > 0:\r
-                               gcodeList.append(line)\r
-                               typeList.append(lineType)\r
+                               if prevLineType != lineType:\r
+                                       gcodeList.append((line, lineType, ))\r
+                               else:\r
+                                       gcodeList.append(line)\r
+                               prevLineType = lineType\r
                gcode = gcodeInterpreter.gcode()\r
                gcode.loadList(gcodeList)\r
                print "Loaded: %s (%d)" % (filename, len(gcodeList))\r
                self.filename = filename\r
                self.gcode = gcode\r
                self.gcodeList = gcodeList\r
-               self.typeList = typeList\r
                \r
                wx.CallAfter(self.progress.SetRange, len(gcodeList))\r
                wx.CallAfter(self.UpdateButtonStates)\r
index 40f3f183b5e6a1f2a1a7d4c23b6410f2db135d01..86dbd76262df47ad3ae8bc974e9f49a736a5f091 100644 (file)
@@ -68,6 +68,8 @@ class gcode(object):
                currentPath.list[0].e = totalExtrusion
                currentLayer.append(currentPath)
                for line in gcodeFile:
+                       if type(line) is tuple:
+                               line = line[0]
                        if self.progressCallback != None:
                                if filePos != gcodeFile.tell():
                                        filePos = gcodeFile.tell()
index fd03fbdee6fb13e4d3c02b14aa7706ca66413995..836b863fa7236ec272e9122c9feec9adce99be10 100644 (file)
@@ -134,6 +134,7 @@ class MachineCom(object):
                self._gcodePos = 0
                self._commandQueue = queue.Queue()
                self._logQueue = queue.Queue(256)
+               self._feedRateModifier = {}
                
                if port == 'AUTO':
                        programmer = stk500v2.Stk500v2()
@@ -323,7 +324,7 @@ class MachineCom(object):
                if ret == '':
                        #self._log("Recv: TIMEOUT")
                        return ''
-               self._log("Recv: %s" % (unicode(ret, 'ascii', 'replace').rstrip()))
+               self._log("Recv: %s" % (unicode(ret, 'ascii', 'replace').encode('ascii', 'replace').rstrip()))
                return ret
        
        def close(self, isError = False):
@@ -355,6 +356,17 @@ class MachineCom(object):
                        self._changeState(self.STATE_OPERATIONAL)
                        return
                line = self._gcodeList[self._gcodePos]
+               if type(line) is tuple:
+                       self._printSection = line[1]
+                       line = line[0]
+               try:
+                       if line == 'M0' or line == 'M1':
+                               self.setPause(True)
+                               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)
+               except:
+                       self._log("Unexpected error: %s" % (getExceptionString()))
                checksum = reduce(lambda x,y:x^y, map(ord, "N%d%s" % (self._gcodePos, line)))
                self._sendCommand("N%d%s*%d" % (self._gcodePos, line, checksum))
                self._gcodePos += 1
@@ -372,6 +384,7 @@ class MachineCom(object):
                        return
                self._gcodeList = gcodeList
                self._gcodePos = 0
+               self._printSection = 'CUSTOM'
                self._changeState(self.STATE_PRINTING)
                for i in xrange(0, 6):
                        self._sendNext()
@@ -387,6 +400,9 @@ class MachineCom(object):
                                self._sendNext()
                if pause and self.isPrinting():
                        self._changeState(self.STATE_PAUSED)
+       
+       def setFeedrateModifier(self, type, value):
+               self._feedRateModifier[type] = value
 
 def getExceptionString():
        locationInfo = traceback.extract_tb(sys.exc_info()[2])[0]