Просмотр исходного кода

Fix: bed leveling for UM+
CURA-4844

Aleksei S 7 лет назад
Родитель
Сommit
290adbd906

+ 8 - 2
cura/PrinterOutput/GenericOutputController.py

@@ -58,8 +58,14 @@ class GenericOutputController(PrinterOutputController):
         self._output_device.sendCommand("G90")
 
     def homeHead(self, printer):
-        self._output_device.sendCommand("G28 X")
-        self._output_device.sendCommand("G28 Y")
+        # Ultimaker+ frimware is 'Marlin V1' and UM2 is "Marlin Ultimaker2"
+        # For this reason UM2 should move only X, Y and not Z, otherwise it might brake the build plate
+        name = self._output_device.getFirmwareName()
+        if name and name.find("Ultimaker2") != -1:
+            self._output_device.sendCommand("G28 X")
+            self._output_device.sendCommand("G28 Y")
+        else:
+            self._output_device.sendCommand("G28")  # Move X-, Y- and Z-coordinate
 
     def homeBed(self, printer):
         self._output_device.sendCommand("G28 Z")

+ 13 - 0
cura/PrinterOutputDevice.py

@@ -71,6 +71,7 @@ class PrinterOutputDevice(QObject, OutputDevice):
 
         self._connection_state = ConnectionState.closed
 
+        self._firmware_name = None
         self._address = ""
         self._connection_text = ""
         self.printersChanged.connect(self._onPrintersChanged)
@@ -198,6 +199,18 @@ class PrinterOutputDevice(QObject, OutputDevice):
         # At this point there may be non-updated configurations
         self._updateUniqueConfigurations()
 
+    ##  Set the device firmware name
+    #
+    #   \param name \type{str} The name of the firmware.
+    def _setFirmwareName(self, name):
+        self._firmware_name = name
+
+    ##  Get the name of device firmware
+    #
+    #   This name can be used to define device type
+    def getFirmwareName(self):
+        return self._firmware_name
+
 
 ##  The current processing state of the backend.
 class ConnectionState(IntEnum):

+ 3 - 0
cura/Settings/MachineManager.py

@@ -335,6 +335,9 @@ class MachineManager(QObject):
             self._initMachineState(containers[0])
             self._onGlobalContainerChanged()
 
+            #The signal should update/reset settings of all connected USB devices
+            #self.usbOutputDeviceChanged.emit()
+
         self.__emitChangedSignals()
 
     ##  Given a definition id, return the machine with this id.

+ 25 - 0
plugins/USBPrinting/USBPrinterOutputDevice.py

@@ -85,6 +85,11 @@ class USBPrinterOutputDevice(PrinterOutputDevice):
         # Queue for commands that need to be send. Used when command is sent when a print is active.
         self._command_queue = Queue()
 
+    ## Reset USB device settings
+    #
+    def resetDeviceSettings(self):
+        self._firmware_name = None
+
     ##  Request the current scene to be sent to a USB-connected printer.
     #
     #   \param nodes A collection of scene nodes to send. This is ignored.
@@ -225,6 +230,8 @@ class USBPrinterOutputDevice(PrinterOutputDevice):
         self._baud_rate = baud_rate
 
     def connect(self):
+        self._firmware_name = None # after each connection ensure that the frimware name is removed
+
         if self._baud_rate is None:
             if self._use_auto_detect:
                 auto_detect_job = AutoDetectBaudJob(self._serial_port)
@@ -286,6 +293,9 @@ class USBPrinterOutputDevice(PrinterOutputDevice):
                 self.sendCommand("M105")
                 self._last_temperature_request = time()
 
+                if self._firmware_name is None:
+                    self.sendCommand("M115")
+
             if b"ok T:" in line or line.startswith(b"T:") or b"ok B:" in line or line.startswith(b"B:"):  # Temperature message. 'T:' for extruder and 'B:' for bed
                 extruder_temperature_matches = re.findall(b"T(\d*): ?([\d\.]+) ?\/?([\d\.]+)?", line)
                 # Update all temperature values
@@ -303,6 +313,9 @@ class USBPrinterOutputDevice(PrinterOutputDevice):
                     if match[1]:
                         self._printers[0].updateTargetBedTemperature(float(match[1]))
 
+            if b"FIRMWARE_NAME:" in line:
+                self._setFirmwareName(line)
+
             if self._is_printing:
                 if line.startswith(b'!!'):
                     Logger.log('e', "Printer signals fatal error. Cancelling print. {}".format(line))
@@ -323,6 +336,18 @@ class USBPrinterOutputDevice(PrinterOutputDevice):
                             # In some cases of the RS command it needs to be handled differently.
                             self._gcode_position = int(line.split()[1])
 
+    def _setFirmwareName(self, name):
+        new_name = re.findall(r"FIRMWARE_NAME:(.*);", str(name))
+        if  new_name:
+            self._firmware_name = new_name[0]
+            Logger.log("i", "USB output device Firmware name: %s", self._firmware_name)
+        else:
+            self._firmware_name = "Unknown"
+            Logger.log("i", "Unknown USB output device Firmware name: %s", str(name))
+
+    def getFirmwareName(self):
+        return self._firmware_name
+
     def pausePrint(self):
         self._paused = True
 

+ 8 - 0
plugins/USBPrinting/USBPrinterOutputDeviceManager.py

@@ -42,6 +42,14 @@ class USBPrinterOutputDeviceManager(QObject, OutputDevicePlugin):
         # Because the model needs to be created in the same thread as the QMLEngine, we use a signal.
         self.addUSBOutputDeviceSignal.connect(self.addOutputDevice)
 
+        Application.getInstance().globalContainerStackChanged.connect(self.updateUSBPrinterOutputDevices)
+
+    # The method updates/reset the USB settings for all connected USB devices
+    def updateUSBPrinterOutputDevices(self):
+        for key, device in self._usb_output_devices.items():
+            if isinstance(device, USBPrinterOutputDevice.USBPrinterOutputDevice):
+                device.resetDeviceSettings()
+
     def start(self):
         self._check_updates = True
         self._update_thread.start()