8#include <freertos/task.h>
11namespace esp32_camera {
13static const char *
const TAG =
"esp32_camera";
27 esp_err_t err = esp_camera_init(&this->
config_);
29 ESP_LOGE(TAG,
"esp_camera_init failed: %s", esp_err_to_name(err));
57 " Data Pins: D0:%d D1:%d D2:%d D3:%d D4:%d D5:%d D6:%d D7:%d\n"
60 " Pixel Clock Pin: %d\n"
61 " External Clock: Pin:%d Frequency:%u\n"
62 " I2C Pins: SDA:%d SCL:%d\n"
65 conf.pin_d4, conf.pin_d5, conf.pin_d6, conf.pin_d7, conf.pin_vsync, conf.pin_href, conf.pin_pclk,
66 conf.pin_xclk, conf.xclk_freq_hz, conf.pin_sccb_sda, conf.pin_sccb_scl, conf.pin_reset);
67 switch (this->
config_.frame_size) {
69 ESP_LOGCONFIG(TAG,
" Resolution: 160x120 (QQVGA)");
72 ESP_LOGCONFIG(TAG,
" Resolution: 176x155 (QCIF)");
75 ESP_LOGCONFIG(TAG,
" Resolution: 240x176 (HQVGA)");
78 ESP_LOGCONFIG(TAG,
" Resolution: 320x240 (QVGA)");
81 ESP_LOGCONFIG(TAG,
" Resolution: 400x296 (CIF)");
84 ESP_LOGCONFIG(TAG,
" Resolution: 640x480 (VGA)");
87 ESP_LOGCONFIG(TAG,
" Resolution: 800x600 (SVGA)");
90 ESP_LOGCONFIG(TAG,
" Resolution: 1024x768 (XGA)");
93 ESP_LOGCONFIG(TAG,
" Resolution: 1280x1024 (SXGA)");
96 ESP_LOGCONFIG(TAG,
" Resolution: 1600x1200 (UXGA)");
99 ESP_LOGCONFIG(TAG,
" Resolution: 1920x1080 (FHD)");
102 ESP_LOGCONFIG(TAG,
" Resolution: 720x1280 (P_HD)");
104 case FRAMESIZE_P_3MP:
105 ESP_LOGCONFIG(TAG,
" Resolution: 864x1536 (P_3MP)");
108 ESP_LOGCONFIG(TAG,
" Resolution: 2048x1536 (QXGA)");
111 ESP_LOGCONFIG(TAG,
" Resolution: 2560x1440 (QHD)");
113 case FRAMESIZE_WQXGA:
114 ESP_LOGCONFIG(TAG,
" Resolution: 2560x1600 (WQXGA)");
116 case FRAMESIZE_P_FHD:
117 ESP_LOGCONFIG(TAG,
" Resolution: 1080x1920 (P_FHD)");
119 case FRAMESIZE_QSXGA:
120 ESP_LOGCONFIG(TAG,
" Resolution: 2560x1920 (QSXGA)");
127 ESP_LOGE(TAG,
" Setup Failed: %s", esp_err_to_name(this->
init_error_));
131 sensor_t *s = esp_camera_sensor_get();
134 " JPEG Quality: %u\n"
135 " Framebuffer Count: %u\n"
136 " Framebuffer Location: %s\n"
140 " Vertical Flip: %s\n"
141 " Horizontal Mirror: %s\n"
142 " Special Effect: %u\n"
143 " White Balance Mode: %u",
144 st.quality, conf.fb_count, this->config_.fb_location == CAMERA_FB_IN_PSRAM ?
"PSRAM" :
"DRAM",
145 st.contrast, st.brightness, st.saturation, ONOFF(st.vflip), ONOFF(st.hmirror), st.special_effect,
150 " Auto Exposure Control: %u\n"
151 " Auto Exposure Control 2: %u\n"
152 " Auto Exposure Level: %d\n"
153 " Auto Exposure Value: %u\n"
157 st.aec, st.aec2, st.ae_level, st.aec_value, st.agc, st.agc_gain, st.gainceiling);
163 ESP_LOGCONFIG(TAG,
" Test Pattern: %s", YESNO(st.colorbar));
196 ESP_LOGVV(TAG,
"No frame ready");
201 ESP_LOGW(TAG,
"Got invalid frame from camera!");
207 ESP_LOGD(TAG,
"Got Image: len=%u", fb->len);
220 this->
config_.ledc_timer = LEDC_TIMER_0;
221 this->
config_.ledc_channel = LEDC_CHANNEL_0;
222 this->
config_.pixel_format = PIXFORMAT_JPEG;
223 this->
config_.frame_size = FRAMESIZE_VGA;
224 this->
config_.jpeg_quality = 10;
226 this->
config_.grab_mode = CAMERA_GRAB_WHEN_EMPTY;
227 this->
config_.fb_location = CAMERA_FB_IN_PSRAM;
233 this->
config_.pin_d0 = pins[0];
234 this->
config_.pin_d1 = pins[1];
235 this->
config_.pin_d2 = pins[2];
236 this->
config_.pin_d3 = pins[3];
237 this->
config_.pin_d4 = pins[4];
238 this->
config_.pin_d5 = pins[5];
239 this->
config_.pin_d6 = pins[6];
240 this->
config_.pin_d7 = pins[7];
250 this->
config_.pin_sccb_sda = sda;
251 this->
config_.pin_sccb_scl = scl;
256 this->
config_.pin_sccb_sda = -1;
257 this->
config_.pin_sccb_scl = -1;
267 this->
config_.frame_size = FRAMESIZE_QQVGA;
270 this->
config_.frame_size = FRAMESIZE_QCIF;
273 this->
config_.frame_size = FRAMESIZE_HQVGA;
276 this->
config_.frame_size = FRAMESIZE_QVGA;
279 this->
config_.frame_size = FRAMESIZE_CIF;
282 this->
config_.frame_size = FRAMESIZE_VGA;
285 this->
config_.frame_size = FRAMESIZE_SVGA;
288 this->
config_.frame_size = FRAMESIZE_XGA;
291 this->
config_.frame_size = FRAMESIZE_SXGA;
294 this->
config_.frame_size = FRAMESIZE_UXGA;
297 this->
config_.frame_size = FRAMESIZE_FHD;
300 this->
config_.frame_size = FRAMESIZE_P_HD;
303 this->
config_.frame_size = FRAMESIZE_P_3MP;
306 this->
config_.frame_size = FRAMESIZE_QXGA;
309 this->
config_.frame_size = FRAMESIZE_QHD;
312 this->
config_.frame_size = FRAMESIZE_WQXGA;
315 this->
config_.frame_size = FRAMESIZE_P_FHD;
318 this->
config_.frame_size = FRAMESIZE_QSXGA;
352 this->
config_.fb_count = fb_count;
356 this->
config_.fb_location = fb_location;
380 sensor_t *s = esp_camera_sensor_get();
389 s->set_exposure_ctrl(s, (
bool) this->
aec_mode_);
390 s->set_aec2(s, this->
aec2_);
394 s->set_gain_ctrl(s, (
bool) this->
agc_mode_);
398 s->set_wb_mode(s, (
int) this->
wb_mode_);
409 camera_fb_t *framebuffer = esp_camera_fb_get();
413 esp_camera_fb_return(framebuffer);
419 this->
image_ = std::static_pointer_cast<ESP32CameraImage>(image);
434 : buffer_(buffer), requesters_(requesters) {}
440 return (this->
requesters_ & (1 << requester)) != 0;
BedjetMode mode
BedJet operating mode.
uint32_t IRAM_ATTR HOT get_loop_component_start_time() const
Get the cached time in milliseconds from when the current component started its loop execution.
virtual void mark_failed()
Mark this component as failed.
constexpr const char * c_str() const
Abstract image reader base class.
void set_i2c_pins(uint8_t sda, uint8_t scl)
void set_agc_value(uint8_t agc_value)
void set_test_pattern(bool test_pattern)
void set_jpeg_quality(uint8_t quality)
void set_wb_mode(ESP32WhiteBalanceMode mode)
ESP32AgcGainCeiling agc_gain_ceiling_
void set_vertical_flip(bool vertical_flip)
void set_aec_value(uint32_t aec_value)
QueueHandle_t framebuffer_return_queue_
void set_contrast(int contrast)
CallbackManager< void(std::shared_ptr< camera::CameraImage >)> new_image_callback_
void set_special_effect(ESP32SpecialEffect effect)
void set_aec_mode(ESP32GainControlMode mode)
QueueHandle_t framebuffer_get_queue_
uint32_t last_idle_request_
CallbackManager< void()> stream_stop_callback_
float get_setup_priority() const override
uint8_t stream_requesters_
void set_data_pins(std::array< uint8_t, 8 > pins)
void stop_stream(camera::CameraRequester requester) override
void add_stream_start_callback(std::function< void()> &&callback)
void set_i2c_id(i2c::InternalI2CBus *i2c_bus)
ESP32GainControlMode agc_mode_
ESP32WhiteBalanceMode wb_mode_
void set_pixel_clock_pin(uint8_t pin)
void set_frame_size(ESP32CameraFrameSize size)
void set_brightness(int brightness)
void set_external_clock(uint8_t pin, uint32_t frequency)
uint32_t idle_update_interval_
bool has_requested_image_() const
bool can_return_image_() const
void set_vsync_pin(uint8_t pin)
void set_ae_level(int ae_level)
void set_max_update_interval(uint32_t max_update_interval)
std::shared_ptr< ESP32CameraImage > current_image_
void add_image_callback(std::function< void(std::shared_ptr< camera::CameraImage >)> &&callback) override
void add_stream_stop_callback(std::function< void()> &&callback)
uint32_t max_update_interval_
ESP32GainControlMode aec_mode_
void set_horizontal_mirror(bool horizontal_mirror)
void dump_config() override
camera::CameraImageReader * create_image_reader() override
void set_frame_buffer_count(uint8_t fb_count)
ESP32SpecialEffect special_effect_
uint8_t single_requesters_
void set_agc_gain_ceiling(ESP32AgcGainCeiling gain_ceiling)
void set_saturation(int saturation)
void set_href_pin(uint8_t pin)
void set_agc_mode(ESP32GainControlMode mode)
void set_frame_buffer_location(camera_fb_location_t fb_location)
void set_frame_buffer_mode(camera_grab_mode_t mode)
i2c::InternalI2CBus * i2c_bus_
void set_idle_update_interval(uint32_t idle_update_interval)
CallbackManager< void()> stream_start_callback_
void set_reset_pin(uint8_t pin)
void update_camera_parameters()
void start_stream(camera::CameraRequester requester) override
void set_power_down_pin(uint8_t pin)
void request_image(camera::CameraRequester requester) override
static void framebuffer_task(void *pv)
size_t get_data_length() override
bool was_requested_by(camera::CameraRequester requester) const override
camera_fb_t * get_raw_buffer()
uint8_t * get_data_buffer() override
ESP32CameraImage(camera_fb_t *buffer, uint8_t requester)
void return_image() override
void set_image(std::shared_ptr< camera::CameraImage > image) override
size_t available() const override
uint8_t * peek_data_buffer() override
std::shared_ptr< ESP32CameraImage > image_
void consume_data(size_t consumed) override
virtual int get_port() const =0
Returns the I2C port number.
CameraRequester
Different sources for filtering.
@ ESP32_CAMERA_SIZE_240X176
@ ESP32_CAMERA_SIZE_640X480
@ ESP32_CAMERA_SIZE_1600X1200
@ ESP32_CAMERA_SIZE_2560X1600
@ ESP32_CAMERA_SIZE_160X120
@ ESP32_CAMERA_SIZE_400X296
@ ESP32_CAMERA_SIZE_176X144
@ ESP32_CAMERA_SIZE_1280X1024
@ ESP32_CAMERA_SIZE_320X240
@ ESP32_CAMERA_SIZE_2560X1440
@ ESP32_CAMERA_SIZE_720X1280
@ ESP32_CAMERA_SIZE_2048X1536
@ ESP32_CAMERA_SIZE_2560X1920
@ ESP32_CAMERA_SIZE_800X600
@ ESP32_CAMERA_SIZE_1080X1920
@ ESP32_CAMERA_SIZE_1920X1080
@ ESP32_CAMERA_SIZE_1024X768
@ ESP32_CAMERA_SIZE_864X1536
const float DATA
For components that import data from directly connected sensors like DHT.
Providing packet encoding functions for exchanging data with a remote host.
uint32_t IRAM_ATTR HOT millis()
Application App
Global storage of Application pointer - only one Application can exist.