Skip to content

Commit 6c3477e

Browse files
authored
Merge pull request #10 from sparkfun/encapsulation
Driver encapsulation
2 parents c3226f5 + 90079d8 commit 6c3477e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1616
-954
lines changed

red_vision/__init__.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
#
44
# Copyright (c) 2025 SparkFun Electronics
55
#-------------------------------------------------------------------------------
6-
# cv2_drivers/touch_screens/__init__.py
6+
# red_vision/__init__.py
77
#
8-
# Imports all available drivers for MicroPython OpenCV.
8+
# Imports all available Red Vision drivers, modules, and utilities.
99
#-------------------------------------------------------------------------------
1010

11-
from . import displays
1211
from . import cameras
12+
from . import displays
1313
from . import touch_screens
14+
from .utils import colors
15+
from .utils import memory

red_vision/cameras/__init__.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,19 @@
33
#
44
# Copyright (c) 2025 SparkFun Electronics
55
#-------------------------------------------------------------------------------
6-
# cv2_drivers/cameras/__init__.py
6+
# red_vision/cameras/__init__.py
77
#
8-
# Imports all available camera drivers for MicroPython OpenCV.
8+
# Imports all available Red Vision camera drivers.
99
#-------------------------------------------------------------------------------
1010

11-
# Import sys module to check platform
12-
import sys
11+
# Import the generic VideoCapture class.
12+
from .video_capture import VideoCapture
13+
14+
# Import platform agnostic drivers.
15+
from .hm01b0 import HM01B0
16+
from .ov5640 import OV5640
1317

14-
# Import RP2 drivers
18+
# Import platform specific drivers.
19+
import sys
1520
if 'rp2' in sys.platform:
16-
from . import hm01b0_pio
17-
from . import ov5640_pio
21+
from .dvp_rp2_pio import DVP_RP2_PIO

red_vision/cameras/cv2_camera.py

Lines changed: 0 additions & 45 deletions
This file was deleted.

red_vision/cameras/dvp_camera.py

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,41 +3,52 @@
33
#
44
# Copyright (c) 2025 SparkFun Electronics
55
#-------------------------------------------------------------------------------
6-
# dvp_camera.py
6+
# red_vision/cameras/dvp_camera.py
77
#
8-
# Base class for OpenCV DVP (Digital Video Port) camera drivers.
8+
# Red Vision abstract base class for DVP (Digital Video Port) camera drivers.
99
#-------------------------------------------------------------------------------
1010

11-
from .cv2_camera import CV2_Camera
11+
from .video_capture_driver import VideoCaptureDriver
1212

13-
class DVP_Camera(CV2_Camera):
13+
class DVP_Camera(VideoCaptureDriver):
1414
"""
15-
Base class for OpenCV DVP (Digital Video Port) camera drivers.
15+
Red Vision abstract base class for DVP (Digital Video Port) camera drivers.
1616
"""
1717
def __init__(
1818
self,
1919
i2c,
20-
i2c_address
20+
i2c_address,
21+
height = None,
22+
width = None,
23+
color_mode = None,
24+
buffer = None,
2125
):
2226
"""
2327
Initializes the DVP camera with I2C communication.
2428
2529
Args:
2630
i2c (I2C): I2C object for communication
2731
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
2836
"""
29-
super().__init__()
30-
37+
# Store I2C parameters.
3138
self._i2c = i2c
3239
self._i2c_address = i2c_address
3340

41+
# Initialize the base VideoCaptureDriver class
42+
super().__init__(height, width, color_mode, buffer)
43+
3444
def _read_register(self, reg, nbytes=1):
3545
"""
36-
Reads a register from the camera over I2C.
46+
Reads a register(s) from the camera over I2C.
3747
3848
Args:
39-
reg (int): Register address to read
40-
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)
4152
4253
Returns:
4354
bytes: Data read from the register
@@ -47,11 +58,11 @@ def _read_register(self, reg, nbytes=1):
4758

4859
def _write_register(self, reg, data):
4960
"""
50-
Writes data to a register on the camera over I2C.
61+
Writes data to a register(s) on the camera over I2C.
5162
5263
Args:
53-
reg (int): Register address to write
54-
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)
5566
"""
5667
if isinstance(data, int):
5768
data = bytes([data])

0 commit comments

Comments
 (0)