123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204 |
- #include "includes.h"
- //static unsigned char sucRedLedFlash=0;
- //static unsigned char sucRedLedSleep=0;
- unsigned char sucRedLedFlash=0;
- unsigned char sucRedLedSleep=0;
- static unsigned char sucBlueLedFlash=0;
- static unsigned char sucBlueLedSleep=0;
- static LED_INDICATOR LedIndicator;
- LED_INDICATOR g_LedInd;
- void LedInit(void)
- {
- GPIO_InitTypeDef GPIO_InitStructure;
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOB, ENABLE);
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_InitStructure.GPIO_Pin = MODEM_LED1_PIN;
- GPIO_Init(MODEM_LED1_PORT, &GPIO_InitStructure);
- GPIO_InitStructure.GPIO_Pin = MODEM_LED2_PIN;
- GPIO_Init(MODEM_LED2_PORT, &GPIO_InitStructure);
-
- GPIO_InitStructure.GPIO_Pin = FLASH_LIGHT_PIN;
- GPIO_Init(FLASH_LIGHT_PORT, &GPIO_InitStructure);
-
- MODEM_LED1_LOW;
- MODEM_LED2_LOW;
- }
- timer_t ledTimer;
- void LedProcess(unsigned char reset)
- {
- static unsigned int sucCt=0;
-
- static unsigned char RedLedCt=0;
- static unsigned char RedLedMaxCt=0;
- static unsigned char RedLedFlash2=0;
- static unsigned char LastRedLedFlash=0xff;
- static unsigned char LastRedLedSleep=0xff;
- static unsigned char BlueLedCt=0;
- static unsigned char BlueLedMaxCt=0;
- static unsigned char BlueLedFlash2=0;
- static unsigned char LastBlueLedFlash=0xff;
- static unsigned char LastBlueLedSleep=0xff;
-
- if(reset){
- sucCt=0;
- RedLedCt=0;
- RedLedMaxCt=0;
- RedLedFlash2=0;
- LastRedLedFlash=0xff;
- LastRedLedSleep=0xff;
- BlueLedCt=0;
- BlueLedMaxCt=0;
- BlueLedFlash2=0;
- LastBlueLedFlash=0xff;
- LastBlueLedSleep=0xff;
- MODEM_LED1_LOW;
- MODEM_LED2_LOW;
- return;
- }
-
- //red led control
- if(sucRedLedFlash==0){ //낀췻
- MODEM_LED1_LOW;
- }else if(sucRedLedSleep==0){//낀좋
- MODEM_LED1_HIGH;
- }else{
- if(LastRedLedFlash!=sucRedLedFlash || LastRedLedSleep!=sucRedLedSleep){
- RedLedCt=0;
- BlueLedCt=0;
- LastRedLedFlash=sucRedLedFlash;
- LastRedLedSleep=sucRedLedSleep;
- RedLedFlash2=sucRedLedFlash*2;
- RedLedMaxCt=RedLedFlash2+LastRedLedSleep*2;
- }
- if(++RedLedCt>RedLedMaxCt)RedLedCt=0;
-
-
- //if(RedLedCt<RedLedFlash2 && (RedLedCt&0x01)==0x01)MODEM_LED1_HIGH;
- if(RedLedCt<RedLedFlash2)MODEM_LED1_HIGH;
- else MODEM_LED1_LOW;
- }
- //blue led control
- if(sucBlueLedFlash==0){ //낀췻
- MODEM_LED2_LOW;
- }else if(sucBlueLedSleep==0){//낀좋
- MODEM_LED2_HIGH;
- }else{
- if(LastBlueLedFlash!=sucBlueLedFlash || LastBlueLedSleep!=sucBlueLedSleep){
- RedLedCt=0;
- BlueLedCt=0;
- LastBlueLedFlash=sucBlueLedFlash;
- LastBlueLedSleep=sucBlueLedSleep;
- BlueLedFlash2=sucBlueLedFlash*2;
- BlueLedMaxCt=BlueLedFlash2+LastBlueLedSleep*2;
- }
- if(++BlueLedCt>BlueLedMaxCt)BlueLedCt=0;
- //if(BlueLedCt<BlueLedFlash2 && (BlueLedCt&0x01)==0x01)MODEM_LED2_HIGH;
- if(BlueLedCt<BlueLedFlash2)MODEM_LED2_HIGH;
- else MODEM_LED2_LOW;
- }
- }
- void SetRedLed(unsigned char flash,unsigned char sleep)
- {
- int t=(flash+sleep)*2;
- if(t>255){
- return;
- }
- sucRedLedFlash=flash;
- sucRedLedSleep=sleep;
- }
- void SetBlueLed(unsigned char flash,unsigned char sleep)
- {
- int t=(flash+sleep)*2;
- if(t>255){
- return;
- }
- sucBlueLedFlash=flash;
- sucBlueLedSleep=sleep;
- }
- void SetLedStatus(LED_STATUS LedStatus)
- {
- switch(LedStatus){
- case NotBright: //엇꼇좋
- SetRedLed(0,0);
- SetBlueLed(0,0);
- break;
- case RedBright: //븐됐끽좋
- SetRedLed(1,0);
- SetBlueLed(0,0);
- break;
- case RedFastFlash: //븐됐우�
- SetRedLed(1,1);
- SetBlueLed(0,0);
- break;
- case RedSlowFlash: //븐됐찹�
- SetRedLed(1,10);
- SetBlueLed(0,0);
- break;
- case BlueBright: //융됐끽좋
- SetRedLed(0,0);
- SetBlueLed(1,0);
- break;
- case BlueFastFlash: //융됐우�
- SetRedLed(0,0);
- SetBlueLed(1,1);
- break;
- case BlueSlowFlash: //융됐찹�
- SetRedLed(0,0);
- SetBlueLed(1,10);
- break;
- case RedBlueBright: //븐융끽좋
- SetRedLed(1,0);
- SetBlueLed(1,0);
- break;
- case RedBlueFastFlash: //븐융우�
- SetRedLed(1,1);
- SetBlueLed(1,1);
- break;
- case RedBlueSlowFlash: //븐융찹�
- SetRedLed(1,10);
- SetBlueLed(1,10);
- break;
- }
- }
- void SetLedIndicator(LED_INDICATOR LedInd)
- {
- switch(LedInd){
- case IndModemErr:
- g_LedInd=IndModemErr;
- SetLedStatus(RedBright);
- break;
- case IndNoNet:
- g_LedInd=IndNoNet;
- SetLedStatus(BlueFastFlash);
-
- break;
- case IndStandby:
- g_LedInd=IndStandby;
- SetLedStatus(BlueSlowFlash);
- break;
- case IndRX:
- g_LedInd=IndRX;
- SetLedStatus(BlueBright);
- break;
- case IndTX:
- g_LedInd=IndTX;
- SetLedStatus(RedBright);
- break;
- }
- }
|