mirror of
https://github.com/esphome/esphome.git
synced 2025-03-15 15:18:16 +00:00
Added check for scan length being longer than addressable light
This commit is contained in:
parent
308bfc3601
commit
ba07df8c22
@ -146,7 +146,8 @@ class AddressableScanEffect : public AddressableLightEffect {
|
||||
void apply(AddressableLight &it, const ESPColor ¤t_color) override {
|
||||
it.all() = ESPColor::BLACK;
|
||||
|
||||
for (auto i = 0; i < this->scan_length_; i++) {
|
||||
const uint32_t scan_length_limited = (scan_length_ < it.size()) ? scan_length_ : it.size();
|
||||
for (auto i = 0; i < scan_length_limited; i++) {
|
||||
it[this->at_led_ + i] = current_color;
|
||||
}
|
||||
|
||||
@ -154,7 +155,7 @@ class AddressableScanEffect : public AddressableLightEffect {
|
||||
if (now - this->last_move_ > this->move_interval_) {
|
||||
if (direction_) {
|
||||
this->at_led_++;
|
||||
if (this->at_led_ == it.size() - scan_length_)
|
||||
if (this->at_led_ == it.size() - scan_length_limited)
|
||||
this->direction_ = false;
|
||||
} else {
|
||||
this->at_led_--;
|
||||
@ -167,7 +168,7 @@ class AddressableScanEffect : public AddressableLightEffect {
|
||||
|
||||
protected:
|
||||
uint32_t move_interval_{};
|
||||
uint32_t scan_length_{10}; //TODO check less than it.size()
|
||||
uint32_t scan_length_{10};
|
||||
uint32_t last_move_{0};
|
||||
int at_led_{0};
|
||||
bool direction_{true};
|
||||
|
Loading…
x
Reference in New Issue
Block a user