Skip to content

Commit 62c35ef

Browse files
committed
don't give an exception if focus failed
1 parent ade586a commit 62c35ef

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

adafruit_pycamera.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -366,14 +366,16 @@ def _send_autofocus_command(self, command, msg):
366366
for _ in range(100):
367367
self._print_focus_status(msg)
368368
if self.read_camera_register(_OV5640_CMD_ACK) == 0x0: # command is finished
369-
break
369+
return True
370370
time.sleep(0.01)
371371
else:
372-
raise RuntimeError(f"Timed out {msg}")
372+
return False
373373

374374
def autofocus(self) -> list[int]:
375-
self._send_autofocus_command(_OV5640_CMD_RELEASE_FOCUS, "release focus")
376-
self._send_autofocus_command(_OV5640_CMD_TRIGGER_AUTOFOCUS, "autofocus")
375+
if not self._send_autofocus_command(_OV5640_CMD_RELEASE_FOCUS, "release focus"):
376+
return [False] * 5
377+
if not self._send_autofocus_command(_OV5640_CMD_TRIGGER_AUTOFOCUS, "autofocus"):
378+
return [False] * 5
377379
zone_focus = [self.read_camera_register(_OV5640_CMD_PARA0 + i) for i in range(5)]
378380
print(f"zones focused: {zone_focus}")
379381
return zone_focus

0 commit comments

Comments
 (0)