整合测试框架

- 整合了原有的功能用例与接口测试
This commit is contained in:
2023-12-27 15:47:51 +08:00
parent 4ccd40bab9
commit a9210ce318
47 changed files with 1437 additions and 1 deletions

3
.gitignore vendored
View File

@@ -1,3 +1,4 @@
**/.build*
**/bin**
.vscode
.vscode
**/__pycache__

82
testcases/conftest.py Executable file
View File

@@ -0,0 +1,82 @@
import time
from _pytest import terminal
import os
import pytest
import sys
from commons.check import Check
from commons.logger_ext import Logger
# 获取当前文件的绝对路径
current_file_path = os.path.abspath(__file__)
# 获取当前文件的上上上一级目录路径
grandparent_directory = os.path.dirname(os.path.dirname(os.path.dirname(current_file_path))).replace('\\', '/')
# 测试结果路径
test_result_file_path = os.path.join(grandparent_directory, "reports", "test_result", "test_result.txt")
def pytest_terminal_summary(terminalreporter, exitstatus, config):
# 收集测试结果
passed = len([i for i in terminalreporter.stats.get('passed', []) if i.when != 'teardown'])
failed = len([i for i in terminalreporter.stats.get('failed', []) if i.when != 'teardown'])
error = len([i for i in terminalreporter.stats.get('error', []) if i.when != 'teardown'])
skipped = len([i for i in terminalreporter.stats.get('skipped', []) if i.when != 'teardown'])
# total = terminalreporter._numcollected
total = passed + failed + error + skipped
success_rate = passed / (total - skipped) * 100
failure_rate = failed / (total - skipped) * 100
error_rate = error / (total - skipped) * 100
skip_rate = skipped / total * 100
# terminalreporter._sessionstarttime 会话开始时间
duration = time.time() - terminalreporter._sessionstarttime
# print('total times: %.2f' % duration, 'seconds')
failure_case_list = []
if failed == 0:
failure_case_list = []
else:
for rep in terminalreporter.stats.get('failed', []):
file_path = rep.nodeid.split("::")[0]
failure_case_list.append(file_path)
with open(test_result_file_path, "w") as fp:
fp.write("TOTAL=%s" % total + "\n")
fp.write("PASSED=%s" % passed + "\n")
fp.write("FAILED=%s" % failed + "\n")
fp.write("ERROR=%s" % error + "\n")
fp.write("SKIPPED=%s" % skipped + "\n")
fp.write("SUCCESS_RATE=%.2f%%" % success_rate + "\n")
fp.write("FAILURE_RATE=%.2f%%" % failure_rate + "\n")
fp.write("ERROR_RATE=%.2f%%" % error_rate + "\n")
fp.write("SKIP_RATE=%.2f%%" % skip_rate + "\n")
fp.write("TOTAL_TIMES=%.2fs" % duration + "\n")
fp.write("FAILURE_CASE_PATH=%s" % failure_case_list + "\n")
fp.close()
@pytest.fixture(scope='function')
def get_logger_check(request):
filename = request.node.name
logger = Logger(name=filename)
check = Check(logger)
request.cls.logger = logger
request.cls.check = check
# 添加命令行参数为功能测试
def pytest_addoption(parser):
parser.addoption("--function", action="store_true")
@pytest.fixture
def function(pytestconfig):
return pytestconfig.getoption("function")
@pytest.fixture
def function(pytestconfig):
# 使用 pytestconfig.getoption 方法尝试获取 'function' 参数
# 如果参数不存在,则返回一个默认值,例如 False
return pytestconfig.getoption("function", default=False)

24
testcases/main.py Normal file
View File

@@ -0,0 +1,24 @@
import os
import pytest
from commons.operate_log import OperateLog
if __name__ == "__main__":
# 获取当前脚本文件所在的目录路径
current_path = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))).replace('\\', '/')
reports_path = os.path.join(current_path, 'reports')
allure_path = os.path.join(current_path, 'reports', 'allure')
test_result_path = os.path.join(current_path, 'reports', 'test_result')
if not os.path.exists(reports_path):
os.makedirs(reports_path)
if not os.path.exists(allure_path):
os.makedirs(allure_path)
if not os.path.exists(test_result_path):
os.makedirs(test_result_path)
#每次执行全部用例之前删除logs下的日志文件
OperateLog().delete_logs()
# 执行测试用例
pytest.main(['-q', "--alluredir", allure_path, '--clean-alluredir'])
#合并生成的日志文件
OperateLog().merge_logs('lib_rgb_test.log')

10
testcases/pytest.ini Normal file
View File

@@ -0,0 +1,10 @@
[pytest]
python_files = test_*.py
python_classes = Test*
python_functions = test_*
addopts = -n 16 --dist=loadscope -p no:warnings
log_cli = 0

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 -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,17 @@
#include <stdint.h>
#include <stdio.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%06lX\n", color);
}

View File

@@ -0,0 +1,34 @@
from pathlib import Path
import pytest
import os
from commons.pyxrun import XMakeRun
@pytest.mark.usefixtures("get_logger_check")
class TestClass:
def test_app_test_HSV_to_RGB(self, capfd, request):
file_path = Path(request.fspath).parent
xmakerun = XMakeRun(self.logger, file_path)
# xmake的命令
xmake_cmd = 'xmake -j'
# 执行xmake命令
xmakerun.xmake_cmd(xmake_cmd)
# app_cycleHSV_vol_level_example
xe_basename = os.path.basename(file_path)
# app_cycleHSV_vol_level_example.xe
xe_name = "{}.xe".format(xe_basename)
# bin/app_cycleHSV_vol_level_example.xe
xrun_file_path = "bin/{}".format(xe_name)
xrun_cmd = f'xsim {xrun_file_path}'
xmakerun.xsim_cmd(xrun_cmd)
out, _ = capfd.readouterr()
expect = "GRB color is: 0x00C700"
self.check.check_equal(out, expect)

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 -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 测试不同的响度值转化为音量等级
* @author Vergil Wong
* @date 2023-11-25
* @param
* @return
*/
#include <platform.h> // 包含对封装的定义,引用以使用 on tile[] 语法
extern "C"
{
void test_vol_to_level();
}
int main() // 定义主函数
{
par
{
on tile[1]: test_vol_to_level();
}
return 0; // 返回0表示程序正常结束
}

View File

@@ -0,0 +1,15 @@
#include <stdint.h>
#include <stdio.h>
#include "rgb_effect.h"
void test_vol_to_level()
{
// 测试不同的响度值
uint32_t test_loudness_values[] = {1, 0, -2, -5, -8, -20, -30, -40, -60, -62, -70, };
int num_tests = sizeof(test_loudness_values) / sizeof(test_loudness_values[0]);
for (int i = 0; i < num_tests; ++i) {
printf("Loudness: %lu dB, Volume Level: %u\n",
test_loudness_values[i],
get_volume_level((int)test_loudness_values[i]));
}
}

View File

@@ -0,0 +1,46 @@
from pathlib import Path
import pytest
import os
from commons.pyxrun import XMakeRun
@pytest.mark.usefixtures("get_logger_check")
class TestClass:
def test_app_test_vol_to_level(self, capfd, request):
file_path = Path(request.fspath).parent
xmakerun = XMakeRun(self.logger, file_path)
# xmake的命令
xmake_cmd = 'xmake -j'
# 执行xmake命令
xmakerun.xmake_cmd(xmake_cmd)
# app_cycleHSV_vol_level_example
xe_basename = os.path.basename(file_path)
# app_cycleHSV_vol_level_example.xe
xe_name = "{}.xe".format(xe_basename)
# bin/app_cycleHSV_vol_level_example.xe
xrun_file_path = "bin/{}".format(xe_name)
xrun_cmd = f'xsim {xrun_file_path}'
xmakerun.xsim_cmd(xrun_cmd)
out, _ = capfd.readouterr()
expect = """Loudness: 1 dB, Volume Level: 6
Loudness: 0 dB, Volume Level: 6
Loudness: 4294967294 dB, Volume Level: 5
Loudness: 4294967291 dB, Volume Level: 4
Loudness: 4294967288 dB, Volume Level: 4
Loudness: 4294967276 dB, Volume Level: 2
Loudness: 4294967266 dB, Volume Level: 2
Loudness: 4294967256 dB, Volume Level: 1
Loudness: 4294967236 dB, Volume Level: 1
Loudness: 4294967234 dB, Volume Level: 1
Loudness: 4294967226 dB, Volume Level: 0
"""
self.check.check_equal(out, expect)

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 -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,38 @@
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h> // 包含基本的输入输出函数
#include "samples_to_levels.h"
#include "rgb_effect.h"
#include "timer.h"
void cycleHSV_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

@@ -0,0 +1,29 @@
/** @brief 测试音量响应&HSV色彩循环
*
* 此函数不断地循环通过HSV色彩空间并根据音量水平来更新RGB条的颜色。
* 每个颜色组都会根据音量水平的随机值来更新其亮度。当前色相值从红色开始,
* 并在每次循环中更新以通过HSV色彩空间进行循环。每次循环后将当前颜色
* 应用到RGB条的相应组中。此函数旨在并发执行以模拟实时音乐响应的灯光效果。
* @author Vergil Wong
* @date 2023-11-25
* @param
* @return
*/
#include <platform.h> // 包含对封装的定义,引用以使用 on tile[] 语法
extern "C"{
void cycleHSV_vol_level_example();
}
int main() // 定义主函数
{
par
{
on tile[1]:
{
cycleHSV_vol_level_example();
}
}
return 0; // 返回0表示程序正常结束
}

View File

@@ -0,0 +1,37 @@
from pathlib import Path
import pytest
import os
from commons.pyxrun import XMakeRun
@pytest.mark.usefixtures("get_logger_check")
class TestClass:
def test_app_cycleHSV_vol_level_example(self, capfd, request, function):
if not function:
self.logger.info("Skipping test because it's functional testing.")
pytest.skip("Skipping test because it's functional testing.")
file_path = Path(request.fspath).parent
xmakerun = XMakeRun(self.logger, file_path)
# xmake的命令
xmake_cmd = 'xmake -j'
# 执行xmake命令
xmakerun.xmake_cmd(xmake_cmd)
# app_cycleHSV_vol_level_example
xe_basename = os.path.basename(file_path)
# app_cycleHSV_vol_level_example.xe
xe_name = "{}.xe".format(xe_basename)
# bin/app_cycleHSV_vol_level_example.xe
xrun_file_path = "bin/{}".format(xe_name)
xrun_cmd = f'xrun {xrun_file_path}'
xmakerun.xrun_cmd(xrun_cmd)
out, _ = capfd.readouterr()
expect = "xrun successful!"
self.check.check_equal(out, expect)

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 -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,56 @@
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h> // 包含基本的输入输出函数
#include "rgb_effect.h"
#include "timer.h"
#define DELAY_DECREASE 40 // 降低亮度时的额外延迟
// 该函数用于平滑过渡HSV颜色和音量级别
void cycleHSV_vol_level_smooth_example()
{
uint32_t buf[NUM_RGBS]; // 存储RGB值的缓冲区
uint32_t current_hue = 0; // 当前色调
uint32_t current_color[NUM_RGB_GROUPS] = {0x000000, 0x000000}; // 当前颜色数组
size_t random_levels[NUM_RGB_GROUPS]; // 随机音量级别数组
size_t previous_levels[NUM_RGB_GROUPS] = {0}; // 存储先前的音量级别
srand(1); // 设置随机数种子
while (1) // 无限循环
{
for (size_t i = 0; i < NUM_RGB_GROUPS; i++) // 遍历RGB组
{
// 获取新的随机音量级别
random_levels[i] = get_volume_level(rand() % 101 - 100);
// 如果新的级别低于之前的级别,逐渐降低
while (previous_levels[i] > random_levels[i])
{
previous_levels[i]--; // 降低当前级别
// 用当前颜色和级别填充渐变
fill_gradient_with_groups(buf, current_color, previous_levels);
delay_milliseconds(DELAY_DECREASE); // 延迟
// 更新每一步的RGB颜色
for (size_t j = 0; j < NUM_RGB_GROUPS; j++)
{
current_color[j] = cycleHSV(&current_hue);
}
}
}
// 用随机颜色和级别填充渐变
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);
}
// 更新先前的音量级别
for (size_t i = 0; i < NUM_RGB_GROUPS; i++)
{
previous_levels[i] = random_levels[i];
}
}
}

View File

@@ -0,0 +1,24 @@
/** @brief 平滑过渡&HSV循环&模拟音量响应
* @author Vergil Wong
* @date 2023-11-25
* @param
* @return
*/
#include <platform.h> // 包含对封装的定义,引用以使用 on tile[] 语法
extern "C"{
void cycleHSV_vol_level_smooth_example();
}
int main() // 定义主函数
{
par
{
on tile[1]:
{
cycleHSV_vol_level_smooth_example();
}
}
return 0; // 返回0表示程序正常结束
}

View File

@@ -0,0 +1,37 @@
from pathlib import Path
import pytest
import os
from commons.pyxrun import XMakeRun
@pytest.mark.usefixtures("get_logger_check")
class TestClass:
def test_app_cycleHSV_vol_level_smooth_example(self, capfd, request, function):
if not function:
self.logger.info("Skipping test because it's functional testing.")
pytest.skip("Skipping test because it's functional testing.")
file_path = Path(request.fspath).parent
xmakerun = XMakeRun(self.logger, file_path)
# xmake的命令
xmake_cmd = 'xmake -j'
# 执行xmake命令
xmakerun.xmake_cmd(xmake_cmd)
# app_cycleHSV_vol_level_example
xe_basename = os.path.basename(file_path)
# app_cycleHSV_vol_level_example.xe
xe_name = "{}.xe".format(xe_basename)
# bin/app_cycleHSV_vol_level_example.xe
xrun_file_path = "bin/{}".format(xe_name)
xrun_cmd = f'xrun {xrun_file_path}'
xmakerun.xrun_cmd(xrun_cmd)
out, _ = capfd.readouterr()
expect = "xrun successful!"
self.check.check_equal(out, expect)

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 -report -fxscope
USED_MODULES = lib_rgb lib_xcore_math
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,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, current_color, NUM_RGBS);
// 延迟以控制显示持续时间
delay_milliseconds(DELAY_TIME_RGB);
// 更改下一个颜色
current_color = cycleHSV(&current_hue);
// 打印出当前的GRB颜色值
// printf("GRB color is: 0x%06X\n", current_color);
}
}

View File

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

View File

@@ -0,0 +1,37 @@
from pathlib import Path
import pytest
import os
from commons.pyxrun import XMakeRun
@pytest.mark.usefixtures("get_logger_check")
class TestClass:
def test_app_hsv_cycle_example(self, capfd, request, function):
if not function:
self.logger.info("Skipping test because it's functional testing.")
pytest.skip("Skipping test because it's functional testing.")
file_path = Path(request.fspath).parent
xmakerun = XMakeRun(self.logger, file_path)
# xmake的命令
xmake_cmd = 'xmake -j'
# 执行xmake命令
xmakerun.xmake_cmd(xmake_cmd)
# app_cycleHSV_vol_level_example
xe_basename = os.path.basename(file_path)
# app_cycleHSV_vol_level_example.xe
xe_name = "{}.xe".format(xe_basename)
# bin/app_cycleHSV_vol_level_example.xe
xrun_file_path = "bin/{}".format(xe_name)
xrun_cmd = f'xrun {xrun_file_path}'
xmakerun.xrun_cmd(xrun_cmd)
out, _ = capfd.readouterr()
expect = "xrun successful!"
self.check.check_equal(out, expect)

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 -report -fxscope -D_XUA_CONF_H_EXISTS_
USED_MODULES = lib_rgb lib_xcore_math
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,26 @@
/**
* @file xua_conf.h
* @brief Defines relating to device configuration and customisation.
* For PXUA-XU316-MC-MAX
*/
#ifndef _XUA_CONF_H_
#define _XUA_CONF_H_
/* Defines relating to feature placement regarding tiles */
#ifndef RGB_TILE
#define RGB_TILE (1)
#endif
#ifndef DELAY_TIME_RGB
#define DELAY_TIME_RGB (60)
#endif
#ifndef RGB_MAX
#define RGB_MAX (20)
#endif
#ifndef HUE_STEP
#define HUE_STEP (10)
#endif
#endif

View File

@@ -0,0 +1,44 @@
#include <stdint.h>
#include <stddef.h>
#include <stdio.h> // 包含基本的输入输出函数
#include "rgb_effect.h"
#include "timer.h"
#include "xmath/xmath.h"
#include <string.h>
void init_colors(uint32_t *current_colors, uint32_t *previous_colors, uint32_t current_hue){
for (size_t i = 0; i < NUM_RGBS; i++)
{
*(current_colors + i) = cycleHSV(&current_hue);
}
xs3_memcpy(previous_colors, current_colors, NUM_RGBS * sizeof(uint32_t));
}
void hsv_cycle_per_rgb_example()
{
uint32_t buf[NUM_RGBS]; // 定义一个用于存储RGB值的缓冲区大小由NUM_RGBS宏确定
uint32_t current_hue = 0; // 从红色开始的当前色相值
uint32_t WORD_ALIGNED current_colors[NUM_RGBS]; //用于存储当前颜色值的数组。
uint32_t WORD_ALIGNED previous_colors[NUM_RGBS];//用于存储上一组颜色值的数组
size_t levels[NUM_RGB_GROUPS]; //指定每个RGB组亮灯的个数
init_colors(current_colors, previous_colors, current_hue); //初始化颜色
while (1)
{
for (size_t i = 0; i < NUM_RGB_GROUPS; i++)
{
*(levels + i) = (NUM_RGBS / NUM_RGB_GROUPS);
}
// 用当前渐变颜色填充RGB数组然后发送给rgb阵列
fill_gradient_with_groups_colorful(buf, current_colors, levels);
// 延迟以控制显示持续时间
delay_milliseconds(DELAY_TIME_RGB);
// 更改下一组颜色其中每个灯继承上一个灯的颜色第一个灯通过cycleHSV计算出新的颜色
xs3_memcpy(current_colors+1, previous_colors, (NUM_RGBS-1) * sizeof(uint32_t));
current_colors[0] = cycleHSV(&current_hue);
// 保留本轮颜色的记录
xs3_memcpy(previous_colors, current_colors, NUM_RGBS * sizeof(uint32_t));
}
}

View File

@@ -0,0 +1,32 @@
/** @brief RGB灯条HSV循环渐变
*
* 此函数使用初始色相值初始化两个颜色数组current_colors和preview_colors。
* 它通过调用'cycleHSV'函数为每个颜色位置生成一个基于当前色相的颜色值。
* 然后,它在一个无限循环中,使用'fill_gradient_with_groups_colorful'函数
* 将颜色渐变填充到一个RGB缓冲区并通过'output_rgb_array'函数输出。
* 在每次循环的末尾,颜色数组会更新,为下一次迭代准备新的颜色。
*
* @author Vergil Wong
* @date 2023-11-26
* @param
* @return
*/
#include <platform.h> // 包含对封装的定义,引用以使用 on tile[] 语法
extern "C"
{
void hsv_cycle_per_rgb_example();
}
int main() // 定义主函数
{
par
{
on tile[1]:
{
hsv_cycle_per_rgb_example();
}
}
return 0; // 返回0表示程序正常结束
}

View File

@@ -0,0 +1,37 @@
from pathlib import Path
import pytest
import os
from commons.pyxrun import XMakeRun
@pytest.mark.usefixtures("get_logger_check")
class TestClass:
def test_app_hsv_cycle_per_rgb_example(self, capfd, request, function):
if not function:
self.logger.info("Skipping test because it's functional testing.")
pytest.skip("Skipping test because it's functional testing.")
file_path = Path(request.fspath).parent
xmakerun = XMakeRun(self.logger, file_path)
# xmake的命令
xmake_cmd = 'xmake -j'
# 执行xmake命令
xmakerun.xmake_cmd(xmake_cmd)
# app_cycleHSV_vol_level_example
xe_basename = os.path.basename(file_path)
# app_cycleHSV_vol_level_example.xe
xe_name = "{}.xe".format(xe_basename)
# bin/app_cycleHSV_vol_level_example.xe
xrun_file_path = "bin/{}".format(xe_name)
xrun_cmd = f'xrun {xrun_file_path}'
xmakerun.xrun_cmd(xrun_cmd)
out, _ = capfd.readouterr()
expect = "xrun successful!"
self.check.check_equal(out, expect)

View File

@@ -0,0 +1,23 @@
# `TARGET` 变量决定了应用程序编译的目标系统。它可以引用源目录中的一个 XN 文件,或者是在编译时作为 `--target` 选项的一个有效参数。
TARGET = XCORE-AI-EXPLORER
# 编译选项
# 构建应用程序时传递给 xcc 的参数
# O2: xcc编译器优化等级2
# report: 打开编译报告
# g: 生成调试信息
# fxscope: 使用 xSCOPE对代码进行跟踪默认使用xlink
BUILD_FLAGS = -O2 -g -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,28 @@
/** @brief 持续更新RGB灯条的颜色
* 在tile[1]上启动一个永久循环该循环会持续更新RGB灯条的颜色。
* 它初始化一个颜色值然后在一个无限循环中不断地调用fill_gradient和cycleRGB函数
* 以实现RGB灯条颜色的渐变效果。颜色的变化方向会根据GradientDirection变量进行调整。
* @author Vergil Wong
* @date 2023-11-25
* @param
* @return
*/
#include <platform.h> // 包含对封装的定义,引用以使用 on tile[] 语法
extern "C"
{
void rgb_cycle_breathing_example();
}
int main() // 定义主函数
{
par
{
on tile[1]:
{
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, current_color, NUM_RGBS);
// 延迟以控制显示持续时间
delay_milliseconds(DELAY_TIME_RGB);
// 更改下一个渐变的基色
current_color = cycleRGB(current_color, &direction);
}
}

View File

@@ -0,0 +1,37 @@
from pathlib import Path
import pytest
import os
from commons.pyxrun import XMakeRun
@pytest.mark.usefixtures("get_logger_check")
class TestClass:
def test_app_rgb_cycle_breathing_example(self, capfd, request, function):
if not function:
self.logger.info("Skipping test because it's functional testing.")
pytest.skip("Skipping test because it's functional testing.")
file_path = Path(request.fspath).parent
xmakerun = XMakeRun(self.logger, file_path)
# xmake的命令
xmake_cmd = 'xmake -j'
# 执行xmake命令
xmakerun.xmake_cmd(xmake_cmd)
# app_cycleHSV_vol_level_example
xe_basename = os.path.basename(file_path)
# app_cycleHSV_vol_level_example.xe
xe_name = "{}.xe".format(xe_basename)
# bin/app_cycleHSV_vol_level_example.xe
xrun_file_path = "bin/{}".format(xe_name)
xrun_cmd = f'xrun {xrun_file_path}'
xmakerun.xrun_cmd(xrun_cmd)
out, _ = capfd.readouterr()
expect = "xrun successful!"
self.check.check_equal(out, expect)

View File

@@ -0,0 +1,25 @@
# `TARGET` 变量决定了应用程序编译的目标系统。它可以引用源目录中的一个 XN 文件,或者是在编译时作为 `--target` 选项的一个有效参数。
TARGET = PXUA-316-MC-MAX.xn
# 编译选项
# 构建应用程序时传递给 xcc 的参数
# O2: xcc编译器优化等级2
# report: 打开编译报告
# g: 生成调试信息
# fxscope: 使用 xSCOPE对代码进行跟踪默认使用xlink
# _XUA_CONF_H_EXISTS_: 提示编译器编译部分文件时包含xua_conf.h
BUILD_FLAGS = -O2 -g -report -fxscope -D_XUA_CONF_H_EXISTS_
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,106 @@
<?xml version="1.0" encoding="UTF-8"?>
<Network xmlns="http://www.xmos.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.xmos.com http://www.xmos.com" ManuallySpecifiedRouting="true">
<Type>Board</Type>
<Name>PXUA-316-MC-MAX</Name>
<Declarations>
<Declaration>tileref tile[2]</Declaration>
<Declaration>tileref usb_tile</Declaration>
</Declarations>
<Packages>
<Package id="0" Type="XS3-UnA-1024-FB265">
<Nodes>
<Node Id="0" InPackageId="0" Type="XS3-L16A-1024" Oscillator="24MHz" SystemFrequency="600MHz" referencefrequency="100MHz">
<Boot>
<Source Location="bootFlash"/>
</Boot>
<Tile Number="0" Reference="tile[0]">
<Port Location="XS1_PORT_1B" Name="PORT_SQI_CS"/> <!-- QSPI_CS_N, 0:Flash 1:PSRAM -->
<Port Location="XS1_PORT_1C" Name="PORT_SQI_SCLK"/>
<Port Location="XS1_PORT_4B" Name="PORT_SQI_SIO"/>
<!-- Audio Ports :PXUA-316-MC-MAX -->
<Port Location="XS1_PORT_1A" Name="PORT_MCLK_IN"/> <!-- MCLK(connected to PLL_OUT) -->
<Port Location="XS1_PORT_1L" Name="PORT_I2S_BCLK"/> <!-- I2S_BCLK_IN -->
<Port Location="XS1_PORT_1D" Name="PORT_I2S_LRCLK"/> <!-- I2S_LRCLK_IN -->
<Port Location="XS1_PORT_1M" Name="PORT_I2S_DAC0"/> <!-- I2S_DAC0/TDM_DAC0 -->
<Port Location="XS1_PORT_1N" Name="PORT_I2S_DAC1"/> <!-- I2S_DAC1/TDM_DAC1 -->
<Port Location="XS1_PORT_1O" Name="PORT_I2S_DAC2"/> <!-- I2S_DAC2/TDM_DAC2 -->
<Port Location="XS1_PORT_1P" Name="PORT_I2S_DAC3"/> <!-- I2S_DAC3/TDM_DAC3 or SPDIF_OUT-->
<Port Location="XS1_PORT_1A" Name="PORT_DSD_CLK"/> <!-- DSD CLK -->
<Port Location="XS1_PORT_1D" Name="PORT_DSD_DAC0"/> <!-- DSD_L -->
<port Location="XS1_PORT_1M" Name="PORT_DSD_DAC1"/> <!-- DSD_R -->
<Port Location="XS1_PORT_1P" Name="PORT_SPDIF_OUT"/> <!-- SPDIF_OUT -->
<!-- Ctrl Ports :PXUA-316-MC-MAX -->
<port Location="XS1_PORT_4E" Name="PORT_I2C"/> <!-- 4E2:I2C_CLK, 4E3:I2C_SDA -->
<port Location="XS1_PORT_4F" Name="PORT_MCLK_SELECT"/> <!-- 4F1:CODEC_RST, 4F2:USB_STATE_LED, 4F3:Crystal Selection Mode(1:45.1584MHz 0:49.152MHz) -->
<port Location="XS1_PORT_8D" Name="PORT_BUTTON"/> <!-- The default is 3.3V. Press 0.
8D4:HID_BUTTON0/VOLUME_UP, 8D5:HID_BUTTON1/VOLUME_DOWN.
8D6:HID_BUTTON2/PLAY/PAUSE, 8D7:CUSTOM_BUTTOM/MUTE. -->
<Port Location="XS1_PORT_1C" Name="PORT_PLL_REF"/>
</Tile>
<Tile Number="1" Reference="tile[1]">
<!-- Audio Ports :PXUA-316-MC-MAX -->
<Port Location="XS1_PORT_1D" Name="PORT_MCLK_IN_USB"/> <!-- I2S_MCLK_OUT(PLL Out) -->
<Port Location="XS1_PORT_1G" Name="PORT_EXTRA_I2S_BCLK"/> <!-- EXTRA_I2S_BCLK_OUT -->
<Port Location="XS1_PORT_1C" Name="PORT_EXTRA_I2S_LRCLK"/> <!-- EXTRA_I2S_LRCLK_OUT -->
<Port Location="XS1_PORT_1A" Name="PORT_EXTRA_I2S_ADC0"/> <!-- EXTRA_I2S_ADC0/TDM_ADC0 -->
<Port Location="XS1_PORT_1B" Name="PORT_EXTRA_I2S_ADC1"/> <!-- EXTRA_I2S_ADC1/TDM_ADC1 or SPDIF_IN -->
<Port Location="XS1_PORT_1F" Name="PORT_EXTRA_I2S_ADC2"/> <!-- EXTRA_I2S_ADC2/TDM_ADC2 -->
<Port Location="XS1_PORT_1K" Name="PORT_EXTRA_I2S_ADC3"/> <!-- EXTRA_I2S_ADC3/TDM_ADC3 -->
<Port Location="XS1_PORT_1B" Name="PORT_SPDIF_IN"/> <!-- SPDIF_IN -->
<!-- Ctrl Ports :PXUA-316-MC-MAX -->
<Port Location="XS1_PORT_4A" Name="PORT_RGB_DAISY_CHAIN"/> <!-- 4A3: PORT_RGB_DAISY_CHAIN -->
<Port Location="XS1_PORT_1K" Name="PORT_UART_TX_PP"/> <!-- 1K: UART_TX -->
<Port Location="XS1_PORT_1F" Name="PORT_UART_RX_PP"/> <!-- 1F: UART_RX -->
<!-- Extensions Feature: MIDI_v1.0 -->
<!-- <Port Location="XS1_PORT_1K" Name="PORT_MIDI_OUT"/> -->
<!-- <Port Location="XS1_PORT_1F" Name="PORT_MIDI_IN"/> -->
</Tile>
</Node>
</Nodes>
</Package>
</Packages>
<Nodes>
<Node Id="2" Type="device:" RoutingId="0x8000">
<Service Id="0" Proto="xscope_host_data(chanend c);">
<Chanend Identifier="c" end="3"/>
</Service>
</Node>
</Nodes>
<Links>
<Link Encoding="2wire" Delays="4,4" Flags="XSCOPE">
<LinkEndpoint NodeId="0" Link="XL0"/>
<LinkEndpoint NodeId="2" Chanend="1"/>
</Link>
</Links>
<ExternalDevices>
<Device NodeId="0" Tile="0" Class="SQIFlash" Name="bootFlash" Type="S25FL116K" PageSize="256" SectorSize="4096" NumPages="8192">
<Attribute Name="PORT_SQI_CS" Value="PORT_SQI_CS"/>
<Attribute Name="PORT_SQI_SCLK" Value="PORT_SQI_SCLK"/>
<Attribute Name="PORT_SQI_SIO" Value="PORT_SQI_SIO"/>
<Attribute Name="QE_REGISTER" Value="flash_qe_location_status_reg_1"/>
<Attribute Name="QE_BIT" Value="flash_qe_bit_1"/>
</Device>
</ExternalDevices>
<JTAGChain>
<JTAGDevice NodeId="0"/>
</JTAGChain>
</Network>

View File

@@ -0,0 +1,14 @@
/**
* @file xua_conf.h
* @brief Defines relating to device configuration and customisation.
* For PXUA-XU316-MC-MAX
*/
#ifndef _XUA_CONF_H_
#define _XUA_CONF_H_
/* Defines relating to feature placement regarding tiles */
#ifndef RGB_TILE
#define RGB_TILE (1)
#endif
#endif

View File

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

View File

@@ -0,0 +1,16 @@
#include <stdint.h>
#include <stdlib.h>
#include "rgb_effect.h"
void test_output_rgb_array_example()
{
uint32_t buf[NUM_RGBS]; // 定义一个用于存储RGB值的缓冲区大小由NUM_RGBS宏确定
uint32_t num_rgbs = 12;
// Initialize the buffer with example RGB values
for (uint32_t i = 0; i < num_rgbs; ++i) {
buf[i] = (i << 16) | (i << 8) | i; // Just an example pattern for RGB values
}
// Call the function with the test buffer and number of RGBs
output_rgb_array(buf, num_rgbs);
}

View File

@@ -0,0 +1,37 @@
from pathlib import Path
import pytest
import os
from commons.pyxrun import XMakeRun
@pytest.mark.usefixtures("get_logger_check")
class TestClass:
def test_app_test_config_rgb_port(self, capfd, request, function):
if not function:
self.logger.info("Skipping test because it's functional testing.")
pytest.skip("Skipping test because it's functional testing.")
file_path = Path(request.fspath).parent
xmakerun = XMakeRun(self.logger, file_path)
# xmake的命令
xmake_cmd = 'xmake -j'
# 执行xmake命令
xmakerun.xmake_cmd(xmake_cmd)
# app_cycleHSV_vol_level_example
xe_basename = os.path.basename(file_path)
# app_cycleHSV_vol_level_example.xe
xe_name = "{}.xe".format(xe_basename)
# bin/app_cycleHSV_vol_level_example.xe
xrun_file_path = "bin/{}".format(xe_name)
xrun_cmd = f'xrun {xrun_file_path}'
xmakerun.xrun_cmd(xrun_cmd)
out, _ = capfd.readouterr()
expect = "xrun successful!"
self.check.check_equal(out, expect)

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 -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,26 @@
/** @brief 测试 fill_gradient_with_groups 函数
* 此测试函数创建一个缓冲区,并定义两种颜色和每组的填充数量,然后调用
* fill_gradient_with_groups 函数来填充缓冲区并渲染RGB。
* @author Vergil Wong
* @date 2023-11-25
* @param
* @return
*/
#include <platform.h> // 包含对封装的定义,引用以使用 on tile[] 语法
extern "C"
{
void test_fill_gradient_with_groups();
}
int main() // 定义主函数
{
par
{
on tile[1]:
{
test_fill_gradient_with_groups();
}
}
return 0; // 返回0表示程序正常结束
}

View File

@@ -0,0 +1,14 @@
#include <stdint.h>
#include <stdio.h> // 包含基本的输入输出函数
#include <platform.h> // 包含对封装的定义,引用以使用 on tile[] 语法
#include "rgb_effect.h"
#include "timer.h"
void test_fill_gradient_with_groups()
{
uint32_t buffer[NUM_RGBS];
uint32_t colors[] = {0x110000, 0x001100, 0x000011}; // 红,绿,蓝
size_t num_filled_rgb[] = {4, 4, 4}; // 每组填充数量
fill_gradient_with_groups(buffer, colors, num_filled_rgb);
}

View File

@@ -0,0 +1,37 @@
from pathlib import Path
import pytest
import os
from commons.pyxrun import XMakeRun
@pytest.mark.usefixtures("get_logger_check")
class TestClass:
def test_app_test_fill_gradient_with_groups(self, capfd, request, function):
if not function:
self.logger.info("Skipping test because it's functional testing.")
pytest.skip("Skipping test because it's functional testing.")
file_path = Path(request.fspath).parent
xmakerun = XMakeRun(self.logger, file_path)
# xmake的命令
xmake_cmd = 'xmake -j'
# 执行xmake命令
xmakerun.xmake_cmd(xmake_cmd)
# app_cycleHSV_vol_level_example
xe_basename = os.path.basename(file_path)
# app_cycleHSV_vol_level_example.xe
xe_name = "{}.xe".format(xe_basename)
# bin/app_cycleHSV_vol_level_example.xe
xrun_file_path = "bin/{}".format(xe_name)
xrun_cmd = f'xrun {xrun_file_path}'
xmakerun.xrun_cmd(xrun_cmd)
out, _ = capfd.readouterr()
expect = "xrun successful!"
self.check.check_equal(out, expect)

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 -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,28 @@
/** @brief 音量响应&平滑过渡
*
* 每个颜色组都会根据音量水平的随机值来更新其亮度。每次循环后,将当前颜色
* 应用到RGB条的相应组中。此函数旨在模拟实时音乐响应的灯光效果并实现平滑过渡下降
* 与app_cy
* @author Vergil Wong
* @date 2023-11-25
* @param
* @return
*/
#include <platform.h> // 包含对封装的定义,引用以使用 on tile[] 语法
extern "C"{
void vol_level_smooth_example();
}
int main() // 定义主函数
{
par
{
on tile[1]:
{
vol_level_smooth_example();
}
}
return 0; // 返回0表示程序正常结束
}

View File

@@ -0,0 +1,42 @@
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h> // 包含基本的输入输出函数
#include "rgb_effect.h"
#include "timer.h"
#define DELAY_DECREASE 40 // 降低亮度时的额外延迟
void vol_level_smooth_example()
{
uint32_t buf[NUM_RGBS]; // 定义一个用于存储RGB值的缓冲区大小由NUM_RGBS宏确定
uint32_t current_color[NUM_RGB_GROUPS] = {0xFF0000, 0xFF0000};
srand(1); // 初始化随机数种子
size_t random_levels[NUM_RGB_GROUPS];
size_t previous_levels[NUM_RGB_GROUPS] = {0}; // 存储先前的音量级别
while (1)
{
for (size_t i = 0; i < NUM_RGB_GROUPS; i++)
{
*(random_levels + i) = get_volume_level(rand() % 101 - 100);
// 如果新的级别低于之前的级别,逐渐降低
while (previous_levels[i] > random_levels[i])
{
previous_levels[i]--; // 降低当前级别
// 用当前颜色和级别填充渐变
fill_gradient_with_groups(buf, current_color, previous_levels);
delay_milliseconds(DELAY_DECREASE); // 延迟
}
}
// 用当前渐变颜色填充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++)
{
previous_levels[i] = random_levels[i];
}
}
}

View File

@@ -0,0 +1,37 @@
from pathlib import Path
import pytest
import os
from commons.pyxrun import XMakeRun
@pytest.mark.usefixtures("get_logger_check")
class TestClass:
def test_app_vol_level_smooth_example(self, capfd, request, function):
if not function:
self.logger.info("Skipping test because it's functional testing.")
pytest.skip("Skipping test because it's functional testing.")
file_path = Path(request.fspath).parent
xmakerun = XMakeRun(self.logger, file_path)
# xmake的命令
xmake_cmd = 'xmake -j'
# 执行xmake命令
xmakerun.xmake_cmd(xmake_cmd)
# app_cycleHSV_vol_level_example
xe_basename = os.path.basename(file_path)
# app_cycleHSV_vol_level_example.xe
xe_name = "{}.xe".format(xe_basename)
# bin/app_cycleHSV_vol_level_example.xe
xrun_file_path = "bin/{}".format(xe_name)
xrun_cmd = f'xrun {xrun_file_path}'
xmakerun.xrun_cmd(xrun_cmd)
out, _ = capfd.readouterr()
expect = "xrun successful!"
self.check.check_equal(out, expect)