process.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. #include "process.h"
  2. #include "gpio.h"
  3. #include "ac780x_gpio.h"
  4. uint16_t g_blinkLedTime; /*LED闪烁频率控制时间*/
  5. uint16_t g_blinkLedTgtTime; /*LED目标闪烁频率*/
  6. uint8_t g_detectTime; /*三个开关状态,检测时间*/
  7. #define STATUS_DETECTINTERVAL (60) /*60ms * 8 == 500ms */
  8. uint8_t g_lockstatus;
  9. uint8_t g_unlockstatus;
  10. uint8_t g_coverstatus;
  11. uint8_t lockbits;
  12. uint8_t unlockbits;
  13. uint8_t coverbits;
  14. void Process_Init(void)
  15. {
  16. /*初始化控制变量.*/
  17. g_blinkLedTime = 0;
  18. g_blinkLedTgtTime = BLINK_LED_DFTT;
  19. g_detectTime = 0;
  20. g_lockstatus = GPIO_LEVEL_HIGH == GPIO_GetPinLevel(GPIO_CLOSE_KEY)? STATUS_OPEN:STATUS_CLOSE;
  21. g_unlockstatus = GPIO_LEVEL_HIGH == GPIO_GetPinLevel(GPIO_OPEN_KEY)? STATUS_OPEN:STATUS_CLOSE;
  22. g_coverstatus = GPIO_LEVEL_HIGH == GPIO_GetPinLevel(GPIO_COVER_KEY)? STATUS_OPEN:STATUS_CLOSE;
  23. lockbits = g_lockstatus == STATUS_OPEN?0xFF:0x00;
  24. unlockbits = g_unlockstatus == STATUS_OPEN?0xFF:0x00;
  25. coverbits = g_coverstatus == STATUS_OPEN?0xFF:0x00;
  26. /*上电默认LED点亮.*/
  27. RUNLED_ON;
  28. }
  29. void Process_RunLedPrd(void)
  30. {
  31. /*周期性地检查LED闪烁,LED2和LED3同时闪烁.*/
  32. if (g_blinkLedTime >= g_blinkLedTgtTime)
  33. {
  34. g_blinkLedTime = 0;
  35. RUNLED_TOGGLE;
  36. }
  37. }
  38. void Process_ThreeStatus(void)
  39. {
  40. if(g_detectTime >= STATUS_DETECTINTERVAL){
  41. g_detectTime = 0;
  42. if (GPIO_LEVEL_HIGH == GPIO_GetPinLevel(GPIO_CLOSE_KEY)){
  43. lockbits=(lockbits<<1)|0x01;
  44. }else{
  45. lockbits=(lockbits<<1)|0x00;
  46. }
  47. if (GPIO_LEVEL_HIGH == GPIO_GetPinLevel(GPIO_OPEN_KEY)){
  48. unlockbits=(unlockbits<<1)|0x01;
  49. }else{
  50. unlockbits=(unlockbits<<1)|0x00;
  51. }
  52. if (GPIO_LEVEL_HIGH == GPIO_GetPinLevel(GPIO_COVER_KEY)){
  53. coverbits=(coverbits<<1)|0x01;
  54. }else{
  55. coverbits=(coverbits<<1)|0x00;
  56. }
  57. if(g_lockstatus == STATUS_CLOSE && lockbits == 0xFF){
  58. g_lockstatus = STATUS_OPEN;
  59. }else if(g_lockstatus == STATUS_OPEN && lockbits == 0x00){
  60. g_lockstatus = STATUS_CLOSE;
  61. }
  62. if(g_unlockstatus == STATUS_CLOSE && unlockbits == 0xFF){
  63. g_unlockstatus = STATUS_OPEN;
  64. }else if(g_unlockstatus == STATUS_OPEN && unlockbits == 0x00){
  65. g_unlockstatus = STATUS_CLOSE;
  66. }
  67. if(g_coverstatus == STATUS_CLOSE && coverbits == 0xFF){
  68. g_coverstatus = STATUS_OPEN;
  69. }else if(g_coverstatus == STATUS_OPEN && coverbits == 0x00){
  70. g_coverstatus = STATUS_CLOSE;
  71. }
  72. }
  73. }
  74. uint8_t Process_LockStatus(void)
  75. {
  76. return g_lockstatus;
  77. }
  78. uint8_t Process_UnlockStatus(void)
  79. {
  80. return g_unlockstatus;
  81. }
  82. uint8_t Process_CoverStatus(void)
  83. {
  84. return g_coverstatus;
  85. }