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.

160 lines
9.1 KiB

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