Rgbww color fix (#967)

* RGBWW color vs white and brightness adjustments
This commit is contained in:
Quinn Hosler 2020-03-11 20:33:20 -04:00 committed by GitHub
parent e0b4226930
commit 177617e6e3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -393,6 +393,36 @@ LightColorValues LightCall::validate_() {
this->color_temperature_.reset(); this->color_temperature_.reset();
} }
// sets RGB to 100% if only White specified
if (this->white_.has_value()) {
if (!this->red_.has_value() && !this->green_.has_value() && !this->blue_.has_value()) {
this->red_ = optional<float>(1.0f);
this->green_ = optional<float>(1.0f);
this->blue_ = optional<float>(1.0f);
}
}
// White to 0% if (exclusively) setting any RGB value
else if (this->red_.has_value() || this->green_.has_value() || this->blue_.has_value()) {
if (!this->white_.has_value()) {
this->white_ = optional<float>(0.0f);
}
}
// if changing Kelvin alone, change to white light
else if (this->color_temperature_.has_value()) {
if (!this->red_.has_value() && !this->green_.has_value() && !this->blue_.has_value()) {
this->red_ = optional<float>(1.0f);
this->green_ = optional<float>(1.0f);
this->blue_ = optional<float>(1.0f);
}
// if setting Kelvin from color (i.e. switching to white light), set White to 100%
auto cv = this->parent_->remote_values;
bool was_color = cv.get_red() != 1.0f || cv.get_blue() != 1.0f || cv.get_green() != 1.0f;
bool now_white = *this->red_ == 1.0f && *this->blue_ == 1.0f && *this->green_ == 1.0f;
if (!this->white_.has_value() && was_color && now_white) {
this->white_ = optional<float>(1.0f);
}
}
#define VALIDATE_RANGE_(name_, upper_name) \ #define VALIDATE_RANGE_(name_, upper_name) \
if (name_##_.has_value()) { \ if (name_##_.has_value()) { \
auto val = *name_##_; \ auto val = *name_##_; \