This commit is contained in:
David Rice
2026-03-12 16:17:47 +00:00
parent d52a8b600a
commit bf54109ca7

View File

@@ -16,10 +16,15 @@ class BrightnessManager:
self.bl_current = 10 self.bl_current = 10
self.bl_direction = 1 # 1 for increasing, -1 for decreasing self.bl_direction = 1 # 1 for increasing, -1 for decreasing
# LED state # Hex to RGB Tuples: 5F016F, FF33BB, FF80D4, FFADE4
self.led_val = 0 self.colors = [
self.led_dir = 5 # Step size for smooth ramping (95, 1, 111), # #5F016F
self.color_index = 0 # 0: Red, 1: Green, 2: Blue (255, 51, 187), # #FF33BB
(255, 128, 212),# #FF80D4
(255, 173, 228) # #FFADE4
]
self.color_index = 0
self.setup_led() self.setup_led()
@@ -27,35 +32,23 @@ class BrightnessManager:
try: try:
with open(self.led_trig_path, 'w') as f: f.write("none") with open(self.led_trig_path, 'w') as f: f.write("none")
with open(self.led_br_path, 'w') as f: f.write("255") with open(self.led_br_path, 'w') as f: f.write("255")
self.change_led_colour()
except Exception as e: except Exception as e:
print(f"LED Setup Error: {e}") print(f"LED Setup Error: {e}")
def update_led_ramp(self): def change_led_colour(self):
# Calculate next brightness step r, g, b = self.colors[self.color_index]
self.led_val += self.led_dir
# If we hit 255 or 0, reverse direction
if self.led_val >= 255:
self.led_val = 255
self.led_dir = -5
elif self.led_val <= 0:
self.led_val = 0
self.led_dir = 5
# Move to the next color once we finish a down-ramp
self.color_index = (self.color_index + 1) % 3
# Construct the RGB string
rgb = [0, 0, 0]
rgb[self.color_index] = self.led_val
try: try:
with open(self.led_multi_path, 'w') as f: with open(self.led_multi_path, 'w') as f:
f.write(f"{rgb[0]} {rgb[1]} {rgb[2]}") f.write(f"{r} {g} {b}")
except: print(f"LED changed to color index {self.color_index}: {r} {g} {b}")
pass except Exception as e:
print(f"Failed to write LED color: {e}")
return True # Keep the GLib timer running
# Increment index for next time
self.color_index = (self.color_index + 1) % len(self.colors)
return True # Keep GLib timer alive
def cycle_backlight(self): def cycle_backlight(self):
"""Standard backlight cycle on touch""" """Standard backlight cycle on touch"""
@@ -126,7 +119,7 @@ def play_kiosk_video():
except FileNotFoundError: except FileNotFoundError:
print("Warning: /dev/input/event2 not found. Brightness control disabled.") print("Warning: /dev/input/event2 not found. Brightness control disabled.")
GLib.timeout_add(20, brightness_manager.update_led_ramp) GLib.timeout_add(30000, brightness_manager.change_led_colour)
# --- LOOPING LOGIC --- # --- LOOPING LOGIC ---
bus = pipeline.get_bus() bus = pipeline.get_bus()