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.

229 lines
11 KiB

12 months ago
11 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
11 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
9 months ago
9 months ago
8 months ago
9 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. // DT600B,
  33. ZASSERT(PORT::isLargeSpaceDM() || PORT::isSamllSpaceDM() || PORT::isPipeDM() || PORT::isDT600B());
  34. /***********************************************************************************************************************
  35. * *
  36. ***********************************************************************************************************************/
  37. if (PORT::isPowerCtrlBoard() && (PORT::isLargeSpaceDM() || PORT::isSamllSpaceDM() || PORT::isPipeDM() || PORT::isDT600B())) {
  38. LargeSpaceDmPowerCtrlBoardHal::HADC1_INIT();
  39. heaterCtrler.initialize(PC7, &hadc1, ADC_CHANNEL_2, &hadc1, ADC_CHANNEL_9);
  40. }
  41. /***********************************************************************************************************************
  42. * *
  43. ***********************************************************************************************************************/
  44. if (PORT::isPowerCtrlBoard() && (PORT::isLargeSpaceDM() || PORT::isSamllSpaceDM() || PORT::isDT600B())) {
  45. LargeSpaceDmPowerCtrlBoardHal::HADC1_INIT();
  46. blowerCtrler.initialize(PC5, &hadc1, ADC_CHANNEL_1);
  47. } //
  48. else if (PORT::isPowerCtrlBoard() && (PORT::isPipeDM())) {
  49. LargeSpaceDmPowerCtrlBoardHal::HADC1_INIT();
  50. LargeSpaceDmPowerCtrlBoardHal::HUART2_INIT(9600, UART_STOPBITS_1);
  51. blowerCtrler.initializeAsHighPowerUartBlower(PC5, &huart2, &hadc1, ADC_CHANNEL_1);
  52. }
  53. /***********************************************************************************************************************
  54. * *
  55. ***********************************************************************************************************************/
  56. if (PORT::isPowerCtrlBoard() && (PORT::isLargeSpaceDM() || PORT::isSamllSpaceDM() || PORT::isPipeDM() || PORT::isDT600B())) {
  57. LargeSpaceDmPowerCtrlBoardHal::HADC1_INIT();
  58. airComCtrler.initialize(PC3, &hadc1, ADC_CHANNEL_0);
  59. }
  60. /***********************************************************************************************************************
  61. * *
  62. ***********************************************************************************************************************/
  63. // null
  64. //
  65. /***********************************************************************************************************************
  66. * H2O2传感器 *
  67. ***********************************************************************************************************************/
  68. if (PORT::isPowerCtrlBoard() && (PORT::isLargeSpaceDM() || PORT::isSamllSpaceDM() || PORT::isPipeDM() || PORT::isDT600B())) {
  69. LargeSpaceDmPowerCtrlBoardHal::HUART3_INIT(19200, UART_STOPBITS_2);
  70. LargeSpaceDmPowerCtrlBoardHal::HADC1_INIT();
  71. osDelay(3000);
  72. h2o2Sensor.initialize(&huart3, &hadc1, ADC_CHANNEL_3);
  73. }
  74. /***********************************************************************************************************************
  75. * *
  76. ***********************************************************************************************************************/
  77. if (PORT::isLiquidCtrlBoard() && (PORT::isLargeSpaceDM() || PORT::isSamllSpaceDM() || PORT::isPipeDM() || PORT::isDT600B())) {
  78. ZLOGI(TAG, "WaterSensor init");
  79. evaporationBinWS.initAsInput(PC7, kxs_gpio_nopull, kxs_gpio_no_irq, false /*mirror*/);
  80. deviceBottomWS.initAsInput(PC8, kxs_gpio_nopull, kxs_gpio_no_irq, false /*mirror*/);
  81. REG_LAMADA_FN(kfn_device_bottom_water_sensor_read_state, [&](ProcessContext* cxt) { zcanbus_send_ack(cxt->packet, deviceBottomWS.read()); });
  82. REG_LAMADA_FN(kfn_evaporation_tank_water_sensor_read_state, [&](ProcessContext* cxt) { zcanbus_send_ack(cxt->packet, evaporationBinWS.read()); });
  83. }
  84. /***********************************************************************************************************************
  85. * TMC电机初始化 *
  86. ***********************************************************************************************************************/
  87. if (PORT::isLiquidCtrlBoard() && (PORT::isLargeSpaceDM() || PORT::isSamllSpaceDM() || PORT::isPipeDM() || PORT::isDT600B())) {
  88. // TMC电机初始化
  89. ZLOGI(TAG, "TMCMotorGroup init");
  90. LargeSpaceDMLiquidCtrlBoardHal::HSPI1_INIT();
  91. tmcPowerGroup.initialize(PB2, {&hspi1, PA4 /*cs*/, PB12 /*en*/}, {&hspi1, PC4 /*cs*/, PB13 /*en*/});
  92. }
  93. /***********************************************************************************************************************
  94. * *
  95. ***********************************************************************************************************************/
  96. if (PORT::isLiquidCtrlBoard() && (PORT::isLargeSpaceDM() || PORT::isSamllSpaceDM() || PORT::isPipeDM() || PORT::isDT600B())) {
  97. // 三色指示灯初始化
  98. ZLOGI(TAG, "WarningLightDriver init");
  99. wlDriver.initialize(PD8, PD7, PD9, PD10);
  100. }
  101. /***********************************************************************************************************************
  102. * *
  103. ***********************************************************************************************************************/
  104. if (PORT::isLiquidCtrlBoard() && (PORT::isLargeSpaceDM() || PORT::isSamllSpaceDM() || PORT::isPipeDM())) {
  105. ZLOGI(TAG, "PXXPSBus init");
  106. osDelay(1500); // 等待传感器上电
  107. LargeSpaceDMLiquidCtrlBoardHal::HUART3_INIT(9600, UART_STOPBITS_1);
  108. psBus.initialize(&huart3);
  109. }
  110. /***********************************************************************************************************************
  111. * *
  112. ***********************************************************************************************************************/
  113. if (PORT::isLiquidCtrlBoard() && (PORT::isPipeDM())) {
  114. ZLOGI(TAG, "ProportionalValveCtrl init");
  115. ZHALIniter::HUART2_INIT(PD5, PD6, 9600, UART_STOPBITS_1);
  116. proportionalValveCtrl.initialize(&huart2);
  117. }
  118. /***********************************************************************************************************************
  119. * *
  120. ***********************************************************************************************************************/
  121. // kAirLeakTestMode_disinfection
  122. // kAirLeakTestMode_inflation
  123. // kAirLeakTestMode_leakTest
  124. if (PORT::isLiquidCtrlBoard() && (PORT::isPipeDM())) {
  125. static air_leak_test_mode_t airLeakTestMode = kAirLeakTestMode_disinfection;
  126. static ZGPIO eValve0;
  127. static ZGPIO eValve1;
  128. static ZGPIO eValve2;
  129. eValve0.initAsOutput(PD14, kxs_gpio_nopull, true, false);
  130. eValve1.initAsOutput(PD15, kxs_gpio_nopull, true, false);
  131. eValve2.initAsOutput(PC6, kxs_gpio_nopull, true, false); // 空气通道电磁阀
  132. REG_LAMADA_FN(kfn_air_leak_test_set_mode, [&](ProcessContext* cxt) {
  133. if (GET_PARAM(0) == kAirLeakTestMode_disinfection) {
  134. eValve2.write(0); // 内管路
  135. eValve0.write(0); // 联通
  136. eValve1.write(0); // 联通
  137. } else if (GET_PARAM(0) == kAirLeakTestMode_inflation) {
  138. eValve2.write(1); // 联通空气
  139. eValve0.write(0); // 联通
  140. eValve1.write(0); // 联通
  141. } else if (GET_PARAM(0) == kAirLeakTestMode_leakTest) {
  142. eValve2.write(0); // 内管路
  143. eValve0.write(1); // 封闭
  144. eValve1.write(1); // 封闭
  145. }
  146. airLeakTestMode = (air_leak_test_mode_t)GET_PARAM(0);
  147. zcanbus_send_ack(cxt->packet, NULL, 0);
  148. });
  149. REG_LAMADA_FN(kfn_air_leak_test_get_mode, [&](ProcessContext* cxt) {
  150. int32_t mode = airLeakTestMode;
  151. zcanbus_send_ack(cxt->packet, mode);
  152. });
  153. }
  154. /**
  155. * @brief
  156. *
  157. */
  158. if (PORT::isLiquidCtrlBoard() && (PORT::isLargeSpaceDM() || PORT::isSamllSpaceDM() || PORT::isPipeDM())) {
  159. static ZGPIO valve;
  160. valve.initAsOutput(PB3, kxs_gpio_nopull, true, false);
  161. REG_LAMADA_FN(kfn_set_add_fluid_channel_selector_valve, [&](ProcessContext* cxt) {
  162. if (GET_PARAM(0) == 0) {
  163. valve.write(0);
  164. } else {
  165. valve.write(1);
  166. }
  167. zcanbus_send_ack(cxt->packet, NULL, 0);
  168. });
  169. }
  170. /**
  171. * @brief
  172. */
  173. if (PORT::isLiquidCtrlBoard() && (PORT::isDT600B())) {
  174. // 初始化
  175. static ZGPIO io0;
  176. static bool io0enable = false;
  177. static ZGPIO io1;
  178. static bool io1enable = false;
  179. static ZGPIO io2;
  180. static bool io2enable = false;
  181. if (PORT::isDT600B()) {
  182. io0.initAsInput(PD11, kxs_gpio_nopull, kxs_gpio_no_irq, true /*mirror*/);
  183. io0enable = true;
  184. }
  185. if (io0enable || io1enable || io2enable) {
  186. REG_LAMADA_FN(kfn_liquid_level_read_io_state, [&](ProcessContext* cxt) {
  187. int32_t liquid_level_state = 0;
  188. if (io0enable) {
  189. liquid_level_state |= (io0.read() ? 0 : 1) << 0; // bit0:低液位置
  190. }
  191. if (io1enable) {
  192. liquid_level_state |= (io1.read() ? 0 : 1) << 1; // bit1:中液位
  193. }
  194. if (io2enable) {
  195. liquid_level_state |= (io2.read() ? 0 : 1) << 2; // bit2:高液位
  196. }
  197. zcanbus_send_ack(cxt->packet, liquid_level_state);
  198. });
  199. }
  200. }
  201. }
  202. /***********************************************************************************************************************
  203. * PROTOCOL_BIND *
  204. ***********************************************************************************************************************/