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.

163 lines
6.7 KiB

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::isLargeSpaceDM() || PORT::isPipeDM());
  32. // 加热片
  33. if (PORT::isPowerCtrlBoard()) {
  34. LargeSpaceDmPowerCtrlBoardHal::HADC1_INIT();
  35. heaterCtrler.initialize(PC7, &hadc1, ADC_CHANNEL_2, &hadc1, ADC_CHANNEL_4);
  36. }
  37. if (isBoardType(kLargeSpaceDMPowerCtrlBoard, kSmallSpaceDMPowerCtrlBoard, kPipeDMPowerCtrlBoard)) {
  38. } else if (isBoardType(kDrawBarDMPowerCtrlBoard)) {
  39. LargeSpaceDmPowerCtrlBoardHal::HADC1_INIT();
  40. heaterCtrler.initialize(PC7, NULL, 0, &hadc1, ADC_CHANNEL_1);
  41. }
  42. // 风机
  43. if (isBoardType(kLargeSpaceDMPowerCtrlBoard, kSmallSpaceDMPowerCtrlBoard)) {
  44. LargeSpaceDmPowerCtrlBoardHal::HADC1_INIT();
  45. blowerCtrler.initialize(PC5, &hadc1, ADC_CHANNEL_1);
  46. } else if (isBoardType(kPipeDMPowerCtrlBoard)) {
  47. LargeSpaceDmPowerCtrlBoardHal::HADC1_INIT();
  48. LargeSpaceDmPowerCtrlBoardHal::HUART2_INIT(9600, UART_STOPBITS_1);
  49. blowerCtrler.initializeAsHighPowerUartBlower(&huart2, &hadc1, ADC_CHANNEL_1);
  50. } else if (isBoardType(kDrawBarDMPowerCtrlBoard)) {
  51. DBDMPowerCtrlBoard::HTIM3_INIT();
  52. blowerCtrler.initializeAsMiniPwmBlower(&htim3, TIM_CHANNEL_3, PC6 /*en*/, PC9 /*fb*/);
  53. }
  54. // 空压机
  55. if (isBoardType(kLargeSpaceDMPowerCtrlBoard, kSmallSpaceDMPowerCtrlBoard, kPipeDMPowerCtrlBoard)) {
  56. LargeSpaceDmPowerCtrlBoardHal::HADC1_INIT();
  57. airComCtrler.initialize(PC3, &hadc1, ADC_CHANNEL_0);
  58. } else if (isBoardType(kDrawBarDMLiquidCtrlBoard)) {
  59. airComCtrler.initialize(PD14, NULL, 0);
  60. }
  61. // 气密性测试空压机
  62. // kfn_air_tightness_test_ac_ctrl
  63. if (isBoardType(kPipeDMPowerCtrlBoard)) {
  64. REG_LAMADA_FN(kfn_air_tightness_test_ac_ctrl, [&](ProcessContext* cxt) {
  65. airComCtrler.open(GET_PARAM(0));
  66. zcanbus_send_ack(cxt->packet, NULL, 0);
  67. });
  68. REG_LAMADA_FN(kfn_air_tightness_test_ac_is_open, [&](ProcessContext* cxt) { zcanbus_send_ack(cxt->packet, airComCtrler.isOpen()); });
  69. } else if (isBoardType(kDrawBarDMLiquidCtrlBoard)) {
  70. static ZGPIO airCompressorCtrlGpio;
  71. airCompressorCtrlGpio.initAsOutput(PD15, kxs_gpio_nopull, true, false);
  72. REG_LAMADA_FN(kfn_air_tightness_test_ac_ctrl, [&](ProcessContext* cxt) {
  73. airCompressorCtrlGpio.write(GET_PARAM(0));
  74. zcanbus_send_ack(cxt->packet, NULL, 0);
  75. });
  76. REG_LAMADA_FN(kfn_air_tightness_test_ac_is_open, [&](ProcessContext* cxt) { zcanbus_send_ack(cxt->packet, airCompressorCtrlGpio.read()); });
  77. }
  78. // H2O2传感器
  79. if (isBoardType(kLargeSpaceDMPowerCtrlBoard, kSmallSpaceDMPowerCtrlBoard, kPipeDMPowerCtrlBoard, kDrawBarDMPowerCtrlBoard)) {
  80. LargeSpaceDmPowerCtrlBoardHal::HUART3_INIT(19200, UART_STOPBITS_2);
  81. LargeSpaceDmPowerCtrlBoardHal::HADC1_INIT();
  82. osDelay(3000);
  83. h2o2Sensor.initialize(&huart3, &hadc1, ADC_CHANNEL_3);
  84. }
  85. // 水浸传感器
  86. if (isBoardType(kLargeSpaceDMLiquidCtrlBoard, kSmallSpaceDMLiquidCtrlBoard, kPipeDMLiquidCtrlBoard)) {
  87. ZLOGI(TAG, "WaterSensor init");
  88. evaporationBinWS.initAsInput(PC7, kxs_gpio_nopull, kxs_gpio_no_irq, true /*mirror*/);
  89. deviceBottomWS.initAsInput(PC8, kxs_gpio_nopull, kxs_gpio_no_irq, true /*mirror*/);
  90. REG_LAMADA_FN(kfn_device_bottom_water_sensor_read_state, [&](ProcessContext* cxt) { zcanbus_send_ack(cxt->packet, deviceBottomWS.read()); });
  91. REG_LAMADA_FN(kfn_evaporation_tank_water_sensor_read_state, [&](ProcessContext* cxt) { zcanbus_send_ack(cxt->packet, evaporationBinWS.read()); });
  92. }
  93. if (isBoardType(kLargeSpaceDMLiquidCtrlBoard, kSmallSpaceDMLiquidCtrlBoard, kPipeDMLiquidCtrlBoard, kDrawBarDMLiquidCtrlBoard)) {
  94. // TMC电机初始化
  95. ZLOGI(TAG, "TMCMotorGroup init");
  96. LargeSpaceDMLiquidCtrlBoardHal::HSPI1_INIT();
  97. tmcPowerGroup.initialize(PB2, {&hspi1, PA4 /*cs*/, PB12 /*en*/}, {&hspi1, PC4 /*cs*/, PB13 /*en*/});
  98. }
  99. // 三色指示灯
  100. if (isBoardType(kLargeSpaceDMLiquidCtrlBoard, kSmallSpaceDMLiquidCtrlBoard, kPipeDMLiquidCtrlBoard)) {
  101. // 三色指示灯初始化
  102. ZLOGI(TAG, "WarningLightDriver init");
  103. wlDriver.initialize(PD8, PD7, PD9, PD10);
  104. }
  105. // 压力传感器初始化
  106. if (isBoardType(kLargeSpaceDMLiquidCtrlBoard, kSmallSpaceDMLiquidCtrlBoard, kPipeDMLiquidCtrlBoard, kDrawBarDMLiquidCtrlBoard)) {
  107. ZLOGI(TAG, "PXXPSBus init");
  108. osDelay(1500); // 等待传感器上电
  109. LargeSpaceDMLiquidCtrlBoardHal::HUART3_INIT(9600, UART_STOPBITS_1);
  110. psBus.initialize(&huart3);
  111. }
  112. // 比例阀初始化
  113. if (isBoardType(kPipeDMLiquidCtrlBoard)) {
  114. ZLOGI(TAG, "ProportionalValveCtrl init");
  115. LargeSpaceDMLiquidCtrlBoardHal::HUART2_INIT(9600);
  116. proportionalValveCtrl.initialize(&huart2);
  117. }
  118. // 气密性测试通道
  119. if (isBoardType(kPipeDMLiquidCtrlBoard)) {
  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_tightness_test_cutoff_ch, [&](ProcessContext* cxt) {
  126. airTightnessTestChGpio.write(1); // 内管路,气密性测试
  127. eValve.write(0); // 电磁阀闭合
  128. state = true;
  129. zcanbus_send_ack(cxt->packet, NULL, 0);
  130. });
  131. REG_LAMADA_FN(kfn_air_tightness_test_release_ch, [&](ProcessContext* cxt) {
  132. airTightnessTestChGpio.write(0); // 连接空气
  133. eValve.write(1); // 电磁阀打开
  134. state = false;
  135. zcanbus_send_ack(cxt->packet, NULL, 0);
  136. });
  137. // kfn_air_tightness_test_is_cutoff
  138. REG_LAMADA_FN(kfn_air_tightness_test_is_cutoff, [&](ProcessContext* cxt) { zcanbus_send_ack(cxt->packet, state); });
  139. }
  140. }
  141. /***********************************************************************************************************************
  142. * PROTOCOL_BIND *
  143. ***********************************************************************************************************************/