diff --git a/backend/main.py b/backend/main.py index 620e4db..62badab 100644 --- a/backend/main.py +++ b/backend/main.py @@ -651,24 +651,37 @@ def _reveiller_canon(): global _reveil_en_cours _reveil_en_cours = True try: - log.info("Réveil Canon — restauration alimentation relais") + log.info("Réveil Canon — restauration alimentation") relais.desactiver("canon") - time.sleep(15) + time.sleep(3) relais.desactiver("canon_usb") - time.sleep(25) - if _canon_sur_usb(): - log.info("Canon visible USB après réveil — connexion...") + + # Poll USB au lieu d'attendre un temps fixe (max 20s) + for i in range(20): + time.sleep(1) + if _canon_sur_usb(): + log.info(f"Canon visible USB après {i+4}s — connexion gphoto2...") + break + else: + log.warning("Canon absent USB après 24s — vérifier branchement physique") + return + + # Laisser le Canon finir son init PTP + time.sleep(3) + + # Tentatives connexion gphoto2 (max 3) + for tentative in range(3): camera.connecter(source="gphoto2") if camera.connectee: _appliquer_config_camera() _canon_stats["derniere_preview"] = time.time() _canon_stats["derniere_capture"] = time.time() - log.info("Canon reconnecté après réveil") _canon_stats["connexions"] += 1 - else: - log.warning("Canon visible USB mais connexion gphoto2 échouée") - else: - log.warning("Canon absent USB après réveil relais — vérifier branchement physique") + log.info(f"Canon reconnecté après réveil (tentative {tentative+1})") + return + log.warning(f"Connexion gphoto2 échouée (tentative {tentative+1}/3)") + time.sleep(3) + log.error("Canon visible USB mais connexion gphoto2 échouée après 3 tentatives") finally: _reveil_en_cours = False diff --git a/frontend/index.html b/frontend/index.html index 1bbd194..2c96f0a 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -1146,7 +1146,7 @@ - + diff --git a/frontend/js/camera.js b/frontend/js/camera.js index 3596b92..61aa2e1 100644 --- a/frontend/js/camera.js +++ b/frontend/js/camera.js @@ -280,12 +280,13 @@ async function lancerCapture() { await chargerCadreImpose(); majCompteurAccueil(); - // Verifier l'etat de la camera — attendre si reveil en cours + // Verifier l'etat de la camera — attendre si pas prete ou reveil en cours try { let statut = await apiGet('/api/camera/statut'); - if ((!statut.connectee || statut.mode === 'erreur') && statut.reveil_en_cours) { - afficherStatut('L\'appareil photo se prepare, un instant...', 'succes'); - for (let att = 0; att < 30; att++) { + if (!statut.connectee || statut.mode === 'erreur') { + afficherStatut('Preparation de l\'appareil photo...', 'succes'); + // Attendre jusqu'a 40s que le Canon soit pret (reveil ou reconnexion) + for (let att = 0; att < 20; att++) { await pause(2000); statut = await apiGet('/api/camera/statut'); if (statut.connectee && statut.mode !== 'erreur') break; @@ -294,12 +295,12 @@ async function lancerCapture() { } if (!statut.connectee || statut.mode === 'erreur') { captureEnCours = false; - afficherErreurCapture('Appareil photo indisponible', 'Reessayez dans quelques instants'); + afficherErreurCapture('Appareil photo indisponible', 'Touchez l\'ecran et reessayez'); return; } } catch (e) { captureEnCours = false; - afficherErreurCapture('Le photobooth demarre', 'Reessayez dans quelques instants'); + afficherErreurCapture('Preparation en cours', 'Touchez l\'ecran et reessayez'); return; }