Skip to content

Commit

Permalink
Merge pull request #81 from hrw/main
Browse files Browse the repository at this point in the history
Small 'quality of life' improvements for qrgen app
  • Loading branch information
Gadgetoid authored Jun 19, 2024
2 parents a7d3ce0 + 22d1ff8 commit 0106c79
Showing 1 changed file with 13 additions and 3 deletions.
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

0 comments on commit 0106c79

Please sign in to comment.