Skip to content

Commit 6b5c54a

Browse files
authored
Merge pull request #25 from adafruit/focus_stack
manual focus control!
2 parents 7698787 + 2748e0c commit 6b5c54a

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

adafruit_pycamera/__init__.py

+20
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@
4848
_OV5640_CMD_TRIGGER_AUTOFOCUS = const(0x03)
4949
_OV5640_CMD_AUTO_AUTOFOCUS = const(0x04)
5050
_OV5640_CMD_RELEASE_FOCUS = const(0x08)
51+
_OV5640_CMD_AF_SET_VCM_STEP = const(0x1A)
52+
_OV5640_CMD_AF_GET_VCM_STEP = const(0x1B)
5153

5254
_OV5640_CMD_MAIN = const(0x3022)
5355
_OV5640_CMD_ACK = const(0x3023)
@@ -493,6 +495,24 @@ def autofocus(self) -> list[int]:
493495
print(f"zones focused: {zone_focus}")
494496
return zone_focus
495497

498+
@property
499+
def autofocus_vcm_step(self):
500+
"""Get the voice coil motor step location"""
501+
if not self._send_autofocus_command(
502+
_OV5640_CMD_AF_GET_VCM_STEP, "get vcm step"
503+
):
504+
return None
505+
return self.read_camera_register(_OV5640_CMD_PARA4)
506+
507+
@autofocus_vcm_step.setter
508+
def autofocus_vcm_step(self, step):
509+
"""Get the voice coil motor step location, from 0 to 255"""
510+
if not 0 <= step <= 255:
511+
raise RuntimeError("VCM step must be 0 to 255")
512+
self.write_camera_register(_OV5640_CMD_PARA3, 0x00)
513+
self.write_camera_register(_OV5640_CMD_PARA4, step)
514+
self._send_autofocus_command(_OV5640_CMD_AF_SET_VCM_STEP, "set vcm step")
515+
496516
def select_setting(self, setting_name):
497517
"""For the point & shoot camera mode, control what setting is being set"""
498518
self._effect_label.color = 0xFFFFFF

0 commit comments

Comments
 (0)