process.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. printf("AirControlBox RUNLED_TOGGLE \r\n");
  36. RUNLED_TOGGLE;
  37. }
  38. }
  39. void Process_ThreeStatus(void)
  40. {
  41. if(g_detectTime >= STATUS_DETECTINTERVAL){
  42. g_detectTime = 0;
  43. /*
  44. if (GPIO_LEVEL_HIGH == GPIO_GetPinLevel(GPIO_CLOSE_KEY)){
  45. lockbits=(lockbits<<1)|0x01;
  46. }else{
  47. lockbits=(lockbits<<1)|0x00;
  48. }
  49. if (GPIO_LEVEL_HIGH == GPIO_GetPinLevel(GPIO_OPEN_KEY)){
  50. unlockbits=(unlockbits<<1)|0x01;
  51. }else{
  52. unlockbits=(unlockbits<<1)|0x00;
  53. }
  54. if (GPIO_LEVEL_HIGH == GPIO_GetPinLevel(GPIO_COVER_KEY)){
  55. coverbits=(coverbits<<1)|0x01;
  56. }else{
  57. coverbits=(coverbits<<1)|0x00;
  58. }
  59. if(g_lockstatus == STATUS_CLOSE && lockbits == 0xFF){
  60. g_lockstatus = STATUS_OPEN;
  61. }else if(g_lockstatus == STATUS_OPEN && lockbits == 0x00){
  62. g_lockstatus = STATUS_CLOSE;
  63. }
  64. if(g_unlockstatus == STATUS_CLOSE && unlockbits == 0xFF){
  65. g_unlockstatus = STATUS_OPEN;
  66. }else if(g_unlockstatus == STATUS_OPEN && unlockbits == 0x00){
  67. g_unlockstatus = STATUS_CLOSE;
  68. }
  69. if(g_coverstatus == STATUS_CLOSE && coverbits == 0xFF){
  70. g_coverstatus = STATUS_OPEN;
  71. }else if(g_coverstatus == STATUS_OPEN && coverbits == 0x00){
  72. g_coverstatus = STATUS_CLOSE;
  73. }
  74. */
  75. }
  76. }
  77. uint8_t Process_LockStatus(void)
  78. {
  79. return g_lockstatus;
  80. }
  81. uint8_t Process_UnlockStatus(void)
  82. {
  83. return g_unlockstatus;
  84. }
  85. uint8_t Process_CoverStatus(void)
  86. {
  87. return g_coverstatus;
  88. }