修改了参数顺序以避免用户误解

This commit is contained in:
2023-11-26 13:06:38 +08:00
parent 68665a63c8
commit 35c884be29
4 changed files with 21 additions and 17 deletions

View File

@@ -12,7 +12,7 @@ void hsv_cycle_example()
while (1) while (1)
{ {
// 用当前渐变颜色填充RGB数组然后发送给rgb阵列 // 用当前渐变颜色填充RGB数组然后发送给rgb阵列
fill_gradient(buf, NUM_RGBS, current_color); fill_gradient(buf, current_color, NUM_RGBS);
// 延迟以控制显示持续时间 // 延迟以控制显示持续时间
delay_milliseconds(DELAY_TIME_RGB); delay_milliseconds(DELAY_TIME_RGB);

View File

@@ -11,7 +11,7 @@ void rgb_cycle_breathing_example()
while (1) while (1)
{ {
// 用当前渐变颜色填充RGB数组 // 用当前渐变颜色填充RGB数组
fill_gradient(buf, NUM_RGBS, current_color); fill_gradient(buf, current_color, NUM_RGBS);
// 延迟以控制显示持续时间 // 延迟以控制显示持续时间
delay_milliseconds(DELAY_TIME_RGB); delay_milliseconds(DELAY_TIME_RGB);
// 更改下一个渐变的基色 // 更改下一个渐变的基色

View File

@@ -145,7 +145,7 @@ uint32_t HSV_to_RGB(uint32_t *hue, uint32_t *sat, uint32_t *value);
* \param buf 指向存储RGB值的缓冲区的指针每个元素代表RGB条中一个颜色单元的颜色值。 * \param buf 指向存储RGB值的缓冲区的指针每个元素代表RGB条中一个颜色单元的颜色值。
* \param color 要填充的统一颜色值。 * \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条中并控制显示颜色的时间长度。 * 将多种颜色分组填充到RGB条中并控制显示颜色的时间长度。

View File

@@ -5,7 +5,7 @@
#include "rgb_driver.h" #include "rgb_driver.h"
#include "samples_to_levels.h" #include "samples_to_levels.h"
#include "misc_utils.h" #include "misc_utils.h"
#include "rgb_effect.h" #include "rgb_effect.h"
// 检查HSV值是否在有效范围内如果溢出则将值设为最大值并打印报错 // 检查HSV值是否在有效范围内如果溢出则将值设为最大值并打印报错
void is_HSV_valid(uint32_t *hue, uint32_t *sat, uint32_t *value) 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 #ifdef HSV_VALID_CHECK
#if HSV_VALID_CHECK == 0 #if HSV_VALID_CHECK == 0
(is_HSV_valid(hue, sat, value)); (is_HSV_valid(hue, sat, value));
#endif #endif
#endif #endif
uint32_t g; // 现在G是最高8位 uint32_t g; // 现在G是最高8位
@@ -141,11 +141,11 @@ uint32_t cycleHSV(uint32_t *hue)
(*hue) = 0; (*hue) = 0;
// printf("--------hue is: 0x%06X----------\n", *hue); // printf("--------hue is: 0x%06X----------\n", *hue);
} }
return(HSV_to_RGB(hue, &sat, &value)); return (HSV_to_RGB(hue, &sat, &value));
} }
// 将单一颜色填充到整个RGB条中并控制显示颜色的时间长度 // 将单一颜色填充到整个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++) 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); delay_milliseconds(DELAY_TIME_RGB);
} }
// 将多种颜色分组填充到RGB条中,并控制显示颜色的时间长度。 // 将多种颜色分组填充到RGB条中
void fill_gradient_with_groups(uint32_t *buf, uint32_t *colors, size_t *num_filled_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; size_t max_leds_per_group = NUM_RGBS / NUM_RGB_GROUPS;
for (size_t group = 0; group < NUM_RGB_GROUPS; group++) { for (size_t group = 0; group < NUM_RGB_GROUPS; group++)
// 填充每个组的LED {
// 填充每个组的RGB
uint32_t *group_buf = buf + group * max_leds_per_group; 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]; *(group_buf + i) = colors[group];
} }
// 熄灭该组剩余的LED // 熄灭该组剩余的RGB
for (size_t i = num_filled_rgb[group]; i < max_leds_per_group; i++) { for (size_t i = num_filled_rgb[group]; i < max_leds_per_group; i++)
{
*(group_buf + i) = 0x000000; *(group_buf + i) = 0x000000;
} }
// 如果组号为奇数翻转该组对应的buffer元素 // 如果组号为奇数翻转该组对应的buffer元素
if (group % 2 != 0) { if (group % 2 != 0)
{
reverse_buf(group_buf, max_leds_per_group); reverse_buf(group_buf, max_leds_per_group);
} }
} }
// 将缓冲区输出到RGB条 // 将缓冲区输出到RGB条
output_rgb_array(buf, NUM_RGBS); output_rgb_array(buf, NUM_RGBS);
}
}