From 16b2bfb0dbd7206656f3c4af6867c10bb9db4466 Mon Sep 17 00:00:00 2001 From: Christopher Nadler Date: Tue, 16 Dec 2025 07:00:32 +0100 Subject: [PATCH 1/4] Refactors camera API examples and documentation to use properties over get/set methods Enhances typings for better autocompletion. Fixed missing acamera module Fixed missing sentinel in property setter --- README.md | 14 ++++++---- examples/CameraSettings.html | 51 +++++++++++++++++++++++++++++++----- examples/CameraSettings.py | 28 +++++++++++--------- manifest.py | 2 +- micropython.cmake | 2 -- src/modcamera_api.c | 7 ++++- typings/acamera.pyi | 5 +++- 7 files changed, 81 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index aed81aa..782a921 100644 --- a/README.md +++ b/README.md @@ -130,10 +130,14 @@ The following keyword arguments have default values: ### Initializing the camera +The camera initializes when constructing the camera object per default. If you set init=False during construction, you need to call the init method manually: + ```python cam.init() ``` +Note that most of the camera seeting can only be set or aquired after initialization. + ### Capture image The general way of capturing an image is calling the `capture` method: @@ -192,14 +196,14 @@ This gives you the possibility of creating an asynchronous application without u Here are just a few examples: ```python -cam.set_quality(90) # The quality goes from 0% to 100%, meaning 100% is the highest but has probably no compression -camera.get_brightness() -camera.set_vflip(True) #Enable vertical flip +cam.quality = 90 # The quality goes from 0% to 100%, meaning 100% is the highest but has probably no compression +print("cam.brightness =", cam.brightness) +camera.vflip = True #Enable vertical flip ``` See autocompletions in Thonny in order to see the list of methods. If you want more insights in the methods and what they actually do, you can find a very good documentation [here](https://docs.circuitpython.org/en/latest/shared-bindings/espcamera/index.html). -Note that each method requires a "get_" or "set_" prefix, depending on the desired action. +Note: "get_" and "set_" prefixed methods are deprecated. Take also a look in the examples folder. @@ -233,7 +237,7 @@ print(f"I2C devices found: {devices}") i2c.writeto(0x42, b'\x00\x01') # Write to another device # Camera sensor communication works too -cam.set_saturation(1) # Uses the shared I2C bus +cam.saturation = 1 # Uses the shared I2C bus ``` #### Alternative: Camera Creates Its Own I2C (Default) diff --git a/examples/CameraSettings.html b/examples/CameraSettings.html index e392005..08fe595 100644 --- a/examples/CameraSettings.html +++ b/examples/CameraSettings.html @@ -3,33 +3,45 @@ Micropython Camera Stream