feat: pre-flash configurable avant fin countdown
🚀 Deploy — JH Photomaton / 🔍 Vérification (push) Has been cancelled
🚀 Deploy — JH Photomaton / 🍓 Deploy sur le Pi (push) Has been cancelled

This commit is contained in:
2026-07-20 23:29:55 +02:00
parent b2ee41c367
commit 69b9cd0901
3 changed files with 35 additions and 6 deletions
+28 -5
View File
@@ -8,8 +8,6 @@ from fastapi import APIRouter, Request, Query
logger = logging.getLogger(__name__)
router = APIRouter()
DEFAULT_COUNTDOWN = 5.0
@router.get("/webhook/photobooth")
async def photobooth_webhook(
@@ -20,19 +18,36 @@ async def photobooth_webhook(
led = request.app.state.led_service
btn = request.app.state.button_service
ws = request.app.state.ws_manager
cfg = request.app.state.config.leds
logger.info("Webhook photobooth: event=%s type=%s", event_key, mediaitem_type)
await ws.broadcast({"type": "photobooth_event", "event": event_key, "media_type": mediaitem_type})
match event_key:
case "counting":
led.play("countdown", countdown_duration=DEFAULT_COUNTDOWN)
if request.app.state.config.leds.auto_brightness:
led.play("countdown", countdown_duration=cfg.countdown_duration)
# Annuler le pre-flash précédent si toujours en attente
prev = getattr(request.app.state, "pre_flash_task", None)
if prev and not prev.done():
prev.cancel()
# Déclencher le flash X secondes avant la fin du countdown
delay = max(0.0, cfg.countdown_duration - cfg.pre_flash_advance)
task = asyncio.create_task(_delayed_flash(led, delay))
request.app.state.pre_flash_task = task
logger.info(
"Pre-flash schedulé dans %.2fs (countdown=%.1fs advance=%.1fs)",
delay, cfg.countdown_duration, cfg.pre_flash_advance,
)
if cfg.auto_brightness:
pb = request.app.state.photobooth_service
asyncio.create_task(_analyze_ambient_lux(led, pb))
case "capture":
led.play("capture")
# Flash déjà lancé par le pre-flash depuis counting ; ne pas redémarrer
logger.debug("Event capture recu (pre-flash déjà actif)")
case "captured":
led.play("captured")
@@ -57,6 +72,14 @@ async def photobooth_webhook(
return {"ok": True, "event": event_key}
async def _delayed_flash(led, delay: float):
"""Attend `delay` secondes puis déclenche l'effet flash."""
if delay > 0:
await asyncio.sleep(delay)
led.play("capture")
logger.info("Pre-flash déclenché (délai=%.2fs)", delay)
async def _delayed_relay_on(btn, delay: float):
await asyncio.sleep(delay)
if btn: