Fixed firmware update screen. CURA-2079.

This commit is contained in:
Jack Ha 2016-08-10 12:57:01 +02:00
parent 9bf4dbd24f
commit 48792aa8f3
4 changed files with 48 additions and 17 deletions

View file

@ -32,16 +32,16 @@ UM.Dialog
} }
text: { text: {
if (manager.progress == 0) if (manager.firmwareUpdateCompleteStatus)
{
//: Firmware update status label
return catalog.i18nc("@label","Starting firmware update, this may take a while.")
}
else if (manager.progress > 99)
{ {
//: Firmware update status label //: Firmware update status label
return catalog.i18nc("@label","Firmware update completed.") 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 else
{ {
//: Firmware update status label //: Firmware update status label
@ -55,10 +55,10 @@ UM.Dialog
ProgressBar ProgressBar
{ {
id: prog id: prog
value: manager.progress value: manager.firmwareUpdateCompleteStatus ? 100 : manager.progress
minimumValue: 0 minimumValue: 0
maximumValue: 100 maximumValue: 100
indeterminate: manager.progress < 100 indeterminate: (manager.progress < 1) && (!manager.firmwareUpdateCompleteStatus)
anchors anchors
{ {
left: parent.left; left: parent.left;
@ -79,7 +79,7 @@ UM.Dialog
Button Button
{ {
text: catalog.i18nc("@action:button","Close"); text: catalog.i18nc("@action:button","Close");
enabled: manager.progress >= 100; enabled: manager.firmwareUpdateCompleteStatus;
onClicked: base.visible = false; onClicked: base.visible = false;
} }
] ]

View file

@ -21,6 +21,7 @@ catalog = i18nCatalog("cura")
class USBPrinterOutputDevice(PrinterOutputDevice): class USBPrinterOutputDevice(PrinterOutputDevice):
def __init__(self, serial_port): def __init__(self, serial_port):
super().__init__(serial_port) super().__init__(serial_port)
self.setName(catalog.i18nc("@item:inmenu", "USB printing")) self.setName(catalog.i18nc("@item:inmenu", "USB printing"))
@ -86,12 +87,14 @@ class USBPrinterOutputDevice(PrinterOutputDevice):
self._updating_firmware = False self._updating_firmware = False
self._firmware_file_name = None self._firmware_file_name = None
self._firmware_update_finished = False
self._error_message = None self._error_message = None
onError = pyqtSignal() onError = pyqtSignal()
firmwareUpdateComplete = pyqtSignal() firmwareUpdateComplete = pyqtSignal()
firmwareUpdateChange = pyqtSignal()
endstopStateChanged = pyqtSignal(str ,bool, arguments = ["key","state"]) endstopStateChanged = pyqtSignal(str ,bool, arguments = ["key","state"])
@ -171,6 +174,7 @@ class USBPrinterOutputDevice(PrinterOutputDevice):
## Private function (threaded) that actually uploads the firmware. ## Private function (threaded) that actually uploads the firmware.
def _updateFirmware(self): def _updateFirmware(self):
self.setProgress(0, 100) self.setProgress(0, 100)
self._firmware_update_finished = False
if self._connection_state != ConnectionState.closed: if self._connection_state != ConnectionState.closed:
self.close() self.close()
@ -207,8 +211,10 @@ class USBPrinterOutputDevice(PrinterOutputDevice):
programmer.close() programmer.close()
self.setProgress(100, 100) self.setProgress(100, 100)
self._firmware_update_finished = True
self.firmwareUpdateComplete.emit() self.firmwareUpdateComplete.emit()
self.firmwareUpdateChange.emit()
## Upload new firmware to machine ## Upload new firmware to machine
# \param filename full path of firmware file to be uploaded # \param filename full path of firmware file to be uploaded
@ -217,6 +223,14 @@ class USBPrinterOutputDevice(PrinterOutputDevice):
self._firmware_file_name = file_name self._firmware_file_name = file_name
self._update_firmware_thread.start() 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() @pyqtSlot()
def startPollEndstop(self): def startPollEndstop(self):
if not self._poll_endstop: if not self._poll_endstop:

View file

@ -48,15 +48,24 @@ class USBPrinterOutputDeviceManager(QObject, OutputDevicePlugin, Extension):
connectionStateChanged = pyqtSignal() connectionStateChanged = pyqtSignal()
progressChanged = pyqtSignal() progressChanged = pyqtSignal()
firmwareUpdateChange = pyqtSignal()
@pyqtProperty(float, notify = progressChanged) @pyqtProperty(float, notify = progressChanged)
def progress(self): def progress(self):
progress = 0 progress = 0
for printer_name, device in self._usb_output_devices.items(): # TODO: @UnusedVariable "printer_name" for printer_name, device in self._usb_output_devices.items(): # TODO: @UnusedVariable "printer_name"
progress += device.progress progress += device.progress
return progress / len(self._usb_output_devices) 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): def start(self):
self._check_updates = True self._check_updates = True
self._update_thread.start() 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() Message(i18n_catalog.i18nc("@info","Cannot update firmware, there were no connected printers found.")).show()
return return
for printer_connection in self._usb_output_devices:
self._usb_output_devices[printer_connection].resetFirmwareUpdateFinished()
self.spawnFirmwareInterface("") self.spawnFirmwareInterface("")
for printer_connection in self._usb_output_devices: for printer_connection in self._usb_output_devices:
try: try:
self._usb_output_devices[printer_connection].updateFirmware(Resources.getPath(CuraApplication.ResourceTypes.Firmware, self._getDefaultFirmwareName())) self._usb_output_devices[printer_connection].updateFirmware(Resources.getPath(CuraApplication.ResourceTypes.Firmware, self._getDefaultFirmwareName()))
except FileNotFoundError: except FileNotFoundError:
# Should only happen in dev environments where the resources/firmware folder is absent.
self._usb_output_devices[printer_connection].setProgress(100, 100) self._usb_output_devices[printer_connection].setProgress(100, 100)
Logger.log("w", "No firmware found for printer %s", printer_connection) 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 continue
@pyqtSlot(str, result = bool) @pyqtSlot(str, result = bool)
@ -200,6 +216,7 @@ class USBPrinterOutputDeviceManager(QObject, OutputDevicePlugin, Extension):
device.connectionStateChanged.connect(self._onConnectionStateChanged) device.connectionStateChanged.connect(self._onConnectionStateChanged)
device.connect() device.connect()
device.progressChanged.connect(self.progressChanged) device.progressChanged.connect(self.progressChanged)
device.firmwareUpdateChange.connect(self.firmwareUpdateChange)
self._usb_output_devices[serial_port] = device 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. ## If one of the states of the connected devices change, we might need to add / remove them from the global list.

View file

@ -20,7 +20,7 @@ class Stk500v2(ispBase.IspBase):
self.serial = None self.serial = None
self.seq = 1 self.seq = 1
self.last_addr = -1 self.last_addr = -1
self.progress_callback = None self.progressCallback = None
def connect(self, port = "COM22", speed = 115200): def connect(self, port = "COM22", speed = 115200):
if self.serial is not None: if self.serial is not None:
@ -92,11 +92,11 @@ class Stk500v2(ispBase.IspBase):
load_count = (len(flash_data) + page_size - 1) / page_size load_count = (len(flash_data) + page_size - 1) / page_size
for i in range(0, int(load_count)): 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)]) 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: if self._has_checksum:
self.progress_callback(i + 1, load_count) self.progressCallback(i + 1, load_count)
else: else:
self.progress_callback(i + 1, load_count*2) self.progressCallback(i + 1, load_count * 2)
def verifyFlash(self, flash_data): def verifyFlash(self, flash_data):
if self._has_checksum: if self._has_checksum:
@ -120,8 +120,8 @@ class Stk500v2(ispBase.IspBase):
load_count = (len(flash_data) + 0xFF) / 0x100 load_count = (len(flash_data) + 0xFF) / 0x100
for i in range(0, int(load_count)): for i in range(0, int(load_count)):
recv = self.sendMessage([0x14, 0x01, 0x00, 0x20])[2:0x102] recv = self.sendMessage([0x14, 0x01, 0x00, 0x20])[2:0x102]
if self.progress_callback is not None: if self.progressCallback is not None:
self.progress_callback(load_count + i + 1, load_count*2) self.progressCallback(load_count + i + 1, load_count * 2)
for j in range(0, 0x100): for j in range(0, 0x100):
if i * 0x100 + j < len(flash_data) and flash_data[i * 0x100 + j] != recv[j]: 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)) raise ispBase.IspError("Verify error at: 0x%x" % (i * 0x100 + j))