ESPHome  2022.8.0
color_mode.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <cstdint>
4 
5 namespace esphome {
6 namespace light {
7 
9 enum class ColorCapability : uint8_t {
11  ON_OFF = 1 << 0,
13  BRIGHTNESS = 1 << 1,
15  WHITE = 1 << 2,
17  COLOR_TEMPERATURE = 1 << 3,
19  COLD_WARM_WHITE = 1 << 4,
21  RGB = 1 << 5
22 };
23 
26  public:
27  constexpr ColorCapabilityHelper(ColorCapability val) : val_(val) {}
28  constexpr operator ColorCapability() const { return val_; }
29  constexpr operator uint8_t() const { return static_cast<uint8_t>(val_); }
30  constexpr operator bool() const { return static_cast<uint8_t>(val_) != 0; }
31 
32  protected:
34 };
36  return static_cast<ColorCapability>(static_cast<uint8_t>(lhs) & static_cast<uint8_t>(rhs));
37 }
39  return static_cast<ColorCapability>(static_cast<uint8_t>(lhs) & static_cast<uint8_t>(rhs));
40 }
42  return static_cast<ColorCapability>(static_cast<uint8_t>(lhs) | static_cast<uint8_t>(rhs));
43 }
45  return static_cast<ColorCapability>(static_cast<uint8_t>(lhs) | static_cast<uint8_t>(rhs));
46 }
47 
49 enum class ColorMode : uint8_t {
51  UNKNOWN = 0,
53  ON_OFF = (uint8_t) ColorCapability::ON_OFF,
66  RGB_WHITE =
74 };
75 
78  public:
79  constexpr ColorModeHelper(ColorMode val) : val_(val) {}
80  constexpr operator ColorMode() const { return val_; }
81  constexpr operator uint8_t() const { return static_cast<uint8_t>(val_); }
82  constexpr operator bool() const { return static_cast<uint8_t>(val_) != 0; }
83 
84  protected:
86 };
88  return static_cast<ColorMode>(static_cast<uint8_t>(lhs) & static_cast<uint8_t>(rhs));
89 }
91  return static_cast<ColorMode>(static_cast<uint8_t>(lhs) & static_cast<uint8_t>(rhs));
92 }
94  return static_cast<ColorMode>(static_cast<uint8_t>(lhs) & static_cast<uint8_t>(rhs));
95 }
97  return static_cast<ColorMode>(static_cast<uint8_t>(lhs) | static_cast<uint8_t>(rhs));
98 }
100  return static_cast<ColorMode>(static_cast<uint8_t>(lhs) | static_cast<uint8_t>(rhs));
101 }
103  return static_cast<ColorMode>(static_cast<uint8_t>(lhs) | static_cast<uint8_t>(rhs));
104 }
105 
106 } // namespace light
107 } // namespace esphome
ColorMode
Color modes are a combination of color capabilities that can be used at the same time.
Definition: color_mode.h:49
RGB color output and a separate white output.
Helper class to allow bitwise operations on ColorMode with ColorCapability.
Definition: color_mode.h:77
Color temperature can be controlled.
constexpr ColorCapabilityHelper operator|(ColorCapability lhs, ColorCapability rhs)
Definition: color_mode.h:41
constexpr ColorCapabilityHelper(ColorCapability val)
Definition: color_mode.h:27
RGB color output, and separate cold and warm white outputs.
Brightness of cold and warm white output can be controlled.
Brightness of white channel can be controlled separately from other channels.
Light can be turned on/off.
RGB color output and a separate white output with controllable color temperature. ...
Helper class to allow bitwise operations on ColorCapability.
Definition: color_mode.h:25
constexpr ColorCapabilityHelper operator &(ColorCapability lhs, ColorCapability rhs)
Definition: color_mode.h:35
Master brightness of the light can be controlled.
No color mode configured (cannot be a supported mode, only active when light is off).
ColorCapability
Color capabilities are the various outputs that a light has and that can be independently controlled ...
Definition: color_mode.h:9
Definition: a4988.cpp:4
Color can be controlled using RGB format (includes a brightness control for the color).
uint32_t val
Definition: datatypes.h:85
constexpr ColorModeHelper(ColorMode val)
Definition: color_mode.h:79