Add actions to animation (#4959)

This commit is contained in:
guillempages
2023-06-20 00:50:02 +02:00
committed by GitHub
parent b2ccd32cd7
commit ee12c68b8f
2 changed files with 73 additions and 2 deletions
+30
View File
@@ -1,6 +1,8 @@
#pragma once
#include "image.h"
#include "esphome/core/automation.h"
namespace esphome {
namespace display {
@@ -33,5 +35,33 @@ class Animation : public Image {
int loop_current_iteration_;
};
template<typename... Ts> class AnimationNextFrameAction : public Action<Ts...> {
public:
AnimationNextFrameAction(Animation *parent) : parent_(parent) {}
void play(Ts... x) override { this->parent_->next_frame(); }
protected:
Animation *parent_;
};
template<typename... Ts> class AnimationPrevFrameAction : public Action<Ts...> {
public:
AnimationPrevFrameAction(Animation *parent) : parent_(parent) {}
void play(Ts... x) override { this->parent_->prev_frame(); }
protected:
Animation *parent_;
};
template<typename... Ts> class AnimationSetFrameAction : public Action<Ts...> {
public:
AnimationSetFrameAction(Animation *parent) : parent_(parent) {}
TEMPLATABLE_VALUE(uint16_t, frame)
void play(Ts... x) override { this->parent_->set_frame(this->frame_.value(x...)); }
protected:
Animation *parent_;
};
} // namespace display
} // namespace esphome