You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

164 lines
9.3 KiB

12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
  1. #include "dmapp.hpp"
  2. #include "board/hal/zhal_initer.hpp"
  3. /**
  4. * @brief
  5. *
  6. * -----
  7. *
  8. * :
  9. * 1.
  10. * 2.
  11. *
  12. * :
  13. * 1. ()
  14. * ------
  15. *
  16. *
  17. */
  18. using namespace iflytop;
  19. using namespace transmit_disfection_protocol;
  20. #define TAG "DMAPP"
  21. DisinfectionApp* DisinfectionApp::ins() {
  22. static DisinfectionApp instance;
  23. return &instance;
  24. }
  25. const char* DisinfectionApp::getName() { return "DisinfectionApp"; }
  26. void DisinfectionApp::initialize() {
  27. int btid = PublicBoard::ins()->getBoardTypeId();
  28. // only support
  29. // large space disinfection machine,
  30. // small space disinfection machine,
  31. // pipe disinfection machine,
  32. ZASSERT(PORT::isLargeSpaceDM() || PORT::isSamllSpaceDM() || PORT::isPipeDM());
  33. /***********************************************************************************************************************
  34. * *
  35. ***********************************************************************************************************************/
  36. if (PORT::isPowerCtrlBoard() && (PORT::isLargeSpaceDM() || PORT::isSamllSpaceDM() || PORT::isPipeDM())) {
  37. LargeSpaceDmPowerCtrlBoardHal::HADC1_INIT();
  38. heaterCtrler.initialize(PC7, &hadc1, ADC_CHANNEL_2, &hadc1, ADC_CHANNEL_9);
  39. }
  40. /***********************************************************************************************************************
  41. * *
  42. ***********************************************************************************************************************/
  43. if (PORT::isPowerCtrlBoard() && (PORT::isLargeSpaceDM() || PORT::isSamllSpaceDM())) {
  44. LargeSpaceDmPowerCtrlBoardHal::HADC1_INIT();
  45. blowerCtrler.initialize(PC5, &hadc1, ADC_CHANNEL_1);
  46. } //
  47. else if (PORT::isPowerCtrlBoard() && (PORT::isPipeDM())) {
  48. LargeSpaceDmPowerCtrlBoardHal::HADC1_INIT();
  49. LargeSpaceDmPowerCtrlBoardHal::HUART2_INIT(9600, UART_STOPBITS_1);
  50. blowerCtrler.initializeAsHighPowerUartBlower(PC5, &huart2, &hadc1, ADC_CHANNEL_1);
  51. }
  52. /***********************************************************************************************************************
  53. * *
  54. ***********************************************************************************************************************/
  55. if (PORT::isPowerCtrlBoard() && (PORT::isLargeSpaceDM() || PORT::isSamllSpaceDM() || PORT::isPipeDM())) {
  56. LargeSpaceDmPowerCtrlBoardHal::HADC1_INIT();
  57. airComCtrler.initialize(PC3, &hadc1, ADC_CHANNEL_0);
  58. }
  59. /***********************************************************************************************************************
  60. * *
  61. ***********************************************************************************************************************/
  62. // null
  63. //
  64. /***********************************************************************************************************************
  65. * H2O2传感器 *
  66. ***********************************************************************************************************************/
  67. if (PORT::isPowerCtrlBoard() && (PORT::isLargeSpaceDM() || PORT::isSamllSpaceDM() || PORT::isPipeDM())) {
  68. LargeSpaceDmPowerCtrlBoardHal::HUART3_INIT(19200, UART_STOPBITS_2);
  69. LargeSpaceDmPowerCtrlBoardHal::HADC1_INIT();
  70. osDelay(3000);
  71. h2o2Sensor.initialize(&huart3, &hadc1, ADC_CHANNEL_3);
  72. }
  73. /***********************************************************************************************************************
  74. * *
  75. ***********************************************************************************************************************/
  76. if (PORT::isLiquidCtrlBoard() && (PORT::isLargeSpaceDM() || PORT::isSamllSpaceDM() || PORT::isPipeDM())) {
  77. ZLOGI(TAG, "WaterSensor init");
  78. evaporationBinWS.initAsInput(PC7, kxs_gpio_nopull, kxs_gpio_no_irq, false /*mirror*/);
  79. deviceBottomWS.initAsInput(PC8, kxs_gpio_nopull, kxs_gpio_no_irq, false /*mirror*/);
  80. REG_LAMADA_FN(kfn_device_bottom_water_sensor_read_state, [&](ProcessContext* cxt) { zcanbus_send_ack(cxt->packet, deviceBottomWS.read()); });
  81. REG_LAMADA_FN(kfn_evaporation_tank_water_sensor_read_state, [&](ProcessContext* cxt) { zcanbus_send_ack(cxt->packet, evaporationBinWS.read()); });
  82. }
  83. /***********************************************************************************************************************
  84. * TMC电机初始化 *
  85. ***********************************************************************************************************************/
  86. if (PORT::isLiquidCtrlBoard() && (PORT::isLargeSpaceDM() || PORT::isSamllSpaceDM() || PORT::isPipeDM())) {
  87. // TMC电机初始化
  88. ZLOGI(TAG, "TMCMotorGroup init");
  89. LargeSpaceDMLiquidCtrlBoardHal::HSPI1_INIT();
  90. tmcPowerGroup.initialize(PB2, {&hspi1, PA4 /*cs*/, PB12 /*en*/}, {&hspi1, PC4 /*cs*/, PB13 /*en*/});
  91. }
  92. /***********************************************************************************************************************
  93. * *
  94. ***********************************************************************************************************************/
  95. if (PORT::isLiquidCtrlBoard() && (PORT::isLargeSpaceDM() || PORT::isSamllSpaceDM() || PORT::isPipeDM())) {
  96. // 三色指示灯初始化
  97. ZLOGI(TAG, "WarningLightDriver init");
  98. wlDriver.initialize(PD8, PD7, PD9, PD10);
  99. }
  100. /***********************************************************************************************************************
  101. * *
  102. ***********************************************************************************************************************/
  103. if (PORT::isLiquidCtrlBoard() && (PORT::isLargeSpaceDM() || PORT::isSamllSpaceDM() || PORT::isPipeDM())) {
  104. ZLOGI(TAG, "PXXPSBus init");
  105. osDelay(1500); // 等待传感器上电
  106. LargeSpaceDMLiquidCtrlBoardHal::HUART3_INIT(9600, UART_STOPBITS_1);
  107. psBus.initialize(&huart3);
  108. }
  109. /***********************************************************************************************************************
  110. * *
  111. ***********************************************************************************************************************/
  112. if (PORT::isLiquidCtrlBoard() && (PORT::isPipeDM())) {
  113. ZLOGI(TAG, "ProportionalValveCtrl init");
  114. ZHALIniter::HUART2_INIT(PD5, PD6, 9600, UART_STOPBITS_1);
  115. proportionalValveCtrl.initialize(&huart2);
  116. }
  117. /***********************************************************************************************************************
  118. * *
  119. ***********************************************************************************************************************/
  120. if (PORT::isLiquidCtrlBoard() && (PORT::isPipeDM())) {
  121. static ZGPIO airTightnessTestChGpio;
  122. static ZGPIO eValve0;
  123. static ZGPIO eValve1;
  124. static bool state = false;
  125. airTightnessTestChGpio.initAsOutput(PD14, kxs_gpio_nopull, true, false);
  126. eValve0.initAsOutput(PD15, kxs_gpio_nopull, false, true);
  127. eValve1.initAsOutput(PC6, kxs_gpio_nopull, false, true);
  128. REG_LAMADA_FN(kfn_air_leak_detect_test_set_mode, [&](ProcessContext* cxt) {
  129. if (GET_PARAM(0) == 1) {
  130. airTightnessTestChGpio.write(1); // 内管路,气密性测试
  131. eValve0.write(0);
  132. eValve1.write(0); // 电磁阀闭合
  133. state = true;
  134. } else {
  135. airTightnessTestChGpio.write(0); // 连接空气
  136. eValve0.write(1);
  137. eValve1.write(1); // 电磁阀打开
  138. state = false;
  139. }
  140. zcanbus_send_ack(cxt->packet, NULL, 0);
  141. });
  142. REG_LAMADA_FN(kfn_air_tightness_test_get_mode, [&](ProcessContext* cxt) { zcanbus_send_ack(cxt->packet, state); });
  143. }
  144. }
  145. /***********************************************************************************************************************
  146. * PROTOCOL_BIND *
  147. ***********************************************************************************************************************/