123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- #include "uio.h"
- #include "board.h"
- volatile unsigned char uiosBitStatus;
- unsigned char gtFlashSpeed=20;
- UIO_SWENUM uiosCtl[UIO_MAX];
- short uioTick[UIO_MAX];
- static void uioUpdateStatus(UIO_TYPEENUM uioType, UIO_STATUSENUM newStatus);
- static void newIoStatus(UIO_TYPEENUM value,UIO_SWENUM swType)
- {
- if(swType == uiosCtl[value]) return;
- uiosCtl[value]=swType;
- ;
- switch (uiosCtl[value])
- {
- case UIO_SW_KEEP_HIGH://保持常高
- case UIO_SW_KEEP_LOW: //保持常低
- uioTick[value]=0;
- break;
- case UIO_SW_FLASH_FAST:
- uioTick[value]=gtFlashSpeed;
- break;
- case UIO_SW_FLASH_SLOW:
- uioTick[value]=50;
- break;
-
- }
- uioUpdateStatus(value,UIO_LOW);//切换状态后让灯先灭
- }
- void uioStatusSet(UIO_INDENUM status){
- switch(status){
- case UIO_INDRX:
- newIoStatus(UIO_LED_RED, UIO_SW_KEEP_LOW);
- newIoStatus(UIO_LED_GREEN, UIO_SW_KEEP_HIGH);
- break;
- case UIO_INDTX:
- newIoStatus(UIO_LED_RED, UIO_SW_KEEP_HIGH);
- newIoStatus(UIO_LED_GREEN, UIO_SW_KEEP_LOW);
- break;
- case UIO_INDGT:
- gtFlashSpeed=10;
- newIoStatus(UIO_LED_RED, UIO_SW_FLASH_FAST);
- newIoStatus(UIO_LED_GREEN, UIO_SW_FLASH_FAST);
- uioTick[UIO_LED_GREEN]=gtFlashSpeed/2;//GT模式下经绿灯快闪错开一下
- break;
- case UIO_INDONLINE:
- newIoStatus(UIO_LED_RED, UIO_SW_KEEP_LOW);
- newIoStatus(UIO_LED_GREEN, UIO_SW_FLASH_SLOW);
- break;
- case UIO_INDOFFLINE:
- newIoStatus(UIO_LED_RED, UIO_SW_KEEP_LOW);
- newIoStatus(UIO_LED_GREEN, UIO_SW_FLASH_FAST);
- break;
- }
- }
- void uioStatusInit(void){
- newIoStatus(UIO_LED_RED, UIO_SW_KEEP_HIGH);
- newIoStatus(UIO_LED_GREEN, UIO_SW_KEEP_LOW);
- }
- static void uioUpdateStatus(UIO_TYPEENUM uioType, UIO_STATUSENUM newStatus){
- UIO_STATUSENUM lastBitStatus;
- if(uiosBitStatus & (1<<uioType)==0) lastBitStatus=UIO_LOW;
- else lastBitStatus=UIO_HIGH;
-
- switch(uioType){
- case UIO_LED_GREEN:
- greenLedCtl(newStatus);
-
- break;
- case UIO_LED_RED:
- redLedCtl(newStatus);
- break;
- default:return;
- }
-
- if(UIO_LOW==newStatus) uiosBitStatus &= ~(1<<uioType);
- else uiosBitStatus |= (1<<uioType);
- }
- /*定时被调用接口:dlyTime ms*/
- void uioProctl(unsigned int dlyTime){
- unsigned char i;
- static UIO_STATUSENUM lastStatus[UIO_MAX];
- for(i=0;i<UIO_MAX;i++){
- switch(uiosCtl[i]){
- case UIO_SW_KEEP_HIGH:
- uioUpdateStatus(i,UIO_HIGH);
- lastStatus[i]=UIO_HIGH;
- break;
- case UIO_SW_KEEP_LOW:
- uioUpdateStatus(i,UIO_LOW);
- lastStatus[i]=UIO_LOW;
- break;
- case UIO_SW_FLASH_FAST:
- if(uioTick[i]==0){
- if(lastStatus[i]==UIO_LOW){
- lastStatus[i]=UIO_HIGH;
- uioTick[i]=1;
- }else{
- lastStatus[i]=UIO_LOW;
- uioTick[i]=gtFlashSpeed;
- }
- uioUpdateStatus(i, lastStatus[i]);
- }else --uioTick[i];
- break;
- case UIO_SW_FLASH_SLOW:
- if(dlyTime<=100){//非休眠时灯的操作(休眠时会进入)
- if(uioTick[i]==0){
- if(lastStatus[i]==UIO_LOW){
- lastStatus[i]=UIO_HIGH;
- uioTick[i]=1;
- }else{
- lastStatus[i]=UIO_LOW;
- uioTick[i]=50;
- }
- uioUpdateStatus(i, lastStatus[i]);
- }else --uioTick[i];
- }else{//休眠时灯的操作
- //亮一会
- uioUpdateStatus(i, UIO_HIGH);
- LSAPI_OSI_ThreadSleep(100);
- uioUpdateStatus(i, UIO_LOW);
- }
- break;
- }
- }
- }
|