selftest improvements

This commit is contained in:
Peter D. Gray 2024-01-09 10:15:08 -05:00
parent dd0ce1a2ba
commit a36506d7a0
No known key found for this signature in database
GPG Key ID: A2DCD558C2BE5D7C
2 changed files with 40 additions and 27 deletions

View File

@ -252,26 +252,26 @@ class NFCHandler:
return await self.share_start(n)
async def share_deposit_address(self, addr):
async def share_deposit_address(self, addr, **kws):
n = ndef.ndefMaker()
n.add_text('Deposit Address')
n.add_custom('bitcoin.org:addr', addr.encode())
return await self.share_start(n)
return await self.share_start(n, **kws)
async def share_json(self, json_data):
async def share_json(self, json_data, **kws):
# a text file of JSON for programs to read
n = ndef.ndefMaker()
n.add_mime_data('application/json', json_data)
return await self.share_start(n)
return await self.share_start(n, **kws)
async def share_text(self, data):
async def share_text(self, data, **kws):
# share text from a list of values
# - just a text file, no multiple records; max usability!
n = ndef.ndefMaker()
n.add_text(data)
return await self.share_start(n)
return await self.share_start(n, **kws)
async def wait_ready(self):
# block until chip ready to continue (ACK happens)
@ -297,7 +297,7 @@ class NFCHandler:
self.write_dyn(GPO_CTRL_Dyn, 0x01) # GPO_EN
self.read_dyn(IT_STS_Dyn) # clear interrupt
async def ux_animation(self, write_mode):
async def ux_animation(self, write_mode, allow_enter=True):
# Run the pretty animation, and detect both when we are written, and/or key to exit/abort.
# - similar when "read" and then removed from field
# - return T if aborted by user
@ -336,10 +336,11 @@ class NFCHandler:
# wait for key or 250ms animation delay
try:
ch = await asyncio.wait_for_ms(ux_wait_keyup(flush=first), 250)
first = False
except asyncio.TimeoutError:
ch = None
first = False
if self.last_edge:
self.last_edge = 0
@ -355,10 +356,14 @@ class NFCHandler:
# 0x2 = RF activity
last_activity = utime.ticks_ms()
# X or OK to quit, with slightly different meanings
if ch and ch in 'xy'+KEY_ENTER+KEY_CANCEL:
aborted = (ch in 'x'+KEY_CANCEL)
break
# X or OK to quit, but with slightly different meanings
if ch:
if ch in 'y'+KEY_CANCEL:
aborted = True
break
elif allow_enter and ch in 'y'+KEY_ENTER:
aborted = False
break
if last_activity:
dt = utime.ticks_diff(utime.ticks_ms(), last_activity)
@ -374,21 +379,21 @@ class NFCHandler:
return aborted
async def share_start(self, ndef_obj):
async def share_start(self, ndef_obj, **kws):
# do the UX while we are sharing a value over NFC
# - assumpting is people know what they are scanning
# - x key to abort early, but also self-clears
await self.big_write(ndef_obj.bytes())
return await self.ux_animation(False)
return await self.ux_animation(False, **kws)
async def start_nfc_rx(self):
async def start_nfc_rx(self, **kws):
# Pretend to be a big warm empty tag ready to be stuffed with data
await self.big_write(ndef.CC_WR_FILE)
# wait until something is written
aborted = await self.ux_animation(True)
aborted = await self.ux_animation(True, **kws)
if aborted: return
# read CCFILE area (header)
@ -504,12 +509,13 @@ class NFCHandler:
@classmethod
async def selftest(cls):
# check for chip present, field present .. and that it works
# Check for chip present, field present .. and that it works
# - important: do not allow user (tester) to quit without sending anything over link
n = cls()
n.setup()
assert n.uid
aborted = await n.share_text("NFC is working: %s" % n.get_uid())
aborted = await n.share_text("NFC is working: %s" % n.get_uid(), allow_enter=False)
assert not aborted, "Aborted"

View File

@ -91,6 +91,10 @@ async def test_qr_scanner():
async def test_battery():
from battery import get_batt_level
dis.clear()
dis.text(None, 1, "Battery Test")
dis.text(None, 3, "Connect 3.3v reference cells.")
while 1:
lvl = get_batt_level()
@ -98,14 +102,16 @@ async def test_battery():
# pass
return
dis.clear()
dis.text(None, 2, "Remove USB cable &")
dis.text(None, 3, "connect 3.3v reference.")
dis.text(None, 4, "Then press ENTER.")
if lvl:
dis.text(None, -1, "VIN Sense reads: %.1f volts" % lvl, dark=True)
else:
dis.text(None, -1, "Remove USB plug.", dark=True)
dis.show()
await wait_ok()
await sleep_ms(100)
if ux_poll_key():
raise RuntimeError("Battery test aborted")
def set_genuine():
# PIN must be blank for this to work
@ -339,6 +345,11 @@ async def test_microsd():
async def start_selftest():
try:
# last, because requires a special power supply
if version.has_battery:
await test_battery()
if version.has_qr:
await test_qr_scanner()
@ -364,10 +375,6 @@ async def start_selftest():
# add more tests here
# last, because required a DC power supply
if version.has_battery:
await test_battery()
settings.set('tested', True)
await ux_show_story("Selftest complete", 'PASS')