feat: 支持颜色校准

This commit is contained in:
Ivan Li 2023-04-17 20:49:10 +08:00
parent f6b7a398cd
commit 40dde8cc89
3 changed files with 32 additions and 3 deletions

9
dependencies.lock Normal file
View File

@ -0,0 +1,9 @@
dependencies:
idf:
component_hash: null
source:
type: idf
version: 4.4.4
manifest_hash: dcf4d39b94252de130019eadceb989d72b0dbc26b552cfdcbb50f6da531d2b92
target: esp32c3
version: 1.0.0

View File

@ -36,6 +36,10 @@ light_mode_t light_mode;
float display_ambient_light_brightness = 1;
uint8_t display_ambient_lighting_level = 255;
float led_strip_red_calibration = 1.0;
float led_strip_green_calibration = 1.0;
float led_strip_blue_calibration = 1.0;
void led_strip_fade_in_light_level(void *pvParameter) {
float target = (float)display_ambient_lighting_level / 255.0;
float step_length = (target - display_ambient_light_brightness) / 40.0;
@ -57,6 +61,12 @@ void led_strip_set_brightness(uint8_t level) {
4096, NULL, 1, NULL);
}
void led_strip_set_color_calibration(float red, float green, float blue) {
led_strip_red_calibration = red;
led_strip_green_calibration = green;
led_strip_blue_calibration = blue;
}
/**
* @brief Simple helper function, converting HSV color space to RGB color
* space
@ -277,11 +287,14 @@ void light_play_colors(uint16_t len, uint8_t *buffer) {
led_index < STRIP_LED_NUMBER && buffer_cursor < len;
led_index++, buffer_cursor += 3) {
uint8_t r = (uint8_t)((float)buffer[buffer_cursor] *
display_ambient_light_brightness),
display_ambient_light_brightness *
led_strip_red_calibration),
g = (uint8_t)((float)buffer[buffer_cursor + 1] *
display_ambient_light_brightness),
display_ambient_light_brightness *
led_strip_green_calibration),
b = (uint8_t)((float)buffer[buffer_cursor + 2] *
display_ambient_light_brightness);
display_ambient_light_brightness *
led_strip_blue_calibration);
ESP_ERROR_CHECK(
light_led_strip->set_pixel(light_led_strip, led_index, r, g, b));
}

View File

@ -40,6 +40,8 @@
#define MQTT_KEY_DESKTOP_ONLINE MQTT_DESKTOP_KEY_PREFIX MQTT_ONLINE_SUFFIX
#define MQTT_KEY_DESKTOP_COLORS MQTT_DESKTOP_KEY_PREFIX MQTT_COLORS_SUFFIX
#define MQTT_KEY_DESKTOP_ALL MQTT_DESKTOP_KEY_PREFIX MQTT_ALL_SUFFIX
#define MQTT_KEY_DESKTOP_COLOR_CALIBRATION \
MQTT_DESKTOP_KEY_PREFIX "color-calibration"
#define MQTT_KEY_BOARD_CMD MQTT_BOARD_KEY_PREFIX MQTT_CMD_SUFFIX
#define MQTT_KEY_DESKTOP_DISPLAY_0_BRIGHTNESS \
@ -124,6 +126,11 @@ static void mqtt_event_handler(void *handler_args, esp_event_base_t base,
.value = (uint16_t)(event->data[0] << 8 | event->data[1]),
};
xQueueSend(mqtt_cmd_event, &mqtt_event, NULL);
} else if (strncmp(event->topic, MQTT_KEY_DESKTOP_COLOR_CALIBRATION,
event->topic_len) == 0) {
led_strip_set_color_calibration((float)event->data[0] / 255.0,
(float)event->data[1] / 255.0,
(float)event->data[2] / 255.0);
} else {
printf("TOPIC=%.*s\r\n", event->topic_len, event->topic);
printf("DATA=%.*s\r\n", event->data_len, event->data);