ESPHome 2026.10.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

virtual ~Snapshot ()=default
 
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.
 

Static Public Member Functions

static void log_action_failed ()
 Log that an action-triggered snapshot did not write a file.
 

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, and encoding the file - is done here, so every component that can take a snapshot behaves the same way.

Definition at line 23 of file snapshot.h.

Constructor & Destructor Documentation

◆ ~Snapshot()

virtual 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.

◆ log_action_failed()

void esphome::snapshot::Snapshot::log_action_failed ( )
static

Log that an action-triggered snapshot did not write a file.

Definition at line 196 of file snapshot.cpp.

◆ 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 29 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_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 198 of file snapshot.cpp.

Field Documentation

◆ snapshot_prefix_

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

Definition at line 50 of file snapshot.h.


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