99import displayio
1010import terminalio
1111from adafruit_button import Button
12- from adafruit_display_shapes .roundrect import RoundRect
1312from adafruit_display_text .label import Label
1413from adafruit_esp32spi import adafruit_esp32spi
1514from adafruit_ntp import NTP
1817# Background Color
1918BACKGROUND = 0x059ACE
2019
21- TEST = True # if you want to print out the tests the hashers
20+ TEST = False # If you want to print out the tests the hashers
2221ALWAYS_ON = True # Set to true if you never want to go to sleep!
2322ON_SECONDS = 60 # how long to stay on if not in always_on mode
2423
@@ -108,11 +107,11 @@ def base32_decode(encoded):
108107 out .append (byte ) # store what we got
109108 return out
110109
111- def int_to_bytestring (i , padding = 8 ):
110+ def int_to_bytestring (int_val , padding = 8 ):
112111 result = []
113- while i != 0 :
114- result .insert (0 , i & 0xFF )
115- i >>= 8
112+ while int_val != 0 :
113+ result .insert (0 , int_val & 0xFF )
114+ int_val >>= 8
116115 result = [0 ] * (padding - len (result )) + result
117116 return bytes (result )
118117
@@ -149,7 +148,7 @@ def generate_otp(int_input, secret_key, digits=6):
149148 external_spi = spi )
150149
151150# Root DisplayIO
152- root_group = displayio .Group (max_size = 200 )
151+ root_group = displayio .Group (max_size = 100 )
153152display .show (root_group )
154153
155154
@@ -160,7 +159,7 @@ def generate_otp(int_input, secret_key, digits=6):
160159background = displayio .TileGrid (bg_bitmap , pixel_shader = bg_palette )
161160
162161# Create a new DisplayIO group
163- splash = displayio .Group (max_size = 100 )
162+ splash = displayio .Group (max_size = 15 )
164163
165164splash .append (background )
166165
@@ -172,7 +171,7 @@ def generate_otp(int_input, secret_key, digits=6):
172171key_group .append (label_secret )
173172
174173label_title = Label (font , max_glyphs = 14 )
175- label_title .text = "loading... "
174+ label_title .text = "loading.."
176175label_title .x = (display .width // 2 ) // 13
177176label_title .y = 5
178177key_group .append (label_title )
@@ -232,6 +231,12 @@ def generate_otp(int_input, secret_key, digits=6):
232231for b in buttons :
233232 splash .append (b .group )
234233
234+ # refrsh timer label
235+ label_timer = Label (font , max_glyphs = 2 )
236+ label_timer .x = (display .width // 2 ) // 13
237+ label_timer .y = 150
238+ splash .append (label_timer )
239+
235240# how long to stay on if not in always_on mode
236241countdown = ON_SECONDS
237242
@@ -244,6 +249,12 @@ def generate_otp(int_input, secret_key, digits=6):
244249 # Calculate current time based on NTP + monotonic
245250 unix_time = t - mono_time + int (time .monotonic ())
246251
252+ timer = time .localtime (time .time ()).tm_sec
253+ print ('Timer:' , timer )
254+ timer = 30 - timer
255+ print ('Timer 2:' , timer )
256+ label_timer .text = str (timer )
257+
247258 p = ts .touch_point
248259 if p :
249260 for i , b in enumerate (buttons ):
@@ -265,11 +276,11 @@ def generate_otp(int_input, secret_key, digits=6):
265276 if current_button == name :
266277 # Generate OTP
267278 otp = generate_otp (unix_time // 30 , secret )
279+ #print('OTP: ', otp)
268280 # display the key's name
269281 label_title .text = name
270282 # format and display the OTP
271283 label_secret .text = "{} {}" .format (str (otp )[0 :3 ], str (otp )[3 :6 ])
272-
273284 # We'll update every 1/4 second, we can hash very fast so its no biggie!
274285 countdown -= 0.25
275286 time .sleep (0.25 )
0 commit comments