ESPHome 2026.11.0-dev
Loading...
Searching...
No Matches
snapshot.h
Go to the documentation of this file.
1#pragma once
2
3#ifdef USE_HOST
4
5#include <cstddef>
6#include <cstdint>
7#include <memory>
8#include <string>
9
10// Directory snapshots are written to. Normally set by codegen to a folder under .esphome; the
11// fallback keeps the component compiling for static analysis, where no defines.h is generated.
12#ifndef ESPHOME_SNAPSHOT_DIR
13#define ESPHOME_SNAPSHOT_DIR "."
14#endif
15
16namespace esphome::snapshot {
17
24class Snapshot {
25 public:
26 // Declared here and defined where Recording is complete, which unique_ptr needs.
28 virtual ~Snapshot();
29
32 void set_snapshot_prefix(const char *prefix) { this->snapshot_prefix_ = prefix; }
33
38 bool take_snapshot(const char *filename);
39
45 bool take_animation(const char *filename, uint32_t frames, float frame_rate);
46
50 void take_snapshot_or_log(const char *filename, uint32_t frames, float frame_rate);
51 void take_snapshot_or_log(const std::string &filename, uint32_t frames, float frame_rate) {
52 this->take_snapshot_or_log(filename.c_str(), frames, frame_rate);
53 }
54
55 protected:
57 virtual int snapshot_width() = 0;
59 virtual int snapshot_height() = 0;
63 virtual bool capture_bgr(uint8_t *dest, size_t row_stride) = 0;
64
65 const char *snapshot_prefix_{"snapshot"};
66
67 private:
68 struct Recording;
69
72 bool record_frame_();
73
74 std::unique_ptr<Recording> recording_;
75};
76
77} // namespace esphome::snapshot
78
79#endif
Base for anything that can hand over the picture it is showing so it can be written to a file.
Definition snapshot.h:24
void take_snapshot_or_log(const char *filename, uint32_t frames, float frame_rate)
Take a snapshot for an automation: an empty name means a generated one, and a snapshot that wrote not...
Definition snapshot.cpp:297
virtual bool capture_bgr(uint8_t *dest, size_t row_stride)=0
Fill in the picture: three bytes per pixel in blue, green, red order, topmost row first,...
const char * snapshot_prefix_
Definition snapshot.h:65
bool take_animation(const char *filename, uint32_t frames, float frame_rate)
Record what is shown as an animated GIF file in the snapshot directory.
Definition snapshot.cpp:325
virtual int snapshot_width()=0
Width of the picture in pixels.
virtual int snapshot_height()=0
Height of the picture in pixels.
void take_snapshot_or_log(const std::string &filename, uint32_t frames, float frame_rate)
Definition snapshot.h:51
void set_snapshot_prefix(const char *prefix)
Set the word generated names start with.
Definition snapshot.h:32
bool take_snapshot(const char *filename)
Write the current picture to a BMP file in the snapshot directory.
Definition snapshot.cpp:305
static void uint32_t