Skip to content

Commit 1efea42

Browse files
yuvadmtravisgoodspeed
authored andcommitted
Catch PipeError and print a friendly debug message
1 parent cb2bbb4 commit 1efea42

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

md380_tool.py

+13-8
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,12 @@ def read_framebuf_line(self, y):
112112
chr(0) + # x1 (x1,y1) = tile's upper left corner
113113
chr(y) + # y1
114114
chr(159) + # x2 (x2,y2) = tile's lower right corner
115-
chr(y) # y2
115+
chr(y) # y2
116116
)
117117
self._device.ctrl_transfer(0x21, Request.DNLOAD, 1, 0, cmdstr)
118118
self.get_status() # this changes state
119119
status = self.get_status() # this gets the status
120-
# read 5-byte header (echo of cmdstr) followed by
120+
# read 5-byte header (echo of cmdstr) followed by
121121
# 160 pixels per line * 3 bytes per pixel (BLUE,GREEN,RED):
122122
rd_result = self.upload(1, 160*3+5, 0);
123123
if rd_result[4] == y: # y2 ok -> got the expected response
@@ -282,8 +282,8 @@ def custom(self, cmd):
282282
status = self.get_status() # this gets the status
283283

284284
def reboot_to_bootloader(self):
285-
"""Reboot into the bootloader with a DFU command.
286-
This will erase (part of) the firmware from flash,
285+
"""Reboot into the bootloader with a DFU command.
286+
This will erase (part of) the firmware from flash,
287287
so you must reprogram the firmware afterwards if you'd like a working radio.
288288
"""
289289
cmd = 0x86 # reboot_to_bootloader
@@ -427,8 +427,8 @@ def screenshot(dfu, filename="screenshot.bmp"):
427427
with open(filename, 'wb') as f:
428428
# Write a simple, hard-coded bitmap file header
429429
# (14 byte "file header" + 40 byte "info block" + 3*160*128 byte "data",
430-
# total size = 0x0000F036 bytes. Here written in little endian format:
431-
f.write( "BM" + chr(0x36)+chr(0xF0)+chr(0x00)+chr(0x00)
430+
# total size = 0x0000F036 bytes. Here written in little endian format:
431+
f.write( "BM" + chr(0x36)+chr(0xF0)+chr(0x00)+chr(0x00)
432432
+ chr(0x00)+chr(0x00)+chr(0x00)+chr(0x00)
433433
+ chr( 54 )+chr(0x00)+chr(0x00)+chr(0x00) )
434434
# Next: Write the "bitmap info header". Keep it simple, use 40 bytes.
@@ -446,7 +446,7 @@ def screenshot(dfu, filename="screenshot.bmp"):
446446
# Write image data with 160 pixels per line, 3 bytes per pixel.
447447
# For a start, just dump the pixels to the file unmodified.
448448
y = 127; # bmp files begin with the 'bottom line' (y=127)
449-
while y>=0:
449+
while y>=0:
450450
buf = dfu.read_framebuf_line(y)
451451
f.write(buf)
452452
y = y-1;
@@ -751,7 +751,7 @@ def usage():
751751
md380-tool readword <0xcafebabe>
752752
Dump 1kB from arbitrary address
753753
md380-tool dump <filename.bin> <address>
754-
Dump calibration data
754+
Dump calibration data
755755
md380-tool calibration
756756
Reboot into the bootloader (erases application, you _must_ reflash firmware afterwards):
757757
md380-tool reboot_to_bootloader
@@ -884,6 +884,11 @@ def main():
884884
except RuntimeError as e:
885885
print(e.args[0])
886886
exit(1)
887+
except usb.core.USBError as ue:
888+
print(ue)
889+
if ue[0] == 32:
890+
print('Make sure the device is already flashed with custom firmware and NOT in DFU mode')
891+
exit(1)
887892
except Exception as e:
888893
print(e)
889894
# print(dfu.get_status())

0 commit comments

Comments
 (0)