7 #include <freertos/task.h> 10 namespace esp32_camera {
12 static const char *
const TAG =
"esp32_camera";
22 esp_err_t err = esp_camera_init(&this->
config_);
24 ESP_LOGE(TAG,
"esp_camera_init failed: %s", esp_err_to_name(err));
48 ESP_LOGCONFIG(TAG,
"ESP32 Camera:");
49 ESP_LOGCONFIG(TAG,
" Name: %s", this->
name_.
c_str());
50 ESP_LOGCONFIG(TAG,
" Internal: %s", YESNO(this->
internal_));
51 ESP_LOGCONFIG(TAG,
" Data Pins: D0:%d D1:%d D2:%d D3:%d D4:%d D5:%d D6:%d D7:%d", conf.pin_d0, conf.pin_d1,
52 conf.pin_d2, conf.pin_d3, conf.pin_d4, conf.pin_d5, conf.pin_d6, conf.pin_d7);
53 ESP_LOGCONFIG(TAG,
" VSYNC Pin: %d", conf.pin_vsync);
54 ESP_LOGCONFIG(TAG,
" HREF Pin: %d", conf.pin_href);
55 ESP_LOGCONFIG(TAG,
" Pixel Clock Pin: %d", conf.pin_pclk);
56 ESP_LOGCONFIG(TAG,
" External Clock: Pin:%d Frequency:%u", conf.pin_xclk, conf.xclk_freq_hz);
57 #ifdef USE_ESP_IDF // Temporary until the espressif/esp32-camera library is updated 58 ESP_LOGCONFIG(TAG,
" I2C Pins: SDA:%d SCL:%d", conf.pin_sscb_sda, conf.pin_sscb_scl);
60 ESP_LOGCONFIG(TAG,
" I2C Pins: SDA:%d SCL:%d", conf.pin_sccb_sda, conf.pin_sccb_scl);
62 ESP_LOGCONFIG(TAG,
" Reset Pin: %d", conf.pin_reset);
63 switch (this->
config_.frame_size) {
65 ESP_LOGCONFIG(TAG,
" Resolution: 160x120 (QQVGA)");
68 ESP_LOGCONFIG(TAG,
" Resolution: 176x155 (QCIF)");
71 ESP_LOGCONFIG(TAG,
" Resolution: 240x176 (HQVGA)");
74 ESP_LOGCONFIG(TAG,
" Resolution: 320x240 (QVGA)");
77 ESP_LOGCONFIG(TAG,
" Resolution: 400x296 (CIF)");
80 ESP_LOGCONFIG(TAG,
" Resolution: 640x480 (VGA)");
83 ESP_LOGCONFIG(TAG,
" Resolution: 800x600 (SVGA)");
86 ESP_LOGCONFIG(TAG,
" Resolution: 1024x768 (XGA)");
89 ESP_LOGCONFIG(TAG,
" Resolution: 1280x1024 (SXGA)");
92 ESP_LOGCONFIG(TAG,
" Resolution: 1600x1200 (UXGA)");
95 ESP_LOGCONFIG(TAG,
" Resolution: 1920x1080 (FHD)");
98 ESP_LOGCONFIG(TAG,
" Resolution: 720x1280 (P_HD)");
100 case FRAMESIZE_P_3MP:
101 ESP_LOGCONFIG(TAG,
" Resolution: 864x1536 (P_3MP)");
104 ESP_LOGCONFIG(TAG,
" Resolution: 2048x1536 (QXGA)");
107 ESP_LOGCONFIG(TAG,
" Resolution: 2560x1440 (QHD)");
109 case FRAMESIZE_WQXGA:
110 ESP_LOGCONFIG(TAG,
" Resolution: 2560x1600 (WQXGA)");
112 case FRAMESIZE_P_FHD:
113 ESP_LOGCONFIG(TAG,
" Resolution: 1080x1920 (P_FHD)");
115 case FRAMESIZE_QSXGA:
116 ESP_LOGCONFIG(TAG,
" Resolution: 2560x1920 (QSXGA)");
123 ESP_LOGE(TAG,
" Setup Failed: %s", esp_err_to_name(this->
init_error_));
127 sensor_t *s = esp_camera_sensor_get();
129 ESP_LOGCONFIG(TAG,
" JPEG Quality: %u", st.quality);
130 ESP_LOGCONFIG(TAG,
" Framebuffer Count: %u", conf.fb_count);
131 ESP_LOGCONFIG(TAG,
" Contrast: %d", st.contrast);
132 ESP_LOGCONFIG(TAG,
" Brightness: %d", st.brightness);
133 ESP_LOGCONFIG(TAG,
" Saturation: %d", st.saturation);
134 ESP_LOGCONFIG(TAG,
" Vertical Flip: %s", ONOFF(st.vflip));
135 ESP_LOGCONFIG(TAG,
" Horizontal Mirror: %s", ONOFF(st.hmirror));
136 ESP_LOGCONFIG(TAG,
" Special Effect: %u", st.special_effect);
137 ESP_LOGCONFIG(TAG,
" White Balance Mode: %u", st.wb_mode);
140 ESP_LOGCONFIG(TAG,
" Auto Exposure Control: %u", st.aec);
141 ESP_LOGCONFIG(TAG,
" Auto Exposure Control 2: %u", st.aec2);
142 ESP_LOGCONFIG(TAG,
" Auto Exposure Level: %d", st.ae_level);
143 ESP_LOGCONFIG(TAG,
" Auto Exposure Value: %u", st.aec_value);
144 ESP_LOGCONFIG(TAG,
" AGC: %u", st.agc);
145 ESP_LOGCONFIG(TAG,
" AGC Gain: %u", st.agc_gain);
146 ESP_LOGCONFIG(TAG,
" Gain Ceiling: %u", st.gainceiling);
152 ESP_LOGCONFIG(TAG,
" Test Pattern: %s", YESNO(st.colorbar));
165 const uint32_t now =
millis();
185 ESP_LOGVV(TAG,
"No frame ready");
190 ESP_LOGW(TAG,
"Got invalid frame from camera!");
196 ESP_LOGD(TAG,
"Got Image: len=%u", fb->len);
209 this->
config_.ledc_timer = LEDC_TIMER_0;
210 this->
config_.ledc_channel = LEDC_CHANNEL_0;
211 this->
config_.pixel_format = PIXFORMAT_JPEG;
212 this->
config_.frame_size = FRAMESIZE_VGA;
213 this->
config_.jpeg_quality = 10;
215 this->
config_.grab_mode = CAMERA_GRAB_WHEN_EMPTY;
216 this->
config_.fb_location = CAMERA_FB_IN_PSRAM;
224 this->
config_.pin_d0 = pins[0];
225 this->
config_.pin_d1 = pins[1];
226 this->
config_.pin_d2 = pins[2];
227 this->
config_.pin_d3 = pins[3];
228 this->
config_.pin_d4 = pins[4];
229 this->
config_.pin_d5 = pins[5];
230 this->
config_.pin_d6 = pins[6];
231 this->
config_.pin_d7 = pins[7];
241 #ifdef USE_ESP_IDF // Temporary until the espressif/esp32-camera library is updated 242 this->
config_.pin_sscb_sda = sda;
243 this->
config_.pin_sscb_scl = scl;
245 this->
config_.pin_sccb_sda = sda;
246 this->
config_.pin_sccb_scl = scl;
256 this->
config_.frame_size = FRAMESIZE_QQVGA;
259 this->
config_.frame_size = FRAMESIZE_QCIF;
262 this->
config_.frame_size = FRAMESIZE_HQVGA;
265 this->
config_.frame_size = FRAMESIZE_QVGA;
268 this->
config_.frame_size = FRAMESIZE_CIF;
271 this->
config_.frame_size = FRAMESIZE_VGA;
274 this->
config_.frame_size = FRAMESIZE_SVGA;
277 this->
config_.frame_size = FRAMESIZE_XGA;
280 this->
config_.frame_size = FRAMESIZE_SXGA;
283 this->
config_.frame_size = FRAMESIZE_UXGA;
286 this->
config_.frame_size = FRAMESIZE_FHD;
289 this->
config_.frame_size = FRAMESIZE_P_HD;
292 this->
config_.frame_size = FRAMESIZE_P_3MP;
295 this->
config_.frame_size = FRAMESIZE_QXGA;
298 this->
config_.frame_size = FRAMESIZE_QHD;
301 this->
config_.frame_size = FRAMESIZE_WQXGA;
304 this->
config_.frame_size = FRAMESIZE_P_FHD;
307 this->
config_.frame_size = FRAMESIZE_QSXGA;
341 this->
config_.fb_count = fb_count;
365 sensor_t *s = esp_camera_sensor_get();
374 s->set_exposure_ctrl(s, (
bool) this->
aec_mode_);
375 s->set_aec2(s, this->
aec2_);
379 s->set_gain_ctrl(s, (
bool) this->
agc_mode_);
383 s->set_wb_mode(s, (
int) this->
wb_mode_);
393 camera_fb_t *framebuffer = esp_camera_fb_get();
397 esp_camera_fb_return(framebuffer);
405 this->image_ = std::move(image);
412 return this->image_->get_data_length() - this->offset_;
425 return (this->
requesters_ & (1 << requester)) != 0;
std::shared_ptr< CameraImage > current_image_
void set_test_pattern(bool test_pattern)
ESP32WhiteBalanceMode wb_mode_
const float DATA
For components that import data from directly connected sensors like DHT.
void request_image(CameraRequester requester)
void add_stream_start_callback(std::function< void()> &&callback)
void set_vertical_flip(bool vertical_flip)
void set_agc_mode(ESP32GainControlMode mode)
void start_stream(CameraRequester requester)
void set_max_update_interval(uint32_t max_update_interval)
bool has_requested_image_() const
void set_power_down_pin(uint8_t pin)
void set_pixel_clock_pin(uint8_t pin)
void set_href_pin(uint8_t pin)
void set_wb_mode(ESP32WhiteBalanceMode mode)
void set_jpeg_quality(uint8_t quality)
bool can_return_image_() const
void add_image_callback(std::function< void(std::shared_ptr< CameraImage >)> &&callback)
QueueHandle_t framebuffer_get_queue_
void consume_data(size_t consumed)
uint8_t stream_requesters_
float get_setup_priority() const override
void stop_stream(CameraRequester requester)
uint32_t IRAM_ATTR HOT millis()
ESP32GainControlMode aec_mode_
uint8_t * peek_data_buffer()
CallbackManager< void()> stream_stop_callback_
void set_aec_mode(ESP32GainControlMode mode)
uint32_t max_update_interval_
ESP32Camera * global_esp32_camera
uint32_t idle_update_interval_
void set_contrast(int contrast)
BedjetMode mode
BedJet operating mode.
void add_stream_stop_callback(std::function< void()> &&callback)
ESP32GainControlMode agc_mode_
void set_external_clock(uint8_t pin, uint32_t frequency)
camera_fb_t * get_raw_buffer()
void set_frame_buffer_count(uint8_t fb_count)
CallbackManager< void()> stream_start_callback_
void set_data_pins(std::array< uint8_t, 8 > pins)
void set_agc_gain_ceiling(ESP32AgcGainCeiling gain_ceiling)
CallbackManager< void(std::shared_ptr< CameraImage >)> new_image_callback_
static void framebuffer_task(void *pv)
ESP32AgcGainCeiling agc_gain_ceiling_
uint8_t * get_data_buffer()
void set_horizontal_mirror(bool horizontal_mirror)
bool was_requested_by(CameraRequester requester) const
constexpr const char * c_str() const
uint32_t last_idle_request_
void set_image(std::shared_ptr< CameraImage > image)
ESP32SpecialEffect special_effect_
void set_aec_value(uint32_t aec_value)
void set_reset_pin(uint8_t pin)
void set_frame_size(ESP32CameraFrameSize size)
virtual void mark_failed()
Mark this component as failed.
void set_agc_value(uint8_t agc_value)
CameraImage(camera_fb_t *buffer, uint8_t requester)
void set_frame_buffer_mode(camera_grab_mode_t mode)
QueueHandle_t framebuffer_return_queue_
void set_special_effect(ESP32SpecialEffect effect)
Implementation of SPI Controller mode.
void dump_config() override
void update_camera_parameters()
void set_idle_update_interval(uint32_t idle_update_interval)
void set_vsync_pin(uint8_t pin)
void set_ae_level(int ae_level)
void set_i2c_pins(uint8_t sda, uint8_t scl)
void set_brightness(int brightness)
void set_saturation(int saturation)
uint8_t single_requesters_