|
30 | 30 | # of lcd.clear() or lcd.fill().)
|
31 | 31 | loc=(lcd.width,lcd.height-4)
|
32 | 32 |
|
| 33 | +screenawake=1 |
| 34 | + |
33 | 35 | while True:
|
34 | 36 | # Is a button pressed
|
35 | 37 | if lcd.is_pressed(lcd.KEY0):
|
36 | 38 | selected_idx = (selected_idx + 1) % len(codes)
|
37 | 39 |
|
38 |
| - # Did the selection change from last time |
39 |
| - if code != codes[selected_idx]: |
40 |
| - code = codes[selected_idx] |
41 |
| - (passwd, expiry) = totp(synchronised_time(), |
42 |
| - code['key'], |
43 |
| - step_secs=code['step'], |
44 |
| - digits=code['digits']) |
45 |
| - |
46 |
| - # is it time to recalculate things yet? |
47 |
| - s=time()%30 |
48 |
| - if s == 0: |
49 |
| - (passwd, expiry) = totp(synchronised_time(), |
50 |
| - code['key'], |
51 |
| - step_secs=code['step'], |
52 |
| - digits=code['digits']) |
53 |
| - |
54 |
| - # Wipe previous text (first run wipes full screen except timer bar) |
55 |
| - lcd.fill_rect(0,0,128,loc[1],0x0000) |
56 |
| - loc=lcd.text(code['name'],0,0,0xffff) |
57 |
| - loc=lcd.text(passwd,0,loc[1],0xffff) |
58 |
| - |
59 |
| - # Time left bar |
60 |
| - if s == 0: |
61 |
| - lcd.fill_rect(4,60,120,4,0x0000) |
62 |
| - lcd.fill_rect(4,60,(s+1)<<2,4,0xffff) |
63 |
| - lcd.show() |
64 |
| - sleep_ms(500) |
| 40 | + if lcd.is_pressed(lcd.KEY1): |
| 41 | + if screenawake: |
| 42 | + screenawake=0 |
| 43 | + else: |
| 44 | + # Empty the timer bar in the framebuffer |
| 45 | + lcd.fill_rect(4,60,120,4,0x0000) |
| 46 | + screenawake=1 |
| 47 | + |
| 48 | + if screenawake: |
| 49 | + # Did the selection change from last time |
| 50 | + if code != codes[selected_idx]: |
| 51 | + code = codes[selected_idx] |
| 52 | + (passwd, expiry) = totp(synchronised_time(), |
| 53 | + code['key'], |
| 54 | + step_secs=code['step'], |
| 55 | + digits=code['digits']) |
| 56 | + |
| 57 | + # is it time to recalculate things yet? |
| 58 | + s=time()%30 |
| 59 | + if s == 0: |
| 60 | + (passwd, expiry) = totp(synchronised_time(), |
| 61 | + code['key'], |
| 62 | + step_secs=code['step'], |
| 63 | + digits=code['digits']) |
| 64 | + |
| 65 | + # Wipe previous text (first run wipes full screen except timer bar) |
| 66 | + lcd.fill_rect(0,0,128,loc[1],0x0000) |
| 67 | + loc=lcd.text(code['name'],0,0,0xffff) |
| 68 | + loc=lcd.text(passwd,0,loc[1],0xffff) |
| 69 | + |
| 70 | + # Time left bar |
| 71 | + if s == 0: |
| 72 | + lcd.fill_rect(4,60,120,4,0x0000) |
| 73 | + lcd.fill_rect(4,60,(s+1)<<2,4,0xffff) |
| 74 | + lcd.on() |
| 75 | + lcd.show() |
| 76 | + else: |
| 77 | + lcd.off() |
65 | 78 |
|
| 79 | + sleep_ms(250) |
0 commit comments