2022-02-22 13:45:11 +00:00
|
|
|
import gc
|
|
|
|
import sys
|
|
|
|
import time
|
|
|
|
import math
|
|
|
|
import machine
|
|
|
|
import badger2040
|
|
|
|
|
|
|
|
page = 0
|
|
|
|
|
|
|
|
examples = [
|
|
|
|
"clock.py",
|
|
|
|
"fonts.py",
|
|
|
|
"clean.py",
|
|
|
|
"interrupt.py",
|
|
|
|
"scanline.py",
|
|
|
|
"lut-test.py",
|
|
|
|
"quictest.py"
|
|
|
|
]
|
|
|
|
|
|
|
|
MAX_PAGE = math.ceil(len(examples) / 3)
|
|
|
|
|
|
|
|
button_a = machine.Pin(badger2040.BUTTON_A, machine.Pin.IN, machine.Pin.PULL_DOWN)
|
|
|
|
button_b = machine.Pin(badger2040.BUTTON_B, machine.Pin.IN, machine.Pin.PULL_DOWN)
|
|
|
|
button_c = machine.Pin(badger2040.BUTTON_C, machine.Pin.IN, machine.Pin.PULL_DOWN)
|
|
|
|
button_up = machine.Pin(badger2040.BUTTON_UP, machine.Pin.IN, machine.Pin.PULL_DOWN)
|
|
|
|
button_down = machine.Pin(badger2040.BUTTON_DOWN, machine.Pin.IN, machine.Pin.PULL_DOWN)
|
|
|
|
|
2022-02-22 20:26:00 +00:00
|
|
|
# Early exit if b + c button is pressed
|
|
|
|
# A button must be held briefly to power on, so we use a combo instead
|
|
|
|
if button_b.value() and button_c.value():
|
2022-02-22 13:45:11 +00:00
|
|
|
sys.exit(0)
|
2022-02-22 14:39:45 +00:00
|
|
|
|
2022-02-22 13:45:11 +00:00
|
|
|
|
|
|
|
screen = badger2040.Badger2040()
|
|
|
|
screen.update_speed(1)
|
|
|
|
|
|
|
|
|
|
|
|
def render():
|
|
|
|
screen.pen(15)
|
|
|
|
screen.clear()
|
|
|
|
screen.pen(0)
|
|
|
|
screen.thickness(2)
|
2022-02-22 14:39:45 +00:00
|
|
|
|
2022-02-22 13:45:11 +00:00
|
|
|
max_icons = min(3, len(examples[(page * 3):]))
|
|
|
|
|
|
|
|
for i in range(max_icons):
|
|
|
|
x = (14 + 80) * i + 14
|
|
|
|
label = examples[i + (page * 3)].replace(".py", "")
|
|
|
|
screen.rectangle(x, 24, 80, 80)
|
|
|
|
screen.text(label, x, 24 + 80 + 10, 0.5)
|
2022-02-22 14:39:45 +00:00
|
|
|
|
2022-02-22 13:45:11 +00:00
|
|
|
for i in range(MAX_PAGE):
|
|
|
|
x = 286
|
|
|
|
y = int((128 / 2) - (MAX_PAGE * 10 / 2) + (i * 10))
|
|
|
|
screen.pen(0)
|
|
|
|
screen.rectangle(x, y, 8, 8)
|
|
|
|
if page != i:
|
|
|
|
screen.pen(15)
|
|
|
|
screen.rectangle(x + 1, y + 1, 6, 6)
|
|
|
|
|
|
|
|
screen.update()
|
|
|
|
|
|
|
|
|
|
|
|
def launch(file):
|
|
|
|
for k in locals().keys():
|
|
|
|
if k not in ("gc", "file"):
|
|
|
|
del locals()[k]
|
|
|
|
gc.collect()
|
|
|
|
__import__(file)
|
|
|
|
|
2022-02-22 14:39:45 +00:00
|
|
|
|
|
|
|
def launch_example(index):
|
2022-02-22 13:45:11 +00:00
|
|
|
try:
|
2022-02-22 14:39:45 +00:00
|
|
|
launch(examples[(page * 3) + index])
|
|
|
|
return True
|
2022-02-22 13:45:11 +00:00
|
|
|
except IndexError:
|
2022-02-22 14:39:45 +00:00
|
|
|
return False
|
2022-02-22 13:45:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
def button(pin):
|
|
|
|
global page
|
|
|
|
if pin == button_a:
|
2022-02-22 14:39:45 +00:00
|
|
|
launch_example(0)
|
2022-02-22 13:45:11 +00:00
|
|
|
if pin == button_b:
|
2022-02-22 14:39:45 +00:00
|
|
|
launch_example(1)
|
2022-02-22 13:45:11 +00:00
|
|
|
if pin == button_c:
|
2022-02-22 14:39:45 +00:00
|
|
|
launch_example(2)
|
2022-02-22 13:45:11 +00:00
|
|
|
if pin == button_up:
|
|
|
|
if page > 0:
|
|
|
|
page -= 1
|
|
|
|
render()
|
|
|
|
if pin == button_down:
|
|
|
|
if page < MAX_PAGE - 1:
|
|
|
|
page += 1
|
|
|
|
render()
|
|
|
|
|
|
|
|
|
2022-02-22 20:26:00 +00:00
|
|
|
render()
|
|
|
|
|
|
|
|
# Wait for wakeup button to be released
|
|
|
|
while button_a.value() or button_b.value() or button_c.value() or button_up.value() or button_down.value():
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
2022-02-22 13:45:11 +00:00
|
|
|
button_a.irq(trigger=machine.Pin.IRQ_RISING, handler=button)
|
|
|
|
button_b.irq(trigger=machine.Pin.IRQ_RISING, handler=button)
|
|
|
|
button_c.irq(trigger=machine.Pin.IRQ_RISING, handler=button)
|
|
|
|
button_up.irq(trigger=machine.Pin.IRQ_RISING, handler=button)
|
|
|
|
button_down.irq(trigger=machine.Pin.IRQ_RISING, handler=button)
|
|
|
|
|
|
|
|
|
|
|
|
while True:
|
|
|
|
time.sleep(1.0)
|