feat: 使用校准的颜色来初始化灯光;避免使用全黑的灯光。
This commit is contained in:
parent
c27418aaf1
commit
ac33f67d77
59
main/light.c
59
main/light.c
@ -210,22 +210,6 @@ void light_for_init() {
|
|||||||
ESP_LOGI(LIGHT_TAG, "light_for_init");
|
ESP_LOGI(LIGHT_TAG, "light_for_init");
|
||||||
ESP_ERROR_CHECK(light_led_strip->clear(light_led_strip, 100));
|
ESP_ERROR_CHECK(light_led_strip->clear(light_led_strip, 100));
|
||||||
|
|
||||||
uint32_t red = 0, green = 0, blue = 0;
|
|
||||||
int8_t i = 0;
|
|
||||||
|
|
||||||
do {
|
|
||||||
for (; i < 50; i++) {
|
|
||||||
for (int j = 0; j < STRIP_LED_NUMBER; j++) {
|
|
||||||
led_strip_hsv2rgb(0, 0, i, &red, &green, &blue);
|
|
||||||
ESP_ERROR_CHECK(
|
|
||||||
light_led_strip->set_pixel(light_led_strip, j, red, green, blue));
|
|
||||||
}
|
|
||||||
ESP_ERROR_CHECK(light_led_strip->refresh(light_led_strip, 100));
|
|
||||||
vTaskDelay(pdMS_TO_TICKS(20));
|
|
||||||
}
|
|
||||||
vTaskDelay(pdMS_TO_TICKS(100));
|
|
||||||
} while (light_mode == light_mode_init);
|
|
||||||
|
|
||||||
nvs_handle local_nvs_handle;
|
nvs_handle local_nvs_handle;
|
||||||
esp_err_t err = nvs_open("storage", NVS_READWRITE, &local_nvs_handle);
|
esp_err_t err = nvs_open("storage", NVS_READWRITE, &local_nvs_handle);
|
||||||
if (err != ESP_OK) {
|
if (err != ESP_OK) {
|
||||||
@ -251,6 +235,28 @@ void light_for_init() {
|
|||||||
|
|
||||||
nvs_close(local_nvs_handle);
|
nvs_close(local_nvs_handle);
|
||||||
|
|
||||||
|
float r_f = (float)r / 255.0;
|
||||||
|
float g_f = (float)g / 255.0;
|
||||||
|
float b_f = (float)b / 255.0;
|
||||||
|
|
||||||
|
uint8_t init_r, init_g, init_b;
|
||||||
|
|
||||||
|
do {
|
||||||
|
for (uint8_t i = 0; i < 50; i++) {
|
||||||
|
init_r = (uint8_t)(r_f * (float)i);
|
||||||
|
init_g = (uint8_t)(g_f * (float)i);
|
||||||
|
init_b = (uint8_t)(b_f * (float)i);
|
||||||
|
|
||||||
|
for (int j = 0; j < STRIP_LED_NUMBER; j++) {
|
||||||
|
ESP_ERROR_CHECK(light_led_strip->set_pixel(light_led_strip, j, init_r,
|
||||||
|
init_g, init_b));
|
||||||
|
}
|
||||||
|
ESP_ERROR_CHECK(light_led_strip->refresh(light_led_strip, 100));
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(20));
|
||||||
|
}
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(100));
|
||||||
|
} while (light_mode == light_mode_init);
|
||||||
|
|
||||||
led_strip_set_color_calibration((float)r / 255.0, (float)g / 255.0,
|
led_strip_set_color_calibration((float)r / 255.0, (float)g / 255.0,
|
||||||
(float)b / 255.0);
|
(float)b / 255.0);
|
||||||
}
|
}
|
||||||
@ -354,6 +360,8 @@ void light_init_strip() {
|
|||||||
void light_play_colors(uint16_t len, uint8_t *buffer) {
|
void light_play_colors(uint16_t len, uint8_t *buffer) {
|
||||||
light_mode = light_mode_desktop_sending_colors;
|
light_mode = light_mode_desktop_sending_colors;
|
||||||
|
|
||||||
|
uint16_t black_count = 0; // count of black pixels. r/g/b <= 10
|
||||||
|
|
||||||
for (uint16_t led_index = 0, buffer_cursor = 0;
|
for (uint16_t led_index = 0, buffer_cursor = 0;
|
||||||
led_index < STRIP_LED_NUMBER && buffer_cursor < len;
|
led_index < STRIP_LED_NUMBER && buffer_cursor < len;
|
||||||
led_index++, buffer_cursor += 3) {
|
led_index++, buffer_cursor += 3) {
|
||||||
@ -366,10 +374,27 @@ void light_play_colors(uint16_t len, uint8_t *buffer) {
|
|||||||
b = (uint8_t)((float)buffer[buffer_cursor + 2] *
|
b = (uint8_t)((float)buffer[buffer_cursor + 2] *
|
||||||
display_ambient_light_brightness *
|
display_ambient_light_brightness *
|
||||||
led_strip_blue_calibration);
|
led_strip_blue_calibration);
|
||||||
|
if (r <= 10 && g <= 10 && b <= 10) {
|
||||||
|
black_count++;
|
||||||
|
}
|
||||||
ESP_ERROR_CHECK(
|
ESP_ERROR_CHECK(
|
||||||
light_led_strip->set_pixel(light_led_strip, led_index, r, g, b));
|
light_led_strip->set_pixel(light_led_strip, led_index, r, g, b));
|
||||||
}
|
}
|
||||||
ESP_ERROR_CHECK(light_led_strip->refresh(light_led_strip, 100));
|
|
||||||
|
if (black_count > STRIP_LED_NUMBER / 4 * 3) {
|
||||||
|
ESP_ERROR_CHECK(light_led_strip->clear(light_led_strip, 50));
|
||||||
|
uint8_t r = (uint8_t)((float)100 * display_ambient_light_brightness *
|
||||||
|
led_strip_red_calibration),
|
||||||
|
g = (uint8_t)((float)100 * display_ambient_light_brightness *
|
||||||
|
led_strip_green_calibration),
|
||||||
|
b = (uint8_t)((float)100 * display_ambient_light_brightness *
|
||||||
|
led_strip_blue_calibration);
|
||||||
|
for (uint16_t led_index = 0; led_index < STRIP_LED_NUMBER; led_index++) {
|
||||||
|
ESP_ERROR_CHECK(
|
||||||
|
light_led_strip->set_pixel(light_led_strip, led_index, r, g, b));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ESP_ERROR_CHECK(light_led_strip->refresh(light_led_strip, 50));
|
||||||
vTaskDelay(pdMS_TO_TICKS(10));
|
vTaskDelay(pdMS_TO_TICKS(10));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user