feat: Allow limiting LED brightness

Signed-off-by: Matthias Blankertz <matthias@blankertz.org>
This commit is contained in:
2025-12-27 15:16:27 +01:00
parent 355a8bd345
commit 4c85683fcb
4 changed files with 18 additions and 9 deletions

View File

@@ -357,7 +357,8 @@
'root.TAG_TIMEOUT_SECS': 'Tag removal timeout (seconds)', 'root.TAG_TIMEOUT_SECS': 'Tag removal timeout (seconds)',
'root.TAGMODE': 'Tag mode', 'root.TAGMODE': 'Tag mode',
'root.LED_COUNT': 'Length of WS2182 (Neopixel) LED chain', '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 = { const config_input_override = {
'root.TAGMODE': { 'root.TAGMODE': {
@@ -399,6 +400,9 @@
}, },
'root.VOLUME_MAX': { 'root.VOLUME_MAX': {
'input-type': 'number' 'input-type': 'number'
},
'root.LED_MAX': {
'input-type': 'number'
} }
}; };

View File

@@ -76,7 +76,8 @@ config = Configuration()
# Setup LEDs # Setup LEDs
np = NeoPixel(hwconfig.LED_DIN, config.get_led_count(), sm=1) 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() np.write()
@@ -84,7 +85,7 @@ def run():
asyncio.new_event_loop() asyncio.new_event_loop()
if machine.Pin(hwconfig.BUTTONS[1], machine.Pin.IN, machine.Pin.PULL_UP).value() == 0: 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() np.write()
# Force default access point # Force default access point
setup_wifi('', '') setup_wifi('', '')
@@ -116,7 +117,7 @@ def run():
buttons=lambda the_app: Buttons(the_app, config, hwconfig), buttons=lambda the_app: Buttons(the_app, config, hwconfig),
playlistdb=lambda _: playlistdb, playlistdb=lambda _: playlistdb,
hwconfig=lambda _: hwconfig, hwconfig=lambda _: hwconfig,
leds=lambda _: LedManager(np), leds=lambda _: LedManager(np, config),
config=lambda _: config) config=lambda _: config)
the_app = app.PlayerApp(deps) the_app = app.PlayerApp(deps)
@@ -149,7 +150,7 @@ def builddb():
def error_blink(): def error_blink():
while True: while True:
np.fill((32, 0, 0)) np.fill((led_max, 0, 0))
np.write() np.write()
time.sleep_ms(500) time.sleep_ms(500)
np.fill((0, 0, 0)) np.fill((0, 0, 0))
@@ -166,5 +167,5 @@ if __name__ == '__main__':
sys.print_exception(ex) sys.print_exception(ex)
error_blink() error_blink()
else: else:
np.fill((32, 0, 0)) np.fill((led_max, 0, 0))
np.write() np.write()

View File

@@ -27,7 +27,8 @@ class Configuration:
'SSID': '', 'SSID': '',
'PASSPHRASE': '', 'PASSPHRASE': '',
}, },
'VOLUME_MAX': 255 'VOLUME_MAX': 255,
'LED_MAX': 255,
} }
def __init__(self, config_path='/config.json'): def __init__(self, config_path='/config.json'):
@@ -101,6 +102,9 @@ class Configuration:
def get_volume_max(self) -> int: def get_volume_max(self) -> int:
return self._get('VOLUME_MAX') return self._get('VOLUME_MAX')
def get_led_max(self) -> int:
return self._get('LED_MAX')
# For the web API # For the web API
def get_config(self) -> Mapping[str, Any]: def get_config(self) -> Mapping[str, Any]:
return self.config return self.config

View File

@@ -12,10 +12,10 @@ class LedManager:
PLAYING = const(1) PLAYING = const(1)
REBOOTING = const(2) REBOOTING = const(2)
def __init__(self, np): def __init__(self, np, config):
self.led_state = LedManager.IDLE self.led_state = LedManager.IDLE
self.brightness = config.get_led_max() / 255
self.np = np self.np = np
self.brightness = 0.1
self.leds = len(self.np) self.leds = len(self.np)
asyncio.create_task(self.run()) asyncio.create_task(self.run())