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.

177 lines
9.7 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
11 months ago
12 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
12 months ago
11 months ago
12 months ago
11 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. // kAirLeakTestMode_disinfection
  121. // kAirLeakTestMode_inflation
  122. // kAirLeakTestMode_leakTest
  123. if (PORT::isLiquidCtrlBoard() && (PORT::isPipeDM())) {
  124. static air_leak_test_mode_t airLeakTestMode = kAirLeakTestMode_disinfection;
  125. static ZGPIO eValve0;
  126. static ZGPIO eValve1;
  127. static ZGPIO eValve2;
  128. eValve0.initAsOutput(PD14, kxs_gpio_nopull, true, false);
  129. eValve1.initAsOutput(PD15, kxs_gpio_nopull, true, false);
  130. eValve2.initAsOutput(PC6, kxs_gpio_nopull, true, false); // 空气通道电磁阀
  131. REG_LAMADA_FN(kfn_air_leak_test_set_mode, [&](ProcessContext* cxt) {
  132. if (GET_PARAM(0) == kAirLeakTestMode_disinfection) {
  133. eValve2.write(0); // 内管路
  134. eValve0.write(0); // 联通
  135. eValve1.write(0); // 联通
  136. } else if (GET_PARAM(0) == kAirLeakTestMode_inflation) {
  137. eValve2.write(1); // 联通空气
  138. eValve0.write(0); // 联通
  139. eValve1.write(0); // 联通
  140. } else if (GET_PARAM(0) == kAirLeakTestMode_leakTest) {
  141. eValve2.write(0); // 内管路
  142. eValve0.write(1); // 封闭
  143. eValve1.write(1); // 封闭
  144. }
  145. airLeakTestMode = (air_leak_test_mode_t)GET_PARAM(0);
  146. zcanbus_send_ack(cxt->packet, NULL, 0);
  147. });
  148. REG_LAMADA_FN(kfn_air_leak_test_get_mode, [&](ProcessContext* cxt) {
  149. int32_t mode = airLeakTestMode;
  150. zcanbus_send_ack(cxt->packet, mode);
  151. });
  152. }
  153. }
  154. /***********************************************************************************************************************
  155. * PROTOCOL_BIND *
  156. ***********************************************************************************************************************/