30 constexpr operator uint8_t()
const {
return static_cast<uint8_t
>(
val_); }
31 constexpr operator bool()
const {
return static_cast<uint8_t
>(
val_) != 0; }
37 return static_cast<ColorCapability>(
static_cast<uint8_t
>(lhs) &
static_cast<uint8_t
>(rhs));
40 return static_cast<ColorCapability>(
static_cast<uint8_t
>(lhs) &
static_cast<uint8_t
>(rhs));
43 return static_cast<ColorCapability>(
static_cast<uint8_t
>(lhs) |
static_cast<uint8_t
>(rhs));
46 return static_cast<ColorCapability>(
static_cast<uint8_t
>(lhs) |
static_cast<uint8_t
>(rhs));
83 constexpr operator uint8_t()
const {
return static_cast<uint8_t
>(
val_); }
84 constexpr operator bool()
const {
return static_cast<uint8_t
>(
val_) != 0; }
90 return static_cast<ColorMode>(
static_cast<uint8_t
>(lhs) &
static_cast<uint8_t
>(rhs));
93 return static_cast<ColorMode>(
static_cast<uint8_t
>(lhs) &
static_cast<uint8_t
>(rhs));
96 return static_cast<ColorMode>(
static_cast<uint8_t
>(lhs) &
static_cast<uint8_t
>(rhs));
99 return static_cast<ColorMode>(
static_cast<uint8_t
>(lhs) |
static_cast<uint8_t
>(rhs));
102 return static_cast<ColorMode>(
static_cast<uint8_t
>(lhs) |
static_cast<uint8_t
>(rhs));
105 return static_cast<ColorMode>(
static_cast<uint8_t
>(lhs) |
static_cast<uint8_t
>(rhs));
128 if (__builtin_is_constant_evaluated())
129 return COLOR_MODE_LOOKUP[bit];
137 static constexpr int MAX_BITS =
sizeof(COLOR_MODE_LOOKUP) /
sizeof(COLOR_MODE_LOOKUP[0]);
140 for (
int i = 0; i <
MAX_BITS; ++i) {
161 uint8_t cap_bit =
static_cast<uint8_t
>(capability);
164 constexpr int color_mode_count =
sizeof(COLOR_MODE_LOOKUP) /
sizeof(COLOR_MODE_LOOKUP[0]);
165 for (
int bit = 0; bit < color_mode_count; ++bit) {
167 if ((mode_val & cap_bit) != 0) {
196 uint8_t cap_val =
static_cast<uint8_t
>(capability);
197#if defined(__GNUC__) || defined(__clang__)
199 return __builtin_ctz(cap_val);
203 while (cap_val > 1) {
BedjetMode mode
BedJet operating mode.
constexpr bitmask_t get_mask() const
Get the raw bitmask value for optimized operations.
Helper class to allow bitwise operations on ColorCapability.
constexpr ColorCapabilityHelper(ColorCapability val)
Helper class to allow bitwise operations on ColorMode with ColorCapability.
constexpr ColorModeHelper(ColorMode val)
constexpr ColorCapabilityHelper operator|(ColorCapability lhs, ColorCapability rhs)
bool has_capability(const ColorModeMask &mask, ColorCapability capability)
Check if any mode in the bitmask has a specific capability Used for checking if a light supports a ca...
constexpr ColorMode COLOR_MODE_LOOKUP[] PROGMEM
constexpr uint16_t compute_capability_bitmask(ColorCapability capability)
Helper to compute capability bitmask at compile time.
uint16_t color_mode_bitmask_t
constexpr ColorMode color_mode_at(unsigned bit)
constexpr int COLOR_CAPABILITY_COUNT
constexpr ColorCapabilityHelper operator&(ColorCapability lhs, ColorCapability rhs)
ColorMode
Color modes are a combination of color capabilities that can be used at the same time.
@ ON_OFF
Only on/off control.
@ RGB_COLD_WARM_WHITE
RGB color output, and separate cold and warm white outputs.
@ BRIGHTNESS
Dimmable light.
@ UNKNOWN
No color mode configured (cannot be a supported mode, only active when light is off).
@ RGB_WHITE
RGB color output and a separate white output.
@ RGB_COLOR_TEMPERATURE
RGB color output and a separate white output with controllable color temperature.
@ COLOR_TEMPERATURE
Controllable color temperature output.
@ WHITE
White output only (use only if the light also has another color mode such as RGB).
@ COLD_WARM_WHITE
Cold and warm white output with individually controllable brightness.
int capability_to_index(ColorCapability capability)
Helper function to convert a power-of-2 ColorCapability value to an array index for CAPABILITY_BITMAS...
ColorCapability
Color capabilities are the various outputs that a light has and that can be independently controlled ...
@ ON_OFF
Light can be turned on/off.
@ BRIGHTNESS
Master brightness of the light can be controlled.
@ RGB
Color can be controlled using RGB format (includes a brightness control for the color).
@ COLOR_TEMPERATURE
Color temperature can be controlled.
@ WHITE
Brightness of white channel can be controlled separately from other channels.
@ COLD_WARM_WHITE
Brightness of cold and warm white output can be controlled.
constexpr uint16_t CAPABILITY_BITMASKS[]
Compile-time lookup table mapping ColorCapability to bitmask This array is computed at compile time u...
uint8_t progmem_read_byte(const uint8_t *addr)
Bit mapping policy for ColorMode Uses lookup table for non-contiguous enum values.
static constexpr ColorMode from_bit(unsigned bit)
static constexpr unsigned to_bit(ColorMode mode)
static constexpr int MAX_BITS