mirror of
https://github.com/esphome/esphome.git
synced 2025-10-27 13:13:50 +00:00
[light] Replace std::vector with FixedVector in strobe and color_wipe effects
This commit is contained in:
@@ -1,9 +1,9 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include "esphome/core/component.h"
|
#include "esphome/core/component.h"
|
||||||
|
#include "esphome/core/helpers.h"
|
||||||
#include "esphome/components/light/light_state.h"
|
#include "esphome/components/light/light_state.h"
|
||||||
#include "esphome/components/light/addressable_light.h"
|
#include "esphome/components/light/addressable_light.h"
|
||||||
|
|
||||||
@@ -113,7 +113,7 @@ struct AddressableColorWipeEffectColor {
|
|||||||
class AddressableColorWipeEffect : public AddressableLightEffect {
|
class AddressableColorWipeEffect : public AddressableLightEffect {
|
||||||
public:
|
public:
|
||||||
explicit AddressableColorWipeEffect(const std::string &name) : AddressableLightEffect(name) {}
|
explicit AddressableColorWipeEffect(const std::string &name) : AddressableLightEffect(name) {}
|
||||||
void set_colors(const std::vector<AddressableColorWipeEffectColor> &colors) { this->colors_ = colors; }
|
void set_colors(const std::initializer_list<AddressableColorWipeEffectColor> &colors) { this->colors_ = colors; }
|
||||||
void set_add_led_interval(uint32_t add_led_interval) { this->add_led_interval_ = add_led_interval; }
|
void set_add_led_interval(uint32_t add_led_interval) { this->add_led_interval_ = add_led_interval; }
|
||||||
void set_reverse(bool reverse) { this->reverse_ = reverse; }
|
void set_reverse(bool reverse) { this->reverse_ = reverse; }
|
||||||
void apply(AddressableLight &it, const Color ¤t_color) override {
|
void apply(AddressableLight &it, const Color ¤t_color) override {
|
||||||
@@ -155,7 +155,7 @@ class AddressableColorWipeEffect : public AddressableLightEffect {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::vector<AddressableColorWipeEffectColor> colors_;
|
FixedVector<AddressableColorWipeEffectColor> colors_;
|
||||||
size_t at_color_{0};
|
size_t at_color_{0};
|
||||||
uint32_t last_add_{0};
|
uint32_t last_add_{0};
|
||||||
uint32_t add_led_interval_{};
|
uint32_t add_led_interval_{};
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include "esphome/core/automation.h"
|
#include "esphome/core/automation.h"
|
||||||
|
#include "esphome/core/helpers.h"
|
||||||
#include "light_effect.h"
|
#include "light_effect.h"
|
||||||
|
|
||||||
namespace esphome {
|
namespace esphome {
|
||||||
@@ -188,10 +188,10 @@ class StrobeLightEffect : public LightEffect {
|
|||||||
this->last_switch_ = now;
|
this->last_switch_ = now;
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_colors(const std::vector<StrobeLightEffectColor> &colors) { this->colors_ = colors; }
|
void set_colors(const std::initializer_list<StrobeLightEffectColor> &colors) { this->colors_ = colors; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::vector<StrobeLightEffectColor> colors_;
|
FixedVector<StrobeLightEffectColor> colors_;
|
||||||
uint32_t last_switch_{0};
|
uint32_t last_switch_{0};
|
||||||
size_t at_color_{0};
|
size_t at_color_{0};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -123,3 +123,43 @@ light:
|
|||||||
red: 100%
|
red: 100%
|
||||||
green: 50%
|
green: 50%
|
||||||
blue: 50%
|
blue: 50%
|
||||||
|
# Test StrobeLightEffect with multiple colors
|
||||||
|
- platform: monochromatic
|
||||||
|
id: test_strobe_multiple
|
||||||
|
name: Strobe Multiple Colors
|
||||||
|
output: test_ledc_1
|
||||||
|
effects:
|
||||||
|
- strobe:
|
||||||
|
name: Strobe Multi
|
||||||
|
colors:
|
||||||
|
- state: true
|
||||||
|
brightness: 100%
|
||||||
|
duration: 500ms
|
||||||
|
- state: false
|
||||||
|
duration: 250ms
|
||||||
|
- state: true
|
||||||
|
brightness: 50%
|
||||||
|
duration: 500ms
|
||||||
|
# Test StrobeLightEffect with transition
|
||||||
|
- platform: rgb
|
||||||
|
id: test_strobe_transition
|
||||||
|
name: Strobe With Transition
|
||||||
|
red: test_ledc_1
|
||||||
|
green: test_ledc_2
|
||||||
|
blue: test_ledc_3
|
||||||
|
effects:
|
||||||
|
- strobe:
|
||||||
|
name: Strobe Transition
|
||||||
|
colors:
|
||||||
|
- state: true
|
||||||
|
red: 100%
|
||||||
|
green: 0%
|
||||||
|
blue: 0%
|
||||||
|
duration: 1s
|
||||||
|
transition_length: 500ms
|
||||||
|
- state: true
|
||||||
|
red: 0%
|
||||||
|
green: 100%
|
||||||
|
blue: 0%
|
||||||
|
duration: 1s
|
||||||
|
transition_length: 500ms
|
||||||
|
|||||||
Reference in New Issue
Block a user