first save

This commit is contained in:
tiijay
2025-10-19 18:29:10 +02:00
commit b5a30adb27
1303 changed files with 234711 additions and 0 deletions

0
app/utils/__init__.py Normal file
View File

98
app/utils/colors.py Normal file
View File

@@ -0,0 +1,98 @@
# colors.py - Color library for LED matrix
# Basic Colors
RED = (255, 0, 0)
GREEN = (0, 255, 0)
BLUE = (0, 0, 255)
# Primary Colors
YELLOW = (255, 255, 0)
MAGENTA = (255, 0, 255)
CYAN = (0, 255, 255)
# White and Black
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
# Grayscale
GRAY = (128, 128, 128)
LIGHT_GRAY = (192, 192, 192)
DARK_GRAY = (64, 64, 64)
# Warm Colors
ORANGE = (255, 165, 0)
PINK = (255, 192, 203)
HOT_PINK = (255, 105, 180)
CORAL = (255, 127, 80)
TOMATO = (255, 99, 71)
# Cool Colors
PURPLE = (128, 0, 128)
INDIGO = (75, 0, 130)
VIOLET = (238, 130, 238)
LAVENDER = (230, 230, 250)
# Earth Tones
BROWN = (165, 42, 42)
CHOCOLATE = (210, 105, 30)
SANDY_BROWN = (244, 164, 96)
GOLD = (255, 215, 0)
# Bright Colors
LIME = (0, 255, 0)
AQUA = (0, 255, 255)
TURQUOISE = (64, 224, 208)
SPRING_GREEN = (0, 255, 127)
# Pastel Colors
PASTEL_RED = (255, 128, 128)
PASTEL_GREEN = (128, 255, 128)
PASTEL_BLUE = (128, 128, 255)
PASTEL_YELLOW = (255, 255, 128)
PASTEL_PURPLE = (255, 128, 255)
PASTEL_CYAN = (128, 255, 255)
# Neon Colors
NEON_RED = (255, 0, 0)
NEON_GREEN = (57, 255, 20)
NEON_BLUE = (0, 0, 255)
NEON_YELLOW = (255, 255, 0)
NEON_PINK = (255, 0, 128)
NEON_ORANGE = (255, 128, 0)
# Rainbow Colors (for rainbow effects)
RAINBOW = [
(255, 0, 0), # Red
(255, 127, 0), # Orange
(255, 255, 0), # Yellow
(0, 255, 0), # Green
(0, 0, 255), # Blue
(75, 0, 130), # Indigo
(148, 0, 211), # Violet
]
# Holiday Colors
CHRISTMAS_RED = (255, 0, 0)
CHRISTMAS_GREEN = (0, 255, 0)
HALLOWEEN_ORANGE = (255, 140, 0)
HALLOWEEN_PURPLE = (128, 0, 128)
# Utility function to create custom colors
def rgb(r, g, b):
"""Create a color from RGB values (0-255)"""
return (r, g, b)
def hex_to_rgb(hex_color):
"""Convert hex color (#RRGGBB) to RGB tuple"""
hex_color = hex_color.lstrip('#')
return tuple(int(hex_color[i : i + 2], 16) for i in (0, 2, 4))
def fade_color(color1, color2, factor):
"""Fade between two colors (factor 0.0 to 1.0)"""
r = int(color1[0] + (color2[0] - color1[0]) * factor)
g = int(color1[1] + (color2[1] - color1[1]) * factor)
b = int(color1[2] + (color2[2] - color1[2]) * factor)
return (r, g, b)

37
app/utils/system_load.py Normal file
View File

@@ -0,0 +1,37 @@
import gc
import time
def show_system_load():
"""Display basic system load information"""
gc.collect() # Run garbage collection first
mem_free = gc.mem_free()
mem_alloc = gc.mem_alloc()
mem_total = mem_free + mem_alloc
mem_usage = (mem_alloc / mem_total) * 100 if mem_total > 0 else 0
print('=== System Load ===')
print(f'Memory: {mem_alloc}/{mem_total} bytes ({mem_usage:.1f}%)')
print(f'Free: {mem_free} bytes')
print(f'Garbage: {gc.mem_free() - mem_free} bytes')
try:
# CPU load approximation (not available on all ports)
start_time = time.ticks_ms()
# Do some work to measure CPU
for i in range(1000):
_ = i * i
end_time = time.ticks_ms()
cpu_time = time.ticks_diff(end_time, start_time)
print(f'CPU load: ~{cpu_time}ms for 1000 iterations')
except (AttributeError, TypeError, ValueError) as e:
print(f'CPU measurement not available: {e}')
print('==================')
# Run periodically
while True:
show_system_load()
time.sleep(5)

84
app/utils/utils.py Normal file
View File

@@ -0,0 +1,84 @@
import time
def get_datetime_string(format='full'):
"""
Return date/time as string with different formats
Args:
format: "full", "date", "time", "short", "ticks"
"""
try:
year, month, day, hour, minute, second, weekday, yearday = time.localtime()
if format == 'full':
return f'{year:04d}-{month:02d}-{day:02d} {hour:02d}:{minute:02d}:{second:02d}'
elif format == 'date':
return f'{year:04d}-{month:02d}-{day:02d}'
elif format == 'time':
return f'{hour:02d}:{minute:02d}:{second:02d}'
elif format == 'short':
return f'{month:02d}/{day:02d} {hour:02d}:{minute:02d}'
else:
return f'Ticks: {time.ticks_ms()} ms'
except:
return f'Ticks: {time.ticks_ms()} ms'
def get_german_datetime():
"""Return German date and time"""
try:
year, month, day, hour, minute, second, weekday, yearday = time.localtime()
weekdays = ['Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa', 'So']
weekday_name = weekdays[weekday]
return f'{weekday_name}.{day:02d}.{month:02d}.{year} {hour:02d}:{minute:02d}'
except:
ticks = time.ticks_ms() // 1000
return f'Zeit: {ticks} sek'
def get_german_timestamp_short():
"""Get German timestamp with short months (for Wokwi)"""
ticks = time.ticks_ms()
day = (ticks // 86400000) % 31 + 1
month = (ticks // 2592000000) % 12 + 1
hour = (ticks // 3600000) % 24
minute = (ticks // 60000) % 60
months = ['Jan', 'Feb', 'Mär', 'Apr', 'Mai', 'Jun', 'Jul', 'Aug', 'Sep', 'Okt', 'Nov', 'Dez']
month_name = months[month - 1]
return f'{day}.{month_name} {hour:02d}:{minute:02d}'
def get_german_time_ticks():
"""Get German time using ticks (works in Wokwi)"""
ticks = time.ticks_ms()
# Simulate time progression
total_seconds = ticks // 1000
hours = (total_seconds // 3600) % 24
minutes = (total_seconds // 60) % 60
seconds = total_seconds % 60
return f'{hours:02d}:{minutes:02d}:{seconds:02d}'
def get_german_date_ticks():
"""Get German date using ticks"""
ticks = time.ticks_ms()
# Simulate date progression (starting from Jan 15, 2024)
days_passed = ticks // (24 * 3600 * 1000)
day = 15 + (days_passed % 28) # Simple month simulation
month = 1 + (days_passed // 28) % 12
year = 2024 + (days_passed // (28 * 12))
months = ['JAN', 'FEB', 'MAR', 'APR', 'MAI', 'JUN', 'JUL', 'AUG', 'SEP', 'OKT', 'NOV', 'DEZ']
month_name = months[month - 1]
return f'{day:02d}.{month_name}.{str(year)[-2:]}'