添加了RGB灯带的幻彩渐变效果

This commit is contained in:
2023-11-26 15:09:33 +08:00
parent 47a202691b
commit 26391ab953
4 changed files with 127 additions and 0 deletions

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,45 @@
#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);
}
// TODO: 当使用xs3_memcpy时复制的后几个数据看起来是随机的
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)-1;
}
// 用当前渐变颜色填充RGB数组然后发送给rgb阵列
fill_gradient_with_groups_colorful(buf, current_colors, levels);
// 延迟以控制显示持续时间
delay_milliseconds(DELAY_TIME_RGB);
// 更改下一组颜色其中每个灯继承上一个灯的颜色第一个灯通过cycleHSV计算出新的颜色
memcpy(current_colors+1, previous_colors, (NUM_RGBS-1) * sizeof(uint32_t));
current_colors[0] = cycleHSV(&current_hue);
// 保留本轮颜色的记录
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表示程序正常结束
}