From 4c85683fcb93b1c19edec0501f87a41dd9bc6527 Mon Sep 17 00:00:00 2001 From: Matthias Blankertz Date: Sat, 27 Dec 2025 15:16:27 +0100 Subject: [PATCH] feat: Allow limiting LED brightness Signed-off-by: Matthias Blankertz --- software/frontend/index.html | 6 +++++- software/src/main.py | 11 ++++++----- software/src/utils/config.py | 6 +++++- software/src/utils/leds.py | 4 ++-- 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/software/frontend/index.html b/software/frontend/index.html index 3b590a9..87dfe92 100644 --- a/software/frontend/index.html +++ b/software/frontend/index.html @@ -357,7 +357,8 @@ 'root.TAG_TIMEOUT_SECS': 'Tag removal timeout (seconds)', 'root.TAGMODE': 'Tag mode', 'root.LED_COUNT': 'Length of WS2182 (Neopixel) LED chain', - 'root.VOLUME_MAX': 'Maximum volume (0-255)' + 'root.VOLUME_MAX': 'Maximum volume (0-255)', + 'root.LED_MAX': 'Maximum LED brightness (0-255)' }; const config_input_override = { 'root.TAGMODE': { @@ -399,6 +400,9 @@ }, 'root.VOLUME_MAX': { 'input-type': 'number' + }, + 'root.LED_MAX': { + 'input-type': 'number' } }; diff --git a/software/src/main.py b/software/src/main.py index cf1deea..f968997 100644 --- a/software/src/main.py +++ b/software/src/main.py @@ -76,7 +76,8 @@ config = Configuration() # Setup LEDs np = NeoPixel(hwconfig.LED_DIN, config.get_led_count(), sm=1) -np.fill((32, 32, 0)) +led_max = config.get_led_max() +np.fill((led_max, led_max, 0)) np.write() @@ -84,7 +85,7 @@ def run(): asyncio.new_event_loop() if machine.Pin(hwconfig.BUTTONS[1], machine.Pin.IN, machine.Pin.PULL_UP).value() == 0: - np.fill((0, 0, 32)) + np.fill((0, 0, led_max)) np.write() # Force default access point setup_wifi('', '') @@ -116,7 +117,7 @@ def run(): buttons=lambda the_app: Buttons(the_app, config, hwconfig), playlistdb=lambda _: playlistdb, hwconfig=lambda _: hwconfig, - leds=lambda _: LedManager(np), + leds=lambda _: LedManager(np, config), config=lambda _: config) the_app = app.PlayerApp(deps) @@ -149,7 +150,7 @@ def builddb(): def error_blink(): while True: - np.fill((32, 0, 0)) + np.fill((led_max, 0, 0)) np.write() time.sleep_ms(500) np.fill((0, 0, 0)) @@ -166,5 +167,5 @@ if __name__ == '__main__': sys.print_exception(ex) error_blink() else: - np.fill((32, 0, 0)) + np.fill((led_max, 0, 0)) np.write() diff --git a/software/src/utils/config.py b/software/src/utils/config.py index bb83398..53485e1 100644 --- a/software/src/utils/config.py +++ b/software/src/utils/config.py @@ -27,7 +27,8 @@ class Configuration: 'SSID': '', 'PASSPHRASE': '', }, - 'VOLUME_MAX': 255 + 'VOLUME_MAX': 255, + 'LED_MAX': 255, } def __init__(self, config_path='/config.json'): @@ -101,6 +102,9 @@ class Configuration: def get_volume_max(self) -> int: return self._get('VOLUME_MAX') + def get_led_max(self) -> int: + return self._get('LED_MAX') + # For the web API def get_config(self) -> Mapping[str, Any]: return self.config diff --git a/software/src/utils/leds.py b/software/src/utils/leds.py index 621c1f4..5f9ece9 100644 --- a/software/src/utils/leds.py +++ b/software/src/utils/leds.py @@ -12,10 +12,10 @@ class LedManager: PLAYING = const(1) REBOOTING = const(2) - def __init__(self, np): + def __init__(self, np, config): self.led_state = LedManager.IDLE + self.brightness = config.get_led_max() / 255 self.np = np - self.brightness = 0.1 self.leds = len(self.np) asyncio.create_task(self.run())