feat: 使用校准的颜色来显示空闲灯光。
This commit is contained in:
parent
ac33f67d77
commit
c8eb0817e8
37
main/light.c
37
main/light.c
@ -62,6 +62,22 @@ void led_strip_set_brightness(uint8_t level) {
|
||||
|
||||
xTaskCreate(led_strip_fade_in_light_level, "LED_STRIP_FADE_IN_LIGHT_LEVEL",
|
||||
4096, NULL, 1, NULL);
|
||||
|
||||
nvs_handle_t nvs_handle;
|
||||
esp_err_t err = nvs_open("storage", NVS_READWRITE, &nvs_handle);
|
||||
err = nvs_set_u8(nvs_handle, "brightness", level);
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGW(LIGHT_TAG, "Error (%s) saving light level!\n",
|
||||
esp_err_to_name(err));
|
||||
nvs_close(nvs_handle);
|
||||
return;
|
||||
}
|
||||
err = nvs_commit(nvs_handle);
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGW(LIGHT_TAG, "Error (%s) saving light level!\n",
|
||||
esp_err_to_name(err));
|
||||
}
|
||||
nvs_close(nvs_handle);
|
||||
}
|
||||
|
||||
void led_strip_set_color_calibration(float red, float green, float blue) {
|
||||
@ -217,6 +233,7 @@ void light_for_init() {
|
||||
}
|
||||
|
||||
uint8_t r = 255, g = 255, b = 255;
|
||||
uint8_t brightness = 200;
|
||||
err = nvs_get_u8(local_nvs_handle, "calibration_r", &r);
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGW(LIGHT_TAG, "Error (%s) reading calibration_r!",
|
||||
@ -232,9 +249,17 @@ void light_for_init() {
|
||||
ESP_LOGW(LIGHT_TAG, "Error (%s) reading calibration_b!",
|
||||
esp_err_to_name(err));
|
||||
}
|
||||
err = nvs_get_u8(local_nvs_handle, "brightness", &brightness);
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGW(LIGHT_TAG, "Error (%s) reading brightness!", esp_err_to_name(err));
|
||||
}
|
||||
|
||||
nvs_close(local_nvs_handle);
|
||||
|
||||
// set brightness
|
||||
led_strip_set_brightness(brightness);
|
||||
|
||||
// play init light
|
||||
float r_f = (float)r / 255.0;
|
||||
float g_f = (float)g / 255.0;
|
||||
float b_f = (float)b / 255.0;
|
||||
@ -293,9 +318,11 @@ void light_for_idle() {
|
||||
// Build RGB values
|
||||
led_strip_hsv2rgb(hue, 50, 30, &red, &green, &blue);
|
||||
|
||||
red = red * display_ambient_light_brightness;
|
||||
green = green * display_ambient_light_brightness;
|
||||
blue = blue * display_ambient_light_brightness;
|
||||
red = red * display_ambient_light_brightness * led_strip_red_calibration;
|
||||
green = green * display_ambient_light_brightness *
|
||||
led_strip_green_calibration;
|
||||
blue =
|
||||
blue * display_ambient_light_brightness * led_strip_blue_calibration;
|
||||
// Write RGB values to strip driver
|
||||
ESP_ERROR_CHECK(
|
||||
light_led_strip->set_pixel(light_led_strip, j, red, green, blue));
|
||||
@ -382,7 +409,7 @@ void light_play_colors(uint16_t len, uint8_t *buffer) {
|
||||
}
|
||||
|
||||
if (black_count > STRIP_LED_NUMBER / 4 * 3) {
|
||||
ESP_ERROR_CHECK(light_led_strip->clear(light_led_strip, 50));
|
||||
ESP_ERROR_CHECK(light_led_strip->clear(light_led_strip, 100));
|
||||
uint8_t r = (uint8_t)((float)100 * display_ambient_light_brightness *
|
||||
led_strip_red_calibration),
|
||||
g = (uint8_t)((float)100 * display_ambient_light_brightness *
|
||||
@ -394,7 +421,7 @@ void light_play_colors(uint16_t len, uint8_t *buffer) {
|
||||
light_led_strip->set_pixel(light_led_strip, led_index, r, g, b));
|
||||
}
|
||||
}
|
||||
ESP_ERROR_CHECK(light_led_strip->refresh(light_led_strip, 50));
|
||||
ESP_ERROR_CHECK(light_led_strip->refresh(light_led_strip, 100));
|
||||
vTaskDelay(pdMS_TO_TICKS(10));
|
||||
}
|
||||
|
||||
|
@ -25,8 +25,8 @@ void app_main(void) {
|
||||
display_print8_str(0, 0, "Ambient Light");
|
||||
ci_03t_init();
|
||||
apes_9960_init();
|
||||
apes_9960_auto_fetch();
|
||||
auto_fetch_temperature();
|
||||
// apes_9960_auto_fetch();
|
||||
// auto_fetch_temperature();
|
||||
pca9555_init();
|
||||
ui_input_init();
|
||||
xTaskCreate(mqtt_publish_ui_input, "mqtt_publish_ui_input", 2048, NULL, 10,
|
||||
|
Loading…
Reference in New Issue
Block a user