|
@ -129,6 +129,11 @@ class YeelightBedsideLampV2LightOutput : public Component, public LightOutput |
|
|
// my output towards the original output. |
|
|
// my output towards the original output. |
|
|
float volt_scaler; |
|
|
float volt_scaler; |
|
|
|
|
|
|
|
|
|
|
|
float red = 1.0; |
|
|
|
|
|
float green = 1.0; |
|
|
|
|
|
float blue = 1.0; |
|
|
|
|
|
float white = 1.0; |
|
|
|
|
|
|
|
|
// Temperature band 370 - 588 |
|
|
// Temperature band 370 - 588 |
|
|
if (temperature <= HOME_ASSISTANT_MIRED_MAX && temperature >= 371) |
|
|
if (temperature <= HOME_ASSISTANT_MIRED_MAX && temperature >= 371) |
|
|
{ |
|
|
{ |
|
@ -139,29 +144,17 @@ class YeelightBedsideLampV2LightOutput : public Component, public LightOutput |
|
|
float band = end - start; |
|
|
float band = end - start; |
|
|
|
|
|
|
|
|
float red_volt = 2.86f * (1.0f - brightness); |
|
|
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_1 = 2.90f + (temperature - start) * (2.97f - 2.90f) / band; |
|
|
float green_100 = 0.45f + (temperature - start) * (1.13f - 0.45f) / 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_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_1 = 0.28f - (temperature - start) * (0.28f - 0.19f) / band; |
|
|
float white_100 = 1.07f - (temperature - start) * (1.07f - 0.22f) / 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_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 |
|
|
// Temperature band 334 - 370 |
|
|
else if (temperature >= 334) |
|
|
else if (temperature >= 334) |
|
@ -169,97 +162,93 @@ class YeelightBedsideLampV2LightOutput : public Component, public LightOutput |
|
|
volt_scaler = 3.23f; |
|
|
volt_scaler = 3.23f; |
|
|
|
|
|
|
|
|
float red_volt = (1.0f - brightness) * 2.86f; |
|
|
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_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_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 |
|
|
// 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 |
|
|
// The light becomes noticably brighter when moving from temperature 334 to |
|
|
// temperature 333. There's a little jump in the lighting output here. |
|
|
// 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 |
|
|
// Possibly this is a switch from warm to cold lighting as imposed by the |
|
|
// LED circuitry, making this unavoidable. However, it would be interesting |
|
|
// 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) |
|
|
else if (temperature >= 313) |
|
|
{ |
|
|
{ |
|
|
volt_scaler = 3.23f; |
|
|
volt_scaler = 3.23f; |
|
|
|
|
|
|
|
|
float red_volt = 2.89f - brightness * (2.89f - 0.32f); |
|
|
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_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 white_volt = 0.42f + brightness * (2.43f - 0.42f); |
|
|
float volt_scaler_white = 3.45f; |
|
|
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 |
|
|
// Temperature band 251 - 312 |
|
|
else if (temperature >= 251) |
|
|
else if (temperature >= 251) |
|
|
{ |
|
|
{ |
|
|
volt_scaler = 3.48f; |
|
|
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 |
|
|
// Temperature band 223 - 250 |
|
|
else if (temperature >= 223) |
|
|
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 |
|
|
// Temperature band 153 - 222 |
|
|
else if (temperature >= HOME_ASSISTANT_MIRED_MIN) |
|
|
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(); |
|
|
} |
|
|
} |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|