Browse Source

Completed work on the temperature-based light controls. Both RGB and white light are now fully functional.

pull/1/head
Maurice Makaay 3 years ago
parent
commit
77a18d52dc
3 changed files with 77 additions and 69 deletions
  1. +19
    -0
      .gitignore
  2. BIN
      .yeelight_bs2.h.swp
  3. +58
    -69
      yeelight_bs2.h

+ 19
- 0
.gitignore View File

@ -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~

BIN
.yeelight_bs2.h.swp View File


+ 58
- 69
yeelight_bs2.h View File

@ -129,6 +129,11 @@ class YeelightBedsideLampV2LightOutput : public Component, public LightOutput
// my output towards the original output.
float volt_scaler;
float red = 1.0;
float green = 1.0;
float blue = 1.0;
float white = 1.0;
// Temperature band 370 - 588
if (temperature <= HOME_ASSISTANT_MIRED_MAX && temperature >= 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();
}
};


Loading…
Cancel
Save