ESPHome 2026.11.0-dev
Loading...
Searching...
No Matches
esp_color_view.h
Go to the documentation of this file.
1#pragma once
2
4#include "esp_hsv_color.h"
6
7namespace esphome::light {
8
10 public:
11 virtual void set(const Color &color) = 0;
12 virtual void set_red(uint8_t red) = 0;
13 virtual void set_green(uint8_t green) = 0;
14 virtual void set_blue(uint8_t blue) = 0;
15 virtual void set_white(uint8_t white) = 0;
16 virtual void set_effect_data(uint8_t effect_data) = 0;
17 virtual void fade_to_white(uint8_t amnt) = 0;
18 virtual void fade_to_black(uint8_t amnt) = 0;
19 virtual void lighten(uint8_t delta) = 0;
20 virtual void darken(uint8_t delta) = 0;
21 void set(const ESPHSVColor &color) { this->set_hsv(color); }
22 void set_hsv(const ESPHSVColor &color) { this->set(color.to_rgb()); }
23 void set_rgb(uint8_t red, uint8_t green, uint8_t blue) {
24 this->set_red(red);
25 this->set_green(green);
26 this->set_blue(blue);
27 }
28 void set_rgbw(uint8_t red, uint8_t green, uint8_t blue, uint8_t white) {
29 this->set_rgb(red, green, blue);
30 this->set_white(white);
31 }
32};
33
35 public:
36 ESPColorView(uint8_t *red, uint8_t *green, uint8_t *blue, uint8_t *white, uint8_t *effect_data,
37 const ESPColorCorrection *color_correction)
38 : red_(red),
39 green_(green),
40 blue_(blue),
41 white_(white),
42 effect_data_(effect_data),
43 color_correction_(color_correction) {}
45 this->set(rhs);
46 return *this;
47 }
49 this->set_hsv(rhs);
50 return *this;
51 }
52 void set(const Color &color) override { this->set_rgbw(color.r, color.g, color.b, color.w); }
53 void set_red(uint8_t red) override { *this->red_ = this->color_correction_->color_correct_red(red); }
54 void set_green(uint8_t green) override { *this->green_ = this->color_correction_->color_correct_green(green); }
55 void set_blue(uint8_t blue) override { *this->blue_ = this->color_correction_->color_correct_blue(blue); }
56 void set_white(uint8_t white) override {
57 if (this->white_ == nullptr)
58 return;
59 *this->white_ = this->color_correction_->color_correct_white(white);
60 }
61 void set_effect_data(uint8_t effect_data) override {
62 if (this->effect_data_ == nullptr)
63 return;
64 *this->effect_data_ = effect_data;
65 }
66 void fade_to_white(uint8_t amnt) override { this->set(this->get().fade_to_white(amnt)); }
67 void fade_to_black(uint8_t amnt) override { this->set(this->get().fade_to_black(amnt)); }
68 void lighten(uint8_t delta) override { this->set(this->get().lighten(delta)); }
69 void darken(uint8_t delta) override { this->set(this->get().darken(delta)); }
70 Color get() const { return Color(this->get_red(), this->get_green(), this->get_blue(), this->get_white()); }
71 uint8_t get_red() const { return this->color_correction_->color_uncorrect_red(*this->red_); }
72 uint8_t get_red_raw() const { return *this->red_; }
73 uint8_t get_green() const { return this->color_correction_->color_uncorrect_green(*this->green_); }
74 uint8_t get_green_raw() const { return *this->green_; }
75 uint8_t get_blue() const { return this->color_correction_->color_uncorrect_blue(*this->blue_); }
76 uint8_t get_blue_raw() const { return *this->blue_; }
77 uint8_t get_white() const {
78 if (this->white_ == nullptr)
79 return 0;
81 }
82 uint8_t get_white_raw() const {
83 if (this->white_ == nullptr)
84 return 0;
85 return *this->white_;
86 }
87 uint8_t get_effect_data() const {
88 if (this->effect_data_ == nullptr)
89 return 0;
90 return *this->effect_data_;
91 }
93 void raw_set_color_correction(const ESPColorCorrection *color_correction) {
94 this->color_correction_ = color_correction;
95 }
97 void set_raw(uint8_t red, uint8_t green, uint8_t blue, uint8_t white) {
98 *this->red_ = red;
99 *this->green_ = green;
100 *this->blue_ = blue;
101 if (this->white_ != nullptr)
102 *this->white_ = white;
103 }
104
105 protected:
106 uint8_t *const red_;
107 uint8_t *const green_;
108 uint8_t *const blue_;
109 uint8_t *const white_;
110 uint8_t *const effect_data_;
112};
113
114} // namespace esphome::light
uint8_t color_uncorrect_red(uint8_t red) const ESPHOME_ALWAYS_INLINE
uint8_t color_correct_blue(uint8_t blue) const ESPHOME_ALWAYS_INLINE
uint8_t color_correct_red(uint8_t red) const ESPHOME_ALWAYS_INLINE
uint8_t color_uncorrect_blue(uint8_t blue) const ESPHOME_ALWAYS_INLINE
uint8_t color_uncorrect_green(uint8_t green) const ESPHOME_ALWAYS_INLINE
uint8_t color_correct_green(uint8_t green) const ESPHOME_ALWAYS_INLINE
uint8_t color_correct_white(uint8_t white) const ESPHOME_ALWAYS_INLINE
uint8_t color_uncorrect_white(uint8_t white) const ESPHOME_ALWAYS_INLINE
virtual void set(const Color &color)=0
void set_rgb(uint8_t red, uint8_t green, uint8_t blue)
void set_hsv(const ESPHSVColor &color)
void set_rgbw(uint8_t red, uint8_t green, uint8_t blue, uint8_t white)
virtual void darken(uint8_t delta)=0
virtual void lighten(uint8_t delta)=0
virtual void set_red(uint8_t red)=0
virtual void fade_to_white(uint8_t amnt)=0
void set(const ESPHSVColor &color)
virtual void set_green(uint8_t green)=0
virtual void set_blue(uint8_t blue)=0
virtual void set_white(uint8_t white)=0
virtual void fade_to_black(uint8_t amnt)=0
virtual void set_effect_data(uint8_t effect_data)=0
ESPColorView & operator=(const ESPHSVColor &rhs)
ESPColorView(uint8_t *red, uint8_t *green, uint8_t *blue, uint8_t *white, uint8_t *effect_data, const ESPColorCorrection *color_correction)
void fade_to_black(uint8_t amnt) override
void fade_to_white(uint8_t amnt) override
void darken(uint8_t delta) override
void set(const Color &color) override
void set_effect_data(uint8_t effect_data) override
void set_white(uint8_t white) override
ESPColorView & operator=(const Color &rhs)
const ESPColorCorrection * get_color_correction() const
const ESPColorCorrection * color_correction_
void raw_set_color_correction(const ESPColorCorrection *color_correction)
void set_raw(uint8_t red, uint8_t green, uint8_t blue, uint8_t white)
Store hardware levels as they are, without the correction.
void set_red(uint8_t red) override
void lighten(uint8_t delta) override
void set_blue(uint8_t blue) override
void set_green(uint8_t green) override
uint8_t w
Definition color.h:42
uint8_t g
Definition color.h:34
uint8_t b
Definition color.h:38
uint8_t r
Definition color.h:30