diff --git a/examples/app_hsv_cycle_example/bin/app_hsv_cycle_example.xe b/examples/app_hsv_cycle_example/bin/app_hsv_cycle_example.xe index b7cc928..af6619e 100644 Binary files a/examples/app_hsv_cycle_example/bin/app_hsv_cycle_example.xe and b/examples/app_hsv_cycle_example/bin/app_hsv_cycle_example.xe differ diff --git a/examples/app_rgb_cycle_breathing_example/bin/app_rgb_cycle_breathing_example.xe b/examples/app_rgb_cycle_breathing_example/bin/app_rgb_cycle_breathing_example.xe index 6b92209..44c1664 100644 Binary files a/examples/app_rgb_cycle_breathing_example/bin/app_rgb_cycle_breathing_example.xe and b/examples/app_rgb_cycle_breathing_example/bin/app_rgb_cycle_breathing_example.xe differ diff --git a/examples/app_test_fill_gradient_with_groups/bin/app_test_fill_gradient_with_groups.xe b/examples/app_test_fill_gradient_with_groups/bin/app_test_fill_gradient_with_groups.xe index 22d0fa9..d9b935e 100644 Binary files a/examples/app_test_fill_gradient_with_groups/bin/app_test_fill_gradient_with_groups.xe and b/examples/app_test_fill_gradient_with_groups/bin/app_test_fill_gradient_with_groups.xe differ diff --git a/examples/app_volume_level_example/bin/app_volume_level_example.xe b/examples/app_volume_level_example/bin/app_volume_level_example.xe index 6bc8d24..99a76c0 100644 Binary files a/examples/app_volume_level_example/bin/app_volume_level_example.xe and b/examples/app_volume_level_example/bin/app_volume_level_example.xe differ diff --git a/lib_rgb/api/misc_utils.h b/lib_rgb/api/misc_utils.h index 1f9e5dc..7e5498b 100644 --- a/lib_rgb/api/misc_utils.h +++ b/lib_rgb/api/misc_utils.h @@ -1,4 +1,13 @@ #include #include -void reverse_buf(uint32_t *start, size_t count); \ No newline at end of file +/** + * 反转缓冲区中的元素。 + * + * @param start 指向要反转的缓冲区开始的指针。 + * @param count 要反转的元素数量。 + * + * 此函数将缓冲区中的元素顺序反转。它通过交换首尾元素,然后向内移动, + * 直到到达中心点,完成反转过程。 + */ +void reverse_buf(uint32_t *start, size_t count); diff --git a/lib_rgb/api/rgb_effect.h b/lib_rgb/api/rgb_effect.h index fce5b12..d90d150 100644 --- a/lib_rgb/api/rgb_effect.h +++ b/lib_rgb/api/rgb_effect.h @@ -2,6 +2,7 @@ #define RGB_EFFECT_H #include +#include /** * 定义渐变方向的枚举类型。 @@ -90,11 +91,46 @@ void cycleRGB_driver(); */ void cycleHSV_driver(); +/** + * 将多种颜色分组填充到RGB条中,并控制显示颜色的时间长度。 + * + * 此函数将RGB条分为若干组,每组填充指定的颜色。每组可以填充不同数量的RGB单元, + * 数量由num_filled_rgb数组指定。填充完所有组指定的颜色后,剩余的RGB单元将被熄灭。 + * 如果组号为奇数,则该组的颜色顺序将被翻转。所有颜色设置完成后,通过调用输出函数 + * 将这些颜色输出到RGB条上。最后,函数调用延迟函数以保持当前颜色一段时间。 + * + * \param buf 指向存储RGB值的缓冲区的指针,每个元素代表RGB条中一个颜色单元的颜色值。 + * \param colors 指向存储每组颜色值的数组的指针,每个元素代表一个组的颜色值。 + * \param num_filled_rgb 指向存储每组已填充RGB单元数量的数组的指针,每个元素代表一个组已填充的RGB单元数量。 + * \param num_groups 组的总数。 + */ +void fill_gradient_with_groups(uint32_t *buf, uint32_t *colors, size_t *num_filled_rgb, size_t num_groups); + +/** + * 测试音量响应&HSV色彩循环 + * + * 此函数不断地循环通过HSV色彩空间,并根据音量水平来更新RGB条的颜色。 + * 每个颜色组都会根据音量水平的随机值来更新其亮度。当前色相值从红色开始, + * 并在每次循环中更新,以通过HSV色彩空间进行循环。每次循环后,将当前颜色 + * 应用到RGB条的相应组中。此函数旨在并发执行,以模拟实时音乐响应的灯光效果。 + * + * 注意:此函数包含无限循环,仅用于测试目的。 + * 注意:使用了par关键词来并发执行代码块,这依赖于特定的硬件或并发模型。 + */ void test_cycleHSV_with_vol_level(); + /** * 用于测试HSV溢出 */ void test_HSV_to_RGB(); +/** + * 测试 fill_gradient_with_groups 函数。 + * + * 此测试函数创建一个缓冲区,并定义两种颜色和每组的填充数量,然后调用 + * fill_gradient_with_groups 函数来填充缓冲区。之后,它会验证缓冲区中的颜色 + * 是否符合预期:每组的前N个LED应该是指定的颜色,剩余的LED应该是关闭的(黑色)。 + * 如果所有LED的颜色都正确,测试通过;否则,输出错误信息并标记测试失败。 + */ void test_fill_gradient_with_groups(); #endif // RGB_EFFECT_H \ No newline at end of file diff --git a/lib_rgb/api/volume_level.h b/lib_rgb/api/volume_level.h index 8f06888..cc104bf 100644 --- a/lib_rgb/api/volume_level.h +++ b/lib_rgb/api/volume_level.h @@ -1,5 +1,20 @@ #include +/** + * 根据响度值获取音量等级。 + * + * @param loudness_value 当前的响度值。 + * @return 对应的音量等级。 + * + * 此函数通过比较响度值与预定义的音量等级表中的响度阈值,来确定当前的音量等级。 + * 它从最大响度阈值开始比较,找到第一个小于或等于当前响度值的阈值,返回对应的音量等级。 + */ unsigned get_volume_level(int loudness_value); +/** + * 测试不同响度值对应的音量等级。 + * + * 此函数定义了一系列响度值,并使用 get_volume_level 函数 + * 来获取每个响度值对应的音量等级,然后打印出来。 + */ void volume_level_test(); \ No newline at end of file diff --git a/lib_rgb/src/misc_utils.xc b/lib_rgb/src/misc_utils.xc index 4021e47..3288589 100644 --- a/lib_rgb/src/misc_utils.xc +++ b/lib_rgb/src/misc_utils.xc @@ -1,6 +1,7 @@ #include #include +// 反转缓冲区中的元素 void reverse_buf(uint32_t *start, size_t count) { uint32_t *end = start + count - 1; while (start < end) { diff --git a/lib_rgb/src/rgb_effect.xc b/lib_rgb/src/rgb_effect.xc index 22eef42..d8568c6 100644 --- a/lib_rgb/src/rgb_effect.xc +++ b/lib_rgb/src/rgb_effect.xc @@ -214,8 +214,7 @@ void fill_gradient(uint32_t *buf, size_t num_filled_rgb, uint32_t color) delay_milliseconds(DELAY_TIME_RGB); } - - +// 将多种颜色分组填充到RGB条中,并控制显示颜色的时间长度。 void fill_gradient_with_groups(uint32_t *buf, uint32_t *colors, size_t *num_filled_rgb, size_t num_groups) { size_t max_leds_per_group = NUM_RGBS / num_groups; @@ -292,6 +291,7 @@ void cycleRGB_driver() } } +// 测试音量响应&HSV色彩循环 void test_cycleHSV_with_vol_level() { @@ -341,6 +341,7 @@ void test_HSV_to_RGB() printf("GRB color is: 0x%06X\n", color); } +// 测试 fill_gradient_with_groups 函数 void test_fill_gradient_with_groups() { uint32_t buffer[NUM_RGBS]; uint32_t colors[] = {0xFF0000, 0x00FF00}; // 红,绿 diff --git a/lib_rgb/src/volume_level.xc b/lib_rgb/src/volume_level.xc index 83f4847..3e0823a 100644 --- a/lib_rgb/src/volume_level.xc +++ b/lib_rgb/src/volume_level.xc @@ -19,6 +19,7 @@ typedef struct { const vol_level_table_t vol_level_table[] = {VOL_LEVEL_TABLE}; #define VOLUME_LEVELS_COUNT (sizeof(vol_level_table) / sizeof(vol_level_table[0])) +// 根据响度值获取音量等级 unsigned get_volume_level(int loudness_value) { // 默认返回音量等级0 int level = 0; @@ -34,6 +35,7 @@ unsigned get_volume_level(int loudness_value) { return level; } +// 测试不同响度值对应的音量等级是否符合预期 void volume_level_test() { // 测试不同的响度值 uint32_t test_loudness_values[] = {1, 0, -2, -5, -8, -20, -30, -40, -60, -62, -70, };