def recover(self): # done using the microSD -- unpower it from main import numpad self.active = False try: os.umount('/sd') except: pass # important: turn off power so touch can work again sd = pyb.SDCard() sd.power(0) numpad.start()
async def do_delay(self, pa): # show # of failures and implement the delay, which could be # very long. from main import numpad dis.clear() dis.text(None, 0, "Checking...", FontLarge) dis.text(None, 24, 'Wait '+pretty_delay(pa.delay_required * pa.seconds_per_tick)) dis.text(None, 40, "(%d failures)" % pa.num_fails) # save a little bit of interrupt load/overhead numpad.stop() while pa.is_delay_needed(): dis.progress_bar(pa.delay_achieved / pa.delay_required) dis.show() pa.delay() numpad.start()
async def usb_keypad_emu(): # Take keypresses on USB virtual serial port (when not in REPL mode) # and converts them into keypad events. Super handy for UX testing/dev. # # IMPORTANT: # - code is **not** used in real product, but left here for devs to use # - this code isn't even called; unless you add code to do so, see ../stm32/my_lib_boot2.py # u = pyb.USB_VCP() while 1: await sleep_ms(100) while u.isconnected() and u.any(): from main import numpad k = u.read(3).decode() remap = { '\r': 'y', '\x1b': 'x', 'q': 'x', '\x1b[A': '5', '\x1b[B': '8', '\x1b[C': '9', '\x1b[D': '7' } if k in remap: k = remap[k] if k in '\x04': # ^D # warm reset from machine import soft_reset soft_reset() if k == 'd': numpad.debug = (numpad.debug + 1) % 3 continue if k == 'n': if numpad.disabled: numpad.start() else: numpad.stop() print("npdis = %d" % numpad.disabled) continue if k == 'r': numpad.trigger_baseline = True continue if k == 's': numpad.sensitivity = (numpad.sensitivity + 1) % 5 print("sensi = %d" % numpad.sensitivity) continue if k == 'U': # enter DFU import callgate callgate.enter_dfu() # not reached if k == 't': ckcc.vcp_enabled(True) print("Repl enabled") continue if k == 'm': import gc print("Memory: %d" % gc.mem_free()) continue if k in '0123456789xy': numpad.inject(k) else: print('? %r' % k)
async def test_microsd(): if ckcc.is_simulator(): return from main import numpad numpad.stop() async def wait_til_state(want): dis.clear() dis.text(None, 10, 'MicroSD Card:') dis.text(None, 34, 'Remove' if sd.present() else 'Insert', font=FontLarge) dis.show() while 1: if want == sd.present(): return await sleep_ms(100) if ux_poll_once(): raise RuntimeError("MicroSD test aborted") try: import pyb sd = pyb.SDCard() sd.power(0) # test presence switch for ph in range(7): await wait_til_state(not sd.present()) if ph >= 2 and sd.present(): # debounce await sleep_ms(100) if sd.present(): break if ux_poll_once(): raise RuntimeError("MicroSD test aborted") dis.clear() dis.text(None, 10, 'MicroSD Card:') dis.text(None, 34, 'Testing', font=FontLarge) dis.show() # card inserted assert sd.present(), "SD not present?" # power up? sd.power(1) await sleep_ms(100) try: blks, bsize, ctype = sd.info() assert bsize == 512, "wrong block size" except: assert 0, "unable to get card info" # just read it a bit, writing would prove little buf = bytearray(512) msize = 256 * 1024 for addr in range(0, msize, 1024): sd.readblocks(addr, buf) dis.progress_bar_show(addr / msize) if addr == 0: assert buf[-2:] == b'\x55\xaa', "Bad read" # force removal, so cards don't get stuck in finished units await wait_til_state(False) finally: # CRTICAL: power it back down sd.power(0) numpad.start()
async def usb_keypad_emu(): # Take keypresses on USB virtual serial port (when not in REPL mode) # and converts them into keypad events. Super handy for UX testing/dev. # # IMPORTANT: # - code is **not** used in real product, but left here for devs to use # - this code isn't even called; unless you add code to do so, see ../stm32/my_lib_boot2.py # from ux import the_ux from menu import MenuSystem from seed import WordNestMenu u = pyb.USB_VCP() remap = { '\r': 'y', '\x1b': 'x', '\x1b[A': '5', '\x1b[B': '8', '\x1b[C': '9', '\x1b[D': '7' } while 1: await sleep_ms(100) while u.isconnected() and u.any(): from main import numpad k = u.read(3).decode() if k in '\x04': # ^D # warm reset from machine import soft_reset soft_reset() if 0: if k == 'd': numpad.debug = (numpad.debug + 1) % 3 continue if k == 'n': if numpad.disabled: numpad.start() else: numpad.stop() print("npdis = %d" % numpad.disabled) continue if k == 'U': # enter DFU import callgate callgate.enter_dfu() # not reached if k == 'T': ckcc.vcp_enabled(True) print("Repl enabled") continue if k == 'M': import gc print("Memory: %d" % gc.mem_free()) continue # word menus: shortcut for first letter top = the_ux.top_of_stack() if top and isinstance(top, WordNestMenu) and len(top.items) > 6: pos = min(len(i.label) for i in top.items) if pos >= 2: for n, it in enumerate(top.items): if it.label[pos-2] == k: top.goto_idx(n) top.show() k = None break if k is None: continue if k in remap: k = remap[k] if k in '0123456789xy': numpad.inject(k) continue print('? %r' % k)