Led.c 4.3 KB

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