Skip to content

Commit b0123ce

Browse files
author
brentru
committed
fill the default button
1 parent ce9ff87 commit b0123ce

1 file changed

Lines changed: 14 additions & 6 deletions

File tree

PyPortal_TOTP_Friend/code.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222
# Background Color
2323
BACKGROUND = 0x059ACE
2424

25-
TEST = True # if you want to print out the tests the hashers
26-
ALWAYS_ON = False # Set to true if you never want to go to sleep!
27-
ON_SECONDS = 60 # how long to stay on if not in always_on mode
25+
TEST = True # if you want to print out the tests the hashers
26+
ALWAYS_ON = True # Set to true if you never want to go to sleep!
27+
ON_SECONDS = 60 # how long to stay on if not in always_on mode
2828

2929
# Get wifi details and more from a secrets.py file
3030
try:
@@ -33,7 +33,6 @@
3333
print("WiFi secrets are kept in secrets.py, please add them there!")
3434
raise
3535

36-
3736
# Initialize PyPortal Display
3837
display = board.DISPLAY
3938

@@ -47,7 +46,6 @@
4746
),
4847
size=(WIDTH, HEIGHT))
4948

50-
5149
# Create a SHA1 Object
5250
SHA1 = hashlib.sha1
5351

@@ -61,6 +59,15 @@
6159
esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset)
6260

6361

62+
def set_backlight(val):
63+
"""Adjust the TFT backlight.
64+
:param val: The backlight brightness. Use a value between ``0`` and ``1``, where ``0`` is
65+
off, and ``1`` is 100% brightness.
66+
"""
67+
val = max(0, min(1.0, val))
68+
board.DISPLAY.auto_brightness = False
69+
board.DISPLAY.brightness = val
70+
6471
# HMAC implementation, as hashlib/hmac wouldn't fit
6572
# From https://en.wikipedia.org/wiki/Hash-based_message_authentication_code
6673
def HMAC(k, m):
@@ -141,7 +148,6 @@ def generate_otp(int_input, secret_key, digits=6):
141148
# GFX Font
142149
font = terminalio.FONT
143150

144-
145151
# Initialize new PyPortal object
146152
pyportal = PyPortal(esp=esp,
147153
external_spi=spi)
@@ -235,6 +241,8 @@ def generate_otp(int_input, secret_key, digits=6):
235241

236242
# current button state, defaults to first item in totp_keys
237243
current_button = secrets['totp_keys'][0][0]
244+
# fill the first button
245+
buttons[0].selected = True
238246

239247
while ALWAYS_ON or (countdown > 0):
240248
# Calculate current time based on NTP + monotonic

0 commit comments

Comments
 (0)