From 3853fb6d192c6bc75b3e5b7f39d07f804928b599 Mon Sep 17 00:00:00 2001 From: Lipu Fei Date: Tue, 27 Aug 2019 08:51:48 +0200 Subject: [PATCH] Add UI feedback on invalid firmware update CURA-6537 --- cura/PrinterOutput/FirmwareUpdater.py | 2 +- plugins/FirmwareUpdater/FirmwareUpdaterMachineAction.qml | 2 ++ plugins/USBPrinting/AvrFirmwareUpdater.py | 3 +++ plugins/USBPrinting/avr_isp/intelHex.py | 7 +++++-- 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/cura/PrinterOutput/FirmwareUpdater.py b/cura/PrinterOutput/FirmwareUpdater.py index 3f20e0f3c4..d33015920a 100644 --- a/cura/PrinterOutput/FirmwareUpdater.py +++ b/cura/PrinterOutput/FirmwareUpdater.py @@ -75,4 +75,4 @@ class FirmwareUpdateState(IntEnum): communication_error = 4 io_error = 5 firmware_not_found_error = 6 - + invalid_firmware_error = 7 diff --git a/plugins/FirmwareUpdater/FirmwareUpdaterMachineAction.qml b/plugins/FirmwareUpdater/FirmwareUpdaterMachineAction.qml index b5b6c15f50..90a27c24e1 100644 --- a/plugins/FirmwareUpdater/FirmwareUpdaterMachineAction.qml +++ b/plugins/FirmwareUpdater/FirmwareUpdaterMachineAction.qml @@ -151,6 +151,8 @@ Cura.MachineAction return catalog.i18nc("@label","Firmware update failed due to an input/output error."); case 6: return catalog.i18nc("@label","Firmware update failed due to missing firmware."); + case 7: + return catalog.i18nc("@label","Firmware update failed due to invalid firmware file."); } } diff --git a/plugins/USBPrinting/AvrFirmwareUpdater.py b/plugins/USBPrinting/AvrFirmwareUpdater.py index 0f7146560d..ded2036efe 100644 --- a/plugins/USBPrinting/AvrFirmwareUpdater.py +++ b/plugins/USBPrinting/AvrFirmwareUpdater.py @@ -27,6 +27,9 @@ class AvrFirmwareUpdater(FirmwareUpdater): except (FileNotFoundError, AssertionError): Logger.log("e", "Unable to read provided hex file. Could not update firmware.") self._setFirmwareUpdateState(FirmwareUpdateState.firmware_not_found_error) + except Exception: + Logger.logException("e", "Failed to read hex file '%s'", self._firmware_file) + self._setFirmwareUpdateState(FirmwareUpdateState.invalid_firmware_error) return programmer = stk500v2.Stk500v2() diff --git a/plugins/USBPrinting/avr_isp/intelHex.py b/plugins/USBPrinting/avr_isp/intelHex.py index 671f1788f7..3c5c66d805 100644 --- a/plugins/USBPrinting/avr_isp/intelHex.py +++ b/plugins/USBPrinting/avr_isp/intelHex.py @@ -5,13 +5,16 @@ See: http://en.wikipedia.org/wiki/Intel_HEX This is a python 3 conversion of the code created by David Braam for the Cura project. """ import io +from typing import List + from UM.Logger import Logger -def readHex(filename): + +def readHex(filename: str) -> List[int]: """ Read an verify an intel hex file. Return the data as an list of bytes. """ - data = [] + data = [] # type: List[int] extra_addr = 0 f = io.open(filename, "r", encoding = "utf-8") for line in f: