#include "process.h" #include "gpio.h" #include "ac780x_gpio.h" uint16_t g_blinkLedTime; /*LED闪烁频率控制时间*/ uint16_t g_blinkLedTgtTime; /*LED目标闪烁频率*/ uint8_t g_detectTime; /*三个开关状态,检测时间*/ #define STATUS_DETECTINTERVAL (60) /*60ms * 8 == 500ms */ uint8_t g_lockstatus; uint8_t g_unlockstatus; uint8_t g_coverstatus; uint8_t lockbits; uint8_t unlockbits; uint8_t coverbits; void Process_Init(void) { /*初始化控制变量.*/ g_blinkLedTime = 0; g_blinkLedTgtTime = BLINK_LED_DFTT; g_detectTime = 0; g_lockstatus = GPIO_LEVEL_HIGH == GPIO_GetPinLevel(GPIO_CLOSE_KEY)? STATUS_OPEN:STATUS_CLOSE; g_unlockstatus = GPIO_LEVEL_HIGH == GPIO_GetPinLevel(GPIO_OPEN_KEY)? STATUS_OPEN:STATUS_CLOSE; g_coverstatus = GPIO_LEVEL_HIGH == GPIO_GetPinLevel(GPIO_COVER_KEY)? STATUS_OPEN:STATUS_CLOSE; lockbits = g_lockstatus == STATUS_OPEN?0xFF:0x00; unlockbits = g_unlockstatus == STATUS_OPEN?0xFF:0x00; coverbits = g_coverstatus == STATUS_OPEN?0xFF:0x00; /*上电默认LED点亮.*/ RUNLED_ON; } void Process_RunLedPrd(void) { /*周期性地检查LED闪烁,LED2和LED3同时闪烁.*/ if (g_blinkLedTime >= g_blinkLedTgtTime) { g_blinkLedTime = 0; RUNLED_TOGGLE; } } void Process_ThreeStatus(void) { if(g_detectTime >= STATUS_DETECTINTERVAL){ g_detectTime = 0; if (GPIO_LEVEL_HIGH == GPIO_GetPinLevel(GPIO_CLOSE_KEY)){ lockbits=(lockbits<<1)|0x01; }else{ lockbits=(lockbits<<1)|0x00; } if (GPIO_LEVEL_HIGH == GPIO_GetPinLevel(GPIO_OPEN_KEY)){ unlockbits=(unlockbits<<1)|0x01; }else{ unlockbits=(unlockbits<<1)|0x00; } if (GPIO_LEVEL_HIGH == GPIO_GetPinLevel(GPIO_COVER_KEY)){ coverbits=(coverbits<<1)|0x01; }else{ coverbits=(coverbits<<1)|0x00; } if(g_lockstatus == STATUS_CLOSE && lockbits == 0xFF){ g_lockstatus = STATUS_OPEN; }else if(g_lockstatus == STATUS_OPEN && lockbits == 0x00){ g_lockstatus = STATUS_CLOSE; } if(g_unlockstatus == STATUS_CLOSE && unlockbits == 0xFF){ g_unlockstatus = STATUS_OPEN; }else if(g_unlockstatus == STATUS_OPEN && unlockbits == 0x00){ g_unlockstatus = STATUS_CLOSE; } if(g_coverstatus == STATUS_CLOSE && coverbits == 0xFF){ g_coverstatus = STATUS_OPEN; }else if(g_coverstatus == STATUS_OPEN && coverbits == 0x00){ g_coverstatus = STATUS_CLOSE; } } } uint8_t Process_LockStatus(void) { return g_lockstatus; } uint8_t Process_UnlockStatus(void) { return g_unlockstatus; } uint8_t Process_CoverStatus(void) { return g_coverstatus; }