diff --git a/plugins/USBPrinting/FirmwareUpdateWindow.qml b/plugins/USBPrinting/FirmwareUpdateWindow.qml index e8f532d24a..d55541f36d 100644 --- a/plugins/USBPrinting/FirmwareUpdateWindow.qml +++ b/plugins/USBPrinting/FirmwareUpdateWindow.qml @@ -32,16 +32,16 @@ UM.Dialog } text: { - if (manager.progress == 0) - { - //: Firmware update status label - return catalog.i18nc("@label","Starting firmware update, this may take a while.") - } - else if (manager.progress > 99) + if (manager.firmwareUpdateCompleteStatus) { //: Firmware update status label return catalog.i18nc("@label","Firmware update completed.") } + else if (manager.progress == 0) + { + //: Firmware update status label + return catalog.i18nc("@label","Starting firmware update, this may take a while.") + } else { //: Firmware update status label @@ -55,10 +55,10 @@ UM.Dialog ProgressBar { id: prog - value: manager.progress + value: manager.firmwareUpdateCompleteStatus ? 100 : manager.progress minimumValue: 0 maximumValue: 100 - indeterminate: manager.progress < 100 + indeterminate: (manager.progress < 1) && (!manager.firmwareUpdateCompleteStatus) anchors { left: parent.left; @@ -79,7 +79,7 @@ UM.Dialog Button { text: catalog.i18nc("@action:button","Close"); - enabled: manager.progress >= 100; + enabled: manager.firmwareUpdateCompleteStatus; onClicked: base.visible = false; } ] diff --git a/plugins/USBPrinting/USBPrinterOutputDevice.py b/plugins/USBPrinting/USBPrinterOutputDevice.py index 9f6c59f1ff..421168b87f 100644 --- a/plugins/USBPrinting/USBPrinterOutputDevice.py +++ b/plugins/USBPrinting/USBPrinterOutputDevice.py @@ -21,6 +21,7 @@ catalog = i18nCatalog("cura") class USBPrinterOutputDevice(PrinterOutputDevice): + def __init__(self, serial_port): super().__init__(serial_port) self.setName(catalog.i18nc("@item:inmenu", "USB printing")) @@ -86,12 +87,14 @@ class USBPrinterOutputDevice(PrinterOutputDevice): self._updating_firmware = False self._firmware_file_name = None + self._firmware_update_finished = False self._error_message = None onError = pyqtSignal() firmwareUpdateComplete = pyqtSignal() + firmwareUpdateChange = pyqtSignal() endstopStateChanged = pyqtSignal(str ,bool, arguments = ["key","state"]) @@ -171,6 +174,7 @@ class USBPrinterOutputDevice(PrinterOutputDevice): ## Private function (threaded) that actually uploads the firmware. def _updateFirmware(self): self.setProgress(0, 100) + self._firmware_update_finished = False if self._connection_state != ConnectionState.closed: self.close() @@ -181,7 +185,7 @@ class USBPrinterOutputDevice(PrinterOutputDevice): return programmer = stk500v2.Stk500v2() - programmer.progressCallback = self.setProgress + programmer.progressCallback = self.setProgress try: programmer.connect(self._serial_port) @@ -207,8 +211,10 @@ class USBPrinterOutputDevice(PrinterOutputDevice): programmer.close() self.setProgress(100, 100) + self._firmware_update_finished = True self.firmwareUpdateComplete.emit() + self.firmwareUpdateChange.emit() ## Upload new firmware to machine # \param filename full path of firmware file to be uploaded @@ -217,6 +223,14 @@ class USBPrinterOutputDevice(PrinterOutputDevice): self._firmware_file_name = file_name self._update_firmware_thread.start() + @property + def firmwareUpdateFinished(self): + return self._firmware_update_finished + + def resetFirmwareUpdateFinished(self): + self._firmware_update_finished = False + self.firmwareUpdateChange.emit() + @pyqtSlot() def startPollEndstop(self): if not self._poll_endstop: diff --git a/plugins/USBPrinting/USBPrinterOutputDeviceManager.py b/plugins/USBPrinting/USBPrinterOutputDeviceManager.py index fc10c217a0..1a53828d06 100644 --- a/plugins/USBPrinting/USBPrinterOutputDeviceManager.py +++ b/plugins/USBPrinting/USBPrinterOutputDeviceManager.py @@ -48,15 +48,24 @@ class USBPrinterOutputDeviceManager(QObject, OutputDevicePlugin, Extension): connectionStateChanged = pyqtSignal() progressChanged = pyqtSignal() + firmwareUpdateChange = pyqtSignal() @pyqtProperty(float, notify = progressChanged) def progress(self): progress = 0 for printer_name, device in self._usb_output_devices.items(): # TODO: @UnusedVariable "printer_name" progress += device.progress - return progress / len(self._usb_output_devices) + ## Return True if all printers finished firmware update + @pyqtProperty(float, notify = firmwareUpdateChange) + def firmwareUpdateCompleteStatus(self): + complete = True + for printer_name, device in self._usb_output_devices.items(): # TODO: @UnusedVariable "printer_name" + if not device.firmwareUpdateFinished: + complete = False + return complete + def start(self): self._check_updates = True self._update_thread.start() @@ -93,13 +102,20 @@ class USBPrinterOutputDeviceManager(QObject, OutputDevicePlugin, Extension): Message(i18n_catalog.i18nc("@info","Cannot update firmware, there were no connected printers found.")).show() return + for printer_connection in self._usb_output_devices: + self._usb_output_devices[printer_connection].resetFirmwareUpdateFinished() self.spawnFirmwareInterface("") for printer_connection in self._usb_output_devices: try: self._usb_output_devices[printer_connection].updateFirmware(Resources.getPath(CuraApplication.ResourceTypes.Firmware, self._getDefaultFirmwareName())) except FileNotFoundError: + # Should only happen in dev environments where the resources/firmware folder is absent. self._usb_output_devices[printer_connection].setProgress(100, 100) Logger.log("w", "No firmware found for printer %s", printer_connection) + Message(i18n_catalog.i18nc("@info", + "Could not find firmware required for the printer at %s.") % printer_connection).show() + self._firmware_view.close() + continue @pyqtSlot(str, result = bool) @@ -200,6 +216,7 @@ class USBPrinterOutputDeviceManager(QObject, OutputDevicePlugin, Extension): device.connectionStateChanged.connect(self._onConnectionStateChanged) device.connect() device.progressChanged.connect(self.progressChanged) + device.firmwareUpdateChange.connect(self.firmwareUpdateChange) self._usb_output_devices[serial_port] = device ## If one of the states of the connected devices change, we might need to add / remove them from the global list. diff --git a/plugins/USBPrinting/avr_isp/stk500v2.py b/plugins/USBPrinting/avr_isp/stk500v2.py index 02d398ef58..3960912e1d 100644 --- a/plugins/USBPrinting/avr_isp/stk500v2.py +++ b/plugins/USBPrinting/avr_isp/stk500v2.py @@ -20,7 +20,7 @@ class Stk500v2(ispBase.IspBase): self.serial = None self.seq = 1 self.last_addr = -1 - self.progress_callback = None + self.progressCallback = None def connect(self, port = "COM22", speed = 115200): if self.serial is not None: @@ -92,11 +92,11 @@ class Stk500v2(ispBase.IspBase): load_count = (len(flash_data) + page_size - 1) / page_size for i in range(0, int(load_count)): recv = self.sendMessage([0x13, page_size >> 8, page_size & 0xFF, 0xc1, 0x0a, 0x40, 0x4c, 0x20, 0x00, 0x00] + flash_data[(i * page_size):(i * page_size + page_size)]) - if self.progress_callback is not None: + if self.progressCallback is not None: if self._has_checksum: - self.progress_callback(i + 1, load_count) + self.progressCallback(i + 1, load_count) else: - self.progress_callback(i + 1, load_count*2) + self.progressCallback(i + 1, load_count * 2) def verifyFlash(self, flash_data): if self._has_checksum: @@ -120,8 +120,8 @@ class Stk500v2(ispBase.IspBase): load_count = (len(flash_data) + 0xFF) / 0x100 for i in range(0, int(load_count)): recv = self.sendMessage([0x14, 0x01, 0x00, 0x20])[2:0x102] - if self.progress_callback is not None: - self.progress_callback(load_count + i + 1, load_count*2) + if self.progressCallback is not None: + self.progressCallback(load_count + i + 1, load_count * 2) for j in range(0, 0x100): if i * 0x100 + j < len(flash_data) and flash_data[i * 0x100 + j] != recv[j]: raise ispBase.IspError("Verify error at: 0x%x" % (i * 0x100 + j))