简单分区+流水灯

This commit is contained in:
dgjames 2025-01-18 00:46:10 +08:00
parent 526c7cb82c
commit 1db683abda
6 changed files with 72 additions and 14 deletions

1
.gitattributes vendored Normal file
View File

@ -0,0 +1 @@
*.pack filter=lfs diff=lfs merge=lfs -text

Binary file not shown.

View File

@ -1,11 +1,12 @@
#include "indicator_led.h"
#define LED_NUM 12 // LED灯珠个数
#define LED_NUM 24 // LED灯珠个数
rt_thread_t led_blink_thread = RT_NULL;
rt_thread_t led_breath_thread = RT_NULL;
// 灯处于特定颜色还是闪烁状态
uint8_t LED_Blink_Staue[LED_NUM] = {0};
// 灯是否处于特定颜色还是闪烁状态
uint8_t LED_Blink_State[LED_NUM] = {LED_NOT_BLINKING};
// 灯闪烁颜色缓存
RGBColor_TypeDef LED_Blink_Color[LED_NUM] = {0};
const RGBColor_TypeDef LED_OFF = {0, 0, 0};
@ -18,20 +19,21 @@ const RGBColor_TypeDef LED_ON = {255, 255, 255};
*/
void LED_Set(uint16_t LedId, RGBColor_TypeDef Color)
{
LED_Blink_Staue[LedId] = 0;
LED_Blink_State[LedId] = 0;
Set_LEDColor(LedId, Color);
RGB_Reflash();
}
/**
* @brief LED的颜色或开关
* @param LedId LED的序号(0~LED_NUM-1)
* @param LedId_begin LED的序号(0~LED_NUM-1)
* @param LedId_end LED的序号(0~LED_NUM-1)
* @param Color / LED_RED,LED_BLUE,LED_OFF,LED_ON()
*/
void LED_SetMore(uint16_t LedId_begin, uint16_t LedId_end, RGBColor_TypeDef Color)
{
for (int LedId = LedId_begin; LedId <=LedId_end ; LedId++)
{
LED_Blink_Staue[LedId] = 0;
LED_Blink_State[LedId] = 0;
Set_LEDColor(LedId, Color);
}
RGB_Reflash();
@ -44,19 +46,20 @@ void LED_SetMore(uint16_t LedId_begin, uint16_t LedId_end, RGBColor_TypeDef Colo
*/
void LED_Blink(uint16_t LedId, RGBColor_TypeDef Color)
{
LED_Blink_Staue[LedId] = 1;
LED_Blink_State[LedId] = 1;
LED_Blink_Color[LedId] = Color;
}
/**
* @brief LED的闪烁
* @param LedId LED的序号(0~LED_NUM-1)
* @param LedId_begin LED的序号(0~LED_NUM-1)
* @param LedId_end LED的序号(0~LED_NUM-1)
* @param Color LED_RED,LED_BLUE
*/
void LED_BlinkMore(uint16_t LedId_begin, uint16_t LedId_end, RGBColor_TypeDef Color)
{
for (int LedId = LedId_begin; LedId <=LedId_end ; LedId++)
{
LED_Blink_Staue[LedId] = 1;
LED_Blink_State[LedId] = 1;
LED_Blink_Color[LedId] = Color;
}
}
@ -70,7 +73,7 @@ void led_blink_entry(void *parameter)
{
for (int LedId = 0; LedId < LED_NUM; LedId++)
{
if (LED_Blink_Staue[LedId])
if (LED_Blink_State[LedId]==LED_IS_BLINKING)
{
if (LED_Blink_ON)
{
@ -87,7 +90,7 @@ void led_blink_entry(void *parameter)
rt_thread_mdelay(500);
}
}
int led_init(void)
int led_blink_init(void)
{
led_blink_thread = rt_thread_create("led blink control thread", led_blink_entry, RT_NULL, 1024, 20, 20);
if (led_blink_thread == RT_NULL)
@ -97,4 +100,49 @@ int led_init(void)
}
rt_thread_mdelay(200); // avoid multi-thread on LED matrix transmit.
rt_thread_startup(led_blink_thread);
}
/**
* @brief 0.5s判断各盏灯是否要翻转
*/
void led_breath_entry(void *parameter)
{
int count = 0;
while (1)
{
for (int i = LED_BREATH_ID(1); i <= LED_BREATH_ID(12); i++)
{
switch (count)
{
case 0:
Set_LEDColor(i, LED_RED);
break;
case 1:
Set_LEDColor(i, LED_GREEN);
break;
case 2:
Set_LEDColor(i, LED_BLUE);
break;
default:
return;
break;
}
RGB_Reflash();
rt_thread_delay(20);
}
count = (count + 1) % 3;
}
}
// MSH_CMD_EXPORT_ALIAS(led_breath_thread,BREATH, "BREATH LIGHT");
int led_breath_init(void)
{
led_breath_thread = rt_thread_create("led breath control thread", led_breath_entry, RT_NULL, 1024, 20, 20);
if (led_breath_thread == RT_NULL)
{
rt_kprintf("led breath control thread creat failed!\n");
return 0;
}
rt_thread_mdelay(200); // avoid multi-thread on LED matrix transmit.
rt_thread_startup(led_breath_thread);
}

View File

@ -1,11 +1,18 @@
#include <rtthread.h>
#include <drv_matrix_led.h>
#define LED_IS_BLINKING 1
#define LED_NOT_BLINKING 0
#define LED_CHARGE_ID(i) (i+12-1)
#define LED_BREATH_ID(i) (i-1)
extern void LED_Set(uint16_t LedId, RGBColor_TypeDef Color);
extern void LED_SetMore(uint16_t LedId_begin,uint16_t LedId_end, RGBColor_TypeDef Color);
extern void LED_Blink(uint16_t LedId, RGBColor_TypeDef Color);
extern void LED_BlinkMore(uint16_t LedId_begin, uint16_t LedId_end, RGBColor_TypeDef Color);
extern int led_init(void);
extern int led_blink_init(void);
extern int led_breath_init(void);
extern const RGBColor_TypeDef LED_OFF;
extern const RGBColor_TypeDef LED_ON;

View File

@ -619,6 +619,8 @@ void my_project(void)
serial_init();
led_init();
led_blink_init();
led_breath_init();
}
MSH_CMD_EXPORT_ALIAS(my_project, myproject, run my project);

View File

@ -79,4 +79,4 @@ void ledset(int argc, char **argv){//设置/查询设备名称
LED_Set(LedId,LED_BLUE);
}
}
MSH_CMD_EXPORT_ALIAS(ledset,LED1, "BLINK LedId Color");
MSH_CMD_EXPORT_ALIAS(ledset,LED1, "BLINK LedId Color");