forked from PAWPAW/lib_rgb
解耦test,example,重构effect为C(解决 #4 #6)
This commit is contained in:
@@ -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
|
||||
|
||||
#=============================================================================
|
||||
|
||||
25
examples/app_hsv_cycle_example/src/hsv_cycle_example.c
Normal file
25
examples/app_hsv_cycle_example/src/hsv_cycle_example.c
Normal 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(¤t_hue, ¤t_sat, ¤t_val);
|
||||
while (1)
|
||||
{
|
||||
// 用当前渐变颜色填充RGB数组,然后发送给rgb阵列
|
||||
fill_gradient(buf, NUM_RGBS, current_color);
|
||||
|
||||
// 延迟以控制显示持续时间
|
||||
delay_milliseconds(DELAY_TIME_RGB);
|
||||
// 更改下一个颜色
|
||||
current_color = cycleHSV(¤t_hue);
|
||||
|
||||
// 打印出当前的GRB颜色值
|
||||
// printf("GRB color is: 0x%06X\n", current_color);
|
||||
}
|
||||
}
|
||||
@@ -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,表示程序正常结束
|
||||
|
||||
@@ -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 应用程序的公共构建基础设施。你无需编辑此处以下的内容。
|
||||
|
||||
@@ -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,表示程序正常结束
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
24
examples/app_test_HSV_to_RGB/Makefile
Normal file
24
examples/app_test_HSV_to_RGB/Makefile
Normal 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
|
||||
22
examples/app_test_HSV_to_RGB/src/main.xc
Normal file
22
examples/app_test_HSV_to_RGB/src/main.xc
Normal 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,表示程序正常结束
|
||||
}
|
||||
16
examples/app_test_HSV_to_RGB/src/test_hsv_to_rgb.c
Normal file
16
examples/app_test_HSV_to_RGB/src/test_hsv_to_rgb.c
Normal 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);
|
||||
}
|
||||
@@ -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,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,表示程序正常结束
|
||||
|
||||
@@ -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(¤t_hue);
|
||||
}
|
||||
|
||||
// 打印出当前的GRB颜色值
|
||||
// printf("GRB color is: 0x%06X\n", current_color);
|
||||
}
|
||||
}
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
#ifndef _RGB_DRIVER_H
|
||||
#define _RGB_DRIVER_H
|
||||
|
||||
#include "stdint.h"
|
||||
#include <stdint.h>
|
||||
|
||||
/** 串行输出24位值。
|
||||
*
|
||||
|
||||
@@ -143,28 +143,6 @@ uint32_t HSV_to_RGB(uint32_t *hue, uint32_t *sat, uint32_t *value);
|
||||
*/
|
||||
void fill_gradient(uint32_t *buf, size_t num_filled_rgb, uint32_t color);
|
||||
|
||||
|
||||
/**
|
||||
* 在tile[1]上启动一个永久循环,该循环会持续更新RGB灯条的颜色。
|
||||
* 它初始化一个颜色值,然后在一个无限循环中不断地调用fill_gradient和cycleRGB函数,
|
||||
* 以实现RGB灯条颜色的渐变效果。颜色的变化方向会根据GradientDirection变量进行调整。
|
||||
*/
|
||||
void cycleRGB_driver();
|
||||
|
||||
/**
|
||||
* 驱动HSV颜色空间中的颜色循环,以实现连续的颜色渐变效果。
|
||||
*
|
||||
* 此函数初始化颜色值,并进入一个无限循环,不断地计算新的颜色值并更新LED阵列。
|
||||
* 使用并发执行关键字 'par' 来实现循环内部的并行处理。这个函数假定运行环境支持并行关键字 'par'。
|
||||
*
|
||||
* 在此循环中,它首先使用当前颜色填充一个预定义大小的缓冲区,然后调用 `cycleHSV` 函数
|
||||
* 来更新当前色相值并获取新的颜色。最后,它打印出当前的GRB颜色值。
|
||||
*
|
||||
* 注意:此函数设计为在嵌入式系统或具有并行处理能力的系统上运行。
|
||||
* 它包含一个无限循环,应确保有适当的机制来安全地退出或中断执行。
|
||||
*/
|
||||
void cycleHSV_driver();
|
||||
|
||||
/**
|
||||
* 将多种颜色分组填充到RGB条中,并控制显示颜色的时间长度。
|
||||
*
|
||||
@@ -179,31 +157,4 @@ void cycleHSV_driver();
|
||||
*/
|
||||
void fill_gradient_with_groups(uint32_t *buf, uint32_t *colors, size_t *num_filled_rgb);
|
||||
|
||||
/**
|
||||
* 测试音量响应&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
|
||||
#endif //RGB_EFFECT_H
|
||||
@@ -3,7 +3,7 @@
|
||||
#include <stdio.h> // 包含基本的输入输出函数
|
||||
#include <timer.h>
|
||||
#include "xclib.h"
|
||||
#include "stdint.h"
|
||||
#include <stdint.h>
|
||||
|
||||
// 如果灯的显示没有出现问题,不要修改这些宏
|
||||
#define MICROSECONDS 100
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
#include <xs1.h> // 包含对XCORE资源的操作
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include "xclib.h"
|
||||
#include "timer.h"
|
||||
#include "rgb_driver.h"
|
||||
#include "samples_to_levels.h"
|
||||
@@ -14,17 +12,17 @@ void is_HSV_valid(uint32_t *hue, uint32_t *sat, uint32_t *value)
|
||||
{
|
||||
if (*hue >= HSV_HUE_MAX)
|
||||
{
|
||||
printf("[x]hue overflow, current: %u\n", *hue);
|
||||
printf("[x]hue overflow, current: %lu\n", *hue);
|
||||
*hue = HSV_HUE_MAX - 1;
|
||||
}
|
||||
if (*sat > HSV_SATURATION_MAX)
|
||||
{
|
||||
printf("[x]sat overflow, current: %u\n", *sat);
|
||||
printf("[x]sat overflow, current: %lu\n", *sat);
|
||||
*sat = HSV_SATURATION_MAX;
|
||||
}
|
||||
if (*value > HSV_VALUE_MAX)
|
||||
{
|
||||
printf("[x]value overflow, current: %u\n", *value);
|
||||
printf("[x]value overflow, current: %lu\n", *value);
|
||||
*value = HSV_VALUE_MAX;
|
||||
}
|
||||
}
|
||||
@@ -193,133 +191,4 @@ void fill_gradient_with_groups(uint32_t *buf, uint32_t *colors, size_t *num_fill
|
||||
// 将缓冲区输出到RGB条
|
||||
output_rgb_array(buf, NUM_RGBS);
|
||||
|
||||
}
|
||||
|
||||
// TODO:添加可合并选项
|
||||
// 驱动HSV颜色空间中的颜色循环,以实现连续的颜色渐变效果。
|
||||
void cycleHSV_driver()
|
||||
{
|
||||
|
||||
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(¤t_hue, ¤t_sat, ¤t_val);
|
||||
par // 使用par关键词并发执行下面的代码块,这些线程默认在tile[1]上运行
|
||||
{
|
||||
while (1)
|
||||
{
|
||||
// 用当前渐变颜色填充RGB数组,然后发送给rgb阵列
|
||||
fill_gradient(buf, NUM_RGBS, current_color);
|
||||
|
||||
// 延迟以控制显示持续时间
|
||||
delay_milliseconds(DELAY_TIME_RGB);
|
||||
// 更改下一个颜色
|
||||
current_color = cycleHSV(¤t_hue);
|
||||
|
||||
// 打印出当前的GRB颜色值
|
||||
// printf("GRB color is: 0x%06X\n", current_color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 持续更新RGB灯条的颜色
|
||||
void cycleRGB_driver()
|
||||
{
|
||||
|
||||
uint32_t buf[NUM_RGBS];
|
||||
uint32_t current_color = 0x000000; // Start from black
|
||||
GradientDirection direction = INCREMENTING; // 开始时设置为递增亮度
|
||||
|
||||
par // 使用par关键词并发执行下面的代码块,这些线程默认在tile[1]上运行
|
||||
{
|
||||
while (1)
|
||||
{
|
||||
// 用当前渐变颜色填充RGB数组
|
||||
fill_gradient(buf, NUM_RGBS, current_color);
|
||||
// 延迟以控制显示持续时间
|
||||
delay_milliseconds(DELAY_TIME_RGB);
|
||||
// 更改下一个渐变的基色
|
||||
current_color = cycleRGB(current_color, &direction);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 测试音量响应&HSV色彩循环
|
||||
void test_cycleHSV_with_vol_level()
|
||||
{
|
||||
|
||||
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];
|
||||
par // 使用par关键词并发执行下面的代码块,这些线程默认在tile[1]上运行
|
||||
{
|
||||
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(¤t_hue);
|
||||
}
|
||||
|
||||
// 打印出当前的GRB颜色值
|
||||
// printf("GRB color is: 0x%06X\n", current_color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 测试 HSV_to_RGB,以及饱和处理
|
||||
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);
|
||||
}
|
||||
|
||||
// 测试 fill_gradient_with_groups 函数
|
||||
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%06X, got 0x%06X\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