mirror of
https://github.com/bkerler/mtkclient.git
synced 2024-11-14 19:25:05 -05:00
Compare commits
4 commits
2669bb91ba
...
d5481d0370
Author | SHA1 | Date | |
---|---|---|---|
|
d5481d0370 | ||
|
e3cd58a837 | ||
|
35c5803ae0 | ||
|
2e65679cc8 |
3 changed files with 34 additions and 49 deletions
|
@ -309,7 +309,7 @@ class UsbClass(DeviceClass):
|
||||||
break
|
break
|
||||||
|
|
||||||
if self.device is None:
|
if self.device is None:
|
||||||
self.debug("Couldn't detect the device. Is it connected ?")
|
# self.debug("Couldn't detect the device. Is it connected ?")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -125,7 +125,19 @@ class Port(metaclass=LogBase):
|
||||||
pass
|
pass
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def run_handshake(self):
|
# def run_handshake(self):
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def handshake(self, maxtries=None, loop=0):
|
||||||
|
counter = 0
|
||||||
|
while not self.cdc.connected:
|
||||||
|
try:
|
||||||
|
if maxtries is not None and counter == maxtries:
|
||||||
|
break
|
||||||
|
counter += 1
|
||||||
|
self.cdc.connect()
|
||||||
ep_out = self.cdc.EP_OUT.write
|
ep_out = self.cdc.EP_OUT.write
|
||||||
ep_in = self.cdc.EP_IN.read
|
ep_in = self.cdc.EP_IN.read
|
||||||
maxinsize = self.cdc.EP_IN.wMaxPacketSize
|
maxinsize = self.cdc.EP_IN.wMaxPacketSize
|
||||||
|
@ -143,45 +155,21 @@ class Port(metaclass=LogBase):
|
||||||
i += 1
|
i += 1
|
||||||
else:
|
else:
|
||||||
i = 0
|
i = 0
|
||||||
|
|
||||||
|
|
||||||
self.info("Device detected :)")
|
self.info("Device detected :)")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
except Exception as serr:
|
except Exception as serr:
|
||||||
self.debug(str(serr))
|
self.debug(str(serr))
|
||||||
time.sleep(0.005)
|
time.sleep(0.005)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def handshake(self, maxtries=None, loop=0):
|
|
||||||
counter = 0
|
|
||||||
|
|
||||||
while not self.cdc.connected:
|
|
||||||
try:
|
|
||||||
if maxtries is not None and counter == maxtries:
|
|
||||||
break
|
|
||||||
counter += 1
|
|
||||||
if self.cdc.connect() and self.run_handshake():
|
|
||||||
return True
|
|
||||||
else:
|
|
||||||
if loop == 5:
|
|
||||||
sys.stdout.write('\n')
|
|
||||||
self.info("Hint:\n\nPower off the phone before connecting.\n" +
|
|
||||||
"For brom mode, press and hold vol up, vol dwn, or all hw buttons and " +
|
|
||||||
"connect usb.\n" +
|
|
||||||
"For preloader mode, don't press any hw button and connect usb.\n"
|
|
||||||
"If it is already connected and on, hold power for 10 seconds to reset.\n")
|
|
||||||
sys.stdout.write('\n')
|
|
||||||
if loop >= 10:
|
|
||||||
sys.stdout.write('.')
|
|
||||||
if loop >= 20:
|
|
||||||
sys.stdout.write('\n')
|
|
||||||
loop = 0
|
|
||||||
loop += 1
|
|
||||||
time.sleep(0.3)
|
|
||||||
sys.stdout.flush()
|
|
||||||
|
|
||||||
except Exception as serr:
|
except Exception as serr:
|
||||||
if "access denied" in str(serr):
|
if "access denied" in str(serr):
|
||||||
self.warning(str(serr))
|
self.warning(str(serr))
|
||||||
self.debug(str(serr))
|
# self.debug(str(serr))
|
||||||
pass
|
pass
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
|
@ -160,9 +160,6 @@ class Preloader(metaclass=LogBase):
|
||||||
else:
|
else:
|
||||||
res = self.mtk.port.handshake(maxtries=maxtries)
|
res = self.mtk.port.handshake(maxtries=maxtries)
|
||||||
if not res:
|
if not res:
|
||||||
if display:
|
|
||||||
self.error("Status: Handshake failed, retrying...")
|
|
||||||
self.config.set_gui_status(self.config.tr("Status: Handshake failed, retrying..."))
|
|
||||||
self.mtk.port.close()
|
self.mtk.port.close()
|
||||||
tries += 1
|
tries += 1
|
||||||
if tries == 1000:
|
if tries == 1000:
|
||||||
|
|
Loading…
Reference in a new issue