Led.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. #include "includes.h"
  2. //static unsigned char sucRedLedFlash=0;
  3. //static unsigned char sucRedLedSleep=0;
  4. unsigned char sucRedLedFlash=0;
  5. unsigned char sucRedLedSleep=0;
  6. static unsigned char sucBlueLedFlash=0;
  7. static unsigned char sucBlueLedSleep=0;
  8. static LED_INDICATOR LedIndicator;
  9. LED_INDICATOR g_LedInd;
  10. void LedInit(void)
  11. {
  12. GPIO_InitTypeDef GPIO_InitStructure;
  13. RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOB, ENABLE);
  14. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  15. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  16. GPIO_InitStructure.GPIO_Pin = MODEM_LED1_PIN;
  17. GPIO_Init(MODEM_LED1_PORT, &GPIO_InitStructure);
  18. GPIO_InitStructure.GPIO_Pin = MODEM_LED2_PIN;
  19. GPIO_Init(MODEM_LED2_PORT, &GPIO_InitStructure);
  20. GPIO_InitStructure.GPIO_Pin = FLASH_LIGHT_PIN;
  21. GPIO_Init(FLASH_LIGHT_PORT, &GPIO_InitStructure);
  22. MODEM_LED1_LOW;
  23. MODEM_LED2_LOW;
  24. }
  25. timer_t ledTimer;
  26. void LedProcess(unsigned char reset)
  27. {
  28. static unsigned int sucCt=0;
  29. static unsigned char RedLedCt=0;
  30. static unsigned char RedLedMaxCt=0;
  31. static unsigned char RedLedFlash2=0;
  32. static unsigned char LastRedLedFlash=0xff;
  33. static unsigned char LastRedLedSleep=0xff;
  34. static unsigned char BlueLedCt=0;
  35. static unsigned char BlueLedMaxCt=0;
  36. static unsigned char BlueLedFlash2=0;
  37. static unsigned char LastBlueLedFlash=0xff;
  38. static unsigned char LastBlueLedSleep=0xff;
  39. if(reset){
  40. sucCt=0;
  41. RedLedCt=0;
  42. RedLedMaxCt=0;
  43. RedLedFlash2=0;
  44. LastRedLedFlash=0xff;
  45. LastRedLedSleep=0xff;
  46. BlueLedCt=0;
  47. BlueLedMaxCt=0;
  48. BlueLedFlash2=0;
  49. LastBlueLedFlash=0xff;
  50. LastBlueLedSleep=0xff;
  51. MODEM_LED1_LOW;
  52. MODEM_LED2_LOW;
  53. return;
  54. }
  55. //red led control
  56. if(sucRedLedFlash==0){ //낀췻
  57. MODEM_LED1_LOW;
  58. }else if(sucRedLedSleep==0){//낀좋
  59. MODEM_LED1_HIGH;
  60. }else{
  61. if(LastRedLedFlash!=sucRedLedFlash || LastRedLedSleep!=sucRedLedSleep){
  62. RedLedCt=0;
  63. BlueLedCt=0;
  64. LastRedLedFlash=sucRedLedFlash;
  65. LastRedLedSleep=sucRedLedSleep;
  66. RedLedFlash2=sucRedLedFlash*2;
  67. RedLedMaxCt=RedLedFlash2+LastRedLedSleep*2;
  68. }
  69. if(++RedLedCt>RedLedMaxCt)RedLedCt=0;
  70. //if(RedLedCt<RedLedFlash2 && (RedLedCt&0x01)==0x01)MODEM_LED1_HIGH;
  71. if(RedLedCt<RedLedFlash2)MODEM_LED1_HIGH;
  72. else MODEM_LED1_LOW;
  73. }
  74. //blue led control
  75. if(sucBlueLedFlash==0){ //낀췻
  76. MODEM_LED2_LOW;
  77. }else if(sucBlueLedSleep==0){//낀좋
  78. MODEM_LED2_HIGH;
  79. }else{
  80. if(LastBlueLedFlash!=sucBlueLedFlash || LastBlueLedSleep!=sucBlueLedSleep){
  81. RedLedCt=0;
  82. BlueLedCt=0;
  83. LastBlueLedFlash=sucBlueLedFlash;
  84. LastBlueLedSleep=sucBlueLedSleep;
  85. BlueLedFlash2=sucBlueLedFlash*2;
  86. BlueLedMaxCt=BlueLedFlash2+LastBlueLedSleep*2;
  87. }
  88. if(++BlueLedCt>BlueLedMaxCt)BlueLedCt=0;
  89. //if(BlueLedCt<BlueLedFlash2 && (BlueLedCt&0x01)==0x01)MODEM_LED2_HIGH;
  90. if(BlueLedCt<BlueLedFlash2)MODEM_LED2_HIGH;
  91. else MODEM_LED2_LOW;
  92. }
  93. }
  94. void SetRedLed(unsigned char flash,unsigned char sleep)
  95. {
  96. int t=(flash+sleep)*2;
  97. if(t>255){
  98. return;
  99. }
  100. sucRedLedFlash=flash;
  101. sucRedLedSleep=sleep;
  102. }
  103. void SetBlueLed(unsigned char flash,unsigned char sleep)
  104. {
  105. int t=(flash+sleep)*2;
  106. if(t>255){
  107. return;
  108. }
  109. sucBlueLedFlash=flash;
  110. sucBlueLedSleep=sleep;
  111. }
  112. void SetLedStatus(LED_STATUS LedStatus)
  113. {
  114. switch(LedStatus){
  115. case NotBright: //엇꼇좋
  116. SetRedLed(0,0);
  117. SetBlueLed(0,0);
  118. break;
  119. case RedBright: //븐됐끽좋
  120. SetRedLed(1,0);
  121. SetBlueLed(0,0);
  122. break;
  123. case RedFastFlash: //븐됐우�
  124. SetRedLed(1,1);
  125. SetBlueLed(0,0);
  126. break;
  127. case RedSlowFlash: //븐됐찹�
  128. SetRedLed(1,10);
  129. SetBlueLed(0,0);
  130. break;
  131. case BlueBright: //융됐끽좋
  132. SetRedLed(0,0);
  133. SetBlueLed(1,0);
  134. break;
  135. case BlueFastFlash: //융됐우�
  136. SetRedLed(0,0);
  137. SetBlueLed(1,1);
  138. break;
  139. case BlueSlowFlash: //융됐찹�
  140. SetRedLed(0,0);
  141. SetBlueLed(1,10);
  142. break;
  143. case RedBlueBright: //븐융끽좋
  144. SetRedLed(1,0);
  145. SetBlueLed(1,0);
  146. break;
  147. case RedBlueFastFlash: //븐융우�
  148. SetRedLed(1,1);
  149. SetBlueLed(1,1);
  150. break;
  151. case RedBlueSlowFlash: //븐융찹�
  152. SetRedLed(1,10);
  153. SetBlueLed(1,10);
  154. break;
  155. }
  156. }
  157. void SetLedIndicator(LED_INDICATOR LedInd)
  158. {
  159. switch(LedInd){
  160. case IndModemErr:
  161. g_LedInd=IndModemErr;
  162. SetLedStatus(RedBright);
  163. break;
  164. case IndNoNet:
  165. g_LedInd=IndNoNet;
  166. SetLedStatus(BlueFastFlash);
  167. break;
  168. case IndStandby:
  169. g_LedInd=IndStandby;
  170. SetLedStatus(BlueSlowFlash);
  171. break;
  172. case IndRX:
  173. g_LedInd=IndRX;
  174. SetLedStatus(BlueBright);
  175. break;
  176. case IndTX:
  177. g_LedInd=IndTX;
  178. SetLedStatus(RedBright);
  179. break;
  180. }
  181. }