Browse Source

Add microSD test to "self-test" flow

v1.0.2-dev
Ken Carpenter 4 years ago
parent
commit
5ed3ca15e1
  1. 6
      ports/stm32/boards/Passport/modules/actions.py
  2. 62
      ports/stm32/boards/Passport/modules/self_test_ux.py
  3. 5
      ports/stm32/boards/Passport/modules/utils.py

6
ports/stm32/boards/Passport/modules/actions.py

@ -21,7 +21,7 @@ import common
from common import settings, system, noise, dis
from utils import (UXStateMachine, imported, pretty_short_delay, xfp2str, to_str,
truncate_string_to_width, set_next_addr, scan_for_address, get_accounts, run_chooser,
make_account_name_num, is_valid_address, save_next_addr)
make_account_name_num, is_valid_address, save_next_addr, needs_microsd)
from wallets.utils import get_export_mode, get_addr_type_from_address, get_deriv_path_from_addr_type_and_acct
from ux import (the_ux, ux_confirm, ux_enter_pin,
ux_enter_text, ux_scan_qr_code, ux_shutdown,
@ -31,10 +31,6 @@ from data_codecs.qr_type import QRType
import trezorcrypto
from seed_check_ux import SeedCheckUX
async def needs_microsd():
# Standard msg shown if no SD card detected when we need one.
return await ux_show_story("Please insert a microSD card.", title='MicroSD', center=True, center_vertically=True)
async def about_info(*a):
from common import system
from display import FontTiny

62
ports/stm32/boards/Passport/modules/self_test_ux.py

@ -5,10 +5,50 @@
#
from common import system
from utils import UXStateMachine
from utils import UXStateMachine, needs_microsd
from ux import ux_show_text_as_ur, ux_keypad_test, ux_scan_qr_code, ux_show_story, ux_draw_alignment_grid
from data_codecs.qr_type import QRType
async def microsd_test():
import uos
import os
from files import CardSlot, CardMissingError
from utils import file_exists
msg = 'The Times 03/Jan/2009 Chancellor on brink of second bailout for banks'
while True:
try:
with CardSlot() as card:
filename = '{}/microsd-test.txt'.format(card.get_sd_root())
if file_exists(filename):
os.remove(filename)
with open(filename, 'wt') as fd:
fd.write(msg)
with open(filename, 'rt') as fd:
read_msg = fd.read()
if read_msg != msg:
await ux_show_story('The text read back from the microSD card did not match that written. Read:\n\n {}'.format(read_msg), title='Error')
return False
os.remove(filename)
await ux_show_story('microSD card is working properly!', title='microSD Test', center=True, center_vertically=True)
return True
except CardMissingError:
result = await needs_microsd()
if result == 'x':
return False
except Exception as e:
await ux_show_story('{}'.format(e), title='Exception')
return False
class SelfTestUX(UXStateMachine):
def __init__(self):
@ -18,6 +58,7 @@ class SelfTestUX(UXStateMachine):
self.CAMERA_TEST = 3
self.CAMERA_TEST_RESULT = 4
self.SCREEN_ALIGNMENT = 5
self.MICROSD_TEST = 6
self.qr_data = None
# print('SelfTestUX init')
@ -39,14 +80,14 @@ class SelfTestUX(UXStateMachine):
# print('Keypad Test!')
result = await ux_keypad_test()
if result == 'x':
self.goto(self.SHOW_SERIAL_NUMBER)
self.goto_prev()
else:
self.goto(self.SCREEN_ALIGNMENT)
elif self.state == self.SCREEN_ALIGNMENT:
result = await ux_draw_alignment_grid(title='Align Screen')
if result == 'x':
self.goto(self.KEYPAD_TEST)
self.goto_prev()
else:
self.goto(self.CAMERA_TEST)
@ -56,19 +97,28 @@ class SelfTestUX(UXStateMachine):
self.qr_data = await ux_scan_qr_code('Camera Test')
# print('qr_data=|{}|'.format(self.qr_data))
system.turbo(False)
self.goto(self.CAMERA_TEST_RESULT)
self.goto(self.CAMERA_TEST_RESULT, save_curr=False)
elif self.state == self.CAMERA_TEST_RESULT:
if self.qr_data == None:
result = await ux_show_story('No QR code scanned.', right_btn='RETRY')
if result == 'x':
self.goto(self.SCREEN_ALIGNMENT)
self.goto_prev()
else:
self.goto(self.CAMERA_TEST)
else:
# Show the data - The QR code used in the factory starts with "Camera Test Passed!"
result = await ux_show_story(self.qr_data, right_btn='DONE')
if result == 'x':
self.goto(self.SCREEN_ALIGNMENT)
self.goto_prev()
else:
self.goto(self.MICROSD_TEST)
elif self.state == self.MICROSD_TEST:
# Describe the microSD test
result = await ux_show_story('This test will exercise the read/write features of the microSD card.', title='microSD Test', right_btn='START', center=True, center_vertically=True)
if result == 'x':
self.goto_prev()
else:
await microsd_test()
return

5
ports/stm32/boards/Passport/modules/utils.py

@ -758,4 +758,9 @@ def is_alphanumeric_qr(buf):
return True
async def needs_microsd():
from ux import ux_show_story
# Standard msg shown if no SD card detected when we need one.
return await ux_show_story("Please insert a microSD card.", title='MicroSD', center=True, center_vertically=True)
# EOF

Loading…
Cancel
Save