ESPHome 2025.12.3
Loading...
Searching...
No Matches
esp_range_view.h
Go to the documentation of this file.
1#pragma once
2
3#include "esp_color_view.h"
4#include "esp_hsv_color.h"
5
6namespace esphome::light {
7
8int32_t interpret_index(int32_t index, int32_t size);
9
10class AddressableLight;
11class ESPRangeIterator;
12
17 public:
18 ESPRangeView(AddressableLight *parent, int32_t begin, int32_t end)
19 : parent_(parent), begin_(begin), end_(end < begin ? begin : end) {}
20 ESPRangeView(const ESPRangeView &) = default;
21
22 int32_t size() const { return this->end_ - this->begin_; }
23 ESPColorView operator[](int32_t index) const;
26
27 void set(const Color &color) override;
28 void set(const ESPHSVColor &color) { this->set(color.to_rgb()); }
29 void set_red(uint8_t red) override;
30 void set_green(uint8_t green) override;
31 void set_blue(uint8_t blue) override;
32 void set_white(uint8_t white) override;
33 void set_effect_data(uint8_t effect_data) override;
34
35 void fade_to_white(uint8_t amnt) override;
36 void fade_to_black(uint8_t amnt) override;
37 void lighten(uint8_t delta) override;
38 void darken(uint8_t delta) override;
39
41 this->set(rhs);
42 return *this;
43 }
45 this->set(rhs.get());
46 return *this;
47 }
49 this->set_hsv(rhs);
50 return *this;
51 }
53
54 protected:
56
58 int32_t begin_;
59 int32_t end_;
60};
61
63 public:
64 ESPRangeIterator(const ESPRangeView &range, int32_t i) : range_(range), i_(i) {}
67 this->i_++;
68 return *this;
69 }
70 bool operator!=(const ESPRangeIterator &other) const { return this->i_ != other.i_; }
71 ESPColorView operator*() const;
72
73 protected:
75 int32_t i_;
76};
77
78} // namespace esphome::light
void set_hsv(const ESPHSVColor &color)
ESPRangeIterator(const ESPRangeView &range, int32_t i)
bool operator!=(const ESPRangeIterator &other) const
ESPRangeIterator(const ESPRangeIterator &)=default
A half-open range of LEDs, inclusive of the begin index and exclusive of the end index,...
ESPRangeView & operator=(const ESPColorView &rhs)
void set_white(uint8_t white) override
void lighten(uint8_t delta) override
void set_blue(uint8_t blue) override
ESPRangeView & operator=(const ESPHSVColor &rhs)
void set_green(uint8_t green) override
void fade_to_white(uint8_t amnt) override
ESPRangeView(const ESPRangeView &)=default
ESPRangeView & operator=(const Color &rhs)
void fade_to_black(uint8_t amnt) override
void set_effect_data(uint8_t effect_data) override
void set(const ESPHSVColor &color)
ESPColorView operator[](int32_t index) const
void set_red(uint8_t red) override
ESPRangeView(AddressableLight *parent, int32_t begin, int32_t end)
void darken(uint8_t delta) override
void set(const Color &color) override
Range range
Definition msa3xx.h:0
int32_t HOT interpret_index(int32_t index, int32_t size)