Skip to content

Commit f5f4f0a

Browse files
committed
Fix docstrings and comments
1 parent 982f3ea commit f5f4f0a

File tree

14 files changed

+133
-91
lines changed

14 files changed

+133
-91
lines changed

red_vision/cameras/dvp_camera.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,26 @@ def __init__(
2929
Args:
3030
i2c (I2C): I2C object for communication
3131
i2c_address (int): I2C address of the camera
32+
height (int, optional): Image height in pixels
33+
width (int, optional): Image width in pixels
34+
color_mode (int, optional): Color mode to use
35+
buffer (ndarray, optional): Pre-allocated image buffer
3236
"""
33-
super().__init__(height, width, color_mode, buffer)
34-
37+
# Store I2C parameters.
3538
self._i2c = i2c
3639
self._i2c_address = i2c_address
3740

41+
# Initialize the base VideoCaptureDriver class
42+
super().__init__(height, width, color_mode, buffer)
43+
3844
def _read_register(self, reg, nbytes=1):
3945
"""
40-
Reads a register from the camera over I2C.
46+
Reads a register(s) from the camera over I2C.
4147
4248
Args:
43-
reg (int): Register address to read
44-
nbytes (int): Number of bytes to read from the register
49+
reg (int): Start register address to read
50+
nbytes (int, optional): Number of bytes to read from the register
51+
(default: 1)
4552
4653
Returns:
4754
bytes: Data read from the register
@@ -51,11 +58,11 @@ def _read_register(self, reg, nbytes=1):
5158

5259
def _write_register(self, reg, data):
5360
"""
54-
Writes data to a register on the camera over I2C.
61+
Writes data to a register(s) on the camera over I2C.
5562
5663
Args:
57-
reg (int): Register address to write
58-
data (bytes, int, list, tuple): Data to write to the register
64+
reg (int): Start register address to write
65+
data (bytes, int, list, tuple): Data to write to the register(s)
5966
"""
6067
if isinstance(data, int):
6168
data = bytes([data])

red_vision/cameras/dvp_rp2_pio.py

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,25 +38,22 @@ def __init__(
3838
Initializes the DVP interface with the specified parameters.
3939
4040
Args:
41+
sm_id (int): PIO state machine ID
4142
pin_d0 (int): Data 0 pin number for DVP interface
4243
pin_vsync (int): Vertical sync pin number
4344
pin_hsync (int): Horizontal sync pin number
4445
pin_pclk (int): Pixel clock pin number
45-
pin_xclk (int): External clock pin number
46-
xclk_freq (int): Frequency in Hz for the external clock
47-
sm_id (int): PIO state machine ID
48-
num_data_pins (int): Number of data pins used in DVP interface
49-
bytes_per_pixel (int): Number of bytes per pixel
50-
byte_swap (bool): Whether to swap bytes in the captured data
51-
continuous (bool): Whether to continuously capture frames
46+
pin_xclk (int, optional): External clock pin number
5247
"""
48+
# Store state machine ID
49+
self._sm_id = sm_id
50+
5351
# Store pin assignments
5452
self._pin_d0 = pin_d0
5553
self._pin_vsync = pin_vsync
5654
self._pin_hsync = pin_hsync
5755
self._pin_pclk = pin_pclk
5856
self._pin_xclk = pin_xclk
59-
self._sm_id = sm_id
6057

6158
def begin(
6259
self,
@@ -66,6 +63,18 @@ def begin(
6663
byte_swap,
6764
continuous = False,
6865
):
66+
"""
67+
Begins the DVP interface with the specified parameters.
68+
69+
Args:
70+
buffer (ndarray): Image buffer to write captured frames into
71+
xclk_freq (int): Frequency in Hz for the XCLK pin, if it is used
72+
num_data_pins (int): Number of data pins used by the camera (1 to 8)
73+
byte_swap (bool): Whether to swap bytes in each pixel
74+
continuous (bool, optional): Whether to continuously capture frames
75+
(default: False)
76+
"""
77+
# Store buffer and its dimensions
6978
self._buffer = buffer
7079
self._height, self._width, self._bytes_per_pixel = buffer.shape
7180

@@ -108,14 +117,17 @@ def begin(
108117

109118
def buffer(self):
110119
"""
111-
Returns the current frame buffer from the camera.
120+
Returns the current frame buffer used by this driver.
112121
113122
Returns:
114123
ndarray: Frame buffer
115124
"""
116125
return self._buffer
117126

118127
def _setup_pio(self):
128+
"""
129+
Sets up the PIO state machine for the DVP interface.
130+
"""
119131
# Copy the PIO program
120132
program = self._pio_read_dvp
121133

@@ -505,6 +517,9 @@ def _assemble_control_blocks(self):
505517
def _add_control_block(self, block):
506518
"""
507519
Helper function to add a control block to the control block array.
520+
521+
Args:
522+
block (array): Control block to add
508523
"""
509524
# Add the control block to the array. Each control block is all 4 DMA
510525
# alias 0 registers in order.

red_vision/cameras/hm01b0.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -249,18 +249,33 @@ def __init__(
249249
Initializes the HM01B0 camera with default settings.
250250
251251
Args:
252+
interface (DVP_Interface): DVP interface driver
252253
i2c (I2C): I2C object for communication
253-
i2c_address (int, optional): I2C address (default: 0x24)
254-
num_data_pins (int, optional): Number of data pins
255-
- 1 (Default)
254+
i2c_address (int, optional): I2C address of the camera (default: 0x24)
255+
num_data_pins (int, optional): Number of data pins for the camera to
256+
use:
257+
- 1 (default)
256258
- 4
257259
- 8
260+
xclk_freq (int, optional): Frequency of the XCLK signal in Hz
261+
(default: 25MHz)
262+
continuous (bool, optional): Whether to run in continuous capture
263+
mode (default: False)
264+
height (int, optional): Image height in pixels
265+
width (int, optional): Image width in pixels
266+
color_mode (int, optional): Color mode to use:
267+
- COLOR_MODE_BAYER_RG (default)
268+
buffer (ndarray, optional): Pre-allocated image buffer
258269
"""
270+
# Store parameters
259271
self._interface = interface
260272
self._continuous = continuous
261273
self._num_data_pins = num_data_pins
274+
275+
# Initialize the base DVP_Camera class
262276
super().__init__(i2c, i2c_address, height, width, color_mode, buffer)
263277

278+
# Begin the interface driver
264279
self._interface.begin(
265280
self._buffer,
266281
xclk_freq = xclk_freq,
@@ -269,6 +284,7 @@ def __init__(
269284
continuous = self._continuous,
270285
)
271286

287+
# Reset and initialize the camera
272288
self._soft_reset()
273289
self._send_init(self._num_data_pins)
274290

red_vision/cameras/ov5640.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -891,6 +891,7 @@ def __init__(
891891
interface,
892892
i2c,
893893
i2c_address = 0x3C,
894+
xclk_freq = 20_000_000,
894895
continuous = False,
895896
height = None,
896897
width = None,
@@ -901,23 +902,39 @@ def __init__(
901902
Initializes the OV5640 camera sensor with default settings.
902903
903904
Args:
905+
interface (DVP_Interface): DVP interface driver
904906
i2c (I2C): I2C object for communication
905-
i2c_address (int, optional): I2C address (default: 0x3C)
907+
i2c_address (int, optional): I2C address of the camera (default: 0x3C)
908+
xclk_freq (int, optional): Frequency of the XCLK signal in Hz
909+
(default: 20MHz)
910+
continuous (bool, optional): Whether to run in continuous capture
911+
mode (default: False)
912+
height (int, optional): Image height in pixels
913+
width (int, optional): Image width in pixels
914+
color_mode (int, optional): Color mode to use:
915+
- COLOR_MODE_BGR565 (default)
916+
buffer (ndarray, optional): Pre-allocated image buffer
906917
"""
918+
# Store parameters
907919
self._interface = interface
908920
self._continuous = continuous
921+
922+
# Initialize the base DVP_Camera class
909923
super().__init__(i2c, i2c_address, height, width, color_mode, buffer)
910924

925+
# Begin the interface driver
911926
self._interface.begin(
912927
self._buffer,
913-
xclk_freq = 20_000_000,
928+
xclk_freq = xclk_freq,
914929
num_data_pins = 8,
915930
byte_swap = False,
916931
continuous = self._continuous,
917932
)
918933

934+
# Initialize the camera
919935
self._write_list(self._sensor_default_regs)
920936

937+
# Set default settings
921938
self._colorspace = self._OV5640_COLOR_RGB
922939
self._flip_x = True
923940
self._flip_y = True
@@ -930,6 +947,7 @@ def __init__(
930947
self._ev = 0
931948
self._white_balance = 0
932949

950+
# Apply the initial size and colorspace
933951
self._set_size_and_colorspace()
934952

935953
def resolution_default(self):

red_vision/cameras/video_capture.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ def __init__(
2222
driver,
2323
):
2424
"""
25-
Initializes the camera.
25+
Initializes a VideoCapture object with the provided driver.
26+
27+
Args:
28+
driver (VideoCaptureDriver): Camera driver to use
2629
"""
2730
# Store driver reference.
2831
self._driver = driver

red_vision/cameras/video_capture_driver.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ class VideoCaptureDriver(VideoDriver):
1414
"""
1515
Red Vision abstract base class for camera drivers.
1616
"""
17+
# No __init__() here, see VideoDriver.
18+
1719
def open(self):
1820
"""
1921
Opens the camera and prepares it for capturing images.

red_vision/displays/dvi.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,20 @@ def __init__(
2828
Args:
2929
width (int): Display width in pixels
3030
height (int): Display height in pixels
31-
rotation (int, optional): Orientation of display
32-
- 0: Portrait (default)
33-
- 1: Landscape
34-
- 2: Inverted portrait
35-
- 3: Inverted landscape
36-
bgr_order (bool, optional): Color order
37-
- True: BGR (default)
38-
- False: RGB
39-
reverse_bytes_in_word (bool, optional):
40-
- Enable if the display uses LSB byte order for color words
31+
color_mode (int, optional): Color mode
32+
- COLOR_BGR233
33+
- COLOR_GRAY8
34+
- COLOR_BGR565 (default)
35+
- COLOR_BGRA8888
36+
buffer (ndarray, optional): Pre-allocated frame buffer.
4137
"""
38+
# Store parameters
4239
self._interface = interface
40+
41+
# Initialize the base display class
4342
super().__init__(height, width, color_mode, buffer)
4443

44+
# Begin the interface driver
4545
self._interface.begin(
4646
self._buffer,
4747
self._color_mode,

red_vision/displays/dvi_rp2_hstx.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,6 @@ def __init__(
120120
Initializes the DVI HSTX display driver.
121121
122122
Args:
123-
width (int): Display width in pixels
124-
height (int): Display height in pixels
125-
color_mode (int, optional): Color mode
126-
- COLOR_BGR233: 8-bit BGR233
127-
- COLOR_GRAY8: 8-bit grayscale
128-
- COLOR_BGR565: 16-bit BGR565 (default)
129-
- COLOR_BGRA8888: 32-bit BGRA8888
130123
pin_clk_p (int, optional): TMDS clock lane positive pin (default: 14)
131124
pin_clk_n (int, optional): TMDS clock lane negative pin (default: 15)
132125
pin_d0_p (int, optional): TMDS data 0 lane positive pin (default: 18)
@@ -135,7 +128,6 @@ def __init__(
135128
pin_d1_n (int, optional): TMDS data 1 lane negative pin (default: 17)
136129
pin_d2_p (int, optional): TMDS data 2 lane positive pin (default: 12)
137130
pin_d2_n (int, optional): TMDS data 2 lane negative pin (default: 13)
138-
buffer (ndarray, optional): Pre-allocated frame buffer.
139131
"""
140132
# Set pin numbers.
141133
self._pin_clk_p = pin_clk_p
@@ -150,6 +142,10 @@ def __init__(
150142
def begin(self, buffer, color_mode):
151143
"""
152144
Begins DVI output.
145+
146+
Args:
147+
buffer (ndarray): Image buffer to read pixel data from
148+
color_mode (int): Color mode of the image buffer
153149
"""
154150
# Store buffer and color mode.
155151
self._buffer = buffer

red_vision/displays/spi_generic.py

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,9 @@ def __init__(
3333
Initializes the ST7789 SPI display driver.
3434
3535
Args:
36-
width (int): Display width in pixels
37-
height (int): Display height in pixels
38-
spi (SPI): SPI bus object
36+
spi (SPI): SPI interface object
3937
pin_dc (int): Data/Command pin number
4038
pin_cs (int, optional): Chip Select pin number
41-
rotation (int, optional): Orientation of display
42-
- 0: Portrait (default)
43-
- 1: Landscape
44-
- 2: Inverted portrait
45-
- 3: Inverted landscape
46-
bgr_order (bool, optional): Color order
47-
- True: BGR (default)
48-
- False: RGB
49-
reverse_bytes_in_word (bool, optional):
50-
- Enable if the display uses LSB byte order for color words
5139
"""
5240
# Store SPI arguments
5341
self._spi = spi

red_vision/displays/spi_rp2_pio.py

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,25 +39,13 @@ def __init__(
3939
Initializes the ST7789 PIO display driver.
4040
4141
Args:
42-
width (int): Display width in pixels
43-
height (int): Display height in pixels
4442
sm_id (int): PIO state machine ID
4543
pin_clk (int): Clock pin number
4644
pin_tx (int): Data pin number
4745
pin_dc (int): Data/Command pin number
4846
pin_cs (int, optional): Chip Select pin number
49-
freq (int, optional): Frequency in Hz for the PIO state machine
50-
Default is -1, which uses the default frequency of 125MHz
51-
rotation (int, optional): Orientation of display
52-
- 0: Portrait (default)
53-
- 1: Landscape
54-
- 2: Inverted portrait
55-
- 3: Inverted landscape
56-
bgr_order (bool, optional): Color order
57-
- True: BGR (default)
58-
- False: RGB
59-
reverse_bytes_in_word (bool, optional):
60-
- Enable if the display uses LSB byte order for color words
47+
freq (int, optional): Frequency in Hz for the PIO state machine.
48+
Default is -1, which uses the system clock frequency
6149
"""
6250
# Store PIO arguments
6351
self._sm_id = sm_id

0 commit comments

Comments
 (0)