ESPHome 2026.10.0-dev
Loading...
Searching...
No Matches
esp_range_view.cpp
Go to the documentation of this file.
1#include "esp_range_view.h"
2#include "addressable_light.h"
3
4namespace esphome::light {
5
6int32_t HOT interpret_index(int32_t index, int32_t size) {
7 if (index < 0)
8 return size + index;
9 return index;
10}
11
13 index = interpret_index(index, this->size()) + this->begin_;
14 return (*this->parent_)[index];
15}
16
17void ESPRangeView::set(const Color &color) {
18 for (int32_t i = this->begin_; i < this->end_; i++) {
19 (*this->parent_)[i] = color;
20 }
21}
22
23void ESPRangeView::set_red(uint8_t red) {
24 for (auto c : *this)
25 c.set_red(red);
26}
27void ESPRangeView::set_green(uint8_t green) {
28 for (auto c : *this)
29 c.set_green(green);
30}
31void ESPRangeView::set_blue(uint8_t blue) {
32 for (auto c : *this)
33 c.set_blue(blue);
34}
35void ESPRangeView::set_white(uint8_t white) {
36 for (auto c : *this)
37 c.set_white(white);
38}
39void ESPRangeView::set_effect_data(uint8_t effect_data) {
40 for (auto c : *this)
41 c.set_effect_data(effect_data);
42}
43
44void ESPRangeView::fade_to_white(uint8_t amnt) {
45 for (auto c : *this)
46 c.fade_to_white(amnt);
47}
48void ESPRangeView::fade_to_black(uint8_t amnt) {
49 for (auto c : *this)
50 c.fade_to_black(amnt);
51}
52void ESPRangeView::lighten(uint8_t delta) {
53 for (auto c : *this)
54 c.lighten(delta);
55}
56void ESPRangeView::darken(uint8_t delta) {
57 for (auto c : *this)
58 c.darken(delta);
59}
61 // If size doesn't match, error (todo warning)
62 if (rhs.size() != this->size())
63 return *this;
64
65 if (this->parent_ != rhs.parent_) {
66 for (int32_t i = 0; i < this->size(); i++)
67 (*this)[i].set(rhs[i].get());
68 return *this;
69 }
70
71 // If both equal, already done
72 if (rhs.begin_ == this->begin_)
73 return *this;
74
75 if (rhs.begin_ > this->begin_) {
76 // Copy from left
77 for (int32_t i = 0; i < this->size(); i++) {
78 (*this)[i].set(rhs[i].get());
79 }
80 } else {
81 // Copy from right
82 for (int32_t i = this->size() - 1; i >= 0; i--) {
83 (*this)[i].set(rhs[i].get());
84 }
85 }
86
87 return *this;
88}
89
91
92} // namespace esphome::light
ESPColorView get(int32_t index)
void set_red(uint8_t red) override
A half-open range of LEDs, inclusive of the begin index and exclusive of the end index,...
void set_white(uint8_t white) override
void lighten(uint8_t delta) override
void set_blue(uint8_t blue) override
void set_green(uint8_t green) override
void fade_to_white(uint8_t amnt) override
ESPRangeView & operator=(const Color &rhs)
void fade_to_black(uint8_t amnt) override
void set_effect_data(uint8_t effect_data) override
ESPColorView operator[](int32_t index) const
void set_red(uint8_t red) override
void darken(uint8_t delta) override
void set(const Color &color) override
int32_t HOT interpret_index(int32_t index, int32_t size)
uint16_t size
Definition helpers.cpp:25