main.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. #include "gd32e230x_conf.h"
  2. #include "main.h"
  3. #include "SysTick.h"
  4. #include "Relay.h"
  5. #include "Key.h"
  6. #include "Led.h"
  7. #include "Timer.h"
  8. #include "Electricity.h"
  9. #include "Temprature.h"
  10. #include "Beep.h"
  11. #include "Fan.h"
  12. #include "Exti.h"
  13. #include "At24xx.h"
  14. #include "Fwdgt.h"
  15. #include "Mb.h"
  16. sts_data_t sts_data;
  17. sts_data_t *get_sts(void)
  18. {
  19. return &sts_data;
  20. }
  21. int main()
  22. {
  23. InitSysTick();
  24. InitKey();
  25. InitLED();
  26. InitTimer();
  27. fans_init();
  28. beep_init();
  29. temp_init();
  30. at24xx_init();
  31. electricity_init();
  32. sts_exti_init();
  33. uint8_t md_addr = ReadKeyValue();
  34. eMBInit(MB_RTU,md_addr,0,115200,MB_PAR_NONE);
  35. eMBEnable();
  36. Fwdgt_Init();
  37. sts_data.read_input_level(INPUT_CHANNEL_1);
  38. sts_data.read_input_level(INPUT_CHANNEL_2);
  39. sts_data.read_switch_level();
  40. if(sts_data.switch_status == INPUT_CHANNEL_1 &&
  41. sts_data.m_data.input_status.input_status[INPUT_CHANNEL_1])
  42. {
  43. sts_data.choise_input(INPUT_CHANNEL_1);
  44. }else
  45. {
  46. sts_data.choise_input(INPUT_CHANNEL_2);
  47. }
  48. if(sts_data.m_data.out_status)
  49. {
  50. sts_data.open_output();
  51. }else
  52. {
  53. sts_data.close_output();
  54. }
  55. uint8_t channel = CH448_CHANNEL_1;
  56. while(1){
  57. Fwdgt_reload();
  58. eMBPoll();
  59. // read consumer
  60. if(sts_data.led_flag)
  61. {
  62. sts_data.led_flag = 0;
  63. sts_data.led_flash();
  64. if(sts_data.beep_flag)
  65. {
  66. sts_data.beep();
  67. }
  68. }
  69. if(sts_data.read_ele_flag)
  70. {
  71. sts_data.read_ele_flag = 0;
  72. sts_data.read_ele(channel);
  73. //
  74. sts_data.check_wanning(channel);
  75. channel ++;
  76. }
  77. if(channel == CH448_CHANNEL_3)
  78. {
  79. //check input and is or not swtict input
  80. if((sts_data.m_data.input_status.input_status[INPUT_CHANNEL_1]) &&
  81. (sts_data.m_data.input_status.input_status[INPUT_CHANNEL_2]))
  82. {
  83. sts_data.beep_flag = 0;
  84. if(sts_data.m_data.md_choise.choise_ch == INPUT_CHANNEL_1)
  85. {
  86. if(STS_INPUT_HAS_WANNING(sts_data.m_data.input_wanning.waning[INPUT_CHANNEL_1]))
  87. {
  88. if(STS_INPUT_HAS_WANNING(sts_data.m_data.input_wanning.waning[INPUT_CHANNEL_2]))
  89. {
  90. sts_data.close_output();
  91. }else
  92. {
  93. sts_data.choise_input(INPUT_CHANNEL_2);
  94. }
  95. }
  96. }else if(sts_data.m_data.md_choise.choise_ch == INPUT_CHANNEL_2)
  97. {
  98. if(STS_INPUT_HAS_WANNING(sts_data.m_data.input_wanning.waning[INPUT_CHANNEL_1]))
  99. {
  100. sts_data.close_output();
  101. }else {
  102. sts_data.choise_input(INPUT_CHANNEL_1);
  103. }
  104. }else
  105. {
  106. ;
  107. }
  108. }else if((sts_data.m_data.input_status.input_status[INPUT_CHANNEL_1]) )
  109. {
  110. sts_data.beep_flag = 1;
  111. if(STS_INPUT_HAS_WANNING(sts_data.m_data.input_wanning.waning[INPUT_CHANNEL_1]))
  112. {
  113. sts_data.close_output();
  114. }
  115. }else if((sts_data.m_data.input_status.input_status[INPUT_CHANNEL_2]) ){
  116. sts_data.beep_flag = 1;
  117. if(STS_INPUT_HAS_WANNING(sts_data.m_data.input_wanning.waning[INPUT_CHANNEL_2]))
  118. {
  119. sts_data.close_output();
  120. }
  121. }
  122. channel = CH448_CHANNEL_1;
  123. }
  124. }
  125. return 0;
  126. }