From ae3dd31989e3ff0a8c6ba2863b126496c5947279 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Sat, 28 Sep 2024 11:08:15 -0400 Subject: [PATCH 1/2] 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 --- .pre-commit-config.yaml | 2 +- adafruit_pycamera/__init__.py | 30 +++++++++++------------------- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 70ade69..374676d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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) diff --git a/adafruit_pycamera/__init__.py b/adafruit_pycamera/__init__.py index 45dcb3c..6a4807c 100644 --- a/adafruit_pycamera/__init__.py +++ b/adafruit_pycamera/__init__.py @@ -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, @@ -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") @@ -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( @@ -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(), @@ -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""" From 5ca0969597e48fe8e1ec00a2e9324c702b71945c Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Sat, 28 Sep 2024 11:19:16 -0400 Subject: [PATCH 2/2] pylint wants yield from --- examples/filter/code.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/examples/filter/code.py b/examples/filter/code.py index 8d4598c..207b55f 100644 --- a/examples/filter/code.py +++ b/examples/filter/code.py @@ -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))