feat: relay inversé, LED idle solid, luminosité manuelle, auto-flash lux
This commit is contained in:
@@ -27,6 +27,9 @@ async def photobooth_webhook(
|
||||
match event_key:
|
||||
case "counting":
|
||||
led.play("countdown", countdown_duration=DEFAULT_COUNTDOWN)
|
||||
if request.app.state.config.leds.auto_brightness:
|
||||
pb = request.app.state.photobooth_service
|
||||
asyncio.create_task(_analyze_ambient_lux(led, pb))
|
||||
|
||||
case "capture":
|
||||
led.play("capture")
|
||||
@@ -58,3 +61,21 @@ async def _delayed_relay_on(btn, delay: float):
|
||||
await asyncio.sleep(delay)
|
||||
if btn:
|
||||
btn.relay_on()
|
||||
|
||||
|
||||
async def _analyze_ambient_lux(led, pb):
|
||||
"""Capture une frame du liveview et calcule la luminosite moyenne."""
|
||||
try:
|
||||
snapshot = await pb.get_liveview_snapshot()
|
||||
if not snapshot:
|
||||
logger.debug("Analyse lux: aucun snapshot disponible")
|
||||
return
|
||||
from PIL import Image
|
||||
import io
|
||||
img = Image.open(io.BytesIO(snapshot)).convert("L").resize((80, 60))
|
||||
pixels = list(img.getdata())
|
||||
avg = sum(pixels) / len(pixels)
|
||||
led.set_ambient_lux(avg)
|
||||
logger.info("Luminosite ambiante: %.1f / 255", avg)
|
||||
except Exception as e:
|
||||
logger.warning("Analyse lux echouee: %s", e)
|
||||
|
||||
Reference in New Issue
Block a user