Restructured main.py for better readability

This commit is contained in:
BlueFox 2024-11-16 16:38:54 +01:00
parent 002b01d572
commit 91a58cca61
Signed by: BlueFox
GPG Key ID: 327233DA85435270

25
main.py
View File

@ -18,15 +18,6 @@ from gc import collect # garbage collector for better memory performance
config = utils.Config()
btn_mapping = {"ok_btn": config.PIN_IN_BTN_1, "next_btn": config.PIN_IN_BTN_2} # the btn mapping for all lcdMenus
if config.STARTUP_WELCOME_SHOW:
ws = WelcomeScreen(config.LCD,
interrupt_pins=[config.PIN_IN_BTN_1, config.PIN_IN_BTN_2, config.PIN_IN_SWITCH],
subtitle=config.STARTUP_PROJECT_NAME,
starting_msg=config.STARTUP_MESSAGE_STARTING,
started_msg=config.STARTUP_MESSAGE_FINISHED)
ws.show(cycles=config.STARTUP_WELCOME_CYCLES)
del ws
collect()
# extra functions to access the garbage collector
def timer():
@ -54,7 +45,7 @@ def settings():
collect()
return True
# create the menus
# create the main menu
main_menu = lcdMenu(config.LCD, btn_mapping, scroll_direction=True, cycle=True, hide_menu_name=False, name="PROGRAMS")
main_programs = [("Timer", timer),
("Manual", manual),
@ -62,5 +53,19 @@ main_programs = [("Timer", timer),
("Settings", settings)]
main_menu.setup(main_programs) # give it the callback list
# -------
# run the welcome screen as defined in the config file
if config.STARTUP_WELCOME_SHOW:
ws = WelcomeScreen(config.LCD,
interrupt_pins=[config.PIN_IN_BTN_1, config.PIN_IN_BTN_2, config.PIN_IN_SWITCH],
subtitle=config.STARTUP_PROJECT_NAME,
starting_msg=config.STARTUP_MESSAGE_STARTING,
started_msg=config.STARTUP_MESSAGE_FINISHED)
ws.show(cycles=config.STARTUP_WELCOME_CYCLES)
del ws
collect()
# and run the main menu (will be an endless loop)
main_menu.run()