From 644890e0fe95c43648735dbdab4776be2a411eb5 Mon Sep 17 00:00:00 2001 From: ladyada Date: Sat, 3 Feb 2024 14:56:45 -0500 Subject: [PATCH] manual focus control! thanks https://github.com/xupsh/Vision-Zynq/blob/master/ov5640_init/OV5640.c#L249 :) --- adafruit_pycamera/__init__.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/adafruit_pycamera/__init__.py b/adafruit_pycamera/__init__.py index 718d082..3368e23 100644 --- a/adafruit_pycamera/__init__.py +++ b/adafruit_pycamera/__init__.py @@ -48,6 +48,8 @@ _OV5640_CMD_TRIGGER_AUTOFOCUS = const(0x03) _OV5640_CMD_AUTO_AUTOFOCUS = const(0x04) _OV5640_CMD_RELEASE_FOCUS = const(0x08) +_OV5640_CMD_AF_SET_VCM_STEP = const(0x1a) +_OV5640_CMD_AF_GET_VCM_STEP = const(0x1b) _OV5640_CMD_MAIN = const(0x3022) _OV5640_CMD_ACK = const(0x3023) @@ -493,6 +495,22 @@ def autofocus(self) -> list[int]: print(f"zones focused: {zone_focus}") return zone_focus + @property + def autofocus_vcm_step(self): + """Get the voice coil motor step location""" + if not self._send_autofocus_command(_OV5640_CMD_AF_GET_VCM_STEP, "get vcm step"): + return None + return self.read_camera_register(_OV5640_CMD_PARA4) + + @autofocus_vcm_step.setter + def autofocus_vcm_step(self, step): + """Get the voice coil motor step location, from 0 to 255""" + if not (0 <= step <= 255): + raise RuntimeError("VCM step must be 0 to 255") + self.write_camera_register(_OV5640_CMD_PARA3, 0x00) + self.write_camera_register(_OV5640_CMD_PARA4, step) + self._send_autofocus_command(_OV5640_CMD_AF_SET_VCM_STEP, "set vcm step") + def select_setting(self, setting_name): """For the point & shoot camera mode, control what setting is being set""" self._effect_label.color = 0xFFFFFF