diff --git a/plugins/USBPrinting/FirmwareUpdateWindow.qml b/plugins/USBPrinting/FirmwareUpdateWindow.qml index d55541f36d..99f3c03bce 100644 --- a/plugins/USBPrinting/FirmwareUpdateWindow.qml +++ b/plugins/USBPrinting/FirmwareUpdateWindow.qml @@ -32,20 +32,49 @@ UM.Dialog } text: { - if (manager.firmwareUpdateCompleteStatus) + if (manager.errorCode == 0) { - //: Firmware update status label - return catalog.i18nc("@label","Firmware update completed.") + 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 + return catalog.i18nc("@label","Updating firmware.") + } } - else if (manager.progress == 0) + else { - //: Firmware update status label - return catalog.i18nc("@label","Starting firmware update, this may take a while.") - } - else - { - //: Firmware update status label - return catalog.i18nc("@label","Updating firmware.") + switch (manager.errorCode) + { + case 1: + //: Firmware update status label + return catalog.i18nc("@label","Firmware update failed due to an unknown error.") + + case 2: + //: Firmware update status label + return catalog.i18nc("@label","Firmware update failed due to an communication error.") + + + case 3: + //: Firmware update status label + return catalog.i18nc("@label","Firmware update failed due to an input/output error.") + + case 4: + //: Firmware update status label + return catalog.i18nc("@label","Firmware update failed due to missing firmware.") + + default: + //: Firmware update status label + return catalog.i18nc("@label", "Unknown error code: %1").arg(manager.errorCode) + } } } diff --git a/plugins/USBPrinting/USBPrinterOutputDevice.py b/plugins/USBPrinting/USBPrinterOutputDevice.py index d0a459e561..e20588afca 100644 --- a/plugins/USBPrinting/USBPrinterOutputDevice.py +++ b/plugins/USBPrinting/USBPrinterOutputDevice.py @@ -14,7 +14,7 @@ from UM.Logger import Logger from cura.PrinterOutputDevice import PrinterOutputDevice, ConnectionState from UM.Message import Message -from PyQt5.QtCore import QUrl, pyqtSlot, pyqtSignal +from PyQt5.QtCore import QUrl, pyqtSlot, pyqtSignal, pyqtProperty from UM.i18n import i18nCatalog catalog = i18nCatalog("cura") @@ -90,6 +90,8 @@ class USBPrinterOutputDevice(PrinterOutputDevice): self._firmware_update_finished = False self._error_message = None + + self._error_code = 0 onError = pyqtSignal() @@ -173,6 +175,7 @@ class USBPrinterOutputDevice(PrinterOutputDevice): ## Private function (threaded) that actually uploads the firmware. def _updateFirmware(self): + self._error_code = 0 self.setProgress(0, 100) self._firmware_update_finished = False @@ -182,7 +185,7 @@ class USBPrinterOutputDevice(PrinterOutputDevice): if len(hex_file) == 0: Logger.log("e", "Unable to read provided hex file. Could not update firmware") - self._updateFirmware_completed() + self._updateFirmwareFailedMissingFirmware() return programmer = stk500v2.Stk500v2() @@ -198,7 +201,7 @@ class USBPrinterOutputDevice(PrinterOutputDevice): if not programmer.isConnected(): Logger.log("e", "Unable to connect with serial. Could not update firmware") - self._updateFirmware_completed() + self._updateFirmwareFailedCommunicationError() return self._updating_firmware = True @@ -206,22 +209,56 @@ class USBPrinterOutputDevice(PrinterOutputDevice): try: programmer.programChip(hex_file) self._updating_firmware = False + except serial.SerialException as e: + Logger.log("e", "SerialException while trying to update firmware: <%s>" %(repr(e))) + self._updateFirmwareFailedIOError() + return except Exception as e: - Logger.log("e", "Exception while trying to update firmware %s" %e) - self._updateFirmware_completed() + Logger.log("e", "Exception while trying to update firmware: <%s>" %(repr(e))) + self._updateFirmwareFailedUnknown() return programmer.close() - self._updateFirmware_completed() + self._updateFirmwareCompletedSucessfully() return - ## Private function which makes sure that firmware update process has completed/ended - def _updateFirmware_completed(self): + ## Private function which makes sure that firmware update process has failed by missing firmware + def _updateFirmwareFailedMissingFirmware(self): + return self._updateFirmwareFailedCommon(4) + + ## Private function which makes sure that firmware update process has failed by an IO error + def _updateFirmwareFailedIOError(self): + return self._updateFirmwareFailedCommon(3) + + ## Private function which makes sure that firmware update process has failed by a communication problem + def _updateFirmwareFailedCommunicationError(self): + return self._updateFirmwareFailedCommon(2) + + ## Private function which makes sure that firmware update process has failed by an unknown error + def _updateFirmwareFailedUnknown(self): + return self._updateFirmwareFailedCommon(1) + + ## Private common function which makes sure that firmware update process has completed/ended with a set progress state + def _updateFirmwareFailedCommon(self, code): + if not code: + raise Exception("Error code not set!") + + self._error_code = code + + self._firmware_update_finished = True + self.resetFirmwareUpdate(update_has_finished = True) + self.progressChanged.emit() + self.firmwareUpdateComplete.emit() + + return + + ## Private function which makes sure that firmware update process has successfully completed + def _updateFirmwareCompletedSucessfully(self): self.setProgress(100, 100) self._firmware_update_finished = True - self.resetFirmwareUpdate(update_has_finished=True) + self.resetFirmwareUpdate(update_has_finished = True) self.firmwareUpdateComplete.emit() - + return ## Upload new firmware to machine diff --git a/plugins/USBPrinting/USBPrinterOutputDeviceManager.py b/plugins/USBPrinting/USBPrinterOutputDeviceManager.py index d9a036c682..801ce4743f 100644 --- a/plugins/USBPrinting/USBPrinterOutputDeviceManager.py +++ b/plugins/USBPrinting/USBPrinterOutputDeviceManager.py @@ -57,6 +57,13 @@ class USBPrinterOutputDeviceManager(QObject, OutputDevicePlugin, Extension): progress += device.progress return progress / len(self._usb_output_devices) + @pyqtProperty(int, notify = progressChanged) + def errorCode(self): + for printer_name, device in self._usb_output_devices.items(): # TODO: @UnusedVariable "printer_name" + if device._error_code: + return device._error_code + return 0 + ## Return True if all printers finished firmware update @pyqtProperty(float, notify = firmwareUpdateChange) def firmwareUpdateCompleteStatus(self):