feat: Allow limiting LED brightness
Signed-off-by: Matthias Blankertz <matthias@blankertz.org>
This commit is contained in:
@@ -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'
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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())
|
||||
|
||||
|
||||
Reference in New Issue
Block a user