ESPHome 2026.11.0b6
Loading...
Searching...
No Matches
esp_range_view.cpp
Go to the documentation of this file.
1#include "esp_range_view.h"
2
3namespace esphome::light {
4
6 for (int32_t i = this->begin_; i < this->end_; i++)
7 this->accessor_->set(i, color);
8}
9void ESPRangeView::set_channel(uint8_t channel, uint8_t value) {
10 for (int32_t i = this->begin_; i < this->end_; i++)
11 this->accessor_->set_channel(i, channel, value);
12}
13void ESPRangeView::set_effect_data(uint8_t effect_data) {
14 for (auto c : *this)
15 c.set_effect_data(effect_data);
16}
17
18void ESPRangeView::fade_to_white(uint8_t amnt) {
19 for (auto c : *this)
20 c.fade_to_white(amnt);
21}
22void ESPRangeView::fade_to_black(uint8_t amnt) {
23 for (auto c : *this)
24 c.fade_to_black(amnt);
25}
26void ESPRangeView::lighten(uint8_t delta) {
27 for (auto c : *this)
28 c.lighten(delta);
29}
30void ESPRangeView::darken(uint8_t delta) {
31 for (auto c : *this)
32 c.darken(delta);
33}
35 // If size doesn't match, error (todo warning)
36 if (rhs.size() != this->size())
37 return *this;
38
39 if (this->accessor_ != rhs.accessor_) {
40 for (int32_t i = 0; i < this->size(); i++)
41 (*this)[i].set(rhs[i].get());
42 return *this;
43 }
44
45 // If both equal, already done
46 if (rhs.begin_ == this->begin_)
47 return *this;
48
49 // The source is read before the destination view is fetched: a partition's views share one correction
50 if (rhs.begin_ > this->begin_) {
51 // Copy from left
52 for (int32_t i = 0; i < this->size(); i++) {
53 const Color color = rhs[i].get();
54 (*this)[i].set(color);
55 }
56 } else {
57 // Copy from right
58 for (int32_t i = this->size() - 1; i >= 0; i--) {
59 const Color color = rhs[i].get();
60 (*this)[i].set(color);
61 }
62 }
63
64 return *this;
65}
66
67} // namespace esphome::light
virtual void set(int32_t index, Color color)=0
virtual void set_channel(int32_t index, uint8_t channel, uint8_t value)=0
A half-open range of LEDs, inclusive of the begin index and exclusive of the end index,...
void lighten(uint8_t delta) override
void set_channel(uint8_t channel, uint8_t value) override
void fade_to_white(uint8_t amnt) override
void fade_to_black(uint8_t amnt) override
ESPColorAccessor *const accessor_
ESPRangeView & operator=(Color color)
void set_effect_data(uint8_t effect_data) override
void set(Color color) override
void darken(uint8_t delta) override
uint32_t value
Definition hal.cpp:41