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

162 lines
6.5 KiB

1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
  1. #include "dmapp.hpp"
  2. /**
  3. * @brief
  4. *
  5. *
  6. *
  7. *
  8. *
  9. * -----
  10. *
  11. * :
  12. * 1.
  13. * 2.
  14. *
  15. * :
  16. * 1. ()
  17. *
  18. * ------
  19. *
  20. *
  21. *
  22. *
  23. */
  24. using namespace iflytop;
  25. using namespace transmit_disfection_protocol;
  26. #define TAG "DMAPP"
  27. DisinfectionApp* DisinfectionApp::ins() {
  28. static DisinfectionApp instance;
  29. return &instance;
  30. }
  31. const char* DisinfectionApp::getName() { return "DisinfectionApp"; }
  32. void DisinfectionApp::initialize() {
  33. int btid = PublicBoard::ins()->getBoardTypeId();
  34. //
  35. // 加热片
  36. if (isBoardType(kLargeSpaceDMPowerCtrlBoard, kSmallSpaceDMPowerCtrlBoard, kPipeDMPowerCtrlBoard)) {
  37. LargeSpaceDmPowerCtrlBoardHal::HADC1_INIT();
  38. heaterCtrler.initialize(PC7, &hadc1, ADC_CHANNEL_2, &hadc1, ADC_CHANNEL_8);
  39. } else if (isBoardType(kDrawBarDMPowerCtrlBoard)) {
  40. LargeSpaceDmPowerCtrlBoardHal::HADC1_INIT();
  41. heaterCtrler.initialize(PC7, NULL, 0, &hadc1, ADC_CHANNEL_1);
  42. }
  43. // 风机
  44. if (isBoardType(kLargeSpaceDMPowerCtrlBoard, kSmallSpaceDMPowerCtrlBoard)) {
  45. LargeSpaceDmPowerCtrlBoardHal::HADC1_INIT();
  46. blowerCtrler.initialize(PC5, &hadc1, ADC_CHANNEL_1);
  47. } else if (isBoardType(kPipeDMPowerCtrlBoard)) {
  48. LargeSpaceDmPowerCtrlBoardHal::HADC1_INIT();
  49. LargeSpaceDmPowerCtrlBoardHal::HUART2_INIT(9600, UART_STOPBITS_1);
  50. blowerCtrler.initializeAsHighPowerUartBlower(&huart2, &hadc1, ADC_CHANNEL_1);
  51. } else if (isBoardType(kDrawBarDMPowerCtrlBoard)) {
  52. DBDMPowerCtrlBoard::HTIM3_INIT();
  53. blowerCtrler.initializeAsMiniPwmBlower(&htim3, TIM_CHANNEL_3, PC6 /*en*/, PC9 /*fb*/);
  54. }
  55. // 空压机
  56. if (isBoardType(kLargeSpaceDMPowerCtrlBoard, kSmallSpaceDMPowerCtrlBoard, kPipeDMPowerCtrlBoard)) {
  57. LargeSpaceDmPowerCtrlBoardHal::HADC1_INIT();
  58. airComCtrler.initialize(PC3, &hadc1, ADC_CHANNEL_0);
  59. } else if (isBoardType(kDrawBarDMLiquidCtrlBoard)) {
  60. airComCtrler.initialize(PD14, NULL, 0);
  61. }
  62. // 气密性测试空压机
  63. // kfn_air_tightness_test_ac_ctrl
  64. if (isBoardType(kPipeDMPowerCtrlBoard)) {
  65. REG_LAMADA_FN(kfn_air_tightness_test_ac_ctrl, [&](ProcessContext* cxt) {
  66. airComCtrler.open(GET_PARAM(0));
  67. zcanbus_send_ack(cxt->packet, NULL, 0);
  68. });
  69. REG_LAMADA_FN(kfn_air_tightness_test_ac_is_open, [&](ProcessContext* cxt) { zcanbus_send_ack(cxt->packet, airComCtrler.isOpen()); });
  70. } else if (isBoardType(kDrawBarDMLiquidCtrlBoard)) {
  71. static ZGPIO airCompressorCtrlGpio;
  72. airCompressorCtrlGpio.initAsOutput(PD15, kxs_gpio_nopull, true, false);
  73. REG_LAMADA_FN(kfn_air_tightness_test_ac_ctrl, [&](ProcessContext* cxt) {
  74. airCompressorCtrlGpio.write(GET_PARAM(0));
  75. zcanbus_send_ack(cxt->packet, NULL, 0);
  76. });
  77. REG_LAMADA_FN(kfn_air_tightness_test_ac_is_open, [&](ProcessContext* cxt) { zcanbus_send_ack(cxt->packet, airCompressorCtrlGpio.read()); });
  78. }
  79. // H2O2传感器
  80. if (isBoardType(kLargeSpaceDMPowerCtrlBoard, kSmallSpaceDMPowerCtrlBoard, kPipeDMPowerCtrlBoard, kDrawBarDMPowerCtrlBoard)) {
  81. LargeSpaceDmPowerCtrlBoardHal::HUART3_INIT(19200, UART_STOPBITS_2);
  82. LargeSpaceDmPowerCtrlBoardHal::HADC1_INIT();
  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, PC4 /*cs*/, PB13 /*en*/}, {&hspi1, PA4 /*cs*/, PB12 /*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. ***********************************************************************************************************************/