mirror of
https://gitee.com/dlmu-cone/bf_original_balance_chassis
synced 2026-07-24 03:27:45 +08:00
增加了部分led的支持
This commit is contained in:
8
modules/led_task/led.md
Normal file
8
modules/led_task/led.md
Normal file
@@ -0,0 +1,8 @@
|
||||
# led_task
|
||||
<p align='right'>neozng1@hnu.edu.cn</p>
|
||||
|
||||
> TODO:
|
||||
> 1. 预计添加不同错误标志,将错误类型和灯的闪烁频率或颜色等对应起来,方便调试
|
||||
|
||||
|
||||
这是legacy support,后续将使用bsp_pwm进行重构
|
||||
59
modules/led_task/led_task.c
Normal file
59
modules/led_task/led_task.c
Normal file
@@ -0,0 +1,59 @@
|
||||
/**
|
||||
* @file led_task.c
|
||||
* @author DJI RM
|
||||
* @author modified by NeoZeng neozng1@hnu.edu.cn
|
||||
* @brief 流水灯效
|
||||
* @version 0.1
|
||||
* @date 2022-11-30
|
||||
*
|
||||
* @copyright Copyright (c) 2022
|
||||
*
|
||||
*/
|
||||
|
||||
#include "led_task.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "bsp_led.h"
|
||||
#include "main.h"
|
||||
|
||||
#define RGB_FLOW_COLOR_CHANGE_TIME 1000
|
||||
#define RGB_FLOW_COLOR_LENGHT 6
|
||||
|
||||
// 蓝 -> 绿(灭) -> 红 -> 蓝(灭) -> 绿 -> 红(灭) -> 蓝
|
||||
uint32_t RGB_flow_color[RGB_FLOW_COLOR_LENGHT + 1] = {0xFF0000FF, 0x0000FF00, 0xFFFF0000, 0x000000FF, 0xFF00FF00, 0x00FF0000, 0xFF0000FF};
|
||||
|
||||
void led_RGB_flow_task()
|
||||
{
|
||||
static float delta_alpha, delta_red, delta_green, delta_blue;
|
||||
static float alpha, red, green, blue;
|
||||
static uint32_t aRGB;
|
||||
|
||||
for (size_t i = 0; i < RGB_FLOW_COLOR_LENGHT; ++i)
|
||||
{
|
||||
alpha = (RGB_flow_color[i] & 0xFF000000) >> 24;
|
||||
red = ((RGB_flow_color[i] & 0x00FF0000) >> 16);
|
||||
green = ((RGB_flow_color[i] & 0x0000FF00) >> 8);
|
||||
blue = ((RGB_flow_color[i] & 0x000000FF) >> 0);
|
||||
|
||||
delta_alpha = (float)((RGB_flow_color[i + 1] & 0xFF000000) >> 24) - (float)((RGB_flow_color[i] & 0xFF000000) >> 24);
|
||||
delta_red = (float)((RGB_flow_color[i + 1] & 0x00FF0000) >> 16) - (float)((RGB_flow_color[i] & 0x00FF0000) >> 16);
|
||||
delta_green = (float)((RGB_flow_color[i + 1] & 0x0000FF00) >> 8) - (float)((RGB_flow_color[i] & 0x0000FF00) >> 8);
|
||||
delta_blue = (float)((RGB_flow_color[i + 1] & 0x000000FF) >> 0) - (float)((RGB_flow_color[i] & 0x000000FF) >> 0);
|
||||
|
||||
delta_alpha /= RGB_FLOW_COLOR_CHANGE_TIME;
|
||||
delta_red /= RGB_FLOW_COLOR_CHANGE_TIME;
|
||||
delta_green /= RGB_FLOW_COLOR_CHANGE_TIME;
|
||||
delta_blue /= RGB_FLOW_COLOR_CHANGE_TIME;
|
||||
for (size_t j = 0; j < RGB_FLOW_COLOR_CHANGE_TIME; ++j)
|
||||
{
|
||||
alpha += delta_alpha;
|
||||
red += delta_red;
|
||||
green += delta_green;
|
||||
blue += delta_blue;
|
||||
|
||||
aRGB = ((uint32_t)(alpha)) << 24 | ((uint32_t)(red)) << 16 | ((uint32_t)(green)) << 8 | ((uint32_t)(blue)) << 0;
|
||||
FlowRGBShow(aRGB);
|
||||
}
|
||||
}
|
||||
}
|
||||
7
modules/led_task/led_task.h
Normal file
7
modules/led_task/led_task.h
Normal file
@@ -0,0 +1,7 @@
|
||||
|
||||
#ifndef LED_TRIGGER_TASK_H
|
||||
#define LED_TRIGGER_TASK_H
|
||||
|
||||
void led_RGB_flow_task();
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user