55from digitalio import DigitalInOut
66import displayio
77import terminalio
8-
8+ from simpleio import map_range
99import adafruit_hashlib as hashlib
1010import adafruit_touchscreen
1111from adafruit_button import Button
@@ -248,7 +248,8 @@ def generate_otp(int_input, secret_key, digits=6):
248248splash .append (label_timer )
249249
250250# create a new progress bar
251- progress_bar = ProgressBar (display .width // 5 , 125 , 200 , 30 )
251+ progress_bar = ProgressBar (display .width // 5 , 125 ,
252+ 200 , 30 , bar_color = 0xFFFFFF )
252253
253254splash .append (progress_bar )
254255
@@ -260,28 +261,27 @@ def generate_otp(int_input, secret_key, digits=6):
260261# fill the first button
261262buttons [0 ].selected = True
262263
264+
263265while ALWAYS_ON or (countdown > 0 ):
264266 # Calculate current time based on NTP + monotonic
265267 unix_time = t - mono_time + int (time .monotonic ())
266268
267269 # Update the key refresh timer
268270 timer = time .localtime (time .time ()).tm_sec
269- print ('Timer:' , timer )
270271 # timer resets on :00/:30
271272 if timer > 30 :
272273 countdown = 60 - timer
273274 else :
274275 countdown = 30 - timer
275- print ('countdown:' , countdown )
276-
276+ print ('NTP Countdown: {}%' .format (countdown ))
277277 # change the timer bar's color if text is about to refresh
278- # TODO: this needs to be added to progressbar!
279- fill_color = 0xFFFFFF
278+ progress_bar .fill = 0xFFFFFF
280279 if countdown < 5 :
281- fill_color = 0xFF0000
282- # "animate" the timer-bar
283- progress_bar .progress = countdown
280+ progress_bar .fill = 0xFF0000
284281
282+ # update the progress_bar with countdown
283+ countdown = map_range (countdown , 0 , 30 , 0.0 , 1.0 )
284+ progress_bar .progress = countdown
285285
286286 # poll the touchscreen
287287 p = ts .touch_point
0 commit comments