mirror of
https://github.com/Threnklyn/esphome-dev.git
synced 2026-05-22 21:58:29 +02:00
ac0d921413
* Socket refactor and SSL * esp-idf temp * Fixes * Echo component and noise * Add noise API transport support * Updates * ESP-IDF * Complete * Fixes * Fixes * Versions update * New i2c APIs * Complete i2c refactor * SPI migration * Revert ESP Preferences migration, too complex for now * OTA support * Remove echo again * Remove ssl again * GPIOFlags updates * Rename esphal and ICACHE_RAM_ATTR * Make ESP32 arduino compilable again * Fix GPIO flags * Complete pin registry refactor and fixes * Fixes to make test1 compile * Remove sdkconfig file * Ignore sdkconfig file * Fixes in reviewing * Make test2 compile * Make test4 compile * Make test5 compile * Run clang-format * Fix lint errors * Use esp-idf APIs instead of btStart * Another round of fixes * Start implementing ESP8266 * Make test3 compile * Guard esp8266 code * Lint * Reformat * Fixes * Fixes v2 * more fixes * ESP-IDF tidy target * Convert ARDUINO_ARCH_ESPxx * Update WiFiSignalSensor * Update time ifdefs * OTA needs millis from hal * RestartSwitch needs delay from hal * ESP-IDF Uart * Fix OTA blank password * Allow setting sdkconfig * Fix idf partitions and allow setting sdkconfig from yaml * Re-add read/write compat APIs and fix esp8266 uart * Fix esp8266 store log strings in flash * Fix ESP32 arduino preferences not initialized * Update ifdefs * Change how sdkconfig change is detected * Add checks to ci-custom and fix them * Run clang-format * Add esp-idf clang-tidy target and fix errors * Fixes from clang-tidy idf round 2 * Fixes from compiling tests with esp-idf * Run clang-format * Switch test5.yaml to esp-idf * Implement ESP8266 Preferences * Lint * Re-do PIO package version selection a bit * Fix arduinoespressif32 package version * Fix unit tests * Lint * Lint fixes * Fix readv/writev not defined * Fix graphing component * Re-add all old options from core/config.py Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
115 lines
3.1 KiB
C++
115 lines
3.1 KiB
C++
#pragma once
|
|
|
|
#ifdef USE_ESP32
|
|
|
|
#include "esphome/core/component.h"
|
|
#include "esphome/core/helpers.h"
|
|
#include <esp_camera.h>
|
|
#include <freertos/FreeRTOS.h>
|
|
#include <freertos/queue.h>
|
|
|
|
namespace esphome {
|
|
namespace esp32_camera {
|
|
|
|
class ESP32Camera;
|
|
|
|
class CameraImage {
|
|
public:
|
|
CameraImage(camera_fb_t *buffer);
|
|
camera_fb_t *get_raw_buffer();
|
|
uint8_t *get_data_buffer();
|
|
size_t get_data_length();
|
|
|
|
protected:
|
|
camera_fb_t *buffer_;
|
|
};
|
|
|
|
class CameraImageReader {
|
|
public:
|
|
void set_image(std::shared_ptr<CameraImage> image);
|
|
size_t available() const;
|
|
uint8_t *peek_data_buffer();
|
|
void consume_data(size_t consumed);
|
|
void return_image();
|
|
|
|
protected:
|
|
std::shared_ptr<CameraImage> image_;
|
|
size_t offset_{0};
|
|
};
|
|
|
|
enum ESP32CameraFrameSize {
|
|
ESP32_CAMERA_SIZE_160X120, // QQVGA
|
|
ESP32_CAMERA_SIZE_176X144, // QCIF
|
|
ESP32_CAMERA_SIZE_240X176, // HQVGA
|
|
ESP32_CAMERA_SIZE_320X240, // QVGA
|
|
ESP32_CAMERA_SIZE_400X296, // CIF
|
|
ESP32_CAMERA_SIZE_640X480, // VGA
|
|
ESP32_CAMERA_SIZE_800X600, // SVGA
|
|
ESP32_CAMERA_SIZE_1024X768, // XGA
|
|
ESP32_CAMERA_SIZE_1280X1024, // SXGA
|
|
ESP32_CAMERA_SIZE_1600X1200, // UXGA
|
|
};
|
|
|
|
class ESP32Camera : public Component, public Nameable {
|
|
public:
|
|
ESP32Camera(const std::string &name);
|
|
void set_data_pins(std::array<uint8_t, 8> pins);
|
|
void set_vsync_pin(uint8_t pin);
|
|
void set_href_pin(uint8_t pin);
|
|
void set_pixel_clock_pin(uint8_t pin);
|
|
void set_external_clock(uint8_t pin, uint32_t frequency);
|
|
void set_i2c_pins(uint8_t sda, uint8_t scl);
|
|
void set_frame_size(ESP32CameraFrameSize size);
|
|
void set_jpeg_quality(uint8_t quality);
|
|
void set_reset_pin(uint8_t pin);
|
|
void set_power_down_pin(uint8_t pin);
|
|
void set_vertical_flip(bool vertical_flip);
|
|
void set_horizontal_mirror(bool horizontal_mirror);
|
|
void set_contrast(int contrast);
|
|
void set_brightness(int brightness);
|
|
void set_saturation(int saturation);
|
|
void set_max_update_interval(uint32_t max_update_interval);
|
|
void set_idle_update_interval(uint32_t idle_update_interval);
|
|
void set_test_pattern(bool test_pattern);
|
|
void setup() override;
|
|
void loop() override;
|
|
void dump_config() override;
|
|
void add_image_callback(std::function<void(std::shared_ptr<CameraImage>)> &&f);
|
|
float get_setup_priority() const override;
|
|
void request_stream();
|
|
void request_image();
|
|
|
|
protected:
|
|
uint32_t hash_base() override;
|
|
bool has_requested_image_() const;
|
|
bool can_return_image_() const;
|
|
|
|
static void framebuffer_task(void *pv);
|
|
|
|
camera_config_t config_{};
|
|
bool vertical_flip_{true};
|
|
bool horizontal_mirror_{true};
|
|
int contrast_{0};
|
|
int brightness_{0};
|
|
int saturation_{0};
|
|
bool test_pattern_{false};
|
|
|
|
esp_err_t init_error_{ESP_OK};
|
|
std::shared_ptr<CameraImage> current_image_;
|
|
uint32_t last_stream_request_{0};
|
|
bool single_requester_{false};
|
|
QueueHandle_t framebuffer_get_queue_;
|
|
QueueHandle_t framebuffer_return_queue_;
|
|
CallbackManager<void(std::shared_ptr<CameraImage>)> new_image_callback_;
|
|
uint32_t max_update_interval_{1000};
|
|
uint32_t idle_update_interval_{15000};
|
|
uint32_t last_update_{0};
|
|
};
|
|
|
|
extern ESP32Camera *global_esp32_camera;
|
|
|
|
} // namespace esp32_camera
|
|
} // namespace esphome
|
|
|
|
#endif
|