From 69118120d9145f24a40c70675de8d5dfda5483a8 Mon Sep 17 00:00:00 2001 From: LuBeDa Date: Tue, 10 May 2022 11:56:29 +0200 Subject: [PATCH] added prev_frame for animation (#3427) --- esphome/components/display/display_buffer.cpp | 6 ++++++ esphome/components/display/display_buffer.h | 1 + 2 files changed, 7 insertions(+) diff --git a/esphome/components/display/display_buffer.cpp b/esphome/components/display/display_buffer.cpp index d00fdd5240..ca866a43d2 100644 --- a/esphome/components/display/display_buffer.cpp +++ b/esphome/components/display/display_buffer.cpp @@ -584,6 +584,12 @@ void Animation::next_frame() { this->current_frame_ = 0; } } +void Animation::prev_frame() { + this->current_frame_--; + if (this->current_frame_ < 0) { + this->current_frame_ = this->animation_frame_count_ - 1; + } +} DisplayPage::DisplayPage(display_writer_t writer) : writer_(std::move(writer)) {} void DisplayPage::show() { this->parent_->show_page(this); } diff --git a/esphome/components/display/display_buffer.h b/esphome/components/display/display_buffer.h index 86221c5f96..33f55aa3d1 100644 --- a/esphome/components/display/display_buffer.h +++ b/esphome/components/display/display_buffer.h @@ -478,6 +478,7 @@ class Animation : public Image { int get_animation_frame_count() const; int get_current_frame() const; void next_frame(); + void prev_frame(); protected: int current_frame_;