8#include <freertos/task.h>
11namespace esp32_camera {
13static const char *
const TAG =
"esp32_camera";
14static constexpr size_t FRAMEBUFFER_TASK_STACK_SIZE = 1792;
15#if ESPHOME_LOG_LEVEL < ESPHOME_LOG_LEVEL_VERBOSE
16static constexpr uint32_t FRAME_LOG_INTERVAL_MS = 60000;
31 esp_err_t err = esp_camera_init(&this->
config_);
33 ESP_LOGE(TAG,
"esp_camera_init failed: %s", esp_err_to_name(err));
47 FRAMEBUFFER_TASK_STACK_SIZE,
61 " Data Pins: D0:%d D1:%d D2:%d D3:%d D4:%d D5:%d D6:%d D7:%d\n"
64 " Pixel Clock Pin: %d\n"
65 " External Clock: Pin:%d Frequency:%u\n"
66 " I2C Pins: SDA:%d SCL:%d\n"
69 conf.pin_d4, conf.pin_d5, conf.pin_d6, conf.pin_d7, conf.pin_vsync, conf.pin_href, conf.pin_pclk,
70 conf.pin_xclk, conf.xclk_freq_hz, conf.pin_sccb_sda, conf.pin_sccb_scl, conf.pin_reset);
71 switch (this->
config_.frame_size) {
73 ESP_LOGCONFIG(TAG,
" Resolution: 160x120 (QQVGA)");
76 ESP_LOGCONFIG(TAG,
" Resolution: 176x155 (QCIF)");
79 ESP_LOGCONFIG(TAG,
" Resolution: 240x176 (HQVGA)");
82 ESP_LOGCONFIG(TAG,
" Resolution: 320x240 (QVGA)");
85 ESP_LOGCONFIG(TAG,
" Resolution: 400x296 (CIF)");
88 ESP_LOGCONFIG(TAG,
" Resolution: 640x480 (VGA)");
91 ESP_LOGCONFIG(TAG,
" Resolution: 800x600 (SVGA)");
94 ESP_LOGCONFIG(TAG,
" Resolution: 1024x768 (XGA)");
97 ESP_LOGCONFIG(TAG,
" Resolution: 1280x1024 (SXGA)");
100 ESP_LOGCONFIG(TAG,
" Resolution: 1600x1200 (UXGA)");
103 ESP_LOGCONFIG(TAG,
" Resolution: 1920x1080 (FHD)");
106 ESP_LOGCONFIG(TAG,
" Resolution: 720x1280 (P_HD)");
108 case FRAMESIZE_P_3MP:
109 ESP_LOGCONFIG(TAG,
" Resolution: 864x1536 (P_3MP)");
112 ESP_LOGCONFIG(TAG,
" Resolution: 2048x1536 (QXGA)");
115 ESP_LOGCONFIG(TAG,
" Resolution: 2560x1440 (QHD)");
117 case FRAMESIZE_WQXGA:
118 ESP_LOGCONFIG(TAG,
" Resolution: 2560x1600 (WQXGA)");
120 case FRAMESIZE_P_FHD:
121 ESP_LOGCONFIG(TAG,
" Resolution: 1080x1920 (P_FHD)");
123 case FRAMESIZE_QSXGA:
124 ESP_LOGCONFIG(TAG,
" Resolution: 2560x1920 (QSXGA)");
131 ESP_LOGE(TAG,
" Setup Failed: %s", esp_err_to_name(this->
init_error_));
135 sensor_t *s = esp_camera_sensor_get();
138 " JPEG Quality: %u\n"
139 " Framebuffer Count: %u\n"
140 " Framebuffer Location: %s\n"
144 " Vertical Flip: %s\n"
145 " Horizontal Mirror: %s\n"
146 " Special Effect: %u\n"
147 " White Balance Mode: %u",
148 st.quality, conf.fb_count, this->config_.fb_location == CAMERA_FB_IN_PSRAM ?
"PSRAM" :
"DRAM",
149 st.contrast, st.brightness, st.saturation, ONOFF(st.vflip), ONOFF(st.hmirror), st.special_effect,
154 " Auto Exposure Control: %u\n"
155 " Auto Exposure Control 2: %u\n"
156 " Auto Exposure Level: %d\n"
157 " Auto Exposure Value: %u\n"
161 st.aec, st.aec2, st.ae_level, st.aec_value, st.agc, st.agc_gain, st.gainceiling);
167 ESP_LOGCONFIG(TAG,
" Test Pattern: %s", YESNO(st.colorbar));
206 ESP_LOGVV(TAG,
"No frame ready");
211 ESP_LOGW(TAG,
"Got invalid frame from camera!");
217#if ESPHOME_LOG_LEVEL >= ESPHOME_LOG_LEVEL_VERBOSE
218 ESP_LOGV(TAG,
"Got Image: len=%u", fb->len);
226 ESP_LOGD(TAG,
"Received %u images in last %us", this->
frame_count_, FRAME_LOG_INTERVAL_MS / 1000);
245 this->
config_.ledc_timer = LEDC_TIMER_0;
246 this->
config_.ledc_channel = LEDC_CHANNEL_0;
247 this->
config_.pixel_format = PIXFORMAT_JPEG;
248 this->
config_.frame_size = FRAMESIZE_VGA;
249 this->
config_.jpeg_quality = 10;
251 this->
config_.grab_mode = CAMERA_GRAB_WHEN_EMPTY;
252 this->
config_.fb_location = CAMERA_FB_IN_PSRAM;
258 this->
config_.pin_d0 = pins[0];
259 this->
config_.pin_d1 = pins[1];
260 this->
config_.pin_d2 = pins[2];
261 this->
config_.pin_d3 = pins[3];
262 this->
config_.pin_d4 = pins[4];
263 this->
config_.pin_d5 = pins[5];
264 this->
config_.pin_d6 = pins[6];
265 this->
config_.pin_d7 = pins[7];
275 this->
config_.pin_sccb_sda = sda;
276 this->
config_.pin_sccb_scl = scl;
281 this->
config_.pin_sccb_sda = -1;
282 this->
config_.pin_sccb_scl = -1;
292 this->
config_.frame_size = FRAMESIZE_QQVGA;
295 this->
config_.frame_size = FRAMESIZE_QCIF;
298 this->
config_.frame_size = FRAMESIZE_HQVGA;
301 this->
config_.frame_size = FRAMESIZE_QVGA;
304 this->
config_.frame_size = FRAMESIZE_CIF;
307 this->
config_.frame_size = FRAMESIZE_VGA;
310 this->
config_.frame_size = FRAMESIZE_SVGA;
313 this->
config_.frame_size = FRAMESIZE_XGA;
316 this->
config_.frame_size = FRAMESIZE_SXGA;
319 this->
config_.frame_size = FRAMESIZE_UXGA;
322 this->
config_.frame_size = FRAMESIZE_FHD;
325 this->
config_.frame_size = FRAMESIZE_P_HD;
328 this->
config_.frame_size = FRAMESIZE_P_3MP;
331 this->
config_.frame_size = FRAMESIZE_QXGA;
334 this->
config_.frame_size = FRAMESIZE_QHD;
337 this->
config_.frame_size = FRAMESIZE_WQXGA;
340 this->
config_.frame_size = FRAMESIZE_P_FHD;
343 this->
config_.frame_size = FRAMESIZE_QSXGA;
377 this->
config_.fb_count = fb_count;
381 this->
config_.fb_location = fb_location;
387 listener->on_stream_start();
393 listener->on_stream_stop();
400 sensor_t *s = esp_camera_sensor_get();
409 s->set_exposure_ctrl(s, (
bool) this->
aec_mode_);
410 s->set_aec2(s, this->
aec2_);
414 s->set_gain_ctrl(s, (
bool) this->
agc_mode_);
418 s->set_wb_mode(s, (
int) this->
wb_mode_);
429 camera_fb_t *framebuffer = esp_camera_fb_get();
437 esp_camera_fb_return(framebuffer);
443 this->
image_ = std::static_pointer_cast<ESP32CameraImage>(image);
458 : buffer_(buffer), requesters_(requesters) {}
464 return (this->
requesters_ & (1 << requester)) != 0;
BedjetMode mode
BedJet operating mode.
void wake_loop_threadsafe()
Wake the main event loop from a FreeRTOS task Thread-safe, can be called from task context to immedia...
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)
void set_special_effect(ESP32SpecialEffect effect)
void set_aec_mode(ESP32GainControlMode mode)
QueueHandle_t framebuffer_get_queue_
uint32_t last_idle_request_
float get_setup_priority() const override
void set_data_pins(std::array< uint8_t, 8 > pins)
void stop_stream(camera::CameraRequester requester) override
std::vector< camera::CameraListener * > listeners_
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_
uint32_t max_update_interval_
ESP32GainControlMode aec_mode_
std::atomic< uint8_t > single_requesters_
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_
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)
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
std::atomic< uint8_t > stream_requesters_
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.