mirror of
https://github.com/esphome/esphome.git
synced 2025-11-14 22:05:54 +00:00
[light] Optimize LambdaLightEffect and AddressableLambdaLightEffect with function pointers (#11556)
This commit is contained in:
@@ -57,9 +57,9 @@ class AddressableLightEffect : public LightEffect {
|
|||||||
|
|
||||||
class AddressableLambdaLightEffect : public AddressableLightEffect {
|
class AddressableLambdaLightEffect : public AddressableLightEffect {
|
||||||
public:
|
public:
|
||||||
AddressableLambdaLightEffect(const char *name, std::function<void(AddressableLight &, Color, bool initial_run)> f,
|
AddressableLambdaLightEffect(const char *name, void (*f)(AddressableLight &, Color, bool initial_run),
|
||||||
uint32_t update_interval)
|
uint32_t update_interval)
|
||||||
: AddressableLightEffect(name), f_(std::move(f)), update_interval_(update_interval) {}
|
: AddressableLightEffect(name), f_(f), update_interval_(update_interval) {}
|
||||||
void start() override { this->initial_run_ = true; }
|
void start() override { this->initial_run_ = true; }
|
||||||
void apply(AddressableLight &it, const Color ¤t_color) override {
|
void apply(AddressableLight &it, const Color ¤t_color) override {
|
||||||
const uint32_t now = millis();
|
const uint32_t now = millis();
|
||||||
@@ -72,7 +72,7 @@ class AddressableLambdaLightEffect : public AddressableLightEffect {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::function<void(AddressableLight &, Color, bool initial_run)> f_;
|
void (*f_)(AddressableLight &, Color, bool initial_run);
|
||||||
uint32_t update_interval_;
|
uint32_t update_interval_;
|
||||||
uint32_t last_run_{0};
|
uint32_t last_run_{0};
|
||||||
bool initial_run_;
|
bool initial_run_;
|
||||||
|
|||||||
@@ -112,8 +112,8 @@ class RandomLightEffect : public LightEffect {
|
|||||||
|
|
||||||
class LambdaLightEffect : public LightEffect {
|
class LambdaLightEffect : public LightEffect {
|
||||||
public:
|
public:
|
||||||
LambdaLightEffect(const char *name, std::function<void(bool initial_run)> f, uint32_t update_interval)
|
LambdaLightEffect(const char *name, void (*f)(bool initial_run), uint32_t update_interval)
|
||||||
: LightEffect(name), f_(std::move(f)), update_interval_(update_interval) {}
|
: LightEffect(name), f_(f), update_interval_(update_interval) {}
|
||||||
|
|
||||||
void start() override { this->initial_run_ = true; }
|
void start() override { this->initial_run_ = true; }
|
||||||
void apply() override {
|
void apply() override {
|
||||||
@@ -130,7 +130,7 @@ class LambdaLightEffect : public LightEffect {
|
|||||||
uint32_t get_current_index() const { return this->get_index(); }
|
uint32_t get_current_index() const { return this->get_index(); }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::function<void(bool initial_run)> f_;
|
void (*f_)(bool initial_run);
|
||||||
uint32_t update_interval_;
|
uint32_t update_interval_;
|
||||||
uint32_t last_run_{0};
|
uint32_t last_run_{0};
|
||||||
bool initial_run_;
|
bool initial_run_;
|
||||||
|
|||||||
Reference in New Issue
Block a user