Skip to content

Commit

Permalink
Cam Drivers Version in API
Browse files Browse the repository at this point in the history
  • Loading branch information
cnadler86 committed Nov 11, 2024
1 parent 2cd3cae commit 3127fe2
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 16 deletions.
10 changes: 7 additions & 3 deletions .github/workflows/ESP32.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ jobs:
cd esp-idf
./install.sh all
cd components
git clone https://github.com/cnadler86/esp32-camera
# latest_cam_driver=$(curl -s https://api.github.com/repos/espressif/esp32-camera/releases/latest | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
# git clone --depth 1 --branch $latest_tag https://github.com/espressif/esp32-camera.git
git clone https://github.com/cnadler86/esp32-camera.git
cd ~/esp-idf/
source ./export.sh
Expand Down Expand Up @@ -145,6 +147,8 @@ jobs:
# Build MicroPython for each board
- name: Build MicroPython
run: |
cd ~/esp-idf/components/esp32-camera
CAM_DRIVER=$(git describe --tags --always --dirty)
cd ~/micropython/ports/esp32
source ~/esp-idf/export.sh
Expand All @@ -153,9 +157,9 @@ jobs:
IFS='-' read -r BOARD_NAME BOARD_VARIANT <<< "${BUILD_TARGET}"
if [ -n "${BOARD_VARIANT}" ]; then
IDF_CMD="idf.py -D MICROPY_BOARD=$BOARD_NAME -D USER_C_MODULES=${{ github.workspace }}/src/micropython.cmake -D MICROPY_BOARD_VARIANT=$BOARD_VARIANT -B build-$BUILD_TARGET"
IDF_CMD="idf.py -D MICROPY_BOARD=$BOARD_NAME -D USER_C_MODULES=${{ github.workspace }}/src/micropython.cmake -D MICROPY_BOARD_VARIANT=$BOARD_VARIANT -B build-$BUILD_TARGET -D MP_CAMERA_DRIVER_VERSION=$CAM_DRIVER"
else
IDF_CMD="idf.py -D MICROPY_BOARD=$BOARD_NAME -D USER_C_MODULES=${{ github.workspace }}/src/micropython.cmake -B build-$BUILD_TARGET"
IDF_CMD="idf.py -D MICROPY_BOARD=$BOARD_NAME -D USER_C_MODULES=${{ github.workspace }}/src/micropython.cmake -B build-$BUILD_TARGET -D MP_CAMERA_DRIVER_VERSION=$CAM_DRIVER"
fi
if [ -n "${CAMERA_MODEL}" ]; then
echo "FW_NAME=${CAMERA_MODEL}" >> $GITHUB_ENV
Expand Down
4 changes: 4 additions & 0 deletions src/micropython.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ if (MICROPY_CAMERA_MODEL)
target_compile_definitions(usermod_mp_camera INTERFACE MICROPY_CAMERA_MODEL_${MICROPY_CAMERA_MODEL}=1)
endif()

if (MP_CAMERA_DRIVER_VERSION)
target_compile_definitions(usermod_mp_camera INTERFACE MP_CAMERA_DRIVER_VERSION=${MP_CAMERA_DRIVER_VERSION})
endif()

target_link_libraries(usermod INTERFACE usermod_mp_camera)

micropy_gather_target_properties(usermod_mp_camera)
3 changes: 3 additions & 0 deletions src/modcamera_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,9 @@ static const mp_rom_map_elem_t camera_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR_FrameSize), MP_ROM_PTR(&mp_camera_frame_size_type) },
{ MP_ROM_QSTR(MP_QSTR_GainCeiling), MP_ROM_PTR(&mp_camera_gainceiling_type) },
{ MP_ROM_QSTR(MP_QSTR_GrabMode), MP_ROM_PTR(&mp_camera_grab_mode_type) },
#ifdef MP_CAMERA_DRIVER_VERSION
{ MP_ROM_QSTR(MP_QSTR_Version), MP_ROM_QSTR(MP_CAMERA_DRIVER_VERSION) },
#endif
};
static MP_DEFINE_CONST_DICT(camera_module_globals, camera_module_globals_table);

Expand Down
32 changes: 19 additions & 13 deletions tests/esp32_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import time
from camera import Camera, FrameSize, PixelFormat

def test_property_get_frame_size():
with Camera() as cam:
Expand All @@ -12,28 +13,33 @@ def test_property_get_frame_size():
def test_property_get_pixel_format():
with Camera() as cam:
print("Test pixel format")
Pixel_Format = PixelFormat.RGB565
cam.reconfigure(pixel_format=Pixel_Format)
assert cam.get_pixel_format() == Pixel_Format
for Pixel_Format_Name in dir(PixelFormat):
Pixel_Format = getattr(PixelFormat, Pixel_Format_Name)
try:
if Pixel_Format_Name.startswith("_") or Pixel_Format_Name.startswith("RGB888"):
continue
cam.reconfigure(pixel_format=Pixel_Format)
assert cam.get_pixel_format() == Pixel_Format
except Exception:
print("\tFailed test for pixel format", Pixel_Format)

def test_must_be_initialized():
with Camera(init=False) as cam:
print(f"Testing get/set methods wothout initalization")
for name in dir(cam):
if name.startswith('get_') or name.startswith('set_'):
method = getattr(cam, name)
try:
method()
print("\tFailed test for method", name)
except Exception:
print(f"Testing capture without initalization")
try:
cam.capture()
assert False, "Capture should have failed"
except Exception as e:
if e == "Camera not initialized":
assert False, "Capture should have failed"
else:
assert True

def test_camera_properties():
with Camera() as cam:
print(f"Testing get/set methods")
for name in dir(cam):
if name.startswith('get_'):

prop_name = name[4:]
set_method_name = f'set_{prop_name}'
if hasattr(cam, set_method_name):
Expand Down Expand Up @@ -68,9 +74,9 @@ def test_invalid_settings():
time.sleep_ms(Delay)

if __name__ == "__main__":
from camera import Camera, FrameSize, PixelFormat
test_property_get_frame_size()
test_property_get_pixel_format()
test_must_be_initialized()
test_camera_properties()
test_invalid_settings()

0 comments on commit 3127fe2

Please sign in to comment.