ESPHome 2026.11.0-dev
Loading...
Searching...
No Matches
esphome::snapshot::Snapshot Class Referenceabstract

Base for anything that can hand over the picture it is showing so it can be written to a file. More...

#include <snapshot.h>

Inheritance diagram for esphome::snapshot::Snapshot:
esphome::sdl::Sdl esphome::snapshot::SnapshotDisplay

Public Member Functions

 Snapshot ()
 
virtual ~Snapshot ()
 
void set_snapshot_prefix (const char *prefix)
 Set the word generated names start with.
 
bool take_snapshot (const char *filename)
 Write the current picture to a BMP file in the snapshot directory.
 
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.
 
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 nothing is logged.
 
void take_snapshot_or_log (const std::string &filename, uint32_t frames, float frame_rate)
 

Protected Member Functions

virtual int snapshot_width ()=0
 Width of the picture in pixels.
 
virtual int snapshot_height ()=0
 Height of the picture in pixels.
 
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, with row_stride bytes from the start of one row to the start of the next.
 

Protected Attributes

const char * snapshot_prefix_ {"snapshot"}
 

Detailed Description

Base for anything that can hand over the picture it is showing so it can be written to a file.

A subclass says how big the picture is and fills in the pixels. Everything else - picking a name, staying inside the snapshot directory, not writing over anything, encoding the file, and timing the frames of an animation - is done here, so every component that can take a snapshot behaves the same way.

Definition at line 24 of file snapshot.h.

Constructor & Destructor Documentation

◆ Snapshot()

esphome::snapshot::Snapshot::Snapshot ( )
default

◆ ~Snapshot()

esphome::snapshot::Snapshot::~Snapshot ( )
virtualdefault

Member Function Documentation

◆ capture_bgr()

virtual bool esphome::snapshot::Snapshot::capture_bgr ( uint8_t * dest,
size_t row_stride )
protectedpure virtual

Fill in the picture: three bytes per pixel in blue, green, red order, topmost row first, with row_stride bytes from the start of one row to the start of the next.

Returns false, having logged why, if the picture could not be read.

Implemented in esphome::sdl::Sdl, and esphome::snapshot::SnapshotDisplay.

◆ set_snapshot_prefix()

void esphome::snapshot::Snapshot::set_snapshot_prefix ( const char * prefix)
inline

Set the word generated names start with.

Codegen passes the component id, so with more than one display in a device it is clear which one a file came from.

Definition at line 32 of file snapshot.h.

◆ snapshot_height()

virtual int esphome::snapshot::Snapshot::snapshot_height ( )
protectedpure virtual

Height of the picture in pixels.

Implemented in esphome::sdl::Sdl, and esphome::snapshot::SnapshotDisplay.

◆ snapshot_width()

virtual int esphome::snapshot::Snapshot::snapshot_width ( )
protectedpure virtual

Width of the picture in pixels.

Implemented in esphome::sdl::Sdl, and esphome::snapshot::SnapshotDisplay.

◆ take_animation()

bool esphome::snapshot::Snapshot::take_animation ( const char * filename,
uint32_t frames,
float frame_rate )

Record what is shown as an animated GIF file in the snapshot directory.

The first frame is taken now and the rest follow at frame_rate frames a second, in the background. Names work as for take_snapshot(), with ".gif" in place of ".bmp". Only one recording can run at a time. Returns true if the recording started.

Definition at line 325 of file snapshot.cpp.

◆ take_snapshot()

bool esphome::snapshot::Snapshot::take_snapshot ( const char * filename)

Write the current picture to a BMP file in the snapshot directory.

Pass nullptr to have a name made up from the prefix and the current time. A file that is already there is never written over. Returns true if a file was written.

Definition at line 305 of file snapshot.cpp.

◆ take_snapshot_or_log() [1/2]

void esphome::snapshot::Snapshot::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 nothing is logged.

A frames of 0 takes a single picture; otherwise an animation is recorded.

Definition at line 297 of file snapshot.cpp.

◆ take_snapshot_or_log() [2/2]

void esphome::snapshot::Snapshot::take_snapshot_or_log ( const std::string & filename,
uint32_t frames,
float frame_rate )
inline

Definition at line 51 of file snapshot.h.

Field Documentation

◆ snapshot_prefix_

const char* esphome::snapshot::Snapshot::snapshot_prefix_ {"snapshot"}
protected

Definition at line 65 of file snapshot.h.


The documentation for this class was generated from the following files: