/********************************************************************************** * File Name: Led.c * Function Describe:The task for LED display * Relate Module: * Explain: 控制指示灯显示任务。在其他任务中可通过SetLedFlash函数设置显示方式 * Writer: ShiLiangWen * Date: 2015.2.10 **********************************************************************************/ #define THIS_FILE_ID 9 //-------------------------------------------------------------------------------- #include "includes.h" OS_TID idLedTask; static unsigned char sucRedLedFlash=0; static unsigned char sucRedLedSleep=0; static unsigned char sucBlueLedFlash=0; static unsigned char sucBlueLedSleep=0; static unsigned char sucLedFlash[2*CHL_TOTAL]={0}; static unsigned char sucLedSleep[2*CHL_TOTAL]={0}; void LedOn(int i); void LedOff(int i); void LedInit(void) { int i; GPIO_InitTypeDef GPIO_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOC, ENABLE); GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Pin = LED1_PIN; GPIO_Init(MODEM_LED1_PORT, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = LED2_PIN; GPIO_Init(MODEM_LED2_PORT, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = LED3_PIN; GPIO_Init(MODEM_LED3_PORT, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = LED4_PIN; GPIO_Init(MODEM_LED4_PORT, &GPIO_InitStructure); for(i=0;i<2*CHL_TOTAL;i++)LedOff(i); FEED_EXTWATCHDOG();//喂狗 IWDG_ReloadCounter();//喂狗 for(i=0;i<2*CHL_TOTAL;i++){ LedOn(i); os_dly_wait(30); FEED_EXTWATCHDOG();//喂狗 IWDG_ReloadCounter();//喂狗 } FEED_EXTWATCHDOG();//喂狗 IWDG_ReloadCounter();//喂狗 for(i=0;i<2*CHL_TOTAL;i++)LedOff(i); // LedProcess(1); //电源指示灯常亮 // SetLedStatus(0,Bright); } void LedOn(int i) { if(i==0)MODEM_LED1_HIGH; else if(i==1)MODEM_LED2_HIGH; else if(i==2)MODEM_LED3_HIGH; else MODEM_LED4_HIGH; } void LedOff(int i) { if(i==0)MODEM_LED1_LOW; else if(i==1)MODEM_LED2_LOW; else if(i==2)MODEM_LED3_LOW; else MODEM_LED4_LOW; } void LedProcess(unsigned char reset) { int i; static unsigned char LedCt[2*CHL_TOTAL]={0}; static unsigned char LedMaxCt[2*CHL_TOTAL]={0}; static unsigned char LedFlash2[2*CHL_TOTAL]={0}; static unsigned char LastLedFlash[2*CHL_TOTAL]={0}; static unsigned char LastLedSleep[2*CHL_TOTAL]={0}; static unsigned char sucCt=0; static unsigned char Uart1LedCt=0; if(reset){ for(i=0;i<2*CHL_TOTAL;i++){ LedCt[i]=0; LedMaxCt[i]=0; LedFlash2[i]=0; LastLedFlash[i]=0; LastLedSleep[i]=0; LedOff(i); } sucCt=0; Uart1LedCt=0; } //控制200ms执行一次 if(++sucCt>20)sucCt=0; else return; //LED1~LED3 for(i=0;i<2*CHL_TOTAL;i++){ if(sucLedFlash[i]==0){ //长灭 LedOff(i); }else if(sucLedSleep[i]==0){//长亮 LedOn(i); }else{ if(LastLedFlash[i]!=sucLedFlash[i] || LastLedSleep[i]!=sucLedSleep[i]){ LedCt[i]=0; LastLedFlash[i]=sucLedFlash[i]; LastLedSleep[i]=sucLedSleep[i]; LedFlash2[i]=sucLedFlash[i]*2; LedMaxCt[i]=(LedFlash2[i]+LastLedSleep[i])*2; } if(++LedCt[i]>LedMaxCt[i])LedCt[i]=0; if(LedCt[i]0){//串口1无数据来就灭灯 // Uart1LedCt=0; // MODEM_LED4_LOW; // } } /******************************************************************** SetLed 设置内部运行参数 *********************************************************************/ void SetLed(unsigned char LedId,unsigned char flash,unsigned char sleep) { //合法性判断 int t=(flash+sleep)*2; if(t>255){ return; } if(LedId>=2*CHL_TOTAL)return; //设置运行参数 sucLedFlash[LedId]=flash; sucLedSleep[LedId]=sleep; } void SetLedStatus(unsigned char LedId,LED_STATUS LedStatus) { switch(LedStatus){ case NotBright: SetLed(LedId,0,0); break; case Bright: SetLed(LedId,1,0); break; case Flash: SetLed(LedId,1,1); break; case OneFlashFast: SetLed(LedId,1,6); break; case TowFlashFast: SetLed(LedId,2,6); break; case ThreeFlashFast: SetLed(LedId,3,6); break; case OneFlashSlow: SetLed(LedId,1,20); break; case TowFlashSlow: SetLed(LedId,2,20); break; case ThreeFlashSlow: SetLed(LedId,3,20); break; } } /* 正面向2个双色指示灯,分别为:左红、左蓝、右红、右绿 四个LED 因为是双色灯,因此需要注意同一位置的指示灯两种颜色叠加时会有混色效果。比如: 红色+蓝色=紫色 =============== 左红:4G模块指示灯 常灭--模块未工作 常亮--模块未插SIM卡 均匀闪烁--模块找网中 慢闪1次--正在打开SOCKET连接 慢闪2次--正在发登陆包 慢闪3次--正常工作 左蓝:GPS模块指示灯 常灭 --模块未工作 慢闪1次 --未定位 常亮 --已定位 右红:电源指示灯 开机后5秒常亮 右绿:水表通讯指示灯 每收到水表数据包并解析成功,闪烁一次 */ #if 0 void SetLedIndicator(void) { //红色指示灯作为电源指示灯,常量 //蓝色灯 定位置指示 if(sutGpsInfo.isGpsWork){ if(sutGpsInfo.isGpsValid){ SetLedStatus(1,Bright); }else{ SetLedStatus(1,OneFlashSlow); } }else{ SetLedStatus(1,NotBright); } //绿色灯 4G模块 if(sutModemStatus.ServerStatus==OPENED){ SetLedStatus(2,ThreeFlashSlow); }else if(sutWLanStatus.Step==WL_STEP_UPLOAD){ SetLedStatus(2,TowFlashSlow); }else if(sutModemStatus.PDPStatus==OPENED){ SetLedStatus(2,OneFlashSlow); }else if(sutModemStatus.CardStatus==OPENED){ SetLedStatus(2,Flash); }else if(sutModemStatus.WorkStatus==OPENED){ SetLedStatus(2,Bright); }else{ SetLedStatus(2,NotBright); } } #else void SetLedIndicator(void) { authLedShow(); } #endif /***********************************************************************************/