Skip to content

Commit ae3dd31

Browse files
committed
use espcamera reset functionality; other minor changes
- espcamera knows how to toggle the power and reset pins to do a reset. Let it do it. - Make docstring be one string - use I2C write_then_readinto
1 parent 40e88ed commit ae3dd31

File tree

2 files changed

+12
-20
lines changed

2 files changed

+12
-20
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ repos:
1818
- id: end-of-file-fixer
1919
- id: trailing-whitespace
2020
- repo: https://github.com/pycqa/pylint
21-
rev: v2.17.4
21+
rev: v3.3.1
2222
hooks:
2323
- id: pylint
2424
name: pylint (library code)

adafruit_pycamera/__init__.py

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,10 @@
8181

8282

8383
class PyCameraBase: # pylint: disable=too-many-instance-attributes,too-many-public-methods
84-
"""Base class for PyCamera hardware"""
84+
"""Base class for PyCamera hardware
8585
86-
"""Wrapper class for the PyCamera hardware with lots of smarts"""
86+
Wrapper class for the PyCamera hardware with lots of smarts
87+
"""
8788

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

256-
self._cam_reset = DigitalInOut(board.CAMERA_RESET)
257-
self._cam_pwdn = DigitalInOut(board.CAMERA_PWDN)
258-
259257
# AW9523 GPIO expander
260258
self._aw = adafruit_aw9523.AW9523(self._i2c, address=0x58)
261259
print("Found AW9523")
@@ -374,14 +372,6 @@ def init_neopixel(self):
374372

375373
def init_camera(self, init_autofocus=True) -> None:
376374
"""Initialize the camera, by default including autofocus"""
377-
print("reset camera")
378-
self._cam_reset.switch_to_output(False)
379-
self._cam_pwdn.switch_to_output(True)
380-
time.sleep(0.01)
381-
self._cam_pwdn.switch_to_output(False)
382-
time.sleep(0.01)
383-
self._cam_reset.switch_to_output(True)
384-
time.sleep(0.01)
385375

386376
print("Initializing camera")
387377
self.camera = espcamera.Camera(
@@ -390,6 +380,8 @@ def init_camera(self, init_autofocus=True) -> None:
390380
pixel_clock_pin=board.CAMERA_PCLK,
391381
vsync_pin=board.CAMERA_VSYNC,
392382
href_pin=board.CAMERA_HREF,
383+
powerdown_pin=board.CAMERA_PWDN,
384+
reset_pin=board.CAMERA_RESET,
393385
pixel_format=espcamera.PixelFormat.RGB565,
394386
frame_size=espcamera.FrameSize.HQVGA,
395387
i2c=board.I2C(),
@@ -455,13 +447,13 @@ def write_camera_list(self, reg_list: Sequence[int]) -> None:
455447

456448
def read_camera_register(self, reg: int) -> int:
457449
"""Read a 1-byte camera register"""
458-
b = bytearray(2)
459-
b[0] = reg >> 8
460-
b[1] = reg & 0xFF
450+
b_out = bytearray(2)
451+
b_out[0] = reg >> 8
452+
b_out[1] = reg & 0xFF
453+
b_in = bytearray(1)
461454
with self._camera_device as i2c:
462-
i2c.write(b)
463-
i2c.readinto(b, end=1)
464-
return b[0]
455+
i2c.write_then_readinto(b_out, b_in)
456+
return b_in[0]
465457

466458
def autofocus_init_from_bitstream(self, firmware: bytes):
467459
"""Initialize the autofocus engine from a bytestring"""

0 commit comments

Comments
 (0)