Skip to content

Commit 8bdbe03

Browse files
committed
Add more getters
1 parent badcae5 commit 8bdbe03

File tree

3 files changed

+131
-0
lines changed

3 files changed

+131
-0
lines changed

ports/espressif/bindings/esp32_camera/Camera.c

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -816,9 +816,91 @@ MP_PROPERTY_GETSET(esp32_camera_camera_lenc_obj,
816816
(mp_obj_t)&esp32_camera_camera_get_lenc_obj,
817817
(mp_obj_t)&esp32_camera_camera_set_lenc_obj);
818818

819+
//| max_frame_size: FrameSize
820+
//| """The maximum frame size that can be captured"""
821+
//|
822+
STATIC mp_obj_t esp32_camera_camera_get_max_frame_size(const mp_obj_t self_in) {
823+
esp32_camera_camera_obj_t *self = MP_OBJ_TO_PTR(self_in);
824+
check_for_deinit(self);
825+
return cp_enum_find(&esp32_camera_frame_size_type, common_hal_esp32_camera_camera_get_max_frame_size(self));
826+
}
827+
STATIC MP_DEFINE_CONST_FUN_OBJ_1(esp32_camera_camera_get_max_frame_size_obj, esp32_camera_camera_get_max_frame_size);
828+
829+
MP_PROPERTY_GETTER(esp32_camera_camera_max_frame_size_obj,
830+
(mp_obj_t)&esp32_camera_camera_get_max_frame_size_obj);
831+
832+
833+
//| address: int
834+
//| """The I2C (SCCB) address of the sensor"""
835+
//|
836+
STATIC mp_obj_t esp32_camera_camera_get_address(const mp_obj_t self_in) {
837+
esp32_camera_camera_obj_t *self = MP_OBJ_TO_PTR(self_in);
838+
check_for_deinit(self);
839+
return MP_OBJ_NEW_SMALL_INT(common_hal_esp32_camera_camera_get_address(self));
840+
}
841+
STATIC MP_DEFINE_CONST_FUN_OBJ_1(esp32_camera_camera_get_address_obj, esp32_camera_camera_get_address);
842+
843+
MP_PROPERTY_GETTER(esp32_camera_camera_address_obj,
844+
(mp_obj_t)&esp32_camera_camera_get_address_obj);
845+
846+
847+
//| sensor_name: str
848+
//| """The name of the sensor"""
849+
//|
850+
STATIC mp_obj_t esp32_camera_camera_get_sensor_name(const mp_obj_t self_in) {
851+
esp32_camera_camera_obj_t *self = MP_OBJ_TO_PTR(self_in);
852+
check_for_deinit(self);
853+
const char *sensor_name = common_hal_esp32_camera_camera_get_sensor_name(self);
854+
return mp_obj_new_str(sensor_name, strlen(sensor_name));
855+
}
856+
STATIC MP_DEFINE_CONST_FUN_OBJ_1(esp32_camera_camera_get_sensor_name_obj, esp32_camera_camera_get_sensor_name);
857+
858+
MP_PROPERTY_GETTER(esp32_camera_camera_sensor_name_obj,
859+
(mp_obj_t)&esp32_camera_camera_get_sensor_name_obj);
860+
861+
862+
//| supports_jpeg: bool
863+
//| """True if the sensor can capture images in JPEG format"""
864+
//|
865+
STATIC mp_obj_t esp32_camera_camera_get_supports_jpeg(const mp_obj_t self_in) {
866+
esp32_camera_camera_obj_t *self = MP_OBJ_TO_PTR(self_in);
867+
check_for_deinit(self);
868+
return mp_obj_new_bool(common_hal_esp32_camera_camera_get_supports_jpeg(self));
869+
}
870+
STATIC MP_DEFINE_CONST_FUN_OBJ_1(esp32_camera_camera_get_supports_jpeg_obj, esp32_camera_camera_get_supports_jpeg);
871+
872+
MP_PROPERTY_GETTER(esp32_camera_camera_supports_jpeg_obj,
873+
(mp_obj_t)&esp32_camera_camera_get_supports_jpeg_obj);
874+
875+
//| height: int
876+
//| """The height of the image being captured"""
877+
//|
878+
STATIC mp_obj_t esp32_camera_camera_get_height(const mp_obj_t self_in) {
879+
esp32_camera_camera_obj_t *self = MP_OBJ_TO_PTR(self_in);
880+
check_for_deinit(self);
881+
return MP_OBJ_NEW_SMALL_INT(common_hal_esp32_camera_camera_get_height(self));
882+
}
883+
STATIC MP_DEFINE_CONST_FUN_OBJ_1(esp32_camera_camera_get_height_obj, esp32_camera_camera_get_height);
884+
885+
MP_PROPERTY_GETTER(esp32_camera_camera_height_obj,
886+
(mp_obj_t)&esp32_camera_camera_get_height_obj);
887+
888+
//| width: int
889+
//| """The width of the image being captured"""
890+
//|
891+
STATIC mp_obj_t esp32_camera_camera_get_width(const mp_obj_t self_in) {
892+
esp32_camera_camera_obj_t *self = MP_OBJ_TO_PTR(self_in);
893+
check_for_deinit(self);
894+
return MP_OBJ_NEW_SMALL_INT(common_hal_esp32_camera_camera_get_width(self));
895+
}
896+
STATIC MP_DEFINE_CONST_FUN_OBJ_1(esp32_camera_camera_get_width_obj, esp32_camera_camera_get_width);
897+
898+
MP_PROPERTY_GETTER(esp32_camera_camera_width_obj,
899+
(mp_obj_t)&esp32_camera_camera_get_width_obj);
819900

820901

821902
STATIC const mp_rom_map_elem_t esp32_camera_camera_locals_table[] = {
903+
{ MP_ROM_QSTR(MP_QSTR_address), MP_ROM_PTR(&esp32_camera_camera_address_obj) },
822904
{ MP_ROM_QSTR(MP_QSTR_aec2), MP_ROM_PTR(&esp32_camera_camera_aec2_obj) },
823905
{ MP_ROM_QSTR(MP_QSTR_aec_value), MP_ROM_PTR(&esp32_camera_camera_aec_value_obj) },
824906
{ MP_ROM_QSTR(MP_QSTR_ae_level), MP_ROM_PTR(&esp32_camera_camera_ae_level_obj) },
@@ -838,17 +920,22 @@ STATIC const mp_rom_map_elem_t esp32_camera_camera_locals_table[] = {
838920
{ MP_ROM_QSTR(MP_QSTR_frame_size), MP_ROM_PTR(&esp32_camera_camera_frame_size_obj) },
839921
{ MP_ROM_QSTR(MP_QSTR_gain_ceiling), MP_ROM_PTR(&esp32_camera_camera_gain_ceiling_obj) },
840922
{ MP_ROM_QSTR(MP_QSTR_gain_ctrl), MP_ROM_PTR(&esp32_camera_camera_gain_ctrl_obj) },
923+
{ MP_ROM_QSTR(MP_QSTR_height), MP_ROM_PTR(&esp32_camera_camera_height_obj) },
841924
{ MP_ROM_QSTR(MP_QSTR_hmirror), MP_ROM_PTR(&esp32_camera_camera_hmirror_obj) },
842925
{ MP_ROM_QSTR(MP_QSTR_lenc), MP_ROM_PTR(&esp32_camera_camera_lenc_obj) },
926+
{ MP_ROM_QSTR(MP_QSTR_max_frame_size), MP_ROM_PTR(&esp32_camera_camera_max_frame_size_obj) },
843927
{ MP_ROM_QSTR(MP_QSTR_pixel_format), MP_ROM_PTR(&esp32_camera_camera_pixel_format_obj) },
844928
{ MP_ROM_QSTR(MP_QSTR_quality), MP_ROM_PTR(&esp32_camera_camera_quality_obj) },
845929
{ MP_ROM_QSTR(MP_QSTR_raw_gma), MP_ROM_PTR(&esp32_camera_camera_raw_gma_obj) },
846930
{ MP_ROM_QSTR(MP_QSTR_saturation), MP_ROM_PTR(&esp32_camera_camera_saturation_obj) },
931+
{ MP_ROM_QSTR(MP_QSTR_sensor_name), MP_ROM_PTR(&esp32_camera_camera_sensor_name_obj) },
847932
{ MP_ROM_QSTR(MP_QSTR_sharpness), MP_ROM_PTR(&esp32_camera_camera_sharpness_obj) },
848933
{ MP_ROM_QSTR(MP_QSTR_special_effect), MP_ROM_PTR(&esp32_camera_camera_special_effect_obj) },
934+
{ MP_ROM_QSTR(MP_QSTR_supports_jpeg), MP_ROM_PTR(&esp32_camera_camera_supports_jpeg_obj) },
849935
{ MP_ROM_QSTR(MP_QSTR_take), MP_ROM_PTR(&esp32_camera_camera_take_obj) },
850936
{ MP_ROM_QSTR(MP_QSTR_vflip), MP_ROM_PTR(&esp32_camera_camera_vflip_obj) },
851937
{ MP_ROM_QSTR(MP_QSTR_wb_mode), MP_ROM_PTR(&esp32_camera_camera_wb_mode_obj) },
938+
{ MP_ROM_QSTR(MP_QSTR_width), MP_ROM_PTR(&esp32_camera_camera_width_obj) },
852939
{ MP_ROM_QSTR(MP_QSTR_whitebal), MP_ROM_PTR(&esp32_camera_camera_whitebal_obj) },
853940
{ MP_ROM_QSTR(MP_QSTR_wpc), MP_ROM_PTR(&esp32_camera_camera_wpc_obj) },
854941
};

ports/espressif/bindings/esp32_camera/Camera.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,11 @@ DECLARE_SENSOR_STATUS_GETSET(bool, bpc, bpc, set_bpc);
9898
DECLARE_SENSOR_STATUS_GETSET(bool, wpc, wpc, set_wpc);
9999
DECLARE_SENSOR_STATUS_GETSET(bool, raw_gma, raw_gma, set_raw_gma);
100100
DECLARE_SENSOR_STATUS_GETSET(bool, lenc, lenc, set_lenc);
101+
102+
// From camera_sensor_info_t
103+
extern int common_hal_esp32_camera_camera_get_address(esp32_camera_camera_obj_t *self);
104+
extern const char *common_hal_esp32_camera_camera_get_sensor_name(esp32_camera_camera_obj_t *self);
105+
extern const bool common_hal_esp32_camera_camera_get_supports_jpeg(esp32_camera_camera_obj_t *self);
106+
extern framesize_t common_hal_esp32_camera_camera_get_max_frame_size(esp32_camera_camera_obj_t *self);
107+
extern int common_hal_esp32_camera_camera_get_width(esp32_camera_camera_obj_t *self);
108+
extern int common_hal_esp32_camera_camera_get_height(esp32_camera_camera_obj_t *self);

ports/espressif/common-hal/esp32_camera/Camera.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,3 +199,39 @@ SENSOR_STATUS_GETSET(bool, bpc, bpc, set_bpc);
199199
SENSOR_STATUS_GETSET(bool, wpc, wpc, set_wpc);
200200
SENSOR_STATUS_GETSET(bool, raw_gma, raw_gma, set_raw_gma);
201201
SENSOR_STATUS_GETSET(bool, lenc, lenc, set_lenc);
202+
203+
const char *common_hal_esp32_camera_camera_get_sensor_name(esp32_camera_camera_obj_t *self) {
204+
sensor_t *sensor = esp_camera_sensor_get();
205+
camera_sensor_info_t *sensor_info = esp_camera_sensor_get_info(&sensor->id);
206+
return sensor_info->name;
207+
}
208+
209+
const bool common_hal_esp32_camera_camera_get_supports_jpeg(esp32_camera_camera_obj_t *self) {
210+
sensor_t *sensor = esp_camera_sensor_get();
211+
camera_sensor_info_t *sensor_info = esp_camera_sensor_get_info(&sensor->id);
212+
return sensor_info->support_jpeg;
213+
}
214+
215+
const framesize_t common_hal_esp32_camera_camera_get_max_frame_size(esp32_camera_camera_obj_t *self) {
216+
sensor_t *sensor = esp_camera_sensor_get();
217+
camera_sensor_info_t *sensor_info = esp_camera_sensor_get_info(&sensor->id);
218+
return sensor_info->max_size;
219+
}
220+
221+
const int common_hal_esp32_camera_camera_get_address(esp32_camera_camera_obj_t *self) {
222+
sensor_t *sensor = esp_camera_sensor_get();
223+
camera_sensor_info_t *sensor_info = esp_camera_sensor_get_info(&sensor->id);
224+
return sensor_info->sccb_addr;
225+
}
226+
227+
const int common_hal_esp32_camera_camera_get_width(esp32_camera_camera_obj_t *self) {
228+
sensor_t *sensor = esp_camera_sensor_get();
229+
framesize_t framesize = sensor->status.framesize;
230+
return resolution[framesize].width;
231+
}
232+
233+
const int common_hal_esp32_camera_camera_get_height(esp32_camera_camera_obj_t *self) {
234+
sensor_t *sensor = esp_camera_sensor_get();
235+
framesize_t framesize = sensor->status.framesize;
236+
return resolution[framesize].height;
237+
}

0 commit comments

Comments
 (0)