mirror of
https://github.com/esphome/esphome.git
synced 2026-06-24 16:04:55 +00:00
[light] Fix unsigned underflow in addressable scan effect (#14546)
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -171,12 +171,27 @@ class AddressableScanEffect : public AddressableLightEffect {
|
||||
if (now - this->last_move_ < this->move_interval_)
|
||||
return;
|
||||
|
||||
if (direction_) {
|
||||
const auto num_leds = static_cast<uint32_t>(it.size());
|
||||
if (this->scan_width_ >= num_leds) {
|
||||
it.all() = current_color;
|
||||
it.schedule_show();
|
||||
this->last_move_ = now;
|
||||
return;
|
||||
}
|
||||
|
||||
const uint32_t max_pos = num_leds - this->scan_width_;
|
||||
if (this->at_led_ >= max_pos) {
|
||||
this->at_led_ = max_pos;
|
||||
this->direction_ = false;
|
||||
}
|
||||
|
||||
if (this->direction_) {
|
||||
this->at_led_++;
|
||||
if (this->at_led_ == it.size() - this->scan_width_)
|
||||
if (this->at_led_ >= max_pos)
|
||||
this->direction_ = false;
|
||||
} else {
|
||||
this->at_led_--;
|
||||
if (this->at_led_ > 0)
|
||||
this->at_led_--;
|
||||
if (this->at_led_ == 0)
|
||||
this->direction_ = true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user