ESPHome  2024.11.0
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 
6 namespace esphome {
7 namespace light {
8 
9 int32_t interpret_index(int32_t index, int32_t size);
10 
11 class AddressableLight;
12 class ESPRangeIterator;
13 
18  public:
19  ESPRangeView(AddressableLight *parent, int32_t begin, int32_t end)
20  : parent_(parent), begin_(begin), end_(end < begin ? begin : end) {}
21  ESPRangeView(const ESPRangeView &) = default;
22 
23  int32_t size() const { return this->end_ - this->begin_; }
24  ESPColorView operator[](int32_t index) const;
27 
28  void set(const Color &color) override;
29  void set(const ESPHSVColor &color) { this->set(color.to_rgb()); }
30  void set_red(uint8_t red) override;
31  void set_green(uint8_t green) override;
32  void set_blue(uint8_t blue) override;
33  void set_white(uint8_t white) override;
34  void set_effect_data(uint8_t effect_data) override;
35 
36  void fade_to_white(uint8_t amnt) override;
37  void fade_to_black(uint8_t amnt) override;
38  void lighten(uint8_t delta) override;
39  void darken(uint8_t delta) override;
40 
41  ESPRangeView &operator=(const Color &rhs) {
42  this->set(rhs);
43  return *this;
44  }
46  this->set(rhs.get());
47  return *this;
48  }
50  this->set_hsv(rhs);
51  return *this;
52  }
53  ESPRangeView &operator=(const ESPRangeView &rhs);
54 
55  protected:
57 
59  int32_t begin_;
60  int32_t end_;
61 };
62 
64  public:
65  ESPRangeIterator(const ESPRangeView &range, int32_t i) : range_(range), i_(i) {}
66  ESPRangeIterator(const ESPRangeIterator &) = default;
68  this->i_++;
69  return *this;
70  }
71  bool operator!=(const ESPRangeIterator &other) const { return this->i_ != other.i_; }
72  ESPColorView operator*() const;
73 
74  protected:
76  int32_t i_;
77 };
78 
79 } // namespace light
80 } // namespace esphome
void set_red(uint8_t red) override
void fade_to_white(uint8_t amnt) override
void set_white(uint8_t white) override
void darken(uint8_t delta) override
ESPRangeView & operator=(const Color &rhs)
int32_t HOT interpret_index(int32_t index, int32_t size)
ESPRangeView(AddressableLight *parent, int32_t begin, int32_t end)
ESPRangeView & operator=(const ESPHSVColor &rhs)
AddressableLight * parent_
void set_hsv(const ESPHSVColor &color)
ESPColorView operator[](int32_t index) const
void fade_to_black(uint8_t amnt) override
ESPRangeView & operator=(const ESPColorView &rhs)
void lighten(uint8_t delta) override
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
A half-open range of LEDs, inclusive of the begin index and exclusive of the end index, using zero-based numbering.
void set_effect_data(uint8_t effect_data) override
bool operator!=(const ESPRangeIterator &other) const
void set_blue(uint8_t blue) override
ESPRangeIterator(const ESPRangeView &range, int32_t i)
void set_green(uint8_t green) override