Skip to content

Commit c3194eb

Browse files
author
brentru
committed
map range, add progress bar fill method
1 parent 5a718e7 commit c3194eb

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

PyPortal_TOTP_Friend/code.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from digitalio import DigitalInOut
66
import displayio
77
import terminalio
8-
8+
from simpleio import map_range
99
import adafruit_hashlib as hashlib
1010
import adafruit_touchscreen
1111
from adafruit_button import Button
@@ -248,7 +248,8 @@ def generate_otp(int_input, secret_key, digits=6):
248248
splash.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

253254
splash.append(progress_bar)
254255

@@ -260,28 +261,27 @@ def generate_otp(int_input, secret_key, digits=6):
260261
# fill the first button
261262
buttons[0].selected = True
262263

264+
263265
while 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

Comments
 (0)