Led.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. /**********************************************************************************
  2. * File Name: Led.c
  3. * Function Describe:The task for LED display
  4. * Relate Module:
  5. * Explain: 控制指示灯显示任务。在其他任务中可通过SetLedFlash函数设置显示方式
  6. * Writer: ShiLiangWen
  7. * Date: 2015.2.10
  8. **********************************************************************************/
  9. #define THIS_FILE_ID 9
  10. //--------------------------------------------------------------------------------
  11. #include "includes.h"
  12. OS_TID idLedTask;
  13. static unsigned char sucRedLedFlash=0;
  14. static unsigned char sucRedLedSleep=0;
  15. static unsigned char sucBlueLedFlash=0;
  16. static unsigned char sucBlueLedSleep=0;
  17. static unsigned char sucLedFlash[2*CHL_TOTAL]={0};
  18. static unsigned char sucLedSleep[2*CHL_TOTAL]={0};
  19. void LedOn(int i);
  20. void LedOff(int i);
  21. void LedInit(void)
  22. {
  23. int i;
  24. GPIO_InitTypeDef GPIO_InitStructure;
  25. RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOC, ENABLE);
  26. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  27. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  28. GPIO_InitStructure.GPIO_Pin = LED1_PIN;
  29. GPIO_Init(MODEM_LED1_PORT, &GPIO_InitStructure);
  30. GPIO_InitStructure.GPIO_Pin = LED2_PIN;
  31. GPIO_Init(MODEM_LED2_PORT, &GPIO_InitStructure);
  32. GPIO_InitStructure.GPIO_Pin = LED3_PIN;
  33. GPIO_Init(MODEM_LED3_PORT, &GPIO_InitStructure);
  34. GPIO_InitStructure.GPIO_Pin = LED4_PIN;
  35. GPIO_Init(MODEM_LED4_PORT, &GPIO_InitStructure);
  36. for(i=0;i<2*CHL_TOTAL;i++)LedOff(i);
  37. FEED_EXTWATCHDOG();//喂狗
  38. IWDG_ReloadCounter();//喂狗
  39. for(i=0;i<2*CHL_TOTAL;i++){
  40. LedOn(i);
  41. os_dly_wait(30);
  42. FEED_EXTWATCHDOG();//喂狗
  43. IWDG_ReloadCounter();//喂狗
  44. }
  45. FEED_EXTWATCHDOG();//喂狗
  46. IWDG_ReloadCounter();//喂狗
  47. for(i=0;i<2*CHL_TOTAL;i++)LedOff(i);
  48. //
  49. LedProcess(1);
  50. //电源指示灯常亮
  51. // SetLedStatus(0,Bright);
  52. }
  53. void LedOn(int i)
  54. {
  55. if(i==0)MODEM_LED1_HIGH;
  56. else if(i==1)MODEM_LED2_HIGH;
  57. else if(i==2)MODEM_LED3_HIGH;
  58. else MODEM_LED4_HIGH;
  59. }
  60. void LedOff(int i)
  61. {
  62. if(i==0)MODEM_LED1_LOW;
  63. else if(i==1)MODEM_LED2_LOW;
  64. else if(i==2)MODEM_LED3_LOW;
  65. else MODEM_LED4_LOW;
  66. }
  67. void LedProcess(unsigned char reset)
  68. {
  69. int i;
  70. static unsigned char LedCt[2*CHL_TOTAL]={0};
  71. static unsigned char LedMaxCt[2*CHL_TOTAL]={0};
  72. static unsigned char LedFlash2[2*CHL_TOTAL]={0};
  73. static unsigned char LastLedFlash[2*CHL_TOTAL]={0};
  74. static unsigned char LastLedSleep[2*CHL_TOTAL]={0};
  75. static unsigned char sucCt=0;
  76. static unsigned char Uart1LedCt=0;
  77. if(reset){
  78. for(i=0;i<2*CHL_TOTAL;i++){
  79. LedCt[i]=0;
  80. LedMaxCt[i]=0;
  81. LedFlash2[i]=0;
  82. LastLedFlash[i]=0;
  83. LastLedSleep[i]=0;
  84. LedOff(i);
  85. }
  86. sucCt=0;
  87. Uart1LedCt=0;
  88. }
  89. //控制200ms执行一次
  90. if(++sucCt>20)sucCt=0;
  91. else return;
  92. //LED1~LED3
  93. for(i=0;i<2*CHL_TOTAL;i++){
  94. if(sucLedFlash[i]==0){ //长灭
  95. LedOff(i);
  96. }else if(sucLedSleep[i]==0){//长亮
  97. LedOn(i);
  98. }else{
  99. if(LastLedFlash[i]!=sucLedFlash[i] || LastLedSleep[i]!=sucLedSleep[i]){
  100. LedCt[i]=0;
  101. LastLedFlash[i]=sucLedFlash[i];
  102. LastLedSleep[i]=sucLedSleep[i];
  103. LedFlash2[i]=sucLedFlash[i]*2;
  104. LedMaxCt[i]=(LedFlash2[i]+LastLedSleep[i])*2;
  105. }
  106. if(++LedCt[i]>LedMaxCt[i])LedCt[i]=0;
  107. if(LedCt[i]<LedFlash2[i] && (LedCt[i]&0x01)==0x01)LedOn(i);
  108. else LedOff(i);
  109. }
  110. }
  111. // //LED4 串口指示灯,来一包数据闪烁一下
  112. // if(g_ucUart1Activated == 1){//串口1有数据来就闪灯
  113. // g_ucUart1Activated=0;
  114. // Uart1LedCt=0;
  115. // MODEM_LED4_HIGH;
  116. // }else if(++Uart1LedCt>0){//串口1无数据来就灭灯
  117. // Uart1LedCt=0;
  118. // MODEM_LED4_LOW;
  119. // }
  120. }
  121. /********************************************************************
  122. SetLed
  123. 设置内部运行参数
  124. *********************************************************************/
  125. void SetLed(unsigned char LedId,unsigned char flash,unsigned char sleep)
  126. {
  127. //合法性判断
  128. int t=(flash+sleep)*2;
  129. if(t>255){
  130. return;
  131. }
  132. if(LedId>=2*CHL_TOTAL)return;
  133. //设置运行参数
  134. sucLedFlash[LedId]=flash;
  135. sucLedSleep[LedId]=sleep;
  136. }
  137. void SetLedStatus(unsigned char LedId,LED_STATUS LedStatus)
  138. {
  139. switch(LedStatus){
  140. case NotBright:
  141. SetLed(LedId,0,0);
  142. break;
  143. case Bright:
  144. SetLed(LedId,1,0);
  145. break;
  146. case Flash:
  147. SetLed(LedId,1,1);
  148. break;
  149. case OneFlashFast:
  150. SetLed(LedId,1,6);
  151. break;
  152. case TowFlashFast:
  153. SetLed(LedId,2,6);
  154. break;
  155. case ThreeFlashFast:
  156. SetLed(LedId,3,6);
  157. break;
  158. case OneFlashSlow:
  159. SetLed(LedId,1,20);
  160. break;
  161. case TowFlashSlow:
  162. SetLed(LedId,2,20);
  163. break;
  164. case ThreeFlashSlow:
  165. SetLed(LedId,3,20);
  166. break;
  167. }
  168. }
  169. /*
  170. 正面向2个双色指示灯,分别为:左红、左蓝、右红、右绿 四个LED
  171. 因为是双色灯,因此需要注意同一位置的指示灯两种颜色叠加时会有混色效果。比如:
  172. 红色+蓝色=紫色
  173. ===============
  174. 左红:4G模块指示灯
  175. 常灭--模块未工作
  176. 常亮--模块未插SIM卡
  177. 均匀闪烁--模块找网中
  178. 慢闪1次--正在打开SOCKET连接
  179. 慢闪2次--正在发登陆包
  180. 慢闪3次--正常工作
  181. 左蓝:GPS模块指示灯
  182. 常灭 --模块未工作
  183. 慢闪1次 --未定位
  184. 常亮 --已定位
  185. 右红:电源指示灯
  186. 开机后5秒常亮
  187. 右绿:水表通讯指示灯
  188. 每收到水表数据包并解析成功,闪烁一次
  189. */
  190. #if 0
  191. void SetLedIndicator(void)
  192. {
  193. //红色指示灯作为电源指示灯,常量
  194. //蓝色灯 定位置指示
  195. if(sutGpsInfo.isGpsWork){
  196. if(sutGpsInfo.isGpsValid){
  197. SetLedStatus(1,Bright);
  198. }else{
  199. SetLedStatus(1,OneFlashSlow);
  200. }
  201. }else{
  202. SetLedStatus(1,NotBright);
  203. }
  204. //绿色灯 4G模块
  205. if(sutModemStatus.ServerStatus==OPENED){
  206. SetLedStatus(2,ThreeFlashSlow);
  207. }else if(sutWLanStatus.Step==WL_STEP_UPLOAD){
  208. SetLedStatus(2,TowFlashSlow);
  209. }else if(sutModemStatus.PDPStatus==OPENED){
  210. SetLedStatus(2,OneFlashSlow);
  211. }else if(sutModemStatus.CardStatus==OPENED){
  212. SetLedStatus(2,Flash);
  213. }else if(sutModemStatus.WorkStatus==OPENED){
  214. SetLedStatus(2,Bright);
  215. }else{
  216. SetLedStatus(2,NotBright);
  217. }
  218. }
  219. #else
  220. void SetLedIndicator(void)
  221. {
  222. authLedShow();
  223. }
  224. #endif
  225. /***********************************************************************************/