11import time
22
3- import board
4- import busio
5- from digitalio import DigitalInOut
6-
73import adafruit_hashlib as hashlib
84import adafruit_touchscreen
5+ import board
6+ import busio
97import displayio
108import terminalio
119from adafruit_button import Button
10+ from adafruit_display_shapes .rect import Rect
1211from adafruit_display_text .label import Label
1312from adafruit_esp32spi import adafruit_esp32spi
1413from adafruit_ntp import NTP
1514from adafruit_pyportal import PyPortal
15+ from digitalio import DigitalInOut
1616
1717# Background Color
1818BACKGROUND = 0x059ACE
@@ -234,9 +234,13 @@ def generate_otp(int_input, secret_key, digits=6):
234234# refrsh timer label
235235label_timer = Label (font , max_glyphs = 2 )
236236label_timer .x = (display .width // 2 ) // 13
237- label_timer .y = 150
237+ label_timer .y = 15
238238splash .append (label_timer )
239239
240+ # timer bar
241+ rect = Rect (0 , 150 , 100 , 20 , fill = 0xFF0000 )
242+ splash .append (rect )
243+
240244# how long to stay on if not in always_on mode
241245countdown = ON_SECONDS
242246
@@ -249,11 +253,22 @@ def generate_otp(int_input, secret_key, digits=6):
249253 # Calculate current time based on NTP + monotonic
250254 unix_time = t - mono_time + int (time .monotonic ())
251255
256+ # Update the key refresh timer
252257 timer = time .localtime (time .time ()).tm_sec
253258 print ('Timer:' , timer )
254- timer = 30 - timer
255- print ('Timer 2:' , timer )
256- label_timer .text = str (timer )
259+ if timer > 30 :
260+ countdown = 60 - timer
261+ else :
262+ countdown = 30 - timer
263+ print ('countdown:' , countdown )
264+
265+ # "animate" the timer-bar
266+ # TODO: make bar reset at :00/:30
267+ # TODO: decrease the timer
268+ # TODO: make bar red when it gets close to :00/:30
269+ splash .remove (rect )
270+ rect = Rect (0 , 140 , countdown , 30 , fill = 0xFF0000 )
271+ splash .append (rect )
257272
258273 p = ts .touch_point
259274 if p :
0 commit comments