chiark / gitweb /
Revert "Disable pause feature"
[cura.git] / Cura / util / printerConnection / serialConnection.py
index 6f5d1a8df0bf67c262edf04a502be87a473efedf..1fd0485d65278b45f4aa07f0c932dd969b91056f 100644 (file)
@@ -67,6 +67,8 @@ class serialConnection(printerConnectionBase.printerConnectionBase):
                self._commState = None
                self._commStateString = None
                self._gcodeData = []
+               self._printProgress = 0
+               self._ZPosition = 0
 
        #Load the data into memory for printing, returns True on success
        def loadGCodeData(self, dataStream):
@@ -94,16 +96,31 @@ class serialConnection(printerConnectionBase.printerConnectionBase):
                        self._process.stdin.write('G:%s\n' % (line))
                self._process.stdin.write('START\n')
                self._printProgress = 0
+               self._ZPosition = 0
+
+       def coolDown(self):
+               cooldown_toolhead = "M104 S0"
+               for i in range(0,3):
+                       change_toolhead = "T%d".format(i)
+                       self.sendCommand(change_toolhead)
+                       self.sendCommand(cooldown_toolhead)
+               self.sendCommand("M140 S0") #Bed
+
+       def disableSteppers(self):
+               self.sendCommand("M18")
 
        #Abort the previously loaded print file
        def cancelPrint(self):
-               if not self.isPrinting() or self._process is None:
+               if (not self.isPrinting() and not self.isPaused()) or \
+                       self._process is None:
                        return
                self._process.stdin.write('STOP\n')
                self._printProgress = 0
+               self.coolDown()
+               self.disableSteppers()
 
        def isPrinting(self):
-               return self._commState == machineCom.MachineCom.STATE_PRINTING or self.isPaused()
+               return self._commState == machineCom.MachineCom.STATE_PRINTING
 
        #Returns true if we have the ability to pause the file printing.
        def hasPause(self):
@@ -114,15 +131,16 @@ class serialConnection(printerConnectionBase.printerConnectionBase):
 
        #Pause or unpause the printing depending on the value, if supported.
        def pause(self, value):
-               if not self.isPrinting() or self._process is None:
+               if not (self.isPrinting() or self.isPaused()) or self._process is None:
                        return
-               self._process.stdin.write('PAUSE\n' if value else "RESUME\n")
+               if value:
+                       self._process.stdin.write("PAUSE\n")
+               else:
+                       self._process.stdin.write("RESUME\n")
 
        #Amount of progression of the current print file. 0.0 to 1.0
        def getPrintProgress(self):
-               if len(self._gcodeData) < 1:
-                       return 0.0
-               return float(self._printProgress) / float(len(self._gcodeData))
+               return (self._printProgress, len(self._gcodeData), self._ZPosition)
 
        # Return if the printer with this connection type is available
        def isAvailable(self):
@@ -222,10 +240,13 @@ class serialConnection(printerConnectionBase.printerConnectionBase):
                                line = line[1].split(':', 1)
                                self._commState = int(line[0])
                                self._commStateString = line[1]
-                               self._doCallback()
+                               self._doCallback('')
                        elif line[0] == 'progress':
                                self._printProgress = int(line[1])
                                self._doCallback()
+                       elif line[0] == 'changeZ':
+                               self._ZPosition = float(line[1])
+                               self._doCallback()
                        else:
                                print line
                        line = self._process.stdout.readline()