FLL/menu.py
2025-10-19 15:29:14 +02:00

45 lines
931 B
Python

# menu.py
import usys
from pybricks.tools import hub_menu, wait
from guida_funzionante import main as run_G
from guidaavantieindietro import main as run_A
from robots import cbrobot as robot
PROGRAMMI = {
"G": run_G,
"A": run_A,
}
def run_with_play(hub, fn, *args, **kwargs):
try:
hub.display.char(">")
return fn(*args, **kwargs)
finally:
hub.display.text("")
def run_once():
labels = list(PROGRAMMI.keys())
if not labels:
print("Nessun programma.")
wait(1500)
return
# if len(labels) == 1: # no menu se solo 1 programma
# run_with_play(robot.hub, PROGRAMMI[labels[0]], robot)
# return
scelta = hub_menu(*labels)
run_with_play(robot.hub, PROGRAMMI[scelta], robot)
while True:
run_once()
# while True:
# try:
# run_once()
# except Exception as e:
# usys.print_exception(e)
# wait(3000)