From c0507e642b6764908c8eebd0e2c0a0736c91e283 Mon Sep 17 00:00:00 2001 From: Maurice Makaay Date: Wed, 7 Apr 2021 18:35:22 +0200 Subject: [PATCH] In RGB mode, brightness level 1 now triggers a night light mode that actually uses the RGB settings. So this makes it possible to have a night light in a specific color, instead of only the default night light setting. In white light mode, this default is used, so color temperature does not affect the night light color. --- color_night_light.h | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/color_night_light.h b/color_night_light.h index d3fd5a9..f2f62dd 100644 --- a/color_night_light.h +++ b/color_night_light.h @@ -13,11 +13,26 @@ class ColorNightLight : public GPIOOutputs { public: bool set_light_color_values(light::LightColorValues v) { values = v; - // Based on measurements using the original device firmware. - red = 0.968f; - green = 0.968f; - blue = 0.972f; - white = 0.0f; + + // This night light mode is activated when white light is selected. + // Based on measurements using the original device firmware, so it + // matches the night light of the original firmware. + if (v.get_white() > 0) { + red = 0.968f; + green = 0.968f; + blue = 0.972f; + white = 0.0f; + } + // In RGB mode, the selected color is used to give the night light + // a specific color, instead of the default. This is a nice extra + // for this firmware, as the original firmware does not support it. + else { + red = 0.9997f - v.get_red() * (0.9997f - 0.9680f); + green = 0.9997f - v.get_green() * (0.9997f - 0.9680f); + auto blue_on = 0.9720f + (0.9680f - 0.9720f) * (1.0f - (v.get_red() + v.get_green())/2.0f); + blue = 0.9997f - v.get_blue() * (0.9997f - blue_on); + white = 0.0f; + } return true; }