8181
8282
8383class 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