diff --git a/plugins/USBPrinting/FirmwareUpdateWindow.qml b/plugins/USBPrinting/FirmwareUpdateWindow.qml index dfde1c1ae1..99f3c03bce 100644 --- a/plugins/USBPrinting/FirmwareUpdateWindow.qml +++ b/plugins/USBPrinting/FirmwareUpdateWindow.qml @@ -35,47 +35,45 @@ UM.Dialog if (manager.errorCode == 0) { if (manager.firmwareUpdateCompleteStatus) - { - //: Firmware update status label - return catalog.i18nc("@label","Firmware update completed.") - } - 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.") + { + //: 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.errorCode == 1) - { - //: Firmware update status label - return catalog.i18nc("@label","Firmware update failed due to an unknown error.") - } - else if (manager.errorCode == 2) - { - //: Firmware update status label - return catalog.i18nc("@label","Firmware update failed due to an communication error.") - } - else if (manager.errorCode == 3) - { - //: Firmware update status label - return catalog.i18nc("@label","Firmware update failed due to an input/output error.") - } - else if (manager.errorCode == 4) - { - //: Firmware update status label - return catalog.i18nc("@label","Firmware update failed due to missing firmware.") - } - else - { - //: Firmware update status label - return catalog.i18nc("@label", "Unknown error code: %1").arg(manager.errorCode) + 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 9d0c8ddb49..e20588afca 100644 --- a/plugins/USBPrinting/USBPrinterOutputDevice.py +++ b/plugins/USBPrinting/USBPrinterOutputDevice.py @@ -90,6 +90,8 @@ class USBPrinterOutputDevice(PrinterOutputDevice): self._firmware_update_finished = False self._error_message = None + + self._error_code = 0 onError = pyqtSignal() @@ -173,7 +175,7 @@ class USBPrinterOutputDevice(PrinterOutputDevice): ## Private function (threaded) that actually uploads the firmware. def _updateFirmware(self): - self._errorCode = 0 + self._error_code = 0 self.setProgress(0, 100) self._firmware_update_finished = False @@ -183,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_missing_firmware() + self._updateFirmwareFailedMissingFirmware() return programmer = stk500v2.Stk500v2() @@ -199,7 +201,7 @@ class USBPrinterOutputDevice(PrinterOutputDevice): if not programmer.isConnected(): Logger.log("e", "Unable to connect with serial. Could not update firmware") - self._updateFirmware_failed_communication_error() + self._updateFirmwareFailedCommunicationError() return self._updating_firmware = True @@ -209,48 +211,39 @@ class USBPrinterOutputDevice(PrinterOutputDevice): self._updating_firmware = False except serial.SerialException as e: Logger.log("e", "SerialException while trying to update firmware: <%s>" %(repr(e))) - self._updateFirmware_failed_io_error() + self._updateFirmwareFailedIOError() return except Exception as e: Logger.log("e", "Exception while trying to update firmware: <%s>" %(repr(e))) - self._updateFirmware_failed_unknown() + self._updateFirmwareFailedUnknown() return programmer.close() - self._updateFirmware_completed_sucessfully() + self._updateFirmwareCompletedSucessfully() return ## Private function which makes sure that firmware update process has failed by missing firmware - def _updateFirmware_failed_missing_firmware(self): - return self._updateFirmware_failed_common(4) + def _updateFirmwareFailedMissingFirmware(self): + return self._updateFirmwareFailedCommon(4) ## Private function which makes sure that firmware update process has failed by an IO error - def _updateFirmware_failed_io_error(self): - return self._updateFirmware_failed_common(3) + def _updateFirmwareFailedIOError(self): + return self._updateFirmwareFailedCommon(3) ## Private function which makes sure that firmware update process has failed by a communication problem - def _updateFirmware_failed_communication_error(self): - return self._updateFirmware_failed_common(2) + def _updateFirmwareFailedCommunicationError(self): + return self._updateFirmwareFailedCommon(2) ## Private function which makes sure that firmware update process has failed by an unknown error - def _updateFirmware_failed_unknown(self): - return self._updateFirmware_failed_common(1) + def _updateFirmwareFailedUnknown(self): + return self._updateFirmwareFailedCommon(1) - ## Private function which makes sure that firmware update process has successfully completed - def _updateFirmware_completed_sucessfully(self): - self.setProgress(100, 100) - self._firmware_update_finished = True - self.resetFirmwareUpdate(update_has_finished = True) - self.firmwareUpdateComplete.emit() - - return - ## Private common function which makes sure that firmware update process has completed/ended with a set progress state - def _updateFirmware_failed_common(self, code): + def _updateFirmwareFailedCommon(self, code): if not code: raise Exception("Error code not set!") - self._errorCode = code + self._error_code = code self._firmware_update_finished = True self.resetFirmwareUpdate(update_has_finished = True) @@ -259,6 +252,15 @@ class USBPrinterOutputDevice(PrinterOutputDevice): 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.firmwareUpdateComplete.emit() + + return + ## Upload new firmware to machine # \param filename full path of firmware file to be uploaded def updateFirmware(self, file_name): diff --git a/plugins/USBPrinting/USBPrinterOutputDeviceManager.py b/plugins/USBPrinting/USBPrinterOutputDeviceManager.py index 3584b8c453..801ce4743f 100644 --- a/plugins/USBPrinting/USBPrinterOutputDeviceManager.py +++ b/plugins/USBPrinting/USBPrinterOutputDeviceManager.py @@ -38,8 +38,6 @@ class USBPrinterOutputDeviceManager(QObject, OutputDevicePlugin, Extension): self._update_thread = threading.Thread(target = self._updateThread) self._update_thread.setDaemon(True) - self._errorCode = 0 - self._check_updates = True self._firmware_view = None @@ -61,7 +59,10 @@ class USBPrinterOutputDeviceManager(QObject, OutputDevicePlugin, Extension): @pyqtProperty(int, notify = progressChanged) def errorCode(self): - return self._errorCode + 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)