From 77a18d52dc4c177dbbbb12b5e592bdb5fed264fc Mon Sep 17 00:00:00 2001 From: Maurice Makaay Date: Fri, 5 Mar 2021 15:15:31 +0100 Subject: [PATCH] Completed work on the temperature-based light controls. Both RGB and white light are now fully functional. --- .gitignore | 19 +++++++ .yeelight_bs2.h.swp | Bin 20480 -> 0 bytes yeelight_bs2.h | 127 ++++++++++++++++++++------------------------ 3 files changed, 77 insertions(+), 69 deletions(-) create mode 100644 .gitignore delete mode 100644 .yeelight_bs2.h.swp diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..19fa632 --- /dev/null +++ b/.gitignore @@ -0,0 +1,19 @@ +# Swap +[._]*.s[a-v][a-z] +!*.svg # comment out if you don't need vector files +[._]*.sw[a-p] +[._]s[a-rt-v][a-z] +[._]ss[a-gi-z] +[._]sw[a-p] + +# Session +Session.vim +Sessionx.vim + +# Temporary +.netrwhist +*~ +# Auto-generated tag files +tags +# Persistent undo +[._]*.un~ diff --git a/.yeelight_bs2.h.swp b/.yeelight_bs2.h.swp deleted file mode 100644 index fb0d1679d2b24e9b8810a425d6e0e9c78dbebff6..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 20480 zcmeI3Ym8%69l)=!2!q9GXYxWwHKb~@8`$DLi6)t%j8nYcT%nVDSyG4-~+?Nr*{ za_{Zb5!d*NL5+YfVxoybiLyqGFFyD{O*AGdpzr~M@sSv#MuY&OAMpA6pL1_}+sK%y-1GRKbN;V(i{r;C_-tZWDNnB%vW-G(z(a+{S}HTpQZ>NxdUbvY;${oGjmLuUCDx=xxT5=bPlkp$X7 zWpwhKWBFWm{F3c2R@=@ywo&V(E|EYYfkXm{1QH1(5=bPFNFb3wB7y%w2?VXvt-rCZ z)4+#kgq+S_i4Y_KAZ1(NYWQmSnLo)Zkw7AWL;{Hf5(y*{NF_>;7za(E`@VoE8KgoWu1h#!`r}x z*TA)KE^LL<;Aaf-A-DqmwAHenga_b$_&nSMuYo+A4&QyYWqkk&a2T$HLv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MgFE4a(1BOMzekVqhr zKq7&sO9DxT6F+Jx<{7P<;Y{M(jeniimzE(OFuvDjNsU;mD5gx3IRA7K=O50uCx`pr zaJY3op%)ZMP)=How522{hcknH`AMZ;CI-@x2sg}RF5@*OL(rGejK#hZq-SCex z_n-NSW#fSD{~^b1en8TnVu|gcsWv+q{Y= 371) { @@ -139,29 +144,17 @@ class YeelightBedsideLampV2LightOutput : public Component, public LightOutput float band = end - start; float red_volt = 2.86f * (1.0f - brightness); - float red = red_volt / volt_scaler; + red = red_volt / volt_scaler; float green_1 = 2.90f + (temperature - start) * (2.97f - 2.90f) / band; float green_100 = 0.45f + (temperature - start) * (1.13f - 0.45f) / band; float green_volt = green_1 + brightness * (green_100 - green_1); - float green = green_volt / volt_scaler; - - float blue = 1.0f; + green = green_volt / volt_scaler; float white_1 = 0.28f - (temperature - start) * (0.28f - 0.19f) / band; float white_100 = 1.07f - (temperature - start) * (1.07f - 0.22f) / band; float white_volt = white_1 + brightness * (white_100 - white_1); - float white = white_volt / volt_scaler; - - ESP_LOGD("temperature_mode", "LED state : RGBW %f, %f, %f, %f", red, green, blue, white); - - red_->set_level(red); - green_->set_level(green); - blue_->set_level(blue); - white_->set_level(white); - master2_->turn_on(); - master1_->turn_on(); - return; + white = white_volt / volt_scaler; } // Temperature band 334 - 370 else if (temperature >= 334) @@ -169,97 +162,93 @@ class YeelightBedsideLampV2LightOutput : public Component, public LightOutput volt_scaler = 3.23f; float red_volt = (1.0f - brightness) * 2.86f; - float red = red_volt / volt_scaler; + red = red_volt / volt_scaler; float green_volt = 2.9f - brightness * (2.9f - 0.45f); - float green = green_volt / volt_scaler; - - float blue = 1.0f; + green = green_volt / volt_scaler; float white_volt = 0.28f + brightness * (1.07f - 0.28f); - float white = white_volt / volt_scaler; - - ESP_LOGD("temperature_mode", "LED state : RGBW %f, %f, %f, %f", red, green, blue, white); - - red_->set_level(red); - green_->set_level(green); - blue_->set_level(blue); - white_->set_level(white); - master2_->turn_on(); - master1_->turn_on(); - return; + white = white_volt / volt_scaler; } // Temperature band 313 - 333 // - // TODO maybe check if we can git rid of a little bug in the original firmware. // The light becomes noticably brighter when moving from temperature 334 to // temperature 333. There's a little jump in the lighting output here. // Possibly this is a switch from warm to cold lighting as imposed by the // LED circuitry, making this unavoidable. However, it would be interesting - // to see if we can smoothen this out. For now, I'll keep the GPIO output - // for this bug-by-bug-compatible. + // to see if we can smoothen this out. + // BTW: This behavior is in sync with the original firmware. else if (temperature >= 313) { volt_scaler = 3.23f; float red_volt = 2.89f - brightness * (2.89f - 0.32f); - float red = red_volt / volt_scaler; + red = red_volt / volt_scaler; float green_volt = 2.96f - brightness * (2.96f - 1.03f); - float green = green_volt / volt_scaler; - - float blue = 1.0f; + green = green_volt / volt_scaler; float white_volt = 0.42f + brightness * (2.43f - 0.42f); float volt_scaler_white = 3.45f; - float white = white_volt / volt_scaler_white; - - ESP_LOGD("temperature_mode", "LED state : RGBW %f, %f, %f, %f", red, green, blue, white); - - red_->set_level(red); - green_->set_level(green); - blue_->set_level(blue); - white_->set_level(white); - master2_->turn_on(); - master1_->turn_on(); - return; + white = white_volt / volt_scaler_white; } // Temperature band 251 - 312 else if (temperature >= 251) { volt_scaler = 3.48f; - float red = 1.0f; - float green = 1.0f; - float blue = 1.0f; - - float white_volt = 0.5f + brightness * (3.28f - 0.5f); - float white = white_volt / volt_scaler; - - ESP_LOGD("temperature_mode", "LED state : RGBW %f, %f, %f, %f", red, green, blue, white); - - red_->set_level(red); - green_->set_level(green); - blue_->set_level(blue); - white_->set_level(white); - master2_->turn_on(); - master1_->turn_on(); - return; + float white_correction = 1.061; + float white_volt = 0.5f + brightness * (3.28f * white_correction - 0.5f); + white = white_volt / volt_scaler; } // Temperature band 223 - 250 else if (temperature >= 223) { + volt_scaler = 3.25f; + + float green_volt = 2.94f - brightness * (2.94f - 0.88f); + green = green_volt / volt_scaler; + + float blue_volt = 3.02f - brightness * (3.02f - 1.59f); + blue = blue_volt / volt_scaler; + + float white_correction = 1.024f; + float white_volt = 0.42f + brightness * (2.51f * white_correction - 0.42f); + float volt_scaler_white = 3.36f; + white = white_volt / volt_scaler_white; } // Temperature band 153 - 222 else if (temperature >= HOME_ASSISTANT_MIRED_MIN) { + float start = 153; + float end = 222; + float band = end - start; + + volt_scaler = 3.23f; + + float green_volt = 2.86f - brightness * 2.86f; + green = green_volt / volt_scaler; + + float blue_1 = 2.92f + (temperature - start) * (2.97f - 2.92f) / band; + float blue_100 = 0.62f + (temperature - start) * (1.17f - 0.62f) / band; + float blue_volt = blue_1 - brightness * (blue_1 - blue_100); + blue = blue_volt / volt_scaler; + + float white_1 = 0.28f + (temperature - start) * (0.37f - 0.28f) / band; + float white_100 = 1.1f + (temperature - start) * (2.0f - 1.1f) / band; + float white_volt = white_1 + brightness * (white_100 - white_1); + float volt_scaler_white = 3.27f; + white = white_volt / volt_scaler_white; } - red_->set_level(0.5); - green_->set_level(0.5); - blue_->set_level(0.5); - master2_->turn_off(); - master1_->turn_off(); + ESP_LOGD("temperature_mode", "LED state : RGBW %f, %f, %f, %f", red, green, blue, white); + + red_->set_level(red); + green_->set_level(green); + blue_->set_level(blue); + white_->set_level(white); + master2_->turn_on(); + master1_->turn_on(); } };