全司美特-单片机程序
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.

187 lines
7.6 KiB

1 year ago
  1. #include "dmapp.hpp"
  2. /**
  3. * @brief
  4. *
  5. *
  6. *
  7. *
  8. * -
  9. * :
  10. * 1.
  11. * 2.
  12. * -
  13. * :
  14. * 1. ()
  15. *
  16. * -
  17. *
  18. */
  19. using namespace iflytop;
  20. using namespace transmit_disfection_protocol;
  21. #define TAG "LargeSpaceDmPowerCtrlBoard"
  22. DisinfectionApp* DisinfectionApp::ins() {
  23. static DisinfectionApp instance;
  24. return &instance;
  25. }
  26. const char* DisinfectionApp::getName() { return "DisinfectionApp"; }
  27. void DisinfectionApp::initialize() {
  28. int btid = PublicBoard::ins()->getBoardTypeId();
  29. //
  30. if (isBoardType(kLargeSpaceDMPowerCtrlBoard, kSmallSpaceDMPowerCtrlBoard, kPipeDMPowerCtrlBoard, kDrawBarDMPowerCtrlBoard)) {
  31. LargeSpaceDmPowerCtrlBoardHal::HADC1_INIT();
  32. heaterCtrler.initialize(PC7, &hadc1, ADC_CHANNEL_2, &hadc1, ADC_CHANNEL_8);
  33. bindHeaterCtrler();
  34. }
  35. if (isBoardType(kLargeSpaceDMPowerCtrlBoard, kSmallSpaceDMPowerCtrlBoard, kDrawBarDMPowerCtrlBoard)) {
  36. LargeSpaceDmPowerCtrlBoardHal::HADC1_INIT();
  37. blowerCtrler.initialize(PC5, &hadc1, ADC_CHANNEL_1);
  38. bindBlowerCtrler();
  39. } else if (isBoardType(kPipeDMPowerCtrlBoard)) {
  40. LargeSpaceDmPowerCtrlBoardHal::HUART2_INIT(9600, UART_STOPBITS_1);
  41. blowerCtrler.initializeAsHighPowerUartBlower(&huart2);
  42. bindBlowerCtrler();
  43. }
  44. if (isBoardType(kLargeSpaceDMPowerCtrlBoard, kSmallSpaceDMPowerCtrlBoard, kPipeDMPowerCtrlBoard, kDrawBarDMPowerCtrlBoard)) {
  45. LargeSpaceDmPowerCtrlBoardHal::HADC1_INIT();
  46. airComCtrler.initialize(PC3, &hadc1, ADC_CHANNEL_0);
  47. bindAirComCtrler();
  48. }
  49. if (isBoardType(kLargeSpaceDMPowerCtrlBoard, kSmallSpaceDMPowerCtrlBoard, kPipeDMPowerCtrlBoard, kDrawBarDMPowerCtrlBoard)) {
  50. LargeSpaceDmPowerCtrlBoardHal::HUART3_INIT(19200, UART_STOPBITS_2);
  51. LargeSpaceDmPowerCtrlBoardHal::HADC1_INIT();
  52. h2o2Sensor.initialize(&huart3, &hadc1, ADC_CHANNEL_10);
  53. bindH2o2Sensor();
  54. }
  55. if (isBoardType(kLargeSpaceDMLiquidCtrlBoard, kSmallSpaceDMLiquidCtrlBoard, kPipeDMLiquidCtrlBoard, kDrawBarDMLiquidCtrlBoard)) {
  56. evaporationBinWS.initAsInput(PC7, kxs_gpio_nopull, kxs_gpio_no_irq, true /*mirror*/);
  57. deviceBottomWS.initAsInput(PC8, kxs_gpio_nopull, kxs_gpio_no_irq, true /*mirror*/);
  58. bindDeviceBottomWS();
  59. bindEvaporationBinWS();
  60. }
  61. if (isBoardType(kLargeSpaceDMLiquidCtrlBoard, kSmallSpaceDMLiquidCtrlBoard, kPipeDMLiquidCtrlBoard, kDrawBarDMLiquidCtrlBoard)) {
  62. // TMC电机初始化
  63. LargeSpaceDMLiquidCtrlBoardHal::HSPI1_INIT();
  64. tmcPowerGroup.initialize(PB2, {&hspi1, PC4 /*cs*/, PB13 /*en*/}, {&hspi1, PA4 /*cs*/, PB12 /*en*/});
  65. bindTmcPowerGroup();
  66. }
  67. if (isBoardType(kLargeSpaceDMLiquidCtrlBoard, kSmallSpaceDMLiquidCtrlBoard, kPipeDMLiquidCtrlBoard, kDrawBarDMLiquidCtrlBoard)) {
  68. // 三色指示灯初始化
  69. wlDriver.initialize(PD8, PD7, PD9, PD10);
  70. bindWlDriver();
  71. }
  72. if (isBoardType(kLargeSpaceDMLiquidCtrlBoard, kSmallSpaceDMLiquidCtrlBoard, kPipeDMLiquidCtrlBoard, kDrawBarDMLiquidCtrlBoard)) {
  73. // 压力传感器初始化
  74. osDelay(1500); // 等待传感器上电
  75. LargeSpaceDMLiquidCtrlBoardHal::HUART3_INIT(9600, UART_STOPBITS_1);
  76. psBus.initialize(&huart3);
  77. bindPsBus();
  78. }
  79. // 比例阀初始化
  80. if (isBoardType(kPipeDMLiquidCtrlBoard)) {
  81. LargeSpaceDMLiquidCtrlBoardHal::HUART2_INIT(9600);
  82. proportionalValveCtrl.initialize(&huart2);
  83. bindProportionalValveCtrl();
  84. }
  85. // 气密性测试通道
  86. if (isBoardType(kPipeDMLiquidCtrlBoard)) {
  87. static ZGPIO airTightnessTestChGpio;
  88. static ZGPIO eValve;
  89. airTightnessTestChGpio.initAsOutput(PD15, kxs_gpio_nopull, true, false);
  90. eValve.initAsOutput(PD14, kxs_gpio_nopull, false, true);
  91. REG_LAMADA_FN(kfn_air_tightness_test_close_ch, [&](ProcessContext* cxt) {
  92. airTightnessTestChGpio.write(1); // 内管路,气密性测试
  93. eValve.write(0); // 电磁阀闭合
  94. zcanbus_send_ack(cxt->packet, NULL, 0);
  95. });
  96. REG_LAMADA_FN(kfn_air_tightness_test_recover_ch, [&](ProcessContext* cxt) {
  97. airTightnessTestChGpio.write(0); // 连接空气
  98. eValve.write(1); // 电磁阀打开
  99. zcanbus_send_ack(cxt->packet, NULL, 0);
  100. });
  101. }
  102. }
  103. /***********************************************************************************************************************
  104. * PROTOCOL_BIND *
  105. ***********************************************************************************************************************/
  106. void DisinfectionApp::bindHeaterCtrler() {
  107. BIND_FN(HeaterController, &heaterCtrler, fn_heater_ctrl);
  108. BIND_FN(HeaterController, &heaterCtrler, fn_heater_ctrl_safe_valve);
  109. BIND_FN(HeaterController, &heaterCtrler, fn_heater_read_electric_current);
  110. BIND_FN(HeaterController, &heaterCtrler, fn_heater_read_temperature_data);
  111. }
  112. void DisinfectionApp::bindBlowerCtrler() {
  113. BIND_FN(BlowerController, &blowerCtrler, fn_blower_ctrl);
  114. BIND_FN(BlowerController, &blowerCtrler, fn_blower_ctrl_safe_valve);
  115. BIND_FN(BlowerController, &blowerCtrler, fn_blower_read_electric_current);
  116. }
  117. void DisinfectionApp::bindAirComCtrler() {
  118. BIND_FN(AirCompressorController, &airComCtrler, fn_air_compressor_ctrl);
  119. BIND_FN(AirCompressorController, &airComCtrler, fn_air_compressor_ctrl_safe_valve);
  120. BIND_FN(AirCompressorController, &airComCtrler, fn_air_compressor_read_electric_current);
  121. }
  122. void DisinfectionApp::bindH2o2Sensor() {
  123. BIND_FN(H2O2SensorDriver, &h2o2Sensor, fn_h2o2_sensor_read_calibration_date);
  124. BIND_FN(H2O2SensorDriver, &h2o2Sensor, fn_h2o2_sensor_read_sub_ic_errorcode);
  125. BIND_FN(H2O2SensorDriver, &h2o2Sensor, fn_h2o2_sensor_read_sub_ic_reg);
  126. }
  127. void DisinfectionApp::bindWlDriver() { BIND_FN(WarningLightDriver, wlDriver, fn_triple_warning_light_ctl); }
  128. void DisinfectionApp::bindTmcPowerGroup() {
  129. BIND_FN(TmcMotorGroup, tmcPowerGroup, fn_pump_rotate);
  130. BIND_FN(TmcMotorGroup, tmcPowerGroup, fn_pump_stop);
  131. BIND_FN(TmcMotorGroup, tmcPowerGroup, fn_pump_set_ihold_irun_idelay);
  132. BIND_FN(TmcMotorGroup, tmcPowerGroup, fn_pump_set_acc);
  133. BIND_FN(TmcMotorGroup, tmcPowerGroup, fn_pump_set_ramp);
  134. BIND_FN(TmcMotorGroup, tmcPowerGroup, fn_pump_set_tzw);
  135. BIND_FN(TmcMotorGroup, tmcPowerGroup, fn_pump_set_subic_reg);
  136. BIND_FN(TmcMotorGroup, tmcPowerGroup, fn_pump_get_subic_reg);
  137. BIND_FN(TmcMotorGroup, tmcPowerGroup, fn_pump_ping);
  138. }
  139. void DisinfectionApp::bindPsBus() {
  140. BIND_FN(PXXPSBus, psBus, fn_psbus_read_data);
  141. BIND_FN(PXXPSBus, psBus, fn_psbus_scan);
  142. }
  143. void DisinfectionApp::bindEvaporationBinWS() {
  144. ProtocolProcesserMgr::ins()->regCmdProcesser( //
  145. CmdProcesser(kfn_evaporation_tank_water_sensor_read_state, //
  146. [this](ProcessContext* cxt) {
  147. int32_t val = evaporationBinWS.read();
  148. zcanbus_send_ack(cxt->packet, (uint8_t*)&val, sizeof(val));
  149. }));
  150. }
  151. void DisinfectionApp::bindDeviceBottomWS() {
  152. ProtocolProcesserMgr::ins()->regCmdProcesser( //
  153. CmdProcesser(kfn_device_bottom_water_sensor_read_state, //
  154. [this](ProcessContext* cxt) {
  155. int32_t val = deviceBottomWS.read();
  156. zcanbus_send_ack(cxt->packet, (uint8_t*)&val, sizeof(val));
  157. }));
  158. }
  159. void DisinfectionApp::bindProportionalValveCtrl() {
  160. BIND_FN(ProportionalValveCtrl, &proportionalValveCtrl, fn_proportional_set_valve);
  161. BIND_FN(ProportionalValveCtrl, &proportionalValveCtrl, fn_proportional_read_pos);
  162. BIND_FN(ProportionalValveCtrl, &proportionalValveCtrl, fn_proportional_is_busy);
  163. }