uv-belichter-software/main.py

79 lines
2.8 KiB
Python

"""
uv-belichter-software - The main program run at the Pi Picos startup
Copyright (C) 2024 Benjamin Burkhardt
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
import config, utils
from lib.ProgramChooserAdapted import ProgramChooser
from lib.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} ")
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
def timer():
# display WIP
config.LCD.clear()
config.LCD.putstr(" Still work-in-progress")
sleep(3)
def uv_on():
config.RELAIS.value(1)
config.LCD.clear()
config.LCD.putstr(" UV turned on ")
sleep(1)
def uv_off():
config.RELAIS.value(0)
config.LCD.clear()
config.LCD.putstr("------ UV ------ turned off ")
sleep(1)
def lcd_big_hello():
import lcd_big_hello
lcd_big_hello.run()
gc.collect()
def settings():
# display WIP
config.LCD.clear()
config.LCD.putstr(" Still work-in-progress")
sleep(3)
# 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)
del ws
gc.collect()
pc = ProgramChooser(programs) # initialize the ProgramChooser
pc.run() # and run it (will be an endless loop)