Fixed small bugs, and added fundamental settings

This commit is contained in:
BlueFox 2024-11-15 19:32:25 +01:00
parent 78933f6090
commit 9d395bd2b8
Signed by: BlueFox
GPG Key ID: 327233DA85435270
2 changed files with 54 additions and 8 deletions

View File

@ -14,5 +14,5 @@
"LCD_I2C_CH": 0, "LCD_I2C_CH": 0,
"LCD_I2C_ADDR": 39, "LCD_I2C_ADDR": 39,
"LCD_I2C_NUM_ROWS": 2, "LCD_I2C_NUM_ROWS": 2,
"LCD_I2C_NUM_COLS": 16, "LCD_I2C_NUM_COLS": 16
} }

60
main.py
View File

@ -13,7 +13,7 @@ You should have received a copy of the GNU General Public License along with thi
import utils import utils
from lcdMenu import lcdMenu from lcdMenu import lcdMenu
from WelcomeScreen import WelcomeScreen from WelcomeScreen import WelcomeScreen
from time import sleep from time import sleep, time_ns
from gc import collect # garbage collector for better memory performance from gc import collect # garbage collector for better memory performance
config = utils.Config() config = utils.Config()
@ -38,13 +38,13 @@ def timer():
sleep(3) sleep(3)
return True # disable the "Quitting" message from lcdMenu return True # disable the "Quitting" message from lcdMenu
def uv_on(): def uv_on():
config.RELAIS.value(1) config.PIN_OUT_RELAIS.value(1)
config.LCD.clear() config.LCD.clear()
config.LCD.putstr("------ UV ------ turned on ") config.LCD.putstr("------ UV ------ turned on ")
sleep(1) sleep(1)
return True # disable the "Quitting" message from lcdMenu return True # disable the "Quitting" message from lcdMenu
def uv_off(): def uv_off():
config.RELAIS.value(0) config.PIN_OUT_RELAIS.value(0)
config.LCD.clear() config.LCD.clear()
config.LCD.putstr("------ UV ------ turned off ") config.LCD.putstr("------ UV ------ turned off ")
sleep(1) sleep(1)
@ -61,10 +61,56 @@ def input_tests():
collect() collect()
return True return True
def settings(): def settings():
# display WIP settings_menu = lcdMenu(config.LCD, btn_mapping, scroll_direction=True, cycle=True, hide_menu_name=False, name="SETTINGS")
config.LCD.clear() def swap_welcome():
config.LCD.putstr(" Still work-in-progress") config.STARTUP_WELCOME_SHOW = not config.STARTUP_WELCOME_SHOW
sleep(3) config.LCD.clear()
config.LCD.putstr(f" Welcome Screen ")
if config.STARTUP_WELCOME_SHOW:
config.LCD.putstr("--- Enabled! ---")
else:
config.LCD.putstr("--- Disabled ---")
sleep(1)
def welcome_cycles():
config.LCD.clear()
current_cycles = config.STARTUP_WELCOME_CYCLES
option_down = [" ", "v"][current_cycles>1]
config.LCD.putstr(f" Cycles \n{option_down} {str(current_cycles).center(12)} ^")
while True:
if config.PIN_IN_BTN_1.value() == 1:
time_ns_when_pressed = time_ns()
while config.PIN_IN_BTN_1.value() == 1:
if (time_ns() - time_ns_when_pressed) > 1000000000: # if the time passed is longer than a second
while config.PIN_IN_BTN_1.value() == 1:
pass # wait till release
config.STARTUP_WELCOME_CYCLES = current_cycles
return True
sleep(0.05)
current_cycles -= 1
if current_cycles < 1: current_cycles = 1
option_down = [" ", "v"][current_cycles>1]
config.LCD.putstr(f" Cycles \n{option_down} {str(current_cycles).center(12)} ^")
if config.PIN_IN_BTN_2.value() == 1:
time_ns_when_pressed = time_ns()
while config.PIN_IN_BTN_2.value() == 1:
if (time_ns() - time_ns_when_pressed) > 1000000000: # if the time passed is longer than a second
while config.PIN_IN_BTN_2.value() == 1:
pass # wait till release
config.STARTUP_WELCOME_CYCLES = current_cycles
return True
sleep(0.05)
current_cycles += 1
option_down = [" ", "v"][current_cycles>1]
config.LCD.putstr(f" Cycles \n{option_down} {str(current_cycles).center(12)} ^")
settings_programs = [("Show welcome", swap_welcome),
("Welcome cycles", welcome_cycles),
("Exit", settings_menu.stop)]
settings_menu.setup(settings_programs) # give it the callback list
settings_menu.run() # run the menu until it's closed
del settings_menu, settings_programs
collect()
return True return True
def run_demo_menu(): def run_demo_menu():
demo_menu = lcdMenu(config.LCD, btn_mapping, scroll_direction=True, cycle=True, hide_menu_name=False, name="DEMOS") demo_menu = lcdMenu(config.LCD, btn_mapping, scroll_direction=True, cycle=True, hide_menu_name=False, name="DEMOS")