Skip to content

Commit e263dad

Browse files
authored
Merge pull request #41 from dhalbert/use-builtin-reset
use espcamera reset functionality; other minor changes
2 parents 40e88ed + 5ca0969 commit e263dad

File tree

3 files changed

+13
-22
lines changed

3 files changed

+13
-22
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"""

examples/filter/code.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,7 @@ def sketch(b):
139139

140140
def cycle(seq):
141141
while True:
142-
for s in seq:
143-
yield s
142+
yield from seq
144143

145144

146145
effects_cycle = iter(cycle(effects))

0 commit comments

Comments
 (0)