mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-10 08:17:49 -06:00
Moved updating firmware to own thread
This commit is contained in:
parent
d66faf6ecd
commit
cc9e67533c
3 changed files with 23 additions and 12 deletions
|
@ -38,6 +38,9 @@ class PrinterConnection(SignalEmitter):
|
||||||
self._listen_thread = threading.Thread(target=self._listen)
|
self._listen_thread = threading.Thread(target=self._listen)
|
||||||
self._listen_thread.daemon = True
|
self._listen_thread.daemon = True
|
||||||
|
|
||||||
|
self._update_firmware_thread = threading.Thread(target= self._updateFirmware)
|
||||||
|
self._update_firmware_thread.demon = True
|
||||||
|
|
||||||
self._heatup_wait_start_time = time.time()
|
self._heatup_wait_start_time = time.time()
|
||||||
|
|
||||||
## Queue for commands that need to be send. Used when command is sent when a print is active.
|
## Queue for commands that need to be send. Used when command is sent when a print is active.
|
||||||
|
@ -79,6 +82,8 @@ class PrinterConnection(SignalEmitter):
|
||||||
|
|
||||||
self._updating_firmware = False
|
self._updating_firmware = False
|
||||||
|
|
||||||
|
self._firmware_file_name = None
|
||||||
|
|
||||||
#TODO: Might need to add check that extruders can not be changed when it started printing or loading these settings from settings object
|
#TODO: Might need to add check that extruders can not be changed when it started printing or loading these settings from settings object
|
||||||
def setNumExtuders(self, num):
|
def setNumExtuders(self, num):
|
||||||
self._extruder_count = num
|
self._extruder_count = num
|
||||||
|
@ -116,20 +121,20 @@ class PrinterConnection(SignalEmitter):
|
||||||
if not self._updating_firmware and not self._connect_thread.isAlive():
|
if not self._updating_firmware and not self._connect_thread.isAlive():
|
||||||
self._connect_thread.start()
|
self._connect_thread.start()
|
||||||
|
|
||||||
def updateFirmware(self, file_name):
|
def _updateFirmware(self):
|
||||||
if self._is_connecting or self._is_connected:
|
if self._is_connecting or self._is_connected:
|
||||||
self.close()
|
self.close()
|
||||||
hex_file = intelHex.readHex(file_name)
|
hex_file = intelHex.readHex(self._firmware_file_name)
|
||||||
if len(hex_file) == 0:
|
if len(hex_file) == 0:
|
||||||
Logger.log('e', "Unable to read provided hex file. Could not update firmware")
|
Logger.log('e', "Unable to read provided hex file. Could not update firmware")
|
||||||
return False
|
return
|
||||||
programmer = stk500v2.Stk500v2()
|
programmer = stk500v2.Stk500v2()
|
||||||
programmer.progressCallback = self.setProgress
|
programmer.progressCallback = self.setProgress
|
||||||
programmer.connect(self._serial_port)
|
programmer.connect(self._serial_port)
|
||||||
time.sleep(1) #Give programmer some time to connect
|
time.sleep(1) #Give programmer some time to connect
|
||||||
if not programmer.isConnected():
|
if not programmer.isConnected():
|
||||||
Logger.log('e', "Unable to connect with serial. Could not update firmware")
|
Logger.log('e', "Unable to connect with serial. Could not update firmware")
|
||||||
return False
|
return
|
||||||
self._updating_firmware = True
|
self._updating_firmware = True
|
||||||
try:
|
try:
|
||||||
programmer.programChip(hex_file)
|
programmer.programChip(hex_file)
|
||||||
|
@ -137,9 +142,14 @@ class PrinterConnection(SignalEmitter):
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
Logger.log("e", "Exception while trying to update firmware %s" %e)
|
Logger.log("e", "Exception while trying to update firmware %s" %e)
|
||||||
self._updating_firmware = False
|
self._updating_firmware = False
|
||||||
return False
|
return
|
||||||
programmer.close()
|
programmer.close()
|
||||||
return True
|
return
|
||||||
|
|
||||||
|
def updateFirmware(self, file_name):
|
||||||
|
self._firmware_file_name = file_name
|
||||||
|
self._update_firmware_thread.start()
|
||||||
|
|
||||||
|
|
||||||
## Private connect function run by thread. Can be started by calling connect.
|
## Private connect function run by thread. Can be started by calling connect.
|
||||||
def _connect(self):
|
def _connect(self):
|
||||||
|
|
|
@ -26,6 +26,7 @@ class IspBase():
|
||||||
self.writeFlash(flashData)
|
self.writeFlash(flashData)
|
||||||
print("Verifying %i bytes" % len(flashData))
|
print("Verifying %i bytes" % len(flashData))
|
||||||
self.verifyFlash(flashData)
|
self.verifyFlash(flashData)
|
||||||
|
print("Completed")
|
||||||
|
|
||||||
def getSignature(self):
|
def getSignature(self):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -80,19 +80,19 @@ class Stk500v2(ispBase.IspBase):
|
||||||
#Set load addr to 0, in case we have more then 64k flash we need to enable the address extension
|
#Set load addr to 0, in case we have more then 64k flash we need to enable the address extension
|
||||||
page_size = self.chip['pageSize'] * 2
|
page_size = self.chip['pageSize'] * 2
|
||||||
flashSize = page_size * self.chip['pageCount']
|
flashSize = page_size * self.chip['pageCount']
|
||||||
|
print("Writing flash")
|
||||||
if flashSize > 0xFFFF:
|
if flashSize > 0xFFFF:
|
||||||
self.sendMessage([0x06, 0x80, 0x00, 0x00, 0x00])
|
self.sendMessage([0x06, 0x80, 0x00, 0x00, 0x00])
|
||||||
else:
|
else:
|
||||||
self.sendMessage([0x06, 0x00, 0x00, 0x00, 0x00])
|
self.sendMessage([0x06, 0x00, 0x00, 0x00, 0x00])
|
||||||
|
load_count = (len(flash_data) + page_size - 1) / page_size
|
||||||
loadCount = (len(flash_data) + page_size - 1) / page_size
|
for i in range(0, int(load_count)):
|
||||||
for i in range(0, loadCount):
|
|
||||||
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.progressCallback is not None:
|
if self.progressCallback is not None:
|
||||||
if self._has_checksum:
|
if self._has_checksum:
|
||||||
self.progressCallback(i + 1, loadCount)
|
self.progressCallback(i + 1, load_count)
|
||||||
else:
|
else:
|
||||||
self.progressCallback(i + 1, loadCount*2)
|
self.progressCallback(i + 1, load_count*2)
|
||||||
|
|
||||||
def verifyFlash(self, flashData):
|
def verifyFlash(self, flashData):
|
||||||
if self._has_checksum:
|
if self._has_checksum:
|
||||||
|
@ -114,7 +114,7 @@ class Stk500v2(ispBase.IspBase):
|
||||||
self.sendMessage([0x06, 0x00, 0x00, 0x00, 0x00])
|
self.sendMessage([0x06, 0x00, 0x00, 0x00, 0x00])
|
||||||
|
|
||||||
loadCount = (len(flashData) + 0xFF) / 0x100
|
loadCount = (len(flashData) + 0xFF) / 0x100
|
||||||
for i in range(0, loadCount):
|
for i in range(0, int(loadCount)):
|
||||||
recv = self.sendMessage([0x14, 0x01, 0x00, 0x20])[2:0x102]
|
recv = self.sendMessage([0x14, 0x01, 0x00, 0x20])[2:0x102]
|
||||||
if self.progressCallback is not None:
|
if self.progressCallback is not None:
|
||||||
self.progressCallback(loadCount + i + 1, loadCount*2)
|
self.progressCallback(loadCount + i + 1, loadCount*2)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue