diff --git a/examples/app_hsv_cycle_example/src/hsv_cycle_example.c b/examples/app_hsv_cycle_example/src/hsv_cycle_example.c index 6479eb6..a9cb75b 100644 --- a/examples/app_hsv_cycle_example/src/hsv_cycle_example.c +++ b/examples/app_hsv_cycle_example/src/hsv_cycle_example.c @@ -12,7 +12,7 @@ void hsv_cycle_example() while (1) { // 用当前渐变颜色填充RGB数组,然后发送给rgb阵列 - fill_gradient(buf, NUM_RGBS, current_color); + fill_gradient(buf, current_color, NUM_RGBS); // 延迟以控制显示持续时间 delay_milliseconds(DELAY_TIME_RGB); diff --git a/examples/app_rgb_cycle_breathing_example/src/rgb_cycle_breathing_example.c b/examples/app_rgb_cycle_breathing_example/src/rgb_cycle_breathing_example.c index 8d445b1..be1de2c 100644 --- a/examples/app_rgb_cycle_breathing_example/src/rgb_cycle_breathing_example.c +++ b/examples/app_rgb_cycle_breathing_example/src/rgb_cycle_breathing_example.c @@ -11,7 +11,7 @@ void rgb_cycle_breathing_example() while (1) { // 用当前渐变颜色填充RGB数组 - fill_gradient(buf, NUM_RGBS, current_color); + fill_gradient(buf, current_color, NUM_RGBS); // 延迟以控制显示持续时间 delay_milliseconds(DELAY_TIME_RGB); // 更改下一个渐变的基色 diff --git a/lib_rgb/api/rgb_effect.h b/lib_rgb/api/rgb_effect.h index 5365503..71dbba3 100644 --- a/lib_rgb/api/rgb_effect.h +++ b/lib_rgb/api/rgb_effect.h @@ -145,7 +145,7 @@ uint32_t HSV_to_RGB(uint32_t *hue, uint32_t *sat, uint32_t *value); * \param buf 指向存储RGB值的缓冲区的指针,每个元素代表RGB条中一个颜色单元的颜色值。 * \param color 要填充的统一颜色值。 */ -void fill_gradient(uint32_t *buf, size_t num_filled_rgb, uint32_t color); +void fill_gradient(uint32_t *buf, uint32_t color, size_t num_filled_rgb); /** * 将多种颜色分组填充到RGB条中,并控制显示颜色的时间长度。 diff --git a/lib_rgb/src/rgb_effect.c b/lib_rgb/src/rgb_effect.c index 5d429d5..e2103d7 100644 --- a/lib_rgb/src/rgb_effect.c +++ b/lib_rgb/src/rgb_effect.c @@ -5,7 +5,7 @@ #include "rgb_driver.h" #include "samples_to_levels.h" #include "misc_utils.h" -#include "rgb_effect.h" +#include "rgb_effect.h" // 检查HSV值是否在有效范围内,如果溢出则将值设为最大值,并打印报错 void is_HSV_valid(uint32_t *hue, uint32_t *sat, uint32_t *value) @@ -33,9 +33,9 @@ uint32_t HSV_to_RGB(uint32_t *hue, uint32_t *sat, uint32_t *value) { #ifdef HSV_VALID_CHECK - #if HSV_VALID_CHECK == 0 - (is_HSV_valid(hue, sat, value)); - #endif +#if HSV_VALID_CHECK == 0 + (is_HSV_valid(hue, sat, value)); +#endif #endif uint32_t g; // 现在G是最高8位 @@ -141,11 +141,11 @@ uint32_t cycleHSV(uint32_t *hue) (*hue) = 0; // printf("--------hue is: 0x%06X----------\n", *hue); } - return(HSV_to_RGB(hue, &sat, &value)); + return (HSV_to_RGB(hue, &sat, &value)); } // 将单一颜色填充到整个RGB条中,并控制显示颜色的时间长度 -void fill_gradient(uint32_t *buf, size_t num_filled_rgb, uint32_t color) +void fill_gradient(uint32_t *buf, uint32_t color, size_t num_filled_rgb) { // 遍历缓冲区的每个元素,将其设置为提供的颜色值 for (size_t i = 0; i < num_filled_rgb; i++) @@ -164,30 +164,34 @@ void fill_gradient(uint32_t *buf, size_t num_filled_rgb, uint32_t color) delay_milliseconds(DELAY_TIME_RGB); } -// 将多种颜色分组填充到RGB条中,并控制显示颜色的时间长度。 +// 将多种颜色按分组填充到RGB条中 void fill_gradient_with_groups(uint32_t *buf, uint32_t *colors, size_t *num_filled_rgb) { size_t max_leds_per_group = NUM_RGBS / NUM_RGB_GROUPS; - for (size_t group = 0; group < NUM_RGB_GROUPS; group++) { - // 填充每个组的LED + for (size_t group = 0; group < NUM_RGB_GROUPS; group++) + { + // 填充每个组的RGB uint32_t *group_buf = buf + group * max_leds_per_group; - for (size_t i = 0; i < num_filled_rgb[group]; i++) { + for (size_t i = 0; i < num_filled_rgb[group]; i++) + { *(group_buf + i) = colors[group]; } - // 熄灭该组剩余的LED - for (size_t i = num_filled_rgb[group]; i < max_leds_per_group; i++) { + // 熄灭该组剩余的RGB + for (size_t i = num_filled_rgb[group]; i < max_leds_per_group; i++) + { *(group_buf + i) = 0x000000; } // 如果组号为奇数,翻转该组对应的buffer元素 - if (group % 2 != 0) { + if (group % 2 != 0) + { reverse_buf(group_buf, max_leds_per_group); } } // 将缓冲区输出到RGB条 output_rgb_array(buf, NUM_RGBS); +} -} \ No newline at end of file