chiark / gitweb /
Revert "Disable pause feature"
[cura.git] / Cura / util / printerConnection / serialConnection.py
index a7591269ebfcc8836648e2e4220cfe70f850eb2d..1fd0485d65278b45f4aa07f0c932dd969b91056f 100644 (file)
@@ -12,6 +12,7 @@ import sys
 import subprocess
 import json
 
+from Cura.util import profile
 from Cura.util import machineCom
 from Cura.util.printerConnection import printerConnectionBase
 
@@ -25,8 +26,11 @@ class serialConnectionGroup(printerConnectionBase.printerConnectionGroup):
                self._connectionMap = {}
 
        def getAvailableConnections(self):
-               serialList = machineCom.serialList(True)
-               for port in machineCom.serialList(True):
+               if profile.getMachineSetting('serial_port') == 'AUTO':
+                       serialList = machineCom.serialList(True)
+               else:
+                       serialList = [profile.getMachineSetting('serial_port')]
+               for port in serialList:
                        if port not in self._connectionMap:
                                self._connectionMap[port] = serialConnection(port)
                for key in self._connectionMap.keys():
@@ -63,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):
@@ -90,22 +96,51 @@ 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
 
+       #Returns true if we have the ability to pause the file printing.
+       def hasPause(self):
+               return True
+
+       def isPaused(self):
+               return self._commState == machineCom.MachineCom.STATE_PAUSED
+
+       #Pause or unpause the printing depending on the value, if supported.
+       def pause(self, value):
+               if not (self.isPrinting() or self.isPaused()) or self._process is None:
+                       return
+               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):
@@ -174,9 +209,10 @@ class serialConnection(printerConnectionBase.printerConnectionBase):
        def _serialCommunicationThread(self):
                if platform.system() == "Darwin" and hasattr(sys, 'frozen'):
                        cmdList = [os.path.join(os.path.dirname(sys.executable), 'Cura'), '--serialCommunication']
+                       cmdList += [self._portName + ':' + profile.getMachineSetting('serial_baud')]
                else:
                        cmdList = [sys.executable, '-m', 'Cura.serialCommunication']
-               cmdList += [self._portName]
+                       cmdList += [self._portName, profile.getMachineSetting('serial_baud')]
                if platform.system() == "Darwin":
                        if platform.machine() == 'i386':
                                cmdList = ['arch', '-i386'] + cmdList
@@ -204,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()