Skip to content

Commit

Permalink
Clean up for Python 3
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesbowman committed Aug 26, 2018
1 parent ad8894b commit dc9d7b3
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions python/samples/flash.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@

def hexdump(s):
def toprint(c):
if 32 <= ord(c) < 127:
return c
if 32 <= c < 127:
return chr(c)
else:
return "."
def hexline(s):
return (" ".join(["%02x" % ord(c) for c in s]).ljust(49) +
bb = struct.unpack("16B", s)
return (" ".join(["%02x" % c for c in bb]).ljust(49) +
"|" +
"".join([toprint(c) for c in s]).ljust(16) +
"".join([toprint(c) for c in bb]).ljust(16) +
"|")
return "\n".join([hexline(s[i:i+16]) for i in range(0, len(s), 16)])

Expand All @@ -38,6 +39,7 @@ def pattern(n):
optdict = dict(optlist)

s = SPIDriver(optdict.get('-h', "/dev/ttyUSB0"))
s.unsel()

while True:
s.sel() # start command
Expand Down

0 comments on commit dc9d7b3

Please sign in to comment.