123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246 |
- /**********************************************************************************
- * 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]<LedFlash2[i] && (LedCt[i]&0x01)==0x01)LedOn(i);
- else LedOff(i);
- }
- }
- // //LED4 串口指示灯,来一包数据闪烁一下
- // if(g_ucUart1Activated == 1){//串口1有数据来就闪灯
- // g_ucUart1Activated=0;
- // Uart1LedCt=0;
- // MODEM_LED4_HIGH;
- // }else if(++Uart1LedCt>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
- /***********************************************************************************/
|