From 5ed3ca15e125a05980ab0bb1ac3b4377424115c4 Mon Sep 17 00:00:00 2001 From: Ken Carpenter Date: Thu, 20 May 2021 10:49:46 -0700 Subject: [PATCH] Add microSD test to "self-test" flow --- .../stm32/boards/Passport/modules/actions.py | 6 +- .../boards/Passport/modules/self_test_ux.py | 62 +++++++++++++++++-- ports/stm32/boards/Passport/modules/utils.py | 5 ++ 3 files changed, 62 insertions(+), 11 deletions(-) diff --git a/ports/stm32/boards/Passport/modules/actions.py b/ports/stm32/boards/Passport/modules/actions.py index f6a43de..22a1636 100644 --- a/ports/stm32/boards/Passport/modules/actions.py +++ b/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 diff --git a/ports/stm32/boards/Passport/modules/self_test_ux.py b/ports/stm32/boards/Passport/modules/self_test_ux.py index 50fa7fb..93009f7 100644 --- a/ports/stm32/boards/Passport/modules/self_test_ux.py +++ b/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 diff --git a/ports/stm32/boards/Passport/modules/utils.py b/ports/stm32/boards/Passport/modules/utils.py index 0126737..add205e 100644 --- a/ports/stm32/boards/Passport/modules/utils.py +++ b/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