Now using lcdMenu as the ProgramChooser library has been retired
This commit is contained in:
100
main.py
100
main.py
@@ -10,69 +10,89 @@ You should have received a copy of the GNU General Public License along with thi
|
||||
"""
|
||||
|
||||
|
||||
import config, utils
|
||||
from lib.ProgramChooserAdapted import ProgramChooser
|
||||
from lib.WelcomeScreen import WelcomeScreen
|
||||
import utils
|
||||
from lcdMenu import lcdMenu
|
||||
from WelcomeScreen import WelcomeScreen
|
||||
from time import sleep
|
||||
import gc # garbage collector for better memory performance
|
||||
|
||||
|
||||
# extra functions to access the garbage collector
|
||||
def manual():
|
||||
config.LCD.clear()
|
||||
set_value = config.RELAIS.value()
|
||||
config.LCD.putstr(f"---- MANUAL ---- State: {set_value} ")
|
||||
utils.cfg.LCD.clear()
|
||||
set_value = utils.cfg.RELAIS.value()
|
||||
utils.cfg.LCD.putstr(f"---- MANUAL ---- State: {set_value} ")
|
||||
while True:
|
||||
if set_value != config.SWITCH.value():
|
||||
config.RELAIS.value(config.SWITCH.value())
|
||||
set_value = config.RELAIS.value()
|
||||
config.LCD.putstr(f"---- MANUAL ---- State: {set_value} ")
|
||||
if config.BTN_1.value() == 1 or config.BTN_2.value() == 1:
|
||||
return # exit on press of these buttons
|
||||
if set_value != utils.cfg.SWITCH.value():
|
||||
utils.cfg.RELAIS.value(utils.cfg.SWITCH.value())
|
||||
set_value = utils.cfg.RELAIS.value()
|
||||
utils.cfg.LCD.putstr(f"---- MANUAL ---- State: {set_value} ")
|
||||
if utils.cfg.BTN_1.value() == 1 or utils.cfg.BTN_2.value() == 1:
|
||||
return True # exit on press of these buttons
|
||||
def timer():
|
||||
# display WIP
|
||||
config.LCD.clear()
|
||||
config.LCD.putstr(" Still work-in-progress")
|
||||
utils.cfg.LCD.clear()
|
||||
utils.cfg.LCD.putstr(" Still work-in-progress")
|
||||
sleep(3)
|
||||
return True # disable the "Quitting" message from lcdMenu
|
||||
def uv_on():
|
||||
config.RELAIS.value(1)
|
||||
config.LCD.clear()
|
||||
config.LCD.putstr(" UV turned on ")
|
||||
utils.cfg.RELAIS.value(1)
|
||||
utils.cfg.LCD.clear()
|
||||
utils.cfg.LCD.putstr("------ UV ------ turned on ")
|
||||
sleep(1)
|
||||
return True # disable the "Quitting" message from lcdMenu
|
||||
def uv_off():
|
||||
config.RELAIS.value(0)
|
||||
config.LCD.clear()
|
||||
config.LCD.putstr("------ UV ------ turned off ")
|
||||
utils.cfg.RELAIS.value(0)
|
||||
utils.cfg.LCD.clear()
|
||||
utils.cfg.LCD.putstr("------ UV ------ turned off ")
|
||||
sleep(1)
|
||||
return True # disable the "Quitting" message from lcdMenu
|
||||
def lcd_big_hello():
|
||||
import lcd_big_hello
|
||||
lcd_big_hello.run()
|
||||
gc.collect()
|
||||
return True
|
||||
def input_tests():
|
||||
import input_tests as input_tests
|
||||
input_tests.run(serial_output=False)
|
||||
gc.collect()
|
||||
return True
|
||||
def settings():
|
||||
# display WIP
|
||||
config.LCD.clear()
|
||||
config.LCD.putstr(" Still work-in-progress")
|
||||
utils.cfg.LCD.clear()
|
||||
utils.cfg.LCD.putstr(" Still work-in-progress")
|
||||
sleep(3)
|
||||
return True
|
||||
|
||||
# create a programs dict, where the items are callables (functions)
|
||||
programs = {
|
||||
"Settings": settings,
|
||||
"LCD Demo": lcd_big_hello,
|
||||
"UV off": uv_off,
|
||||
"UV on": uv_on,
|
||||
"Timer": timer,
|
||||
"Manual": manual,
|
||||
}
|
||||
|
||||
if config.STARTUP_WELCOME_SHOW:
|
||||
ws = WelcomeScreen(config.LCD,
|
||||
interrupt_pins=[config.BTN_1, config.BTN_2, config.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)
|
||||
if utils.cfg.STARTUP_WELCOME_SHOW:
|
||||
ws = WelcomeScreen(utils.cfg.LCD,
|
||||
interrupt_pins=[utils.cfg.BTN_1, utils.cfg.BTN_2, utils.cfg.SWITCH],
|
||||
subtitle=utils.cfg.STARTUP_PROJECT_NAME,
|
||||
starting_msg=utils.cfg.STARTUP_MESSAGE_STARTING,
|
||||
started_msg=utils.cfg.STARTUP_MESSAGE_FINISHED)
|
||||
ws.show(cycles=utils.cfg.STARTUP_WELCOME_CYCLES)
|
||||
del ws
|
||||
gc.collect()
|
||||
|
||||
pc = ProgramChooser(programs) # initialize the ProgramChooser
|
||||
pc.run() # and run it (will be an endless loop)
|
||||
|
||||
# create the menus
|
||||
btn_mapping = {"ok_btn": utils.cfg.BTN_1, "next_btn": utils.cfg.BTN_2} # the btn mapping for all menus
|
||||
|
||||
demo_menu = lcdMenu(utils.cfg.LCD, btn_mapping, scroll_direction=True, cycle=True, hide_menu_name=False, name="DEMOS")
|
||||
demo_programs = [("LCD Demo", lcd_big_hello),
|
||||
("Input tests", input_tests),
|
||||
("Exit", demo_menu.stop)]
|
||||
demo_menu.setup(demo_programs) # give it the callback list
|
||||
|
||||
main_menu = lcdMenu(utils.cfg.LCD, btn_mapping, scroll_direction=True, cycle=True, hide_menu_name=False, name="PROGRAMS")
|
||||
main_programs = [("Timer", timer),
|
||||
("Manual", manual),
|
||||
("UV off", uv_off),
|
||||
("UV on", uv_on),
|
||||
("Demos", demo_menu.run),
|
||||
("Settings", settings)]
|
||||
main_menu.setup(main_programs) # give it the callback list
|
||||
|
||||
# and run the main menu (will be an endless loop)
|
||||
main_menu.run()
|
||||
|
||||
Reference in New Issue
Block a user