Skip to content

Commit cacff27

Browse files
feat(lightbulb): Add precise color control capability
1 parent fb1e84f commit cacff27

File tree

6 files changed

+31
-42
lines changed

6 files changed

+31
-42
lines changed

components/led/lightbulb_driver/include/lightbulb.h

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -147,31 +147,18 @@ typedef struct {
147147
} lightbulb_cct_mapping_data_t;
148148

149149
/**
150-
* @brief Color (Correlated Color Temperature) mapping data
150+
* @brief Color mode mapping data
151151
*
152-
* @note This structure is used for precise color temperature calibration.
153-
* Each color temperature value (cct_kelvin) needs to have a corresponding percentage (cct_percentage) determined,
154-
* which is used to calibrate the color temperature more accurately.
155-
* The rgbcw array specifies the current coefficients for the RGBCW channels.
156-
* These coefficients are instrumental in adjusting the intensity of each color channel
157-
* (Red, Green, Blue, Cool White, Warm White) to achieve the desired color temperature.
158-
* They are also used for power limiting to ensure energy efficiency and LED longevity.
159-
* Therefore, the sum of all values in the rgbcw array must equal 1 to maintain the correct power balance.
152+
* @note Used for calibrating color accuracy in color mode.
160153
*
161154
*/
162155
typedef struct {
163-
float rgbcw_100[5];
164-
float rgbcw_50[5];
165-
float rgbcw_0[5];
156+
float rgbcw_100[5]; /**< The RGBCW components required when saturation is 100 at a specific hue. */
157+
float rgbcw_50[5]; /**< The RGBCW components required when saturation is 50 at a specific hue. */
158+
float rgbcw_0[5]; /**< The RGBCW components required when saturation is 10 at a specific hue. */
166159
uint16_t hue;
167160
} lightbulb_color_mapping_data_t;
168161

169-
// typedef struct {
170-
// float abcdef_100[5];
171-
// float abcdef_50[5];
172-
// float abcdef_10[5];
173-
// } lightbulb_color_data_t;
174-
175162
/**
176163
* @brief Gamma correction and color balance configuration
177164
*

components/led/lightbulb_driver/src/hal_driver.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,7 +1047,7 @@ esp_err_t hal_get_driver_feature(hal_feature_query_list_t type, void *out_data)
10471047
return ESP_OK;
10481048
}
10491049

1050-
esp_err_t hal_get_curve_table_value(uint8_t input, uint16_t *output)
1050+
esp_err_t hal_get_curve_table_value(uint16_t input, uint16_t *output)
10511051
{
10521052
LIGHTBULB_CHECK(s_hal_obj, "init() must be called first", return ESP_ERR_INVALID_STATE);
10531053
LIGHTBULB_CHECK(output, "out_data is null", return ESP_ERR_INVALID_STATE);
@@ -1057,7 +1057,7 @@ esp_err_t hal_get_curve_table_value(uint8_t input, uint16_t *output)
10571057
return ESP_OK;
10581058
}
10591059

1060-
esp_err_t hal_get_linear_table_value(uint8_t input, uint16_t *output)
1060+
esp_err_t hal_get_linear_table_value(uint16_t input, uint16_t *output)
10611061
{
10621062
LIGHTBULB_CHECK(s_hal_obj, "init() must be called first", return ESP_ERR_INVALID_STATE);
10631063
LIGHTBULB_CHECK(output, "out_data is null", return ESP_ERR_INVALID_STATE);

components/led/lightbulb_driver/src/lightbulb.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -310,17 +310,18 @@ static void cct_and_brightness_convert_and_power_limit(lightbulb_led_beads_comb_
310310
hal_get_linear_table_value((uint8_t)value1, &white_value[3]);
311311
hal_get_linear_table_value((uint8_t)value2, &white_value[4]);
312312
} else if (led_beads == LED_BEADS_2CH_CW || ((led_beads == LED_BEADS_5CH_RGBCW) && (s_lb_obj->cap.enable_precise_cct_control == false))) {
313-
uint16_t max_value = 255;
313+
uint16_t max_value;
314314
float max_power;
315315
float _c = cct / 100.0;
316316
float _w = (100 - cct) / 100.0;
317317

318+
hal_get_driver_feature(QUERY_MAX_INPUT_VALUE, &max_value);
318319
float baseline = MAX(_c, _w);
319320
max_power = MIN(max_value * multiple, max_value / baseline);
320321
_c = max_power * _c * (brightness / 100.0);
321322
_w = max_power * _w * (brightness / 100.0);
322-
hal_get_linear_table_value((uint8_t)_c, &white_value[3]);
323-
hal_get_linear_table_value((uint8_t)_w, &white_value[4]);
323+
hal_get_linear_table_value((uint16_t)_c, &white_value[3]);
324+
hal_get_linear_table_value((uint16_t)_w, &white_value[4]);
324325
} else {
325326
uint16_t max_value;
326327
float max_power;

components/led/lightbulb_driver/src/priv_include/hal_driver.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ esp_err_t hal_output_init(hal_config_t *config, lightbulb_gamma_config_t *gamma,
5555
esp_err_t hal_output_deinit(void);
5656
esp_err_t hal_regist_channel(int channel, gpio_num_t gpio_num);
5757
esp_err_t hal_get_driver_feature(hal_feature_query_list_t type, void *out_data);
58-
esp_err_t hal_get_curve_table_value(uint8_t input, uint16_t *output);
59-
esp_err_t hal_get_linear_table_value(uint8_t input, uint16_t *output);
58+
esp_err_t hal_get_curve_table_value(uint16_t input, uint16_t *output);
59+
esp_err_t hal_get_linear_table_value(uint16_t input, uint16_t *output);
6060
esp_err_t hal_set_channel(int channel, uint16_t value, uint16_t fade_ms);
6161
esp_err_t hal_set_channel_group(uint16_t value[], uint8_t channel_mask, uint16_t fade_ms);
6262
esp_err_t hal_start_channel_action(int channel, uint16_t value_min, uint16_t value_max, uint16_t period_ms, bool fade_flag);

examples/lighting/lightbulb/main/lightbulb_example_cmd.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,6 @@ static int do_set_rgb_cmd(int argc, char **argv)
8383
arg_print_errors(stderr, set_rgb_args.end, argv[0]);
8484
return 1;
8585
}
86-
// uint16_t hsv[3] = {0};
87-
// if (lightbulb_rgb2hsv(set_rgb_args.rgb->ival[0], set_rgb_args.rgb->ival[1], set_rgb_args.rgb->ival[2], &hsv[0], (uint8_t *)&hsv[1], (uint8_t *)&hsv[2]) != ESP_OK) {
88-
// return 1;
89-
// }
90-
91-
// if (lightbulb_set_hsv(hsv[0], hsv[1], hsv[2]) != ESP_OK) {
92-
// return 1;
93-
// }
9486

9587
lightbulb_set_rgb(set_rgb_args.rgb->ival[0], set_rgb_args.rgb->ival[1], set_rgb_args.rgb->ival[2]);
9688

examples/lighting/lightbulb/main/lightbulb_example_main.c

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,15 @@ lightbulb_color_mapping_data_t color_data[COLOR_SZIE] = {
6666
{.rgbcw_100 = {0.9110, 0.0000, 0.0890}, .rgbcw_50 = {0.5762, 0.2810, 0.1429}, .rgbcw_0 = {0.4000, 0.4190, 0.1810}, .hue = 345}
6767
};
6868

69+
lightbulb_power_limit_t limit = {
70+
.color_max_power = 100,
71+
.color_max_value = 100,
72+
.color_min_value = 10,
73+
.white_max_power = 100,
74+
.white_max_brightness = 100,
75+
.white_min_brightness = 10
76+
};
77+
6978
void app_main(void)
7079
{
7180
/* Not a warning, just highlighted */
@@ -93,9 +102,9 @@ void app_main(void)
93102
.type = DRIVER_BP57x8D,
94103
.driver_conf.bp57x8d.freq_khz = 300,
95104
.driver_conf.bp57x8d.enable_iic_queue = true,
96-
.driver_conf.bp57x8d.iic_clk = CONFIG_BP5758D_IIC_CLK_GPIO,
97-
.driver_conf.bp57x8d.iic_sda = CONFIG_BP5758D_IIC_SDA_GPIO,
98-
.driver_conf.bp57x8d.current = {15, 16, 15, 25, 25},
105+
.driver_conf.bp57x8d.iic_clk = 3,
106+
.driver_conf.bp57x8d.iic_sda = 7,
107+
.driver_conf.bp57x8d.current = {10, 10, 10, 30, 30},
99108
#endif
100109
// 2. Configure the drive capability
101110
.capability.enable_fade = true,
@@ -106,7 +115,7 @@ void app_main(void)
106115
.capability.led_beads = LED_BEADS_3CH_RGB,
107116
#elif CONFIG_LIGHTBULB_DEMO_DRIVER_SELECT_BP5758D
108117
#if TEST_IIC_RGBWW_LIGHTBULB
109-
.capability.led_beads = LED_BEADS_5CH_RGBW,
118+
.capability.led_beads = LED_BEADS_5CH_RGBCW,
110119
#else
111120
.capability.led_beads = LED_BEADS_5CH_RGBCW,
112121
#endif
@@ -126,14 +135,14 @@ void app_main(void)
126135
.io_conf.pwm_io.warm_brightness = PWM_W_GPIO,
127136
#endif
128137
#ifdef CONFIG_LIGHTBULB_DEMO_DRIVER_SELECT_BP5758D
129-
.io_conf.iic_io.red = OUT3,
138+
.io_conf.iic_io.red = OUT1,
130139
.io_conf.iic_io.green = OUT2,
131-
.io_conf.iic_io.blue = OUT1,
140+
.io_conf.iic_io.blue = OUT3,
132141
.io_conf.iic_io.cold_white = OUT5,
133142
.io_conf.iic_io.warm_yellow = OUT4,
134143
#endif
135144
//4. Limit param
136-
.external_limit = NULL,
145+
.external_limit = &limit,
137146

138147
//5. Gamma param
139148
.gamma_conf = NULL,
@@ -142,12 +151,12 @@ void app_main(void)
142151
#ifdef CONFIG_LIGHTBULB_DEMO_DRIVER_SELECT_BP5758D
143152
.color_mix_mode.precise.table = color_data,
144153
.color_mix_mode.precise.table_size = COLOR_SZIE,
145-
.capability.enable_precise_color_control = 1,
154+
.capability.enable_precise_color_control = 0,
146155
#endif
147156
#if CONFIG_LIGHTBULB_DEMO_DRIVER_SELECT_BP5758D && TEST_IIC_RGBWW_LIGHTBULB
148157
.cct_mix_mode.precise.table_size = MIX_TABLE_SIZE,
149158
.cct_mix_mode.precise.table = table,
150-
.capability.enable_precise_cct_control = true,
159+
.capability.enable_precise_cct_control = 0,
151160
#else
152161
.cct_mix_mode.standard.kelvin_max = 6500,
153162
.cct_mix_mode.standard.kelvin_min = 2200,

0 commit comments

Comments
 (0)