|
@@ -7,7 +7,7 @@
|
|
# This is free and unencumbered software released into the public domain.
|
|
# This is free and unencumbered software released into the public domain.
|
|
# See the file COPYING for more details, or visit <http://unlicense.org>.
|
|
# See the file COPYING for more details, or visit <http://unlicense.org>.
|
|
|
|
|
|
-import os, sys, serial
|
|
|
|
|
|
+import os, sys, serial, struct, time
|
|
|
|
|
|
from greaseweazle import version
|
|
from greaseweazle import version
|
|
from greaseweazle import usb as USB
|
|
from greaseweazle import usb as USB
|
|
@@ -39,16 +39,39 @@ def with_drive_selected(fn, usb, args):
|
|
usb.drive_select(False)
|
|
usb.drive_select(False)
|
|
|
|
|
|
|
|
|
|
|
|
+def usb_reopen(usb, is_update):
|
|
|
|
+ mode = { False: 1, True: 0 }
|
|
|
|
+ try:
|
|
|
|
+ usb.switch_fw_mode(mode[is_update])
|
|
|
|
+ except (serial.SerialException, struct.error):
|
|
|
|
+ # Mac and Linux raise SerialException ("... returned no data")
|
|
|
|
+ # Win10 pyserial returns a short read which fails struct.unpack
|
|
|
|
+ pass
|
|
|
|
+ usb.ser.close()
|
|
|
|
+ for i in range(10):
|
|
|
|
+ time.sleep(0.5)
|
|
|
|
+ try:
|
|
|
|
+ usb.ser.open()
|
|
|
|
+ except serial.SerialException:
|
|
|
|
+ # Device not found
|
|
|
|
+ pass
|
|
|
|
+ else:
|
|
|
|
+ return USB.Unit(usb.ser)
|
|
|
|
+ return None
|
|
|
|
+
|
|
|
|
+
|
|
def usb_open(devicename, is_update=False):
|
|
def usb_open(devicename, is_update=False):
|
|
|
|
|
|
usb = USB.Unit(serial.Serial(devicename))
|
|
usb = USB.Unit(serial.Serial(devicename))
|
|
|
|
|
|
- print("** %s v%u.%u, Host Tools v%u.%u"
|
|
|
|
|
|
+ print("** %s v%u.%u [F%u], Host Tools v%u.%u"
|
|
% (("Greaseweazle", "Bootloader")[usb.update_mode],
|
|
% (("Greaseweazle", "Bootloader")[usb.update_mode],
|
|
- usb.major, usb.minor,
|
|
|
|
|
|
+ usb.major, usb.minor, usb.hw_type,
|
|
version.major, version.minor))
|
|
version.major, version.minor))
|
|
|
|
|
|
if usb.update_mode and not is_update:
|
|
if usb.update_mode and not is_update:
|
|
|
|
+ if usb.hw_type == 7:
|
|
|
|
+ return usb_reopen(usb, is_update)
|
|
print("Greaseweazle is in Firmware Update Mode:")
|
|
print("Greaseweazle is in Firmware Update Mode:")
|
|
print(" The only available action is \"update <update_file>\"")
|
|
print(" The only available action is \"update <update_file>\"")
|
|
if usb.update_jumpered:
|
|
if usb.update_jumpered:
|
|
@@ -58,6 +81,8 @@ def usb_open(devicename, is_update=False):
|
|
sys.exit(1)
|
|
sys.exit(1)
|
|
|
|
|
|
if is_update and not usb.update_mode:
|
|
if is_update and not usb.update_mode:
|
|
|
|
+ if usb.hw_type == 7:
|
|
|
|
+ return usb_reopen(usb, is_update)
|
|
print("Greaseweazle is in Normal Mode:")
|
|
print("Greaseweazle is in Normal Mode:")
|
|
print(" To \"update\" you must install the Update Jumper")
|
|
print(" To \"update\" you must install the Update Jumper")
|
|
sys.exit(1)
|
|
sys.exit(1)
|
|
@@ -65,7 +90,10 @@ def usb_open(devicename, is_update=False):
|
|
if not usb.update_mode and usb.update_needed:
|
|
if not usb.update_mode and usb.update_needed:
|
|
print("Firmware is out of date: Require v%u.%u"
|
|
print("Firmware is out of date: Require v%u.%u"
|
|
% (version.major, version.minor))
|
|
% (version.major, version.minor))
|
|
- print("Install the Update Jumper and \"update <update_file>\"")
|
|
|
|
|
|
+ if usb.hw_type == 7:
|
|
|
|
+ print("Run \"update <update_file>\"")
|
|
|
|
+ else:
|
|
|
|
+ print("Install the Update Jumper and \"update <update_file>\"")
|
|
sys.exit(1)
|
|
sys.exit(1)
|
|
|
|
|
|
return usb
|
|
return usb
|