Browse Source

Getting ready for 2021.9.1 release.

main
Maurice Makaay 3 years ago
parent
commit
76fd479ee5
1 changed files with 16 additions and 16 deletions
  1. +16
    -16
      components/xiaomi_bslamp2/light/light_transformer.h

+ 16
- 16
components/xiaomi_bslamp2/light/light_transformer.h View File

@ -30,8 +30,8 @@ class XiaomiBslamp2LightTransitionTransformer : public light::LightTransitionTra
void start() override { void start() override {
// Determine the GPIO outputs to use for the start and end point. // Determine the GPIO outputs to use for the start and end point.
// This light transition transformer will then transition linearly between them. // This light transition transformer will then transition linearly between them.
light_->copy_to(start_);
end_->set_light_color_values(target_values_);
light_->copy_to(&start_);
end_.set_light_color_values(target_values_);
// Update the light mode of the light HAL to the target state, unless // Update the light mode of the light HAL to the target state, unless
// this is night mode. For night mode, the update is done after the // this is night mode. For night mode, the update is done after the
@ -41,14 +41,14 @@ class XiaomiBslamp2LightTransitionTransformer : public light::LightTransitionTra
// and transitioning to night light in 10 seconds, interrupting this // and transitioning to night light in 10 seconds, interrupting this
// after 5 seconds with a new night light setting should not make the // after 5 seconds with a new night light setting should not make the
// transition instant. // transition instant.
if (end_->light_mode != LIGHT_MODE_NIGHT) {
light_->set_light_mode(end_->light_mode);
if (end_.light_mode != LIGHT_MODE_NIGHT) {
light_->set_light_mode(end_.light_mode);
} }
// Run callbacks. These are normally called from the LightOutput, but // Run callbacks. These are normally called from the LightOutput, but
// since I don't call LightOutput::write_state() from this transformer's // since I don't call LightOutput::write_state() from this transformer's
// code, these callbacks must be called from this transformer instead. // code, these callbacks must be called from this transformer instead.
light_mode_callback_.call(end_->light_mode);
light_mode_callback_.call(end_.light_mode);
state_callback_.call(target_values_); state_callback_.call(target_values_);
} }
@ -56,26 +56,26 @@ class XiaomiBslamp2LightTransitionTransformer : public light::LightTransitionTra
// When transitioning between night mode light colors, then do this immediately. // When transitioning between night mode light colors, then do this immediately.
// The LED driver circuitry is not capable of doing clean color or brightness // The LED driver circuitry is not capable of doing clean color or brightness
// transitions at the low levels as used for the night light. // transitions at the low levels as used for the night light.
if (end_->light_mode == LIGHT_MODE_NIGHT && start_->light_mode == LIGHT_MODE_NIGHT) {
light_->set_state(end_);
if (end_.light_mode == LIGHT_MODE_NIGHT && start_.light_mode == LIGHT_MODE_NIGHT) {
light_->set_state(&end_);
force_finish_ = true; force_finish_ = true;
} }
// Otherwise perform a standard transformation. // Otherwise perform a standard transformation.
else { else {
auto smoothed = light::LightTransitionTransformer::smoothed_progress(get_progress_()); auto smoothed = light::LightTransitionTransformer::smoothed_progress(get_progress_());
light_->set_rgbw( light_->set_rgbw(
esphome::lerp(smoothed, start_->red, end_->red),
esphome::lerp(smoothed, start_->green, end_->green),
esphome::lerp(smoothed, start_->blue, end_->blue),
esphome::lerp(smoothed, start_->white, end_->white));
if (end_->light_mode != LIGHT_MODE_OFF) {
esphome::lerp(smoothed, start_.red, end_.red),
esphome::lerp(smoothed, start_.green, end_.green),
esphome::lerp(smoothed, start_.blue, end_.blue),
esphome::lerp(smoothed, start_.white, end_.white));
if (end_.light_mode != LIGHT_MODE_OFF) {
light_->turn_on(); light_->turn_on();
} }
} }
if (is_finished()) { if (is_finished()) {
light_->set_light_mode(end_->light_mode);
if (end_->light_mode == LIGHT_MODE_OFF) {
light_->set_light_mode(end_.light_mode);
if (end_.light_mode == LIGHT_MODE_OFF) {
light_->turn_off(); light_->turn_off();
} }
@ -88,8 +88,8 @@ class XiaomiBslamp2LightTransitionTransformer : public light::LightTransitionTra
protected: protected:
LightHAL *light_; LightHAL *light_;
bool force_finish_{false}; bool force_finish_{false};
GPIOOutputValues *start_ = new GPIOOutputValues();
ColorHandler *end_ = new ColorHandlerChain();
GPIOOutputValues start_{};
ColorHandlerChain end_{};
CallbackManager<void(std::string)> light_mode_callback_{}; CallbackManager<void(std::string)> light_mode_callback_{};
CallbackManager<void(light::LightColorValues)> state_callback_{}; CallbackManager<void(light::LightColorValues)> state_callback_{};
}; };


Loading…
Cancel
Save