mirror of
https://github.com/esphome/esphome.git
synced 2025-02-23 05:18:15 +00:00
## Description: Move esphome-core codebase into esphome (and a bunch of other refactors). See https://github.com/esphome/feature-requests/issues/97 Yes this is a shit ton of work and no there's no way to automate it :( But it will be worth it 👍 Progress: - Core support (file copy etc): 80% - Base Abstractions (light, switch): ~50% - Integrations: ~10% - Working? Yes, (but only with ported components). Other refactors: - Moves all codegen related stuff into a single class: `esphome.codegen` (imported as `cg`) - Rework coroutine syntax - Move from `component/platform.py` to `domain/component.py` structure as with HA - Move all defaults out of C++ and into config validation. - Remove `make_...` helpers from Application class. Reason: Merge conflicts with every single new integration. - Pointer Variables are stored globally instead of locally in setup(). Reason: stack size limit. Future work: - Rework const.py - Move all `CONF_...` into a conf class (usage `conf.UPDATE_INTERVAL` vs `CONF_UPDATE_INTERVAL`). Reason: Less convoluted import block - Enable loading from `custom_components` folder. **Related issue (if applicable):** https://github.com/esphome/feature-requests/issues/97 **Pull request in [esphome-docs](https://github.com/esphome/esphome-docs) with documentation (if applicable):** esphome/esphome-docs#<esphome-docs PR number goes here> ## Checklist: - [ ] The code change is tested and works locally. - [ ] Tests have been added to verify that the new code works (under `tests/` folder). If user exposed functionality or configuration variables are added/changed: - [ ] Documentation added/updated in [esphomedocs](https://github.com/OttoWinter/esphomedocs).
114 lines
3.1 KiB
C++
114 lines
3.1 KiB
C++
#pragma once
|
|
|
|
#ifdef ARDUINO_ARCH_ESP32
|
|
|
|
#include "esphome/core/component.h"
|
|
#include "esphome/core/helpers.h"
|
|
#include <esp_camera.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_128X160, // QQVGA2
|
|
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
|