Firmware flasher now uses logger instead of print

CURA-1809
This commit is contained in:
Jaime van Kessel 2016-11-03 14:26:41 +01:00
parent 450eb5443f
commit 7eec074b0f
3 changed files with 10 additions and 7 deletions

View file

@ -5,6 +5,8 @@ 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. This is a python 3 conversion of the code created by David Braam for the Cura project.
""" """
import io import io
from UM.Logger import Logger
def readHex(filename): def readHex(filename):
""" """
@ -41,6 +43,6 @@ def readHex(filename):
elif rec_type == 2: #Extended Segment Address Record elif rec_type == 2: #Extended Segment Address Record
extra_addr = int(line[9:13], 16) * 16 extra_addr = int(line[9:13], 16) * 16
else: else:
print(rec_type, rec_len, addr, check_sum, line) Logger.log("d", "%s, %s, %s, %s, %s", rec_type, rec_len, addr, check_sum, line)
f.close() f.close()
return data return data

View file

@ -8,6 +8,7 @@ The ISP AVR programmer can load firmware into AVR chips. Which are commonly used
""" """
from . import chipDB from . import chipDB
from UM.Logger import Logger
class IspBase(): class IspBase():
""" """
@ -22,11 +23,11 @@ class IspBase():
raise IspError("Chip with signature: " + str(self.getSignature()) + "not found") raise IspError("Chip with signature: " + str(self.getSignature()) + "not found")
self.chipErase() self.chipErase()
print("Flashing %i bytes" % len(flash_data)) Logger.log("d", "Flashing %i bytes", len(flash_data))
self.writeFlash(flash_data) self.writeFlash(flash_data)
print("Verifying %i bytes" % len(flash_data)) Logger.log("d", "Verifying %i bytes", len(flash_data))
self.verifyFlash(flash_data) self.verifyFlash(flash_data)
print("Completed") Logger.log("d", "Completed")
def getSignature(self): def getSignature(self):
""" """

View file

@ -11,6 +11,7 @@ import time
from serial import Serial from serial import Serial
from serial import SerialException from serial import SerialException
from serial import SerialTimeoutException from serial import SerialTimeoutException
from UM.Logger import Logger
from . import ispBase, intelHex from . import ispBase, intelHex
@ -84,7 +85,7 @@ 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
flash_size = page_size * self.chip["pageCount"] flash_size = page_size * self.chip["pageCount"]
print("Writing flash") Logger.log("d", "Writing flash")
if flash_size > 0xFFFF: if flash_size > 0xFFFF:
self.sendMessage([0x06, 0x80, 0x00, 0x00, 0x00]) self.sendMessage([0x06, 0x80, 0x00, 0x00, 0x00])
else: else:
@ -151,7 +152,6 @@ class Stk500v2(ispBase.IspBase):
raise ispBase.IspError("Timeout") raise ispBase.IspError("Timeout")
b = struct.unpack(">B", s)[0] b = struct.unpack(">B", s)[0]
checksum ^= b checksum ^= b
#print(hex(b))
if state == "Start": if state == "Start":
if b == 0x1B: if b == 0x1B:
state = "GetSeq" state = "GetSeq"
@ -206,7 +206,7 @@ def main():
""" Entry point to call the stk500v2 programmer from the commandline. """ """ Entry point to call the stk500v2 programmer from the commandline. """
import threading import threading
if sys.argv[1] == "AUTO": if sys.argv[1] == "AUTO":
print(portList()) Logger.log("d", portList())
for port in portList(): for port in portList():
threading.Thread(target=runProgrammer, args=(port,sys.argv[2])).start() threading.Thread(target=runProgrammer, args=(port,sys.argv[2])).start()
time.sleep(5) time.sleep(5)