FLL/menu.py
2025-11-02 16:23:37 +01:00

44 lines
983 B
Python

# menu.py
import usys
from pybricks.tools import hub_menu, wait
import batteria
from giro_leo_prova import main as run_L
from guida_funzionante import main as run_G
from guidaavantieindietro import main as run_A
from robot_local import robot
PROGRAMMI = {"G": run_G, "A": run_A, "L": run_L}
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)