matrix
This commit is contained in:
parent
07968c8045
commit
aefa067ab4
@ -1,41 +1,40 @@
|
|||||||
#include "indicator_led.h"
|
#include "indicator_led.h"
|
||||||
#include "rtdevice.h"
|
#include "rtdevice.h"
|
||||||
|
|
||||||
#define ADC_DEV_NAME "adc1" /* ADC 设备名称 */
|
#define LED_BREATH_PERIOD 4000
|
||||||
#define ADC_DEV_CHANNEL 5 /* ADC 通道 */
|
#define LED_BREATH_MDELAY 20
|
||||||
#define REFER_VOLTAGE 330 /* 参考电压 3.3V,数据精度乘以100保留2位小数*/
|
#define LED_BREATH_HALF_TIMES (LED_BREATH_PERIOD / LED_BREATH_MDELAY / 2)
|
||||||
#define CONVERT_BITS (1 << 12) /* 转换位数为12位 */
|
const uint8_t gamma_table[256] = {
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2,
|
||||||
|
2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5,
|
||||||
|
5, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 9, 9, 10, 10, 10,
|
||||||
|
11, 11, 11, 12, 12, 13, 13, 13, 14, 14, 15, 15, 16, 16, 17, 17,
|
||||||
|
18, 18, 19, 19, 20, 20, 21, 21, 22, 23, 23, 24, 24, 25, 26, 26,
|
||||||
|
27, 28, 28, 29, 30, 30, 31, 32, 32, 33, 34, 35, 35, 36, 37, 38,
|
||||||
|
38, 39, 40, 41, 42, 42, 43, 44, 45, 46, 47, 48, 49, 49, 50, 51,
|
||||||
|
52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67,
|
||||||
|
69, 70, 71, 72, 73, 74, 75, 76, 78, 79, 80, 81, 82, 84, 85, 86,
|
||||||
|
87, 89, 90, 91, 92, 94, 95, 96, 98, 99,100,102,103,104,106,107,
|
||||||
|
109,110,112,113,114,116,117,119,120,122,123,125,126,128,130,131,
|
||||||
|
133,134,136,138,139,141,143,144,146,148,149,151,153,154,156,158,
|
||||||
|
160,161,163,165,167,169,170,172,174,176,178,180,182,183,185,187,
|
||||||
|
189,191,193,195,197,199,201,203,205,207,209,211,213,215,218,220,
|
||||||
|
222,224,226,228,230,233,235,237,239,241,244,246,248,250,253,255,
|
||||||
|
};
|
||||||
|
|
||||||
#define LED_NUM 24 // LED灯珠个数
|
|
||||||
|
|
||||||
rt_thread_t led_blink_thread = RT_NULL;
|
rt_thread_t led_blink_thread = RT_NULL;
|
||||||
rt_thread_t led_breath_thread = RT_NULL;
|
rt_thread_t led_breath_thread = RT_NULL;
|
||||||
|
rt_thread_t led_reflash_thread = RT_NULL;
|
||||||
|
|
||||||
// 灯是否处于特定颜色还是闪烁状态
|
// 灯是否处于特定颜色还是闪烁状态
|
||||||
uint8_t LED_Blink_State[LED_NUM] = {LED_NOT_BLINKING};
|
uint8_t LED_State[LED_NUM] = {LED_NOT_BLINKING};
|
||||||
// 呼吸灯是否开启
|
|
||||||
uint8_t LED_Breath_State = LED_BREATH_OFF;
|
|
||||||
// 灯闪烁颜色缓存
|
// 灯闪烁颜色缓存
|
||||||
RGBColor_TypeDef LED_Blink_Color[LED_NUM] = {0};
|
RGBColor_TypeDef LED_Color[LED_NUM] = {0};
|
||||||
const RGBColor_TypeDef LED_OFF = {0, 0, 0};
|
// 灯闪烁(呼吸)颜色当前值
|
||||||
const RGBColor_TypeDef LED_ON = {255, 255, 255};
|
RGBColor_TypeDef LED_Tmp_Color = {0};
|
||||||
/**
|
|
||||||
* @brief 设置呼吸LED的开关
|
|
||||||
* @param LedBreath_state 开/关 LED_BREATH_ON/LED_BREATH_OFF
|
|
||||||
*/
|
|
||||||
void LED_BreathTurn(uint8_t LedBreath_state)
|
|
||||||
{
|
|
||||||
LED_Breath_State = LedBreath_state;
|
|
||||||
// if (LedBreath_state == LED_BREATH_OFF)
|
|
||||||
// {
|
|
||||||
// // rt_thread_suspend(led_breath_thread);
|
|
||||||
// LED_SetMore(LED_BREATH_ID(1), LED_BREATH_ID(12), LED_OFF);
|
|
||||||
// }
|
|
||||||
// else if (LedBreath_state == LED_BREATH_ON)
|
|
||||||
// {
|
|
||||||
// // rt_thread_resume(led_breath_thread);
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
/**
|
/**
|
||||||
* @brief 设置特定LED的颜色或开关
|
* @brief 设置特定LED的颜色或开关
|
||||||
* @param LedId LED的序号(0~LED_NUM-1)
|
* @param LedId LED的序号(0~LED_NUM-1)
|
||||||
@ -43,8 +42,7 @@ void LED_BreathTurn(uint8_t LedBreath_state)
|
|||||||
*/
|
*/
|
||||||
void LED_Set(uint16_t LedId, RGBColor_TypeDef Color)
|
void LED_Set(uint16_t LedId, RGBColor_TypeDef Color)
|
||||||
{
|
{
|
||||||
LedId=LED_CHARGE_ID(LedId);
|
LED_State[LedId] = LED_NOT_BLINKING;
|
||||||
LED_Blink_State[LedId] = 0;
|
|
||||||
Set_LEDColor(LedId, Color);
|
Set_LEDColor(LedId, Color);
|
||||||
RGB_Reflash();
|
RGB_Reflash();
|
||||||
}
|
}
|
||||||
@ -56,11 +54,9 @@ void LED_Set(uint16_t LedId, RGBColor_TypeDef Color)
|
|||||||
*/
|
*/
|
||||||
void LED_SetMore(uint16_t LedId_begin, uint16_t LedId_end, RGBColor_TypeDef Color)
|
void LED_SetMore(uint16_t LedId_begin, uint16_t LedId_end, RGBColor_TypeDef Color)
|
||||||
{
|
{
|
||||||
LedId_begin=LED_CHARGE_ID(LedId_begin);
|
|
||||||
LedId_end=LED_CHARGE_ID(LedId_end);
|
|
||||||
for (int LedId = LedId_begin; LedId <= LedId_end; LedId++)
|
for (int LedId = LedId_begin; LedId <= LedId_end; LedId++)
|
||||||
{
|
{
|
||||||
LED_Blink_State[LedId] = 0;
|
LED_State[LedId] = LED_NOT_BLINKING;
|
||||||
Set_LEDColor(LedId, Color);
|
Set_LEDColor(LedId, Color);
|
||||||
}
|
}
|
||||||
RGB_Reflash();
|
RGB_Reflash();
|
||||||
@ -73,9 +69,8 @@ void LED_SetMore(uint16_t LedId_begin, uint16_t LedId_end, RGBColor_TypeDef Colo
|
|||||||
*/
|
*/
|
||||||
void LED_Blink(uint16_t LedId, RGBColor_TypeDef Color)
|
void LED_Blink(uint16_t LedId, RGBColor_TypeDef Color)
|
||||||
{
|
{
|
||||||
LedId=LED_CHARGE_ID(LedId);
|
LED_State[LedId] = LED_IS_BLINKING;
|
||||||
LED_Blink_State[LedId] = 1;
|
LED_Color[LedId] = Color;
|
||||||
LED_Blink_Color[LedId] = Color;
|
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @brief 设置连续多个特定LED的闪烁
|
* @brief 设置连续多个特定LED的闪烁
|
||||||
@ -85,146 +80,150 @@ void LED_Blink(uint16_t LedId, RGBColor_TypeDef Color)
|
|||||||
*/
|
*/
|
||||||
void LED_BlinkMore(uint16_t LedId_begin, uint16_t LedId_end, RGBColor_TypeDef Color)
|
void LED_BlinkMore(uint16_t LedId_begin, uint16_t LedId_end, RGBColor_TypeDef Color)
|
||||||
{
|
{
|
||||||
LedId_begin=LED_CHARGE_ID(LedId_begin);
|
|
||||||
LedId_end=LED_CHARGE_ID(LedId_end);
|
|
||||||
for (int LedId = LedId_begin; LedId <= LedId_end; LedId++)
|
for (int LedId = LedId_begin; LedId <= LedId_end; LedId++)
|
||||||
{
|
{
|
||||||
LED_Blink_State[LedId] = 1;
|
LED_State[LedId] = LED_IS_BLINKING;
|
||||||
LED_Blink_Color[LedId] = Color;
|
LED_Color[LedId] = Color;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @brief 每0.5s判断各盏灯是否要翻转
|
* @brief 设置特定LED的呼吸
|
||||||
|
* @param LedId LED的序号(0~LED_NUM-1)
|
||||||
|
* @param Color 颜色 LED_RED,LED_BLUE……
|
||||||
|
*/
|
||||||
|
void LED_Breath(uint16_t LedId, RGBColor_TypeDef Color)
|
||||||
|
{
|
||||||
|
LED_State[LedId] = LED_IS_BREATHING;
|
||||||
|
LED_Color[LedId] = Color;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @brief 设置连续多个特定LED的呼吸
|
||||||
|
* @param LedId_begin LED的序号(0~LED_NUM-1)开始
|
||||||
|
* @param LedId_end LED的序号(0~LED_NUM-1)结束
|
||||||
|
* @param Color 颜色 LED_RED,LED_BLUE……
|
||||||
|
*/
|
||||||
|
void LED_BreathMore(uint16_t LedId_begin, uint16_t LedId_end, RGBColor_TypeDef Color)
|
||||||
|
{
|
||||||
|
for (int LedId = LedId_begin; LedId <= LedId_end; LedId++)
|
||||||
|
{
|
||||||
|
LED_State[LedId] = LED_IS_BREATHING;
|
||||||
|
LED_Color[LedId] = Color;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @brief 灯的闪烁,每0.5s判断各盏灯是否要翻转
|
||||||
*/
|
*/
|
||||||
void led_blink_entry(void *parameter)
|
void led_blink_entry(void *parameter)
|
||||||
{
|
{
|
||||||
uint8_t LED_Blink_ON = 1;
|
(void)parameter;
|
||||||
|
uint16_t LED_Blink_ON = 1, cnt_blink = 0;
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
|
cnt_blink = 0;
|
||||||
for (int LedId = 0; LedId < LED_NUM; LedId++)
|
for (int LedId = 0; LedId < LED_NUM; LedId++)
|
||||||
{
|
{
|
||||||
if (LED_Blink_State[LedId] == LED_IS_BLINKING)
|
if (LED_State[LedId] == LED_IS_BLINKING)
|
||||||
{
|
{
|
||||||
|
cnt_blink++;
|
||||||
if (LED_Blink_ON)
|
if (LED_Blink_ON)
|
||||||
{
|
{
|
||||||
Set_LEDColor(LedId, LED_Blink_Color[LedId]);
|
Set_LEDColor(LedId, LED_Color[LedId]);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Set_LEDColor(LedId, LED_OFF);
|
Set_LEDColor(LedId, LEDI_OFF);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
LED_Blink_ON = !LED_Blink_ON;
|
LED_Blink_ON = !LED_Blink_ON;
|
||||||
|
if (cnt_blink)
|
||||||
RGB_Reflash();
|
RGB_Reflash();
|
||||||
rt_thread_mdelay(500);
|
rt_thread_mdelay(500);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
void breath_add(float *LED_Breath_Percentage)
|
||||||
* @brief 流水灯
|
{
|
||||||
*/
|
static int breath_cnt = 0;
|
||||||
|
if(breath_cnt<=LED_BREATH_HALF_TIMES)
|
||||||
|
{
|
||||||
|
*LED_Breath_Percentage =gamma_table[(uint8_t)256.0*breath_cnt/LED_BREATH_HALF_TIMES];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
*LED_Breath_Percentage =gamma_table[(uint8_t)256.0*(LED_BREATH_HALF_TIMES*2-breath_cnt)/LED_BREATH_HALF_TIMES];
|
||||||
|
if (breath_cnt>=LED_BREATH_HALF_TIMES*2)
|
||||||
|
{
|
||||||
|
breath_cnt=0;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
breath_cnt++;
|
||||||
|
}
|
||||||
|
|
||||||
void led_breath_entry(void *parameter)
|
void led_breath_entry(void *parameter)
|
||||||
{
|
{
|
||||||
int count = 0;
|
(void)parameter;
|
||||||
|
float LED_Breath_Percentage = 255;
|
||||||
|
uint16_t LED_Breath_ON = 1, breath_num=0;
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
for (int i = LED_BREATH_ID(1); i <= LED_BREATH_ID(12); i++)
|
breath_num = 0;
|
||||||
|
for (int LedId = 0; LedId < LED_NUM; LedId++)
|
||||||
{
|
{
|
||||||
if (LED_Breath_State==LED_BREATH_OFF)
|
if (LED_State[LedId] == LED_IS_BREATHING)
|
||||||
{
|
{
|
||||||
rt_thread_mdelay(100);
|
breath_num++;
|
||||||
i = LED_BREATH_ID(1);
|
LED_Tmp_Color.G = (uint8_t)LED_Color[LedId].G * LED_Breath_Percentage/255;
|
||||||
continue;
|
LED_Tmp_Color.R = (uint8_t)LED_Color[LedId].R * LED_Breath_Percentage/255;
|
||||||
|
LED_Tmp_Color.B = (uint8_t)LED_Color[LedId].B * LED_Breath_Percentage/255;
|
||||||
|
Set_LEDColor(LedId, LED_Tmp_Color);
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
breath_add(&LED_Breath_Percentage);
|
||||||
|
if (breath_num)
|
||||||
RGB_Reflash();
|
RGB_Reflash();
|
||||||
rt_thread_delay(40);
|
rt_thread_mdelay(LED_BREATH_MDELAY);
|
||||||
}
|
|
||||||
count = (count + 1) % 3;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#define BORAD_NOT_CORRECT 25
|
void led_reflash_entry(void *parameter)
|
||||||
#define BORAD_CORRECT_VOL 250
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief 检测一下当前接入的是否是正确的板
|
|
||||||
*/
|
|
||||||
static int borad_check(void)
|
|
||||||
{
|
{
|
||||||
rt_adc_device_t adc_dev;
|
(void)parameter;
|
||||||
rt_uint32_t value, vol;
|
while (1)
|
||||||
rt_err_t ret = RT_EOK;
|
|
||||||
|
|
||||||
/* 查找设备 */
|
|
||||||
adc_dev = (rt_adc_device_t)rt_device_find(ADC_DEV_NAME);
|
|
||||||
if (adc_dev == RT_NULL)
|
|
||||||
{
|
{
|
||||||
rt_kprintf("adc sample run failed! can't find %s device!\n", ADC_DEV_NAME);
|
RGB_Reflash();
|
||||||
return RT_ERROR;
|
rt_thread_mdelay(500);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 使能设备 */
|
|
||||||
ret = rt_adc_enable(adc_dev, ADC_DEV_CHANNEL);
|
|
||||||
|
|
||||||
/* 读取采样值 */
|
|
||||||
value = rt_adc_read(adc_dev, ADC_DEV_CHANNEL);
|
|
||||||
|
|
||||||
/* 转换为对应电压值 */
|
|
||||||
vol = value * REFER_VOLTAGE / CONVERT_BITS;
|
|
||||||
if(vol>=BORAD_CORRECT_VOL)
|
|
||||||
{
|
|
||||||
rt_kprintf("NOT correct borad!\n");
|
|
||||||
rt_kprintf("the value is :%d \n", value);
|
|
||||||
rt_kprintf("the voltage is :%d.%02d \n", vol / 100, vol % 100);
|
|
||||||
return BORAD_NOT_CORRECT;
|
|
||||||
}
|
|
||||||
/* 关闭通道 */
|
|
||||||
ret = rt_adc_disable(adc_dev, ADC_DEV_CHANNEL);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
/* 导出到 msh 命令列表中 */
|
|
||||||
MSH_CMD_EXPORT(borad_check, adc voltage convert sample);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief LED的初始化
|
* @brief LED的初始化
|
||||||
*/
|
*/
|
||||||
int led_init(void)
|
int led_init(void)
|
||||||
{
|
{
|
||||||
if (borad_check()==BORAD_NOT_CORRECT)
|
|
||||||
{
|
led_blink_thread = rt_thread_create("ledblT", led_blink_entry, RT_NULL, 1024, 20, 20);
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
led_blink_thread = rt_thread_create("led blink control thread", led_blink_entry, RT_NULL, 1024, 20, 20);
|
|
||||||
if (led_blink_thread == RT_NULL)
|
if (led_blink_thread == RT_NULL)
|
||||||
{
|
{
|
||||||
rt_kprintf("led blink control thread creat failed!\n");
|
rt_kprintf("led blink control thread creat failed!\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
led_breath_thread = rt_thread_create("led breath control thread", led_breath_entry, RT_NULL, 1024, 20, 20);
|
rt_thread_startup(led_blink_thread);
|
||||||
|
|
||||||
|
led_breath_thread = rt_thread_create("ledbrT", led_breath_entry, RT_NULL, 1024, 20, 20);
|
||||||
if (led_breath_thread == RT_NULL)
|
if (led_breath_thread == RT_NULL)
|
||||||
{
|
{
|
||||||
rt_kprintf("led breath control thread creat failed!\n");
|
rt_kprintf("led breath control thread creat failed!\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
rt_thread_mdelay(200); // avoid multi-thread on LED matrix transmit.
|
|
||||||
rt_thread_startup(led_blink_thread);
|
|
||||||
rt_thread_startup(led_breath_thread);
|
rt_thread_startup(led_breath_thread);
|
||||||
|
|
||||||
|
led_reflash_thread = rt_thread_create("ledreT", led_reflash_entry, RT_NULL, 1024, 20, 20);
|
||||||
|
if (led_reflash_thread == RT_NULL)
|
||||||
|
{
|
||||||
|
rt_kprintf("led reflash control thread creat failed!\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
rt_thread_startup(led_reflash_thread);
|
||||||
|
return 0;
|
||||||
}
|
}
|
@ -1,20 +1,22 @@
|
|||||||
#include <rtthread.h>
|
#include <rtthread.h>
|
||||||
#include <drv_matrix_led.h>
|
#include <drv_matrix_led.h>
|
||||||
|
|
||||||
|
#define LED_NUM 19 // LED灯珠个数
|
||||||
|
|
||||||
#define LED_IS_BLINKING 1
|
#define LED_IS_BLINKING 1
|
||||||
#define LED_NOT_BLINKING 0
|
#define LED_NOT_BLINKING 0
|
||||||
#define LED_BREATH_ON 1
|
#define LED_BREATH_ON 1
|
||||||
#define LED_BREATH_OFF 0
|
#define LED_BREATH_OFF 0
|
||||||
|
#define LED_BREATH_OFF_LASTING 2
|
||||||
|
#define LED_IS_BREATHING 6
|
||||||
|
|
||||||
#define LED_CHARGE_ID(i) (i+12-1) //电源指示灯序号(1-12)
|
#define LED_CHARGE_ID(i) (i+12-1) //电源指示灯序号(1-12)
|
||||||
#define LED_BREATH_ID(i) (i-1) //呼吸灯序号(1-12)
|
#define LED_BREATH_ID(i) (i-12) //呼吸灯序号(1-12)
|
||||||
|
|
||||||
extern void LED_Set(uint16_t LedId, RGBColor_TypeDef Color);
|
void LED_Set(uint16_t LedId, RGBColor_TypeDef Color);
|
||||||
extern void LED_SetMore(uint16_t LedId_begin,uint16_t LedId_end, RGBColor_TypeDef Color);
|
void LED_SetMore(uint16_t LedId_begin,uint16_t LedId_end, RGBColor_TypeDef Color);
|
||||||
extern void LED_Blink(uint16_t LedId, RGBColor_TypeDef Color);
|
void LED_Blink(uint16_t LedId, RGBColor_TypeDef Color);
|
||||||
extern void LED_BlinkMore(uint16_t LedId_begin, uint16_t LedId_end, RGBColor_TypeDef Color);
|
void LED_BlinkMore(uint16_t LedId_begin, uint16_t LedId_end, RGBColor_TypeDef Color);
|
||||||
extern void LED_BreathTurn(uint8_t LedBreath_state);
|
void LED_Breath(uint16_t LedId, RGBColor_TypeDef Color);
|
||||||
extern int led_init(void);
|
void LED_BreathMore(uint16_t LedId_begin, uint16_t LedId_end, RGBColor_TypeDef Color);
|
||||||
|
int led_init(void);
|
||||||
extern const RGBColor_TypeDef LED_OFF;
|
|
||||||
extern const RGBColor_TypeDef LED_ON;
|
|
@ -15,11 +15,11 @@ void ledblinkm(int argc, char **argv){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
MSH_CMD_EXPORT_ALIAS(ledblinkm,LEDB, "BLINKS LedId Color");
|
MSH_CMD_EXPORT_ALIAS(ledblinkm,LEDB, "BLINKS LedId Color");
|
||||||
void ledbreath(int argc, char **argv){
|
// void ledbreath(int argc, char **argv){
|
||||||
|
|
||||||
LED_BreathTurn(atoi(argv[1]));
|
// LED_BreathTurn(atoi(argv[1]));
|
||||||
}
|
// }
|
||||||
MSH_CMD_EXPORT_ALIAS(ledbreath,LEDBR, "BLINKS LedId Color");
|
// MSH_CMD_EXPORT_ALIAS(ledbreath,LEDBR, "BLINKS LedId Color");
|
||||||
void ledsetm(int argc, char **argv){
|
void ledsetm(int argc, char **argv){
|
||||||
|
|
||||||
int LedId_begin = atoi(argv[2]);
|
int LedId_begin = atoi(argv[2]);
|
||||||
|
@ -55,22 +55,22 @@ float MQ2_GetData_PPM(void)
|
|||||||
|
|
||||||
float tempData = 0;
|
float tempData = 0;
|
||||||
|
|
||||||
|
|
||||||
for (uint8_t i = 0; i < MQ2_READ_TIMES; i++)
|
for (uint8_t i = 0; i < MQ2_READ_TIMES; i++)
|
||||||
{
|
{
|
||||||
tempData += Air_Read();;
|
tempData += Air_Read();
|
||||||
rt_thread_mdelay(5);;
|
;
|
||||||
|
rt_thread_mdelay(5);
|
||||||
|
;
|
||||||
}
|
}
|
||||||
tempData /= MQ2_READ_TIMES;
|
tempData /= MQ2_READ_TIMES;
|
||||||
|
|
||||||
float Vol = (tempData*5/4096);
|
float Vol = (tempData * 5 / 4096);
|
||||||
float RS = (5-Vol)/(Vol*0.5);
|
float RS = (5 - Vol) / (Vol * 0.5);
|
||||||
float R0=6.64;
|
float R0 = 6.64;
|
||||||
|
|
||||||
float ppm = pow(11.5428*R0/RS, 0.6549f);
|
float ppm = pow(11.5428 * R0 / RS, 0.6549f);
|
||||||
|
|
||||||
return ppm;
|
return ppm;
|
||||||
|
|
||||||
}
|
}
|
||||||
float PM25_Read()
|
float PM25_Read()
|
||||||
{
|
{
|
||||||
@ -104,23 +104,23 @@ float PM25_GetData(void)
|
|||||||
int dustVal = 0;
|
int dustVal = 0;
|
||||||
float Voltage;
|
float Voltage;
|
||||||
|
|
||||||
rt_pin_write(GPIO_PIN, PIN_HIGH);//置1 开启内部LED
|
rt_pin_write(GPIO_PIN, PIN_HIGH); // 置1 开启内部LED
|
||||||
|
|
||||||
rt_hw_us_delay(280);
|
rt_hw_us_delay(280);
|
||||||
ADCVal = PM25_Read();
|
ADCVal = PM25_Read();
|
||||||
rt_hw_us_delay(25);
|
rt_hw_us_delay(25);
|
||||||
rt_pin_write(GPIO_PIN, PIN_LOW); //置0 关闭内部LED
|
rt_pin_write(GPIO_PIN, PIN_LOW); // 置0 关闭内部LED
|
||||||
rt_hw_us_delay(9680); //需要脉宽比0.32ms/10ms的PWM信号驱动传感器中的LED
|
rt_hw_us_delay(9680); // 需要脉宽比0.32ms/10ms的PWM信号驱动传感器中的LED
|
||||||
|
|
||||||
Voltage = 3.3f * ADCVal / 4096.f * 2; //获得AO输出口的电压值
|
Voltage = 3.3f * ADCVal / 4096.f * 2; // 获得AO输出口的电压值
|
||||||
|
|
||||||
dustVal = (0.17*Voltage-0.1)*1000; //乘以1000单位换成ug/m3//
|
dustVal = (0.17 * Voltage - 0.1) * 1000; // 乘以1000单位换成ug/m3//
|
||||||
|
|
||||||
if (dustVal < 0)
|
if (dustVal < 0)
|
||||||
dustVal = 0; //限位//
|
dustVal = 0; // 限位//
|
||||||
|
|
||||||
if (dustVal>500)
|
if (dustVal > 500)
|
||||||
dustVal=500;
|
dustVal = 500;
|
||||||
|
|
||||||
return dustVal;
|
return dustVal;
|
||||||
}
|
}
|
||||||
@ -132,30 +132,33 @@ float PM25_GetData(void)
|
|||||||
*/
|
*/
|
||||||
float Get_PM25_Average_Data(void)
|
float Get_PM25_Average_Data(void)
|
||||||
{
|
{
|
||||||
float temp_val=0;
|
float temp_val = 0;
|
||||||
float t;
|
float t;
|
||||||
for(t=0;t<PM25_READ_TIMES;t++) //#define PM25_READ_TIMES 20 定义读取次数,读这么多次,然后取平均值
|
for (t = 0; t < PM25_READ_TIMES; t++) // #define PM25_READ_TIMES 20 定义读取次数,读这么多次,然后取平均值
|
||||||
|
|
||||||
{
|
{
|
||||||
temp_val+=PM25_GetData(); //读取ADC值
|
temp_val += PM25_GetData(); // 读取ADC值
|
||||||
rt_thread_mdelay(5);
|
rt_thread_mdelay(5);
|
||||||
}
|
}
|
||||||
temp_val/=PM25_READ_TIMES;//得到平均值
|
temp_val /= PM25_READ_TIMES; // 得到平均值
|
||||||
return temp_val;//返回算出的ADC平均值
|
return temp_val; // 返回算出的ADC平均值
|
||||||
}
|
}
|
||||||
|
|
||||||
void warning_range(char* str,float value, float min, float max)
|
int warning_range(char *str, float value, float min, float max)
|
||||||
{
|
{
|
||||||
if (value < min)
|
if (value < min)
|
||||||
{
|
{
|
||||||
LOG5("%s's value:%f is too low\n",str, value);
|
LOG5("%s's value:%f is too low\n", str, value);
|
||||||
danger_status();
|
danger_status();
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
else if (value > max)
|
else if (value > max)
|
||||||
{
|
{
|
||||||
LOG5("%s's value:%f is too high\n",str, value);
|
LOG5("%s's value:%f is too high\n", str, value);
|
||||||
danger_status();
|
danger_status();
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void sensor_thread(void *parameter)
|
static void sensor_thread(void *parameter)
|
||||||
@ -166,9 +169,14 @@ static void sensor_thread(void *parameter)
|
|||||||
ADC_PM25 = Get_PM25_Average_Data(); // PM2.5传感器数值0-500 表示从优秀到查差
|
ADC_PM25 = Get_PM25_Average_Data(); // PM2.5传感器数值0-500 表示从优秀到查差
|
||||||
ADC_pressure = Pressure_Read(); // 压力传感器数值 0-4095 表示从差到优秀
|
ADC_pressure = Pressure_Read(); // 压力传感器数值 0-4095 表示从差到优秀
|
||||||
// LOG5("ADC_air:%f,ADC_PM25:%f,ADC_pressure:%f", ADC_air, ADC_PM25, ADC_pressure);
|
// LOG5("ADC_air:%f,ADC_PM25:%f,ADC_pressure:%f", ADC_air, ADC_PM25, ADC_pressure);
|
||||||
warning_range("air", ADC_air, 0, 6.8);
|
int cnt_warning = 0;
|
||||||
warning_range("PM25", ADC_PM25, 0, 260);
|
cnt_warning += warning_range("air", ADC_air, 0, 6.8);
|
||||||
warning_range("pressure", ADC_pressure, 3500, 4095);
|
cnt_warning += warning_range("PM25", ADC_PM25, 0, 260);
|
||||||
|
cnt_warning += warning_range("pressure", ADC_pressure, 3500, 4095);
|
||||||
|
if (cnt_warning == 0)
|
||||||
|
{
|
||||||
|
normal_status();
|
||||||
|
}
|
||||||
rt_thread_mdelay(500);
|
rt_thread_mdelay(500);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
#include <assistant.h>
|
#include <assistant.h>
|
||||||
#include <sim.h>
|
#include <sim.h>
|
||||||
#include <motor.h>
|
#include <motor.h>
|
||||||
|
#include "indicator_led.h"
|
||||||
|
|
||||||
|
|
||||||
#define THREAD_PRIORITY 25
|
#define THREAD_PRIORITY 25
|
||||||
@ -28,14 +29,6 @@
|
|||||||
#define PIN_LED_B GET_PIN(E, 12)
|
#define PIN_LED_B GET_PIN(E, 12)
|
||||||
#define LED_ON PIN_HIGH
|
#define LED_ON PIN_HIGH
|
||||||
#define LED_OFF PIN_LOW
|
#define LED_OFF PIN_LOW
|
||||||
void danger_status(void)
|
|
||||||
{
|
|
||||||
char *str = "aa";
|
|
||||||
serial_send(str);
|
|
||||||
sim_call("17318112360");
|
|
||||||
}
|
|
||||||
MSH_CMD_EXPORT_ALIAS(danger_status, danger, show danger_status);
|
|
||||||
|
|
||||||
void fan_on(void)
|
void fan_on(void)
|
||||||
{
|
{
|
||||||
LOG3("fan on!");
|
LOG3("fan on!");
|
||||||
@ -61,3 +54,19 @@ void light_off(void)
|
|||||||
rt_pin_mode(PIN_LED_B, PIN_MODE_OUTPUT);
|
rt_pin_mode(PIN_LED_B, PIN_MODE_OUTPUT);
|
||||||
rt_pin_write(PIN_LED_B, LED_OFF);
|
rt_pin_write(PIN_LED_B, LED_OFF);
|
||||||
}
|
}
|
||||||
|
void danger_status(void)
|
||||||
|
{
|
||||||
|
char *str = "aa";
|
||||||
|
serial_send(str);
|
||||||
|
sim_call("17318112360");
|
||||||
|
fan_on();
|
||||||
|
light_on();
|
||||||
|
LED_BreathMore(0,LED_NUM-1,LED_RED);
|
||||||
|
}
|
||||||
|
MSH_CMD_EXPORT_ALIAS(danger_status, danger, show danger_status);
|
||||||
|
void normal_status(void)
|
||||||
|
{
|
||||||
|
fan_off();
|
||||||
|
light_off();
|
||||||
|
LED_SetMore(0,LED_NUM-1,LEDI_OFF);
|
||||||
|
}
|
@ -1,4 +1,5 @@
|
|||||||
void danger_status(void);
|
void danger_status(void);
|
||||||
|
void normal_status(void);
|
||||||
void fan_on(void);
|
void fan_on(void);
|
||||||
void fan_off(void);
|
void fan_off(void);
|
||||||
void light_on(void);
|
void light_on(void);
|
||||||
|
@ -50,12 +50,24 @@ const RGBColor_TypeDef LED_GREEN = {255, 0, 0};
|
|||||||
const RGBColor_TypeDef LED_RED = {0, 255, 0};
|
const RGBColor_TypeDef LED_RED = {0, 255, 0};
|
||||||
const RGBColor_TypeDef LED_BLUE = {0, 0, 255};
|
const RGBColor_TypeDef LED_BLUE = {0, 0, 255};
|
||||||
const RGBColor_TypeDef LED_WHITE = {255, 255, 255};
|
const RGBColor_TypeDef LED_WHITE = {255, 255, 255};
|
||||||
|
|
||||||
|
|
||||||
const RGBColor_TypeDef LT_RED = {0, 32, 0};
|
const RGBColor_TypeDef LT_RED = {0, 32, 0};
|
||||||
const RGBColor_TypeDef LT_GREEN = {32, 0, 0};
|
const RGBColor_TypeDef LT_GREEN = {32, 0, 0};
|
||||||
const RGBColor_TypeDef LT_BLUE = {0, 0, 32};
|
const RGBColor_TypeDef LT_BLUE = {0, 0, 32};
|
||||||
const RGBColor_TypeDef LT_WHITE = {16, 16, 16};
|
const RGBColor_TypeDef LT_WHITE = {16, 16, 16};
|
||||||
|
const RGBColor_TypeDef LT_PURPLE = {0,32,32};
|
||||||
|
const RGBColor_TypeDef LT_YELLOW = {256/8, 256/8, 0};
|
||||||
|
const RGBColor_TypeDef LLT_RED = {0, 8, 0};
|
||||||
|
const RGBColor_TypeDef LLT_GREEN = {8, 0, 0};
|
||||||
|
const RGBColor_TypeDef LLT_BLUE = {0, 0, 8};
|
||||||
|
const RGBColor_TypeDef LLT_WHITE = {4, 4, 4};
|
||||||
|
const RGBColor_TypeDef LLT_PURPLE = {0,8,8};
|
||||||
|
const RGBColor_TypeDef LLT_YELLOW = {8, 8, 0};
|
||||||
|
|
||||||
|
|
||||||
|
const RGBColor_TypeDef LEDI_OFF = {0, 0, 0};
|
||||||
|
const RGBColor_TypeDef LEDI_ON = {255, 255, 255};
|
||||||
|
|
||||||
|
|
||||||
// 灯颜色缓存
|
// 灯颜色缓存
|
||||||
|
@ -15,11 +15,27 @@ typedef struct RGBColor_TypeDef
|
|||||||
// // 灯闪烁颜色缓存
|
// // 灯闪烁颜色缓存
|
||||||
// extern RGBColor_TypeDef LED_Blink_Color[LED_NUM] = {0};
|
// extern RGBColor_TypeDef LED_Blink_Color[LED_NUM] = {0};
|
||||||
|
|
||||||
extern const RGBColor_TypeDef LED_DARK;
|
extern const RGBColor_TypeDef LED_DARK ;
|
||||||
extern const RGBColor_TypeDef LED_GREEN;
|
extern const RGBColor_TypeDef LED_GREEN;
|
||||||
extern const RGBColor_TypeDef LED_RED;
|
extern const RGBColor_TypeDef LED_RED ;
|
||||||
extern const RGBColor_TypeDef LED_BLUE;
|
extern const RGBColor_TypeDef LED_BLUE ;
|
||||||
extern const RGBColor_TypeDef LED_WHITE;
|
extern const RGBColor_TypeDef LED_WHITE ;
|
||||||
|
|
||||||
|
extern const RGBColor_TypeDef LT_RED ;
|
||||||
|
extern const RGBColor_TypeDef LT_GREEN ;
|
||||||
|
extern const RGBColor_TypeDef LT_BLUE ;
|
||||||
|
extern const RGBColor_TypeDef LT_WHITE ;
|
||||||
|
extern const RGBColor_TypeDef LT_PURPLE;
|
||||||
|
extern const RGBColor_TypeDef LT_YELLOW;
|
||||||
|
extern const RGBColor_TypeDef LLT_RED ;
|
||||||
|
extern const RGBColor_TypeDef LLT_GREEN;
|
||||||
|
extern const RGBColor_TypeDef LLT_BLUE ;
|
||||||
|
extern const RGBColor_TypeDef LLT_WHITE;
|
||||||
|
extern const RGBColor_TypeDef LLT_PURPLE;
|
||||||
|
extern const RGBColor_TypeDef LLT_YELLOW;
|
||||||
|
|
||||||
|
extern const RGBColor_TypeDef LEDI_OFF ;
|
||||||
|
extern const RGBColor_TypeDef LEDI_ON ;
|
||||||
extern void Set_LEDColor(uint16_t LedId, RGBColor_TypeDef Color);
|
extern void Set_LEDColor(uint16_t LedId, RGBColor_TypeDef Color);
|
||||||
|
|
||||||
extern void RGB_Reflash(void);
|
extern void RGB_Reflash(void);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user