diff --git a/.gitignore b/.gitignore index 7d721a9..3fad1a9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ **/.build* +**/bin** .vscode \ No newline at end of file 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 deleted file mode 100644 index 05e56be..0000000 Binary files a/examples/app_hsv_cycle_example/bin/app_hsv_cycle_example.xe and /dev/null 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 deleted file mode 100644 index ddab217..0000000 Binary files a/examples/app_rgb_cycle_breathing_example/bin/app_rgb_cycle_breathing_example.xe and /dev/null differ diff --git a/examples/app_test_cycleHSV_with_vol_level_example/bin/app_test_cycleHSV_with_vol_level_example.xe b/examples/app_test_cycleHSV_with_vol_level_example/bin/app_test_cycleHSV_with_vol_level_example.xe deleted file mode 100644 index f13f981..0000000 Binary files a/examples/app_test_cycleHSV_with_vol_level_example/bin/app_test_cycleHSV_with_vol_level_example.xe and /dev/null 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 deleted file mode 100644 index 2339a56..0000000 Binary files a/examples/app_test_fill_gradient_with_groups/bin/app_test_fill_gradient_with_groups.xe and /dev/null differ diff --git a/lib_rgb/api/rgb_effect.h b/lib_rgb/api/rgb_effect.h index 01b0cc2..07f6e42 100644 --- a/lib_rgb/api/rgb_effect.h +++ b/lib_rgb/api/rgb_effect.h @@ -1,5 +1,5 @@ -#ifndef _RGB_EFFECT_H -#define _RGB_EFFECT_H +#ifndef RGB_EFFECT_H +#define RGB_EFFECT_H #include #include @@ -7,6 +7,48 @@ #include "volume_level.h" #include "misc_utils.h" +// RGB灯的数量 +#ifndef NUM_RGBS +#define NUM_RGBS (12) +#endif + +// RGB灯组的数量,不应超过NUM_RGBS +#ifndef NUM_RGB_GROUPS +#define NUM_RGB_GROUPS (2) +#endif + +// 控制RGB亮度的最大值,不超过255 +#ifndef RGB_MAX +#define RGB_MAX (20) +#endif + +// TODO:优化为编译时检查? +// 开关饱和检查,该检查会引入性能损失,在需要高刷新率时关闭它 +#ifndef HSV_VALID_CHECK +#define HSV_VALID_CHECK (1) +#endif + +// 控制HUE的最大值,不超过360° +#ifndef HSV_HUE_MAX +#define HSV_HUE_MAX (360) +#endif + +// 控制饱和度的最大值,不超过100 +#ifndef HSV_SATURATION_MAX +#define HSV_SATURATION_MAX (100) +#endif + +// 控制VALUE,不超过100 +#ifndef HSV_VALUE_MAX +#define HSV_VALUE_MAX (100) +#endif + +// 微秒,定义每次颜色更新的延迟,在cycleRGB下, +// (1000/RGB_MAX)代表每个B/R/G值的爬升/缓降时间约为1000ms +#ifndef DELAY_TIME_RGB +#define DELAY_TIME_RGB (1000 / RGB_MAX) +#endif + /** * 定义渐变方向的枚举类型。 * @@ -99,7 +141,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, uint32_t color); +void fill_gradient(uint32_t *buf, size_t num_filled_rgb, uint32_t color); /** @@ -134,9 +176,8 @@ void cycleHSV_driver(); * \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); +void fill_gradient_with_groups(uint32_t *buf, uint32_t *colors, size_t *num_filled_rgb); /** * 测试音量响应&HSV色彩循环 @@ -165,4 +206,4 @@ void test_HSV_to_RGB(); * 如果所有LED的颜色都正确,测试通过;否则,输出错误信息并标记测试失败。 */ void test_fill_gradient_with_groups(); -#endif // _RGB_EFFECT_H \ No newline at end of file +#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 43e2a7e..7c7e1e8 100644 --- a/lib_rgb/api/volume_level.h +++ b/lib_rgb/api/volume_level.h @@ -1,6 +1,5 @@ -#ifndef _VOLUME_LEVEL_H -#define _VOLUME_LEVEL_H - +#ifndef VOLUME_LEVEL_H +#define VOLUME_LEVEL_H #include /** @@ -22,4 +21,4 @@ unsigned get_volume_level(int loudness_value); */ void volume_level_test(); -#endif // _VOLUME_LEVEL_H \ No newline at end of file +#endif //VOLUME_LEVEL_H \ No newline at end of file diff --git a/lib_rgb/src/rgb_effect.xc b/lib_rgb/src/rgb_effect.xc index 3d31aa3..cd8dd17 100644 --- a/lib_rgb/src/rgb_effect.xc +++ b/lib_rgb/src/rgb_effect.xc @@ -7,56 +7,10 @@ #include "rgb_driver.h" #include "volume_level.h" #include "misc_utils.h" - -// RGB灯的数量 -#ifndef NUM_RGBS -#define NUM_RGBS (12) -#endif - -// RGB灯组的数量,不应超过NUM_RGBS -#ifndef NUM_RGB_GROUPS -#define NUM_RGB_GROUPS (2) -#endif - -// 控制RGB亮度的最大值,不超过255 -#ifndef RGB_MAX -#define RGB_MAX (20) -#endif - -// TODO:优化为编译时检查? -// 开关饱和检查,该检查会引入性能损失,在需要高刷新率时关闭它 -#ifndef HSV_VALID_CHECK -#define HSV_VALID_CHECK (1) -#endif - -// 控制HUE的最大值,不超过360° -#ifndef HSV_HUE_MAX -#define HSV_HUE_MAX (360) -#endif - -// 控制饱和度的最大值,不超过100 -#ifndef HSV_SATURATION_MAX -#define HSV_SATURATION_MAX (100) -#endif - -// 控制VALUE,不超过100 -#ifndef HSV_VALUE_MAX -#define HSV_VALUE_MAX (100) -#endif - -// 微秒,定义每次颜色更新的延迟,在cycleRGB下, -// (1000/RGB_MAX)代表每个B/R/G值的爬升/缓降时间约为1000ms -#ifndef DELAY_TIME_RGB -#define DELAY_TIME_RGB (1000 / RGB_MAX) -#endif +#include "rgb_effect.h" // TODO:当RGB_MAX等值超限时,raise error // 定义一个枚举来表示渐变方向 -typedef enum -{ - INCREMENTING, // 亮度递增 - DECREMENTING // 亮度递减 -} GradientDirection; // 检查HSV值是否在有效范围内,如果溢出则将值设为最大值,并打印报错 @@ -218,11 +172,11 @@ void fill_gradient(uint32_t *buf, size_t num_filled_rgb, uint32_t color) } // 将多种颜色分组填充到RGB条中,并控制显示颜色的时间长度。 -void fill_gradient_with_groups(uint32_t *buf, uint32_t *colors, size_t *num_filled_rgb, size_t num_groups) +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_groups; + size_t max_leds_per_group = NUM_RGBS / NUM_RGB_GROUPS; - for (size_t group = 0; group < num_groups; group++) { + for (size_t group = 0; group < NUM_RGB_GROUPS; group++) { // 填充每个组的LED uint32_t *group_buf = buf + group * max_leds_per_group; for (size_t i = 0; i < num_filled_rgb[group]; i++) { @@ -243,8 +197,6 @@ void fill_gradient_with_groups(uint32_t *buf, uint32_t *colors, size_t *num_fill // 将缓冲区输出到RGB条 output_rgb_array(buf, NUM_RGBS); - // 延迟以控制显示持续时间 - delay_milliseconds(DELAY_TIME_RGB); } // TODO:添加可合并选项 @@ -263,7 +215,9 @@ void cycleHSV_driver() { // 用当前渐变颜色填充RGB数组,然后发送给rgb阵列 fill_gradient(buf, NUM_RGBS, current_color); - + + // 延迟以控制显示持续时间 + delay_milliseconds(DELAY_TIME_RGB); // 更改下一个颜色 current_color = cycleHSV(¤t_hue); @@ -287,7 +241,8 @@ void cycleRGB_driver() { // 用当前渐变颜色填充RGB数组 fill_gradient(buf, NUM_RGBS, current_color); - + // 延迟以控制显示持续时间 + delay_milliseconds(DELAY_TIME_RGB); // 更改下一个渐变的基色 current_color = cycleRGB(current_color, &direction); } @@ -316,8 +271,9 @@ void test_cycleHSV_with_vol_level() } // 用当前渐变颜色填充RGB数组,然后发送给rgb阵列 - fill_gradient_with_groups(buf, current_color, random_levels, NUM_RGB_GROUPS); - + fill_gradient_with_groups(buf, current_color, random_levels); + // 延迟以控制显示持续时间 + delay_milliseconds(DELAY_TIME_RGB); // 更改下一个颜色 for (size_t i = 0; i < NUM_RGB_GROUPS; i++) { @@ -352,8 +308,9 @@ void test_fill_gradient_with_groups() { size_t num_groups = sizeof(colors) / sizeof(colors[0]); int success = 1; // 使用int代替bool,1代表true,0代表false - fill_gradient_with_groups(buffer, colors, num_filled_rgb, num_groups); - + fill_gradient_with_groups(buffer, colors, num_filled_rgb); + // 延迟以控制显示持续时间 + delay_milliseconds(DELAY_TIME_RGB); // 验证 for (size_t i = 0; i < NUM_RGBS; i++) { size_t group = i / (NUM_RGBS / num_groups); diff --git a/lib_rgb/src/volume_level.xc b/lib_rgb/src/volume_level.xc index 3e0823a..683eebd 100644 --- a/lib_rgb/src/volume_level.xc +++ b/lib_rgb/src/volume_level.xc @@ -25,7 +25,7 @@ unsigned get_volume_level(int loudness_value) { int level = 0; // 从最大响度值开始向下找 - for (int i = 0; i < VOLUME_LEVELS_COUNT; ++i) { + for (size_t i = 0; i < VOLUME_LEVELS_COUNT; ++i) { if (loudness_value >= vol_level_table[i].vol) { level = vol_level_table[i].level; break; // 找到后立即退出循环 @@ -42,8 +42,8 @@ void volume_level_test() { int num_tests = sizeof(test_loudness_values) / sizeof(test_loudness_values[0]); for (int i = 0; i < num_tests; ++i) { - printf("Loudness: %d dB, Volume Level: %d\n", + printf("Loudness: %u dB, Volume Level: %u\n", test_loudness_values[i], - get_volume_level(test_loudness_values[i])); + get_volume_level((int)test_loudness_values[i])); } } \ No newline at end of file