简单分区+流水灯
This commit is contained in:
parent
526c7cb82c
commit
1db683abda
1
.gitattributes
vendored
Normal file
1
.gitattributes
vendored
Normal file
@ -0,0 +1 @@
|
||||
*.pack filter=lfs diff=lfs merge=lfs -text
|
Binary file not shown.
@ -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);
|
||||
}
|
@ -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;
|
@ -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);
|
@ -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");
|
||||
|
Loading…
x
Reference in New Issue
Block a user