PASII/CandeII_1.4/Taskrun/shockLed_task.c

124 lines
2.8 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*****************************************************************
;Project: Light
;MCU:
;Date:
;File:
;Function:
******************************************************************/
#include "shockLed_task.h"
#include "ws2812.h"
#include "tick.h"
#include "adc.h"
#include "config.h"
#include "detect_task.h"
/*---------------------------------------------------------------*/
//外部变量调用声明
extern AD_Value_t AD_Value;
extern TaskFlagUnion_t tTaskFlag;
extern unsigned char VoltageStableFlag; //电池电压稳定标志
/*---------------------------------------------------------------*/
//振动显示电量任务
void shockLed_Task(void)
{
static unsigned char shock_state=0;
static unsigned short time=0;
static unsigned char powerLedNum = 0;
unsigned int powerColor=0;
if((tTaskFlag.tFlag.shockFlag == 1)&&(VoltageStableFlag == 1))
{
if(Get_TaskInitFlag() == 1)
{
shock_state = 0;
WS_CloseAll();
Set_TaskInitFlag(0);
}
switch(shock_state)
{
case 0:
if(AD_Value.PowerScale <= 30) //电量小于等于30%显示红灯,大于显示绿灯
powerColor=POWER_WARNCOLOR;
else
powerColor=POWER_SAFECOLOR;
//--得到以10个灯等比显示当前电量的灯数
//数据处理将每10个划分一个等级0~9->0,10~19->1,90~99->9,97~100->10
if(AD_Value.PowerScale >= 100)
powerLedNum = 10;
else
powerLedNum = AD_Value.PowerScale/10;
if(AD_Value.PowerScale <= 10)
{
powerLedNum = 1;
}
//--ledBuff清零
LedBuff_CleanAll();
//--指定ledBuff写入color并亮灯
LedBuff_WriteNum(powerLedNum,powerColor);
WS_Show();
//--设置一个时间闹钟
TimerSet(time,5000); //亮5s
shock_state = 1;
break;
case 1: //检查时间有没到
//--检查闹钟时间是否到达
if(TimerCheck(time,5000))
{
//--指定led灭灯
WS_CloseAll();
shock_state = 0;
tTaskFlag.tFlag.shockFlag = 0;
}
break;
default:
shock_state = 0;
break;
}
}
}
/*---------------------------------------------------------------*/
//LED闪烁任务
unsigned char flash_state=0;
void FlashLed_Task(void)
{
static unsigned short time=0;
switch(flash_state)
{
case 0:
LedBuff_WriteNum(10,0xff0000);
WS_Show();
TimerSet(time,200);
flash_state = 1;
break;
case 1:
if(TimerCheck(time,200))
{
WS_CloseAll();
TimerSet(time,200);
flash_state = 2;
}
break;
case 2:
if(TimerCheck(time,200))
{
flash_state = 0;
}
break;
default: flash_state = 0;
break;
}
}