[light] Fix unsigned underflow in addressable scan effect (#14546)

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Jonathan Swoboda
2026-03-06 14:42:05 -05:00
committed by GitHub
parent 219d5170e0
commit 9ab5f5d451

View File

@@ -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;
}