forked from PAWPAW/lib_rgb
解耦test,example,重构effect为C(解决 #4 #6)
This commit is contained in:
@@ -14,7 +14,7 @@ USED_MODULES = lib_rgb
|
||||
|
||||
XCC_FLAGS = $(BUILD_FLAGS)
|
||||
|
||||
XMOS_MODULE_PATH = ../..
|
||||
XMOS_MODULE_PATH = ../../..
|
||||
XCOMMON_DISABLE_AUTO_MODULE_SEARCH = 1
|
||||
|
||||
#=============================================================================
|
||||
|
||||
@@ -1,16 +1,20 @@
|
||||
/** @brief 循环输出整个HSV色域
|
||||
/** @brief 测试 fill_gradient_with_groups 函数
|
||||
* 此测试函数创建一个缓冲区,并定义两种颜色和每组的填充数量,然后调用
|
||||
* fill_gradient_with_groups 函数来填充缓冲区。之后,它会验证缓冲区中的颜色
|
||||
* 是否符合预期:每组的前N个LED应该是指定的颜色,剩余的LED应该是关闭的(黑色)。
|
||||
* 如果所有LED的颜色都正确,测试通过;否则,输出错误信息并标记测试失败。
|
||||
* @author Vergil Wong
|
||||
* @date 2023-11-11
|
||||
* @date 2023-11-25
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
|
||||
#include "stdint.h"
|
||||
#include <stdio.h> // 包含基本的输入输出函数
|
||||
#include <platform.h> // 包含对封装的定义,引用以使用 on tile[] 语法
|
||||
#include "samples_to_levels.h"
|
||||
#include "rgb_effect.h"
|
||||
|
||||
extern "C"
|
||||
{
|
||||
void test_fill_gradient_with_groups();
|
||||
}
|
||||
int main() // 定义主函数
|
||||
{
|
||||
par
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
#include <stdint.h>
|
||||
#include <stdio.h> // 包含基本的输入输出函数
|
||||
#include <platform.h> // 包含对封装的定义,引用以使用 on tile[] 语法
|
||||
#include "samples_to_levels.h"
|
||||
#include "rgb_effect.h"
|
||||
#include "timer.h"
|
||||
|
||||
void test_fill_gradient_with_groups()
|
||||
{
|
||||
uint32_t buffer[NUM_RGBS];
|
||||
uint32_t colors[] = {0xFF0000, 0x00FF00}; // 红,绿
|
||||
size_t num_filled_rgb[] = {2, 3}; // 每组填充数量
|
||||
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);
|
||||
// 延迟以控制显示持续时间
|
||||
delay_milliseconds(DELAY_TIME_RGB);
|
||||
// 验证
|
||||
for (size_t i = 0; i < NUM_RGBS; i++)
|
||||
{
|
||||
size_t group = i / (NUM_RGBS / num_groups);
|
||||
size_t group_led_start = group * (NUM_RGBS / num_groups);
|
||||
uint32_t expected_color = (i < group_led_start + num_filled_rgb[group]) ? colors[group] : 0x000000;
|
||||
if (buffer[i] != expected_color)
|
||||
{
|
||||
success = 0; // 设置为false
|
||||
printf("Test failed at LED %zu: expected 0x%06lX, got 0x%06lX\n", i, expected_color, buffer[i]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (success)
|
||||
{
|
||||
printf("Test passed: All LEDs are correctly set.\n");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user