Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small 'quality of life' improvements for qrgen app #81

Merged
merged 3 commits into from
Jun 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions badger_os/examples/qrgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@

# Load all available QR Code Files
try:
CODES = [f for f in os.listdir("/qrcodes") if f.endswith(".txt")]
CODES = sorted([f for f in os.listdir("/qrcodes") if f.endswith(".txt")])
TOTAL_CODES = len(CODES)
except OSError:
pass
Expand Down Expand Up @@ -121,6 +121,11 @@ def draw_qr_file(n):


badger_os.state_load("qrcodes", state)

# When we removed some files code may try to display not existing entry
if state["current_qr"] > TOTAL_CODES - 1:
state["current_qr"] = 0

changed = True

while True:
Expand All @@ -133,11 +138,16 @@ def draw_qr_file(n):
if state["current_qr"] > 0:
state["current_qr"] -= 1
changed = True
else:
state["current_qr"] = TOTAL_CODES - 1
changed = True

if display.pressed(badger2040.BUTTON_DOWN):
elif display.pressed(badger2040.BUTTON_DOWN):
if state["current_qr"] < TOTAL_CODES - 1:
state["current_qr"] += 1
changed = True
else:
state["current_qr"] = 0
changed = True

if display.pressed(badger2040.BUTTON_B) or display.pressed(badger2040.BUTTON_C):
display.set_pen(15)
Expand Down