Keepalive Canon anti-veille : get_config() toutes les 10s quand preview KO

Quand capture_preview() echoue (I/O error, miroir bloque), le thread
preview n'envoyait plus de commande PTP au Canon → l'appareil finissait
par s'eteindre via auto power off. Ajoute un keepalive de secours via
get_config() qui declenche ptp_canon_eos_keepdeviceon cote libgphoto2.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-06-27 00:21:59 +02:00
parent 5a81907a0e
commit 29e65ab1bd
2 changed files with 22 additions and 2 deletions

View File

@@ -330,6 +330,18 @@ class Camera:
except Exception as e: except Exception as e:
log.warning(f"Viewfinder non supporté : {e}") log.warning(f"Viewfinder non supporté : {e}")
def keepalive(self) -> bool:
"""Envoie une commande legere au Canon pour empecher l'auto power off.
Utilise get_config qui declenche internement ptp_canon_eos_keepdeviceon."""
if self.mode != "gphoto2" or not self.connectee or not self.camera:
return False
try:
with self._gp_lock:
self.camera.get_config()
return True
except Exception:
return False
def _preview_gphoto2(self) -> bytes | None: def _preview_gphoto2(self) -> bytes | None:
try: try:
with self._gp_lock: with self._gp_lock:

View File

@@ -61,10 +61,13 @@ _preview_none_count = 0
_PREVIEW_GRACE_FRAMES = 40 # 40 x 50ms = 2s avant de declarer une erreur (Canon LiveView peut être lent à démarrer) _PREVIEW_GRACE_FRAMES = 40 # 40 x 50ms = 2s avant de declarer une erreur (Canon LiveView peut être lent à démarrer)
_derniere_keepalive = 0.0
def _thread_preview(): def _thread_preview():
"""Thread de fond : capture les frames DSLR en continu. """Thread de fond : capture les frames DSLR en continu.
Tourne TOUJOURS quand le DSLR est connecte pour maintenir le miroir leve.""" Tourne TOUJOURS quand le DSLR est connecte pour maintenir le miroir leve.
global _derniere_frame_preview Envoie un keepalive PTP toutes les 30s meme quand le preview n'est pas actif."""
global _derniere_frame_preview, _derniere_keepalive
while True: while True:
try: try:
if capture_en_cours or camera.mode != "gphoto2" or not camera.connectee: if capture_en_cours or camera.mode != "gphoto2" or not camera.connectee:
@@ -74,9 +77,14 @@ def _thread_preview():
donnees = camera.preview() donnees = camera.preview()
with _preview_lock: with _preview_lock:
_derniere_frame_preview = donnees _derniere_frame_preview = donnees
_derniere_keepalive = time.time()
except Exception: except Exception:
with _preview_lock: with _preview_lock:
_derniere_frame_preview = None _derniere_frame_preview = None
# Preview echoue → keepalive de secours via get_config
if time.time() - _derniere_keepalive > 10:
camera.keepalive()
_derniere_keepalive = time.time()
time.sleep(0.033) # ~30 fps max time.sleep(0.033) # ~30 fps max
except Exception as e: except Exception as e:
log.error(f"_thread_preview crash: {e}") log.error(f"_thread_preview crash: {e}")