Auto-détection DSLR + reset USB au démarrage et toutes les 10s
- _usb_reset_done() : reset USB via usbreset pour libérer tout claim obsolète avant d'initialiser libgphoto2 (fix erreur -53) - Appelé au démarrage et dans _cam_loop() toutes les 10s en simulation - _cam_loop() : log les erreurs d'auto-detect pour diagnostic Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -91,6 +91,30 @@ THEMES = {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# ── Utilitaire USB ───────────────────────────────────────────────────────────
|
||||||
|
def _usb_reset_done():
|
||||||
|
"""Reset USB des DSLR Canon/Nikon/Sony pour libérer tout claim obsolète."""
|
||||||
|
import glob, subprocess as _sp
|
||||||
|
for dev_path in glob.glob('/sys/bus/usb/devices/[0-9]*-[0-9.]*'):
|
||||||
|
prod_file = f"{dev_path}/product"
|
||||||
|
if not os.path.exists(prod_file):
|
||||||
|
continue
|
||||||
|
try:
|
||||||
|
prod = open(prod_file).read().strip()
|
||||||
|
except:
|
||||||
|
continue
|
||||||
|
if not any(b in prod for b in ('Canon', 'Nikon', 'Sony', 'Digital Camera')):
|
||||||
|
continue
|
||||||
|
try:
|
||||||
|
bus = int(open(f"{dev_path}/busnum").read().strip())
|
||||||
|
dev = int(open(f"{dev_path}/devnum").read().strip())
|
||||||
|
usb_path = f"/dev/bus/usb/{bus:03d}/{dev:03d}"
|
||||||
|
_sp.run(['sudo', 'usbreset', usb_path], capture_output=True, timeout=5)
|
||||||
|
print(f"USB reset: {usb_path} ({prod})")
|
||||||
|
time.sleep(1.2)
|
||||||
|
except Exception as e:
|
||||||
|
print(f"USB reset err: {e}")
|
||||||
|
|
||||||
# ── États ────────────────────────────────────────────────────────────────────
|
# ── États ────────────────────────────────────────────────────────────────────
|
||||||
S_ACCUEIL = "accueil"
|
S_ACCUEIL = "accueil"
|
||||||
S_MODE = "mode"
|
S_MODE = "mode"
|
||||||
@@ -528,6 +552,7 @@ class PB:
|
|||||||
self.sim = "--sim" in sys.argv
|
self.sim = "--sim" in sys.argv
|
||||||
self.cam = None
|
self.cam = None
|
||||||
if not self.sim:
|
if not self.sim:
|
||||||
|
_usb_reset_done() # libère tout claim USB obsolète avant init
|
||||||
for i in range(3):
|
for i in range(3):
|
||||||
try:
|
try:
|
||||||
self.cam = gp.Camera(); self.cam.init()
|
self.cam = gp.Camera(); self.cam.init()
|
||||||
@@ -715,9 +740,10 @@ class PB:
|
|||||||
def _cam_loop(self):
|
def _cam_loop(self):
|
||||||
errs = 0
|
errs = 0
|
||||||
while True:
|
while True:
|
||||||
# En simulation : tentative de connexion automatique toutes les 8s
|
# En simulation : tentative de connexion automatique toutes les 10s
|
||||||
if self.sim:
|
if self.sim:
|
||||||
time.sleep(8)
|
time.sleep(10)
|
||||||
|
_usb_reset_done()
|
||||||
for _ in range(2):
|
for _ in range(2):
|
||||||
try:
|
try:
|
||||||
c = gp.Camera(); c.init()
|
c = gp.Camera(); c.init()
|
||||||
@@ -727,7 +753,9 @@ class PB:
|
|||||||
self.cam = c; self.sim = False; self.prev_actif = True
|
self.cam = c; self.sim = False; self.prev_actif = True
|
||||||
print("DSLR détecté automatiquement")
|
print("DSLR détecté automatiquement")
|
||||||
break
|
break
|
||||||
except: time.sleep(1)
|
except Exception as e:
|
||||||
|
print(f"Auto-detect caméra: {e}")
|
||||||
|
time.sleep(1)
|
||||||
continue
|
continue
|
||||||
if self.prev_actif:
|
if self.prev_actif:
|
||||||
try:
|
try:
|
||||||
|
|||||||
Reference in New Issue
Block a user