detection.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /*********************************************************************************************************
  2. * Module : detection
  3. * Abstract :
  4. * Version : 1.0.0
  5. * Author : Leopul(COPYRIGHT 2025 ~ 2027 Leopul. All rights reserved.)
  6. * Complete : 2025-04-08
  7. * Content : None
  8. * Note : None
  9. *********************************************************************************************************/
  10. #include "detection.h"
  11. #include "gd32e23x.h"
  12. #include "common.h"
  13. #include "board_cfg.h"
  14. #include "relay.h"
  15. #define DERECTION_GPIO GPIOB
  16. #define DETECTION_1 GPIO_PIN_8
  17. #define DETECTION_2 GPIO_PIN_9
  18. static board_t *board = 0;
  19. static void get_detection(void);
  20. static void detection_opt(void);
  21. void detection_init(void)
  22. {
  23. board = get_board();
  24. rcu_periph_clock_enable(RCU_GPIOB);
  25. gpio_mode_set(DERECTION_GPIO, GPIO_MODE_INPUT, GPIO_PUPD_PULLUP, DETECTION_1 | DETECTION_2);
  26. board->detection = get_detection;
  27. board->opt_detection = detection_opt;
  28. }
  29. void key_init(void)
  30. {
  31. }
  32. static void get_detection()
  33. {
  34. if(board)
  35. {
  36. uint16_t data = 0;
  37. uint8_t val = 0;
  38. val = gpio_input_bit_get(DERECTION_GPIO,DETECTION_1);
  39. if(val== 0)
  40. {
  41. data |= (1 << 0);
  42. }
  43. #if SURPPORT_2_PT
  44. val = gpio_input_bit_get(DERECTION_GPIO,DETECTION_2);
  45. if(val== 0)
  46. {
  47. data |= (1 << 1);
  48. }
  49. #endif
  50. board->md_data.r_data.detection = data;
  51. }
  52. }
  53. static void detection_opt(void)
  54. {
  55. if(board)
  56. {
  57. #if RELAY_REMENBER
  58. if(board->md_data.r_data.detection & 0x1)
  59. {
  60. if(board->handle_input_pt[0] == 0)
  61. {
  62. board->handle_input_pt[0] = 1;
  63. for(uint8_t k = 0; k < PT_SUB_COUNT;k++)
  64. {
  65. async_data da = {0};
  66. da.channel =k;
  67. da.fire_or_zero = _FIRE;
  68. da.method = DELAY_CTRL;
  69. da.reg = &board->relay_staging_staus[k];
  70. da.status = board->handle_status[k];
  71. da.w_eep_flag = FLAG_N_W_EEP;
  72. set_relay_sta_async(&da);
  73. }
  74. }
  75. }else
  76. {
  77. if(board->handle_input_pt[0] == 1)
  78. {
  79. for(uint8_t k = 0; k < PT_SUB_COUNT;k++)
  80. {
  81. board->handle_status[k] = board->md_data.r_data.state.state[k].state;
  82. async_data da = {0};
  83. da.channel =k;
  84. da.fire_or_zero = _FIRE;
  85. da.method = PROMPT_CTRL;
  86. da.reg = &board->relay_staging_staus[k];
  87. da.status = RELAY_CLOSE;
  88. da.w_eep_flag = FLAG_N_W_EEP;
  89. set_relay_sta_async(&da);
  90. }
  91. board->handle_input_pt[0] = 0;
  92. }
  93. }
  94. #if SURPPORT_2_PT
  95. if(board->md_data.r_data.detection & 0x2)
  96. {
  97. if(board->handle_input_pt[1] == 0)
  98. {
  99. board->handle_input_pt[1] = 1;
  100. for(uint8_t k = PT_SUB_COUNT; k < RelaySlaveChaNum;k++)
  101. {
  102. async_data da = {0};
  103. da.channel =k;
  104. da.fire_or_zero = _FIRE;
  105. da.method = DELAY_CTRL;
  106. da.reg = &board->relay_staging_staus[k];
  107. da.status = board->handle_status[k];
  108. da.w_eep_flag = FLAG_N_W_EEP;
  109. set_relay_sta_async(&da);
  110. }
  111. }
  112. }else
  113. {
  114. if(board->handle_input_pt[1] == 1)
  115. {
  116. for(uint8_t k = PT_SUB_COUNT; k < RelaySlaveChaNum;k++)
  117. {
  118. board->handle_status[k] = board->md_data.r_data.state.state[k].state;
  119. async_data da = {0};
  120. da.channel =k;
  121. da.fire_or_zero = _FIRE;
  122. da.method = PROMPT_CTRL;
  123. da.reg = &board->relay_staging_staus[k];
  124. da.status = RELAY_CLOSE;
  125. da.w_eep_flag = FLAG_N_W_EEP;
  126. set_relay_sta_async(&da);
  127. }
  128. board->handle_input_pt[1] = 0;
  129. }
  130. }
  131. #endif
  132. #endif
  133. }
  134. }