forked from PAWPAW/lib_rgb
修复了示例
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include "rgb_effect.h"
|
||||
void test_hsv_to_rgb()
|
||||
{
|
||||
@@ -12,5 +13,5 @@ void test_hsv_to_rgb()
|
||||
|
||||
color = HSV_to_RGB(&hue, &sat, &value);
|
||||
|
||||
printf("GRB color is: 0x%06X\n", color);
|
||||
printf("GRB color is: 0x%06lX\n", color);
|
||||
}
|
||||
@@ -1,8 +1,6 @@
|
||||
/** @brief 测试 fill_gradient_with_groups 函数
|
||||
* 此测试函数创建一个缓冲区,并定义两种颜色和每组的填充数量,然后调用
|
||||
* fill_gradient_with_groups 函数来填充缓冲区。之后,它会验证缓冲区中的颜色
|
||||
* 是否符合预期:每组的前N个LED应该是指定的颜色,剩余的LED应该是关闭的(黑色)。
|
||||
* 如果所有LED的颜色都正确,测试通过;否则,输出错误信息并标记测试失败。
|
||||
* fill_gradient_with_groups 函数来填充缓冲区,并渲染RGB。
|
||||
* @author Vergil Wong
|
||||
* @date 2023-11-25
|
||||
* @param
|
||||
|
||||
@@ -1,36 +1,14 @@
|
||||
#include <stdint.h>
|
||||
#include <stdio.h> // 包含基本的输入输出函数
|
||||
#include <platform.h> // 包含对封装的定义,引用以使用 on tile[] 语法
|
||||
#include "samples_to_levels.h"
|
||||
#define NUM_RGB_GROUPS 3
|
||||
|
||||
#include "rgb_effect.h"
|
||||
#include "timer.h"
|
||||
void test_fill_gradient_with_groups()
|
||||
{
|
||||
uint32_t buffer[NUM_RGBS];
|
||||
uint32_t colors[] = {0xFF0000, 0x00FF00, 0x0000FF}; // 红,绿,蓝
|
||||
uint32_t colors[] = {0x110000, 0x001100, 0x000011}; // 红,绿,蓝
|
||||
size_t num_filled_rgb[] = {4, 4, 4}; // 每组填充数量
|
||||
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_RGB_GROUPS);
|
||||
size_t group_led_start = group * (NUM_RGBS / NUM_RGB_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