5
5
from digitalio import DigitalInOut
6
6
import displayio
7
7
import terminalio
8
-
8
+ from simpleio import map_range
9
9
import adafruit_hashlib as hashlib
10
10
import adafruit_touchscreen
11
11
from adafruit_button import Button
@@ -248,7 +248,8 @@ def generate_otp(int_input, secret_key, digits=6):
248
248
splash .append (label_timer )
249
249
250
250
# 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 )
252
253
253
254
splash .append (progress_bar )
254
255
@@ -260,28 +261,27 @@ def generate_otp(int_input, secret_key, digits=6):
260
261
# fill the first button
261
262
buttons [0 ].selected = True
262
263
264
+
263
265
while ALWAYS_ON or (countdown > 0 ):
264
266
# Calculate current time based on NTP + monotonic
265
267
unix_time = t - mono_time + int (time .monotonic ())
266
268
267
269
# Update the key refresh timer
268
270
timer = time .localtime (time .time ()).tm_sec
269
- print ('Timer:' , timer )
270
271
# timer resets on :00/:30
271
272
if timer > 30 :
272
273
countdown = 60 - timer
273
274
else :
274
275
countdown = 30 - timer
275
- print ('countdown:' , countdown )
276
-
276
+ print ('NTP Countdown: {}%' .format (countdown ))
277
277
# 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
280
279
if countdown < 5 :
281
- fill_color = 0xFF0000
282
- # "animate" the timer-bar
283
- progress_bar .progress = countdown
280
+ progress_bar .fill = 0xFF0000
284
281
282
+ # update the progress_bar with countdown
283
+ countdown = map_range (countdown , 0 , 30 , 0.0 , 1.0 )
284
+ progress_bar .progress = countdown
285
285
286
286
# poll the touchscreen
287
287
p = ts .touch_point
0 commit comments