From 197ccfe0d37cdf774c94aa5fd62a2649f08401cc Mon Sep 17 00:00:00 2001 From: Maurice Makaay Date: Thu, 22 Apr 2021 23:35:47 +0200 Subject: [PATCH] Suppress transitions for night light mode. Fixes #10 "When changing RGB color settings, while night light mode is active, transitions don't look good. On many of the transitions, the light level shows a significant drop." This commit fully suppresses transitions when the light is in night light mode. --- light/color_transition_handler.h | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/light/color_transition_handler.h b/light/color_transition_handler.h index dc77de3..0c0184b 100644 --- a/light/color_transition_handler.h +++ b/light/color_transition_handler.h @@ -84,14 +84,27 @@ public: } light_mode = end_->light_mode; + progress_ = transformer_->get_progress(); // Determine required GPIO outputs for current transition progress. - progress_ = transformer_->get_progress(); - auto smoothed = light::LightTransitionTransformer::smoothed_progress(progress_); - red = esphome::lerp(smoothed, start_->red, end_->red); - green = esphome::lerp(smoothed, start_->green, end_->green); - blue = esphome::lerp(smoothed, start_->blue, end_->blue); - white = esphome::lerp(smoothed, start_->white, end_->white); + + // In night light mode, do not use actual transitions. Transitioning + // between colors at the very low LED output levels of the night light, + // results in light drops, which are plain ugly to watch. + if (light_mode == "night") { + red = end_->red; + green = end_->green; + blue = end_->blue; + white = end_->white; + } + // In other light modes, apply smooth transitioning. + else { + auto smoothed = light::LightTransitionTransformer::smoothed_progress(progress_); + red = esphome::lerp(smoothed, start_->red, end_->red); + green = esphome::lerp(smoothed, start_->green, end_->green); + blue = esphome::lerp(smoothed, start_->blue, end_->blue); + white = esphome::lerp(smoothed, start_->white, end_->white); + } return true; }