ESPHome  2024.11.0
animation.h
Go to the documentation of this file.
1 #pragma once
3 
5 
6 namespace esphome {
7 namespace animation {
8 
9 class Animation : public image::Image {
10  public:
11  Animation(const uint8_t *data_start, int width, int height, uint32_t animation_frame_count, image::ImageType type);
12 
13  uint32_t get_animation_frame_count() const;
14  int get_current_frame() const;
15  void next_frame();
16  void prev_frame();
17 
22  void set_frame(int frame);
23 
24  void set_loop(uint32_t start_frame, uint32_t end_frame, int count);
25 
26  protected:
27  void update_data_start_();
28 
29  const uint8_t *animation_data_start_;
33  uint32_t loop_end_frame_;
36 };
37 
38 template<typename... Ts> class AnimationNextFrameAction : public Action<Ts...> {
39  public:
40  AnimationNextFrameAction(Animation *parent) : parent_(parent) {}
41  void play(Ts... x) override { this->parent_->next_frame(); }
42 
43  protected:
45 };
46 
47 template<typename... Ts> class AnimationPrevFrameAction : public Action<Ts...> {
48  public:
49  AnimationPrevFrameAction(Animation *parent) : parent_(parent) {}
50  void play(Ts... x) override { this->parent_->prev_frame(); }
51 
52  protected:
54 };
55 
56 template<typename... Ts> class AnimationSetFrameAction : public Action<Ts...> {
57  public:
58  AnimationSetFrameAction(Animation *parent) : parent_(parent) {}
59  TEMPLATABLE_VALUE(uint16_t, frame)
60  void play(Ts... x) override { this->parent_->set_frame(this->frame_.value(x...)); }
61 
62  protected:
64 };
65 
66 } // namespace animation
67 } // namespace esphome
void set_frame(int frame)
Selects a specific frame within the animation.
Definition: animation.cpp:50
uint16_t x
Definition: tt21100.cpp:17
uint32_t get_animation_frame_count() const
Definition: animation.cpp:25
TEMPLATABLE_VALUE(uint16_t, frame) void play(Ts... x) override
Definition: animation.h:59
const uint8_t * animation_data_start_
Definition: animation.h:29
void set_loop(uint32_t start_frame, uint32_t end_frame, int count)
Definition: animation.cpp:18
Animation(const uint8_t *data_start, int width, int height, uint32_t animation_frame_count, image::ImageType type)
Definition: animation.cpp:8
uint8_t type
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7