Compare commits
No commits in common. "c8eb0817e88afecdf17ba6869fc50c95c418a0fd" and "c27418aaf1f0c943fa2e7967212d537868166282" have entirely different histories.
c8eb0817e8
...
c27418aaf1
90
main/light.c
90
main/light.c
@ -62,22 +62,6 @@ void led_strip_set_brightness(uint8_t level) {
|
|||||||
|
|
||||||
xTaskCreate(led_strip_fade_in_light_level, "LED_STRIP_FADE_IN_LIGHT_LEVEL",
|
xTaskCreate(led_strip_fade_in_light_level, "LED_STRIP_FADE_IN_LIGHT_LEVEL",
|
||||||
4096, NULL, 1, NULL);
|
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) {
|
void led_strip_set_color_calibration(float red, float green, float blue) {
|
||||||
@ -226,6 +210,22 @@ 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) {
|
||||||
@ -233,7 +233,6 @@ void light_for_init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
uint8_t r = 255, g = 255, b = 255;
|
uint8_t r = 255, g = 255, b = 255;
|
||||||
uint8_t brightness = 200;
|
|
||||||
err = nvs_get_u8(local_nvs_handle, "calibration_r", &r);
|
err = nvs_get_u8(local_nvs_handle, "calibration_r", &r);
|
||||||
if (err != ESP_OK) {
|
if (err != ESP_OK) {
|
||||||
ESP_LOGW(LIGHT_TAG, "Error (%s) reading calibration_r!",
|
ESP_LOGW(LIGHT_TAG, "Error (%s) reading calibration_r!",
|
||||||
@ -249,39 +248,9 @@ void light_for_init() {
|
|||||||
ESP_LOGW(LIGHT_TAG, "Error (%s) reading calibration_b!",
|
ESP_LOGW(LIGHT_TAG, "Error (%s) reading calibration_b!",
|
||||||
esp_err_to_name(err));
|
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);
|
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;
|
|
||||||
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
@ -318,11 +287,9 @@ void light_for_idle() {
|
|||||||
// Build RGB values
|
// Build RGB values
|
||||||
led_strip_hsv2rgb(hue, 50, 30, &red, &green, &blue);
|
led_strip_hsv2rgb(hue, 50, 30, &red, &green, &blue);
|
||||||
|
|
||||||
red = red * display_ambient_light_brightness * led_strip_red_calibration;
|
red = red * display_ambient_light_brightness;
|
||||||
green = green * display_ambient_light_brightness *
|
green = green * display_ambient_light_brightness;
|
||||||
led_strip_green_calibration;
|
blue = blue * display_ambient_light_brightness;
|
||||||
blue =
|
|
||||||
blue * display_ambient_light_brightness * led_strip_blue_calibration;
|
|
||||||
// Write RGB values to strip driver
|
// Write RGB values to strip driver
|
||||||
ESP_ERROR_CHECK(
|
ESP_ERROR_CHECK(
|
||||||
light_led_strip->set_pixel(light_led_strip, j, red, green, blue));
|
light_led_strip->set_pixel(light_led_strip, j, red, green, blue));
|
||||||
@ -387,8 +354,6 @@ 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) {
|
||||||
@ -401,26 +366,9 @@ 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));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (black_count > STRIP_LED_NUMBER / 4 * 3) {
|
|
||||||
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 *
|
|
||||||
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, 100));
|
ESP_ERROR_CHECK(light_led_strip->refresh(light_led_strip, 100));
|
||||||
vTaskDelay(pdMS_TO_TICKS(10));
|
vTaskDelay(pdMS_TO_TICKS(10));
|
||||||
}
|
}
|
||||||
|
@ -25,8 +25,8 @@ void app_main(void) {
|
|||||||
display_print8_str(0, 0, "Ambient Light");
|
display_print8_str(0, 0, "Ambient Light");
|
||||||
ci_03t_init();
|
ci_03t_init();
|
||||||
apes_9960_init();
|
apes_9960_init();
|
||||||
// apes_9960_auto_fetch();
|
apes_9960_auto_fetch();
|
||||||
// auto_fetch_temperature();
|
auto_fetch_temperature();
|
||||||
pca9555_init();
|
pca9555_init();
|
||||||
ui_input_init();
|
ui_input_init();
|
||||||
xTaskCreate(mqtt_publish_ui_input, "mqtt_publish_ui_input", 2048, NULL, 10,
|
xTaskCreate(mqtt_publish_ui_input, "mqtt_publish_ui_input", 2048, NULL, 10,
|
||||||
|
Loading…
Reference in New Issue
Block a user