解耦test,example,重构effect为C(解决 #4 #6)

This commit is contained in:
2023-11-25 16:36:04 +08:00
parent 5024b92298
commit 1d8c7663f1
20 changed files with 242 additions and 217 deletions

View File

@@ -10,11 +10,11 @@ TARGET = XCORE-AI-EXPLORER
# fxscope: 使用 xSCOPE对代码进行跟踪默认使用xlink
BUILD_FLAGS = -O2 -g -DDEBUG_PRINT_ENABLE=1 -report -fxscope
USED_MODULES = lib_rgb
USED_MODULES = lib_rgb lib_xcore_math
XCC_FLAGS = $(BUILD_FLAGS)
XMOS_MODULE_PATH = ../..
XMOS_MODULE_PATH = ../../..
XCOMMON_DISABLE_AUTO_MODULE_SEARCH = 1
#=============================================================================

View File

@@ -0,0 +1,25 @@
#include <stdint.h>
#include <stdio.h> // 包含基本的输入输出函数
#include "rgb_effect.h"
#include "timer.h"
void hsv_cycle_example()
{
uint32_t buf[NUM_RGBS]; // 定义一个用于存储RGB值的缓冲区大小由NUM_RGBS宏确定
uint32_t current_hue = 0; // 从红色开始的当前色相值
uint32_t current_sat = 100; // 当前饱和度值,初始化为满饱和度
uint32_t current_val = 100; // 当前亮度值,初始化为最大亮度
uint32_t current_color = HSV_to_RGB(&current_hue, &current_sat, &current_val);
while (1)
{
// 用当前渐变颜色填充RGB数组然后发送给rgb阵列
fill_gradient(buf, NUM_RGBS, current_color);
// 延迟以控制显示持续时间
delay_milliseconds(DELAY_TIME_RGB);
// 更改下一个颜色
current_color = cycleHSV(&current_hue);
// 打印出当前的GRB颜色值
// printf("GRB color is: 0x%06X\n", current_color);
}
}

View File

@@ -1,14 +1,24 @@
/** @brief RGB循环呼吸
*
* 驱动HSV颜色空间中的颜色循环以实现连续的颜色渐变效果。
*
* 此函数初始化颜色值并进入一个无限循环不断地计算新的颜色值并更新LED阵列。
* 使用并发执行关键字 'par' 来实现循环内部的并行处理。这个函数假定运行环境支持并行关键字 'par'。
*
* 在此循环中,它首先使用当前颜色填充一个预定义大小的缓冲区,然后调用 `cycleHSV` 函数
* 来更新当前色相值并获取新的颜色。最后它打印出当前的GRB颜色值。
* @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 "rgb_effect.h"
extern "C"
{
void hsv_cycle_example();
}
int main() // 定义主函数
{
@@ -16,7 +26,7 @@ int main() // 定义主函数
{
on tile[1]:
{
cycleHSV_driver();
hsv_cycle_example();
}
}
return 0; // 返回0表示程序正常结束

View File

@@ -14,7 +14,7 @@ USED_MODULES = lib_rgb
XCC_FLAGS = $(BUILD_FLAGS)
XMOS_MODULE_PATH = ../..
XMOS_MODULE_PATH = ../../..
XCOMMON_DISABLE_AUTO_MODULE_SEARCH = 1
#=============================================================================
# 下面部分的 Makefile 包含了用于编译 XMOS 应用程序的公共构建基础设施。你无需编辑此处以下的内容。

View File

@@ -1,14 +1,19 @@
/** @brief 循环输出整个HSV色域
/** @brief 持续更新RGB灯条的颜色
* 在tile[1]上启动一个永久循环该循环会持续更新RGB灯条的颜色。
* 它初始化一个颜色值然后在一个无限循环中不断地调用fill_gradient和cycleRGB函数
* 以实现RGB灯条颜色的渐变效果。颜色的变化方向会根据GradientDirection变量进行调整。
* @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 "rgb_effect.h"
extern "C"
{
void rgb_cycle_breathing_example();
}
int main() // 定义主函数
{
@@ -16,7 +21,7 @@ int main() // 定义主函数
{
on tile[1]:
{
cycleRGB_driver();
rgb_cycle_breathing_example();
}
}
return 0; // 返回0表示程序正常结束

View File

@@ -0,0 +1,20 @@
#include <stdint.h>
#include <stdio.h> // 包含基本的输入输出函数
#include "rgb_effect.h"
#include "timer.h"
void rgb_cycle_breathing_example()
{
uint32_t buf[NUM_RGBS];
uint32_t current_color = 0x000000; // Start from black
GradientDirection direction = INCREMENTING; // 开始时设置为递增亮度
while (1)
{
// 用当前渐变颜色填充RGB数组
fill_gradient(buf, NUM_RGBS, current_color);
// 延迟以控制显示持续时间
delay_milliseconds(DELAY_TIME_RGB);
// 更改下一个渐变的基色
current_color = cycleRGB(current_color, &direction);
}
}

View File

@@ -0,0 +1,24 @@
# `TARGET` 变量决定了应用程序编译的目标系统。它可以引用源目录中的一个 XN 文件,或者是在编译时作为 `--target` 选项的一个有效参数。
TARGET = XCORE-AI-EXPLORER
# 编译选项
# 构建应用程序时传递给 xcc 的参数
# O2: xcc编译器优化等级2
# report: 打开编译报告
# g: 生成调试信息
# fxscope: 使用 xSCOPE对代码进行跟踪默认使用xlink
BUILD_FLAGS = -O2 -g -DDEBUG_PRINT_ENABLE=1 -report -fxscope
USED_MODULES = lib_rgb
XCC_FLAGS = $(BUILD_FLAGS)
XMOS_MODULE_PATH = ../../..
XCOMMON_DISABLE_AUTO_MODULE_SEARCH = 1
#=============================================================================
# 下面部分的 Makefile 包含了用于编译 XMOS 应用程序的公共构建基础设施。你无需编辑此处以下的内容。
XMOS_MAKE_PATH ?= ../..
include $(XMOS_MAKE_PATH)/xcommon/module_xcommon/build/Makefile.common

View File

@@ -0,0 +1,22 @@
/** @brief 测试 HSV_to_RGB以及饱和处理
* @author Vergil Wong
* @date 2023-11-25
* @param
* @return
*/
#include <platform.h> // 包含对封装的定义,引用以使用 on tile[] 语法
extern "C"
{
void test_hsv_to_rgb();
}
int main() // 定义主函数
{
par
{
on tile[1]: test_hsv_to_rgb();
}
return 0; // 返回0表示程序正常结束
}

View File

@@ -0,0 +1,16 @@
#include <stdint.h>
#include "rgb_effect.h"
void test_hsv_to_rgb()
{
uint32_t hue, sat, value; // HSV值
uint32_t color; // RGB值
// 测试转换
hue = 999;
sat = 999;
value = 999;
color = HSV_to_RGB(&hue, &sat, &value);
printf("GRB color is: 0x%06X\n", color);
}

View File

@@ -14,7 +14,7 @@ USED_MODULES = lib_rgb
XCC_FLAGS = $(BUILD_FLAGS)
XMOS_MODULE_PATH = ../..
XMOS_MODULE_PATH = ../../..
XCOMMON_DISABLE_AUTO_MODULE_SEARCH = 1
#=============================================================================

View File

@@ -1,15 +1,20 @@
/** @brief 循环输出整个HSV色
/** @brief 测试音量响应&HSV色彩循环
*
* 此函数不断地循环通过HSV色彩空间并根据音量水平来更新RGB条的颜色。
* 每个颜色组都会根据音量水平的随机值来更新其亮度。当前色相值从红色开始,
* 并在每次循环中更新以通过HSV色彩空间进行循环。每次循环后将当前颜色
* 应用到RGB条的相应组中。此函数旨在并发执行以模拟实时音乐响应的灯光效果。
* @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_cycleHSV_with_vol_level_example();
}
int main() // 定义主函数
{
@@ -17,8 +22,7 @@ int main() // 定义主函数
{
on tile[1]:
{
// volume_level_test();
test_cycleHSV_with_vol_level();
test_cycleHSV_with_vol_level_example();
}
}
return 0; // 返回0表示程序正常结束

View File

@@ -0,0 +1,38 @@
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h> // 包含基本的输入输出函数
#include "samples_to_levels.h"
#include "rgb_effect.h"
#include "timer.h"
void test_cycleHSV_with_vol_level_example()
{
uint32_t buf[NUM_RGBS]; // 定义一个用于存储RGB值的缓冲区大小由NUM_RGBS宏确定
uint32_t current_hue = 0; // 从红色开始的当前色相值
// uint32_t current_sat = 100; // 当前饱和度值,初始化为满饱和度
// uint32_t current_val = 100; // 当前亮度值,初始化为最大亮度
uint32_t current_color[NUM_RGB_GROUPS] = {0x000000, 0x000000};
srand(1); // 初始化随机数种子
size_t random_levels[NUM_RGB_GROUPS];
while (1)
{
for (size_t i = 0; i < NUM_RGB_GROUPS; i++)
{
*(random_levels + i) = get_volume_level(rand() % 101 - 100);
}
// 用当前渐变颜色填充RGB数组然后发送给rgb阵列
fill_gradient_with_groups(buf, current_color, random_levels);
// 延迟以控制显示持续时间
delay_milliseconds(DELAY_TIME_RGB);
// 更改下一个颜色
for (size_t i = 0; i < NUM_RGB_GROUPS; i++)
{
*(current_color + i) = cycleHSV(&current_hue);
}
// 打印出当前的GRB颜色值
// printf("GRB color is: 0x%06X\n", current_color);
}
}

View File

@@ -14,7 +14,7 @@ USED_MODULES = lib_rgb
XCC_FLAGS = $(BUILD_FLAGS)
XMOS_MODULE_PATH = ../..
XMOS_MODULE_PATH = ../../..
XCOMMON_DISABLE_AUTO_MODULE_SEARCH = 1
#=============================================================================

View File

@@ -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

View File

@@ -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代替bool1代表true0代表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");
}
}