Capture : viewfinder=0 avant prise (AF phase-détection), timeout 20s, spinner UI
- camera.py : désactiver LiveView avant capture (viewfinder=0) → miroir abaissé → AF phase-détection Canon actif. Remplace _declencher_af_liveview (autofocusdrive=1 pouvait bloquer sur certains corps Canon). activer_viewfinder() après la prise. - main.py : fix bug global _preview_actif dans api_capturer (était variable locale, le global restait True). Timeout asyncio 20s sur run_in_executor pour éviter freeze permanent si capture bloque. Logs INFO avant/après capture. - camera.js + index.html + style.css : spinner "Capture en cours..." entre le flash et l'affichage du résultat. Cacher le spinner dans afficherErreurCapture aussi. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -146,24 +146,22 @@ class Camera:
|
||||
else:
|
||||
return self._capture_simulation(chemin_dest)
|
||||
|
||||
def _declencher_af_liveview(self):
|
||||
"""Déclenche l'autofocus LiveView Canon avant la capture (best-effort)."""
|
||||
try:
|
||||
cfg = self.camera.get_config()
|
||||
af = cfg.get_child_by_name("autofocusdrive")
|
||||
af.set_value(1)
|
||||
self.camera.set_config(cfg)
|
||||
time.sleep(0.4) # Attendre que l'AF se verrouille
|
||||
except Exception:
|
||||
pass # Non supporté sur ce modèle ou en mode MF
|
||||
|
||||
def _capture_gphoto2(self, chemin_dest: Path) -> Path | None:
|
||||
from PIL import Image as PILImage
|
||||
|
||||
for attempt in range(3):
|
||||
try:
|
||||
with self._gp_lock:
|
||||
self._declencher_af_liveview()
|
||||
# Désactiver LiveView : miroir abaissé → AF phase-détection Canon disponible
|
||||
try:
|
||||
cfg = self.camera.get_config()
|
||||
vf = cfg.get_child_by_name("viewfinder")
|
||||
vf.set_value(0)
|
||||
self.camera.set_config(cfg)
|
||||
time.sleep(0.2) # Laisser le miroir descendre
|
||||
except Exception:
|
||||
pass
|
||||
log.info(f"Déclenchement capture DSLR (tentative {attempt+1}/3)")
|
||||
chemin_camera = self.camera.capture(gp.GP_CAPTURE_IMAGE)
|
||||
fichier_camera = gp.CameraFile()
|
||||
self.camera.file_get(
|
||||
|
||||
@@ -259,19 +259,30 @@ async def api_config_update(modifications: dict):
|
||||
|
||||
@app.post("/api/capturer")
|
||||
async def api_capturer():
|
||||
global capture_en_cours
|
||||
global capture_en_cours, _preview_actif
|
||||
# Verifier le compteur
|
||||
etat = compteur_restant()
|
||||
if etat["actif"] and etat["restantes"] <= 0:
|
||||
return JSONResponse({"erreur": "Limite de photos atteinte"}, status_code=403)
|
||||
|
||||
capture_en_cours = True
|
||||
_preview_actif = False # Eviter faux camera_erreur si race condition HTTP avant preview_stop
|
||||
_preview_actif = False # Eviter faux camera_erreur (race condition HTTP avant preview_stop)
|
||||
log.info("Capture déclenchée — preview figé, thread en attente de lock")
|
||||
try:
|
||||
loop = asyncio.get_event_loop()
|
||||
chemin = await loop.run_in_executor(None, camera.capturer)
|
||||
try:
|
||||
chemin = await asyncio.wait_for(
|
||||
loop.run_in_executor(None, camera.capturer),
|
||||
timeout=20.0
|
||||
)
|
||||
except asyncio.TimeoutError:
|
||||
log.error("TIMEOUT capture DSLR après 20s — déconnexion forcée")
|
||||
camera.deconnecter()
|
||||
await diffuser_ws({"type": "camera_erreur", "message": "Timeout capture"})
|
||||
return JSONResponse({"erreur": "Timeout capture — vérifiez le DSLR"}, status_code=500)
|
||||
finally:
|
||||
capture_en_cours = False
|
||||
log.info(f"Capture terminée : {chemin}")
|
||||
if chemin is None:
|
||||
return JSONResponse({"erreur": "Echec capture"}, status_code=500)
|
||||
nom = chemin.name
|
||||
|
||||
Reference in New Issue
Block a user