diff --git a/lib_rgb/api/rgb_effect.h b/lib_rgb/api/rgb_effect.h index 71dbba3..ad3c0ee 100644 --- a/lib_rgb/api/rgb_effect.h +++ b/lib_rgb/api/rgb_effect.h @@ -53,6 +53,10 @@ #define DELAY_TIME_RGB (1000 / RGB_MAX) #endif +// 控制cycleHSV中,HUE递增的步进值,该步进值应能整除360,且不超过它 +#ifndef HUE_STEP +#define HUE_STEP (1) +#endif /** * 定义渐变方向的枚举类型。 * @@ -161,4 +165,5 @@ void fill_gradient(uint32_t *buf, uint32_t color, size_t num_filled_rgb); */ void fill_gradient_with_groups(uint32_t *buf, uint32_t *colors, size_t *num_filled_rgb); +void fill_gradient_with_groups_colorful(uint32_t *buf, uint32_t *colors, size_t *num_filled_rgb); #endif //RGB_EFFECT_H \ No newline at end of file diff --git a/lib_rgb/src/rgb_effect.c b/lib_rgb/src/rgb_effect.c index e2103d7..39085a0 100644 --- a/lib_rgb/src/rgb_effect.c +++ b/lib_rgb/src/rgb_effect.c @@ -133,7 +133,7 @@ uint32_t cycleHSV(uint32_t *hue) uint32_t value = 100; if (*hue < 359) { - (*hue) += 1; + (*hue) += HUE_STEP; // printf("hue is: 0x%06X\n", *hue); } else @@ -195,3 +195,32 @@ void fill_gradient_with_groups(uint32_t *buf, uint32_t *colors, size_t *num_fill output_rgb_array(buf, NUM_RGBS); } +// 将多种颜色按RGB的数量,分组填充到RGB条中 +void fill_gradient_with_groups_colorful(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++) + { + // 填充每个组的RGB,其中每个RGB的颜色是独立赋值的 + uint32_t *group_buf = buf + group * max_leds_per_group; + for (size_t i = 0; i < num_filled_rgb[group]; i++) + { + *(group_buf + i) = colors[i + group * max_leds_per_group]; + } + + // 熄灭该组剩余的RGB + for (size_t i = num_filled_rgb[group]; i < max_leds_per_group; i++) + { + *(group_buf + i) = 0x000000; + } + + // 如果组号为奇数,翻转该组对应的buffer元素 + 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