diff --git a/backend/main.py b/backend/main.py index 91053de..92de707 100644 --- a/backend/main.py +++ b/backend/main.py @@ -33,23 +33,20 @@ log = logging.getLogger("photobooth") clients_ws: list[WebSocket] = [] +capture_en_cours = False + async def surveiller_dslr(): """Verifie periodiquement si un DSLR est branche et bascule dessus.""" while True: - await asyncio.sleep(5) + await asyncio.sleep(10) + if capture_en_cours: + continue try: if camera.mode != "gphoto2" and GPHOTO2_DISPONIBLE: dslrs = gp.Camera.autodetect() if len(dslrs) > 0: log.info(f"DSLR detecte : {dslrs[0][0]}, bascule automatique") camera.connecter(source="gphoto2") - elif camera.mode == "gphoto2": - # Verifier que le DSLR repond encore - try: - camera.camera.get_summary() - except Exception: - log.warning("DSLR deconnecte, reconnexion...") - camera.connecter() except Exception: pass @@ -100,12 +97,17 @@ async def api_config_update(modifications: dict): @app.post("/api/capturer") async def api_capturer(): + global capture_en_cours # Verifier le compteur etat = compteur_restant() if etat["actif"] and etat["restantes"] <= 0: return JSONResponse({"erreur": "Limite de photos atteinte"}, status_code=403) - chemin = camera.capturer() + capture_en_cours = True + try: + chemin = camera.capturer() + finally: + capture_en_cours = False if chemin is None: return JSONResponse({"erreur": "Echec capture"}, status_code=500) nom = chemin.name diff --git a/frontend/js/camera.js b/frontend/js/camera.js index 8fdae5c..4f7b451 100644 --- a/frontend/js/camera.js +++ b/frontend/js/camera.js @@ -34,21 +34,32 @@ wsOnMessage('preview', (msg) => { async function lancerCapture() { photosSession = []; - lancerPreview(); + photoImpression = null; + + // Vider les aperçus precedents + document.getElementById('photo-resultat').src = ''; + document.getElementById('photo-partage').src = ''; + majCompteurAccueil(); const nbPhotos = getNombrePhotos(); const compteurEl = document.getElementById('capture-compteur'); for (let i = 0; i < nbPhotos; i++) { + // Lancer la preview pour que l'utilisateur se voit + lancerPreview(); + await pause(500); + if (nbPhotos > 1) { compteurEl.textContent = `Photo ${i + 1} / ${nbPhotos}`; } + // Compte a rebours par dessus la preview await compteARebours(); + // Arreter la preview et attendre que le DSLR soit libre arreterPreview(); - await pause(300); // Laisser le DSLR se liberer du preview + await pause(300); afficherFlash(); @@ -72,11 +83,6 @@ async function lancerCapture() { if (resultat.nom) { photosSession.push(resultat.nom); } - - if (i < nbPhotos - 1) { - lancerPreview(); - await pause(500); - } } await traiterCapture();