mirror of
https://github.com/esphome/esphome.git
synced 2025-10-06 03:43:49 +01:00
feat: esp32-camera add stream event (#3285)
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
#ifdef USE_ESP32
|
||||
|
||||
#include "esphome/core/automation.h"
|
||||
#include "esphome/core/component.h"
|
||||
#include "esphome/core/entity_base.h"
|
||||
#include "esphome/core/helpers.h"
|
||||
@@ -145,6 +146,9 @@ class ESP32Camera : public Component, public EntityBase {
|
||||
void request_image(CameraRequester requester);
|
||||
void update_camera_parameters();
|
||||
|
||||
void add_stream_start_callback(std::function<void()> &&callback);
|
||||
void add_stream_stop_callback(std::function<void()> &&callback);
|
||||
|
||||
protected:
|
||||
/* internal methods */
|
||||
uint32_t hash_base() override;
|
||||
@@ -187,6 +191,8 @@ class ESP32Camera : public Component, public EntityBase {
|
||||
QueueHandle_t framebuffer_get_queue_;
|
||||
QueueHandle_t framebuffer_return_queue_;
|
||||
CallbackManager<void(std::shared_ptr<CameraImage>)> new_image_callback_;
|
||||
CallbackManager<void()> stream_start_callback_{};
|
||||
CallbackManager<void()> stream_stop_callback_{};
|
||||
|
||||
uint32_t last_idle_request_{0};
|
||||
uint32_t last_update_{0};
|
||||
@@ -195,6 +201,23 @@ class ESP32Camera : public Component, public EntityBase {
|
||||
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
|
||||
extern ESP32Camera *global_esp32_camera;
|
||||
|
||||
class ESP32CameraStreamStartTrigger : public Trigger<> {
|
||||
public:
|
||||
explicit ESP32CameraStreamStartTrigger(ESP32Camera *parent) {
|
||||
parent->add_stream_start_callback([this]() { this->trigger(); });
|
||||
}
|
||||
|
||||
protected:
|
||||
};
|
||||
class ESP32CameraStreamStopTrigger : public Trigger<> {
|
||||
public:
|
||||
explicit ESP32CameraStreamStopTrigger(ESP32Camera *parent) {
|
||||
parent->add_stream_stop_callback([this]() { this->trigger(); });
|
||||
}
|
||||
|
||||
protected:
|
||||
};
|
||||
|
||||
} // namespace esp32_camera
|
||||
} // namespace esphome
|
||||
|
||||
|
Reference in New Issue
Block a user