Skip to content

Commit

Permalink
Merge pull request #41 from dhalbert/use-builtin-reset
Browse files Browse the repository at this point in the history
use espcamera reset functionality; other minor changes
  • Loading branch information
dhalbert authored Sep 29, 2024
2 parents 40e88ed + 5ca0969 commit e263dad
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ repos:
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/pycqa/pylint
rev: v2.17.4
rev: v3.3.1
hooks:
- id: pylint
name: pylint (library code)
Expand Down
30 changes: 11 additions & 19 deletions adafruit_pycamera/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,10 @@


class PyCameraBase: # pylint: disable=too-many-instance-attributes,too-many-public-methods
"""Base class for PyCamera hardware"""
"""Base class for PyCamera hardware
"""Wrapper class for the PyCamera hardware with lots of smarts"""
Wrapper class for the PyCamera hardware with lots of smarts
"""

_finalize_firmware_load = (
0x3022,
Expand Down Expand Up @@ -253,9 +254,6 @@ def __init__(self) -> None: # pylint: disable=too-many-statements
self.shutter_button.switch_to_input(Pull.UP)
self.shutter = Button(self.shutter_button)

self._cam_reset = DigitalInOut(board.CAMERA_RESET)
self._cam_pwdn = DigitalInOut(board.CAMERA_PWDN)

# AW9523 GPIO expander
self._aw = adafruit_aw9523.AW9523(self._i2c, address=0x58)
print("Found AW9523")
Expand Down Expand Up @@ -374,14 +372,6 @@ def init_neopixel(self):

def init_camera(self, init_autofocus=True) -> None:
"""Initialize the camera, by default including autofocus"""
print("reset camera")
self._cam_reset.switch_to_output(False)
self._cam_pwdn.switch_to_output(True)
time.sleep(0.01)
self._cam_pwdn.switch_to_output(False)
time.sleep(0.01)
self._cam_reset.switch_to_output(True)
time.sleep(0.01)

print("Initializing camera")
self.camera = espcamera.Camera(
Expand All @@ -390,6 +380,8 @@ def init_camera(self, init_autofocus=True) -> None:
pixel_clock_pin=board.CAMERA_PCLK,
vsync_pin=board.CAMERA_VSYNC,
href_pin=board.CAMERA_HREF,
powerdown_pin=board.CAMERA_PWDN,
reset_pin=board.CAMERA_RESET,
pixel_format=espcamera.PixelFormat.RGB565,
frame_size=espcamera.FrameSize.HQVGA,
i2c=board.I2C(),
Expand Down Expand Up @@ -455,13 +447,13 @@ def write_camera_list(self, reg_list: Sequence[int]) -> None:

def read_camera_register(self, reg: int) -> int:
"""Read a 1-byte camera register"""
b = bytearray(2)
b[0] = reg >> 8
b[1] = reg & 0xFF
b_out = bytearray(2)
b_out[0] = reg >> 8
b_out[1] = reg & 0xFF
b_in = bytearray(1)
with self._camera_device as i2c:
i2c.write(b)
i2c.readinto(b, end=1)
return b[0]
i2c.write_then_readinto(b_out, b_in)
return b_in[0]

def autofocus_init_from_bitstream(self, firmware: bytes):
"""Initialize the autofocus engine from a bytestring"""
Expand Down
3 changes: 1 addition & 2 deletions examples/filter/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,7 @@ def sketch(b):

def cycle(seq):
while True:
for s in seq:
yield s
yield from seq


effects_cycle = iter(cycle(effects))
Expand Down

0 comments on commit e263dad

Please sign in to comment.