Did a huge refactoring and outsouring for modularity and a small performance improvement

This commit is contained in:
2024-11-16 16:31:33 +01:00
parent a6b531c394
commit aba5927221
8 changed files with 389 additions and 326 deletions

33
demos/input_tests.py Normal file
View File

@@ -0,0 +1,33 @@
"""
uv-belichter-software - A simple program that prints out the current sate of the three input devices present on my "UV-Belichter"
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/>.
"""
from utils import Config
from time import sleep
cfg = Config()
def run(endless_loop: bool = True, serial_output: bool = True):
while endless_loop:
if cfg.PIN_IN_BTN_1.value() and cfg.PIN_IN_BTN_2.value() and cfg.PIN_IN_SWITCH.value():
cfg.LCD.move_to(0,0)
cfg.LCD.putstr("In: Y1 | G1 | S1 Exiting! ")
if serial_output:
print("All configured inputs pressed! Exiting...")
sleep(0.2)
break
cfg.LCD.move_to(0,0)
cfg.LCD.putstr(f"In: Y{cfg.PIN_IN_BTN_1.value()} | G{cfg.PIN_IN_BTN_2.value()} | S{cfg.PIN_IN_SWITCH.value()}Push all to exit")
if serial_output:
print(f"Y_BTN: {cfg.PIN_IN_BTN_1.value()}; G_BTN: {cfg.PIN_IN_BTN_2.value()}; Lever: {cfg.PIN_IN_SWITCH.value()}")
sleep(0.05)
if __name__ == "__main__":
run() # run the program

76
demos/lcd_big_hello.py Normal file
View File

@@ -0,0 +1,76 @@
"""
An example "program" which can be used with the lcdMenu library, see also main.py
Copyright (C) 2024 Benjamin Burkhardt <bluefox@privacynerd.de>
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/>.
"""
"""
@ Feature: Fades "HELLO" over two lines in and out
"""
import time
line1 = str(chr(0) + chr(2) + chr(1) + chr(0) + chr(4) + " " + chr(1) + " " + chr(1) + " " + chr(0) + chr(3) + chr(1))
line2 = str(chr(0) + chr(3) + chr(1) + chr(0) + chr(5) + " " + chr(6) + chr(7) + chr(6) + chr(7) + chr(0) + chr(2) + chr(1))
def right2left(lcd, line1, line2, speed=0.3):
padding = " " # 16 spaces
line2 = padding + line2 + padding
line1 = padding + line1 + padding
for i in range(32):
line2 = line2[1:]
line1 = line1[1:]
lcd.putstr(line1[0:16] + line2[0:16])
time.sleep(speed)
def top2bottom(lcd, line1, line2, speed=0.2):
lcd.clear()
time.sleep(speed)
lcd.putstr(line2)
time.sleep(speed)
lcd.clear()
lcd.putstr(line1)
lcd.move_to(0,1)
lcd.putstr(line2)
time.sleep(speed)
lcd.clear()
lcd.move_to(0,1)
lcd.putstr(line1)
time.sleep(speed)
lcd.clear()
time.sleep(speed)
def showAll(lcd, waitAfter=0.5):
lcd.clear()
lcd.putstr(line1)
lcd.move_to(0,1)
lcd.putstr(line2)
time.sleep(waitAfter)
def run(lcd): # for the ProgramChooser as callback
lcd.custom_char(0, bytearray([0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03])) # right
lcd.custom_char(1, bytearray([0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18])) # left
lcd.custom_char(2, bytearray([0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0x1F])) # 2-down
lcd.custom_char(3, bytearray([0x1F,0x1F,0x00,0x00,0x00,0x00,0x00,0x00])) # 2-up
lcd.custom_char(4, bytearray([0x1F,0x1F,0x00,0x00,0x00,0x00,0x00,0x1F])) # e-up
lcd.custom_char(5, bytearray([0x1F,0x00,0x00,0x00,0x00,0x00,0x1F,0x1F])) # e-down
lcd.custom_char(6, bytearray([0x18,0x18,0x18,0x18,0x18,0x18,0x1F,0x1F])) # l-down
lcd.custom_char(7, bytearray([0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x18])) # l-right
right2left(lcd, line1, line2, 0.2)
top2bottom(lcd, line1, line2, 0.2)
showAll(lcd)
if __name__ == "__main__":
from utils import Config
cfg = Config()
run(cfg.LCD) # run once

62
demos/lcd_driver_demo.py Normal file
View File

@@ -0,0 +1,62 @@
"""
An example "program" which can be used with the lcdMenu library on a 2x16 display (with some tweaks also on 4x20 displays)
Copyright (C) 2024 Benjamin Burkhardt <bluefox@privacynerd.de>
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/>.
"""
"""
@ Feature: Demonstrates the lcd driver's functionality
"""
from time import sleep
from utils import log
# lcd is an object of the I2C_LCD class (https://git.privacynerd.de/BlueFox/micropython-libraries/src/branch/main/PCF8574T)
def run(lcd):
# Show off basic functionality of the lcd driver
log(2, "Running the lcd driver demo")
lcd.putstr("Driver demo".center(16))
sleep(1)
lcd.clear()
lcd.putstr("Lorem ipsum dolor sit amet")
sleep(1)
lcd.show_cursor()
sleep(1)
lcd.hide_cursor()
sleep(1)
lcd.blink_cursor_on()
sleep(1)
lcd.blink_cursor_off()
sleep(1)
lcd.backlight_off()
sleep(1)
lcd.backlight_on()
sleep(1)
lcd.display_off()
sleep(1)
lcd.display_on()
sleep(1)
lcd.clear()
sleep(1)
s = ""
for x in range(32, 127):
s += chr(x)
while len(s) > 0:
lcd.clear()
lcd.move_to(0,0)
lcd.putstr(s[:32])
s = s[32:]
sleep(1)
lcd.clear()
return True
if __name__ == "__main__":
import utils
run(utils.Config().LCD)