mk3 cleanups

This commit is contained in:
Peter D. Gray 2024-02-08 10:29:39 -05:00
parent 6715c73834
commit ae87b63524
No known key found for this signature in database
GPG Key ID: A2DCD558C2BE5D7C
2 changed files with 17 additions and 23 deletions

View File

@ -283,14 +283,18 @@ class PinAttempt:
assert 1 <= len(pin_prefix) <= MAX_PIN_LEN, len(pin_prefix)
global _word_cache
if version.has_608:
for k,v in _word_cache:
if pin_prefix == k:
return v
for k,v in _word_cache:
if pin_prefix == k:
return v
buf = bytearray(pin_prefix + b'\0'*MAX_PIN_LEN)
err = ckcc.gate(16, buf, len(pin_prefix))
if err:
for retry in range(3):
buf = bytearray(pin_prefix + b'\0'*MAX_PIN_LEN)
err = ckcc.gate(16, buf, len(pin_prefix))
if not err:
break
if err == 5: # EIO
# serial comm error; can be noise.
continue
raise RuntimeError(err)
# use just 22 bits of that
@ -300,20 +304,13 @@ class PinAttempt:
rv = wordlist_en[w1], wordlist_en[w2]
if version.has_608:
# MRU: keep only a few
if len(_word_cache) > 4:
_word_cache.pop()
_word_cache.insert(0, (pin_prefix, rv))
# MRU: keep only a few
if len(_word_cache) > 4:
_word_cache.pop()
_word_cache.insert(0, (pin_prefix, rv))
return rv
def is_delay_needed(self):
# obsolete starting w/ mk3 and values re-used for other stuff
if version.has_608:
return False
return self.delay_achieved < self.delay_required
def is_blank(self):
# device has no PIN at this point
return bool(self.state_flags & PA_IS_BLANK)

View File

@ -124,13 +124,13 @@ async def test_battery():
dis.text(None, -1, "Remove USB plug.", dark=True)
dis.show()
await sleep_ms(100)
if settings.get('tested', False):
# auto-pass this test if we've been thru here before; customer may
# not have magic batteries and so on.
break
await sleep_ms(100)
if ux_poll_key():
raise RuntimeError("Battery test aborted")
@ -145,7 +145,6 @@ def set_genuine():
if not pa.is_successful():
# assume blank pin during factory selftest
pa.setup(b'')
assert not pa.is_delay_needed() # "PIN failures?"
if not pa.is_successful():
pa.login()
@ -366,8 +365,6 @@ async def test_microsd():
async def start_selftest():
try:
# last, because requires a special power supply
if version.has_battery:
await test_battery()