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.

149 lines
4.0 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. #include "main.hpp"
  2. #include <stddef.h>
  3. #include <stdio.h>
  4. #include "main.h"
  5. #include "project.hpp"
  6. //
  7. // #include "sdk/components/single_axis_motor_control_v2/single_axis_motor_control_v2.hpp"
  8. #include "sdk/components/iflytop_can_slave_modules/idcard_reader_service.hpp"
  9. #include "sdk/components/single_axis_motor_control/single_axis_motor_control.hpp"
  10. #include "sdk/hal/zhal.hpp"
  11. #include "sdk\components\iflytop_can_slave_modules\io_control_service.hpp"
  12. #include "sdk\components\iflytop_can_slave_v1\iflytop_can_slave.hpp"
  13. #include "sdk\components\m3078\m3078_code_scaner.hpp"
  14. #include "sdk\components\tmc\ic\ztmc4361A.hpp"
  15. #include "sdk\components\tmc\ic\ztmc5130.hpp"
  16. //
  17. #include "sdk\components\huacheng_sensor\dp600_pressure_sensor.hpp"
  18. #include "sdk\components\zcan_module\huacheng_pressure_sensor.hpp"
  19. #include "sdk\components\zcan_module\zcan_basic_order_module.hpp"
  20. #include "sdk\components\zcan_module\zcan_pump_ctrl_module.hpp"
  21. #include "sdk\components\zcan_module\zcan_trigle_warning_light_ctl_module.hpp"
  22. //
  23. #include "sdk\components\zcan_module\zcan_high_power_electrical_ctl_module.hpp"
  24. #define TAG "main"
  25. namespace iflytop {
  26. Main gmain;
  27. };
  28. using namespace iflytop;
  29. IflytopCanProtocolStackProcesser m_protocolStack;
  30. // TMC5130 m_motor1;
  31. // TMC5130 m_motor2;
  32. ZGPIO debuglight;
  33. ZGPIO AirCompressorCtrl1;
  34. ZGPIO AirCompressorCtrl2;
  35. ZGPIO AirBlowerCtrl1;
  36. ZGPIO AirBlowerCtrl2;
  37. ZGPIO HeatingStripCtrl1;
  38. ZGPIO HeatingStripCtrl2;
  39. ZCanReceiver m_canReceiver;
  40. ZCanBasicOrderModule m_basicOrderModule;
  41. ZCanHighPowerElectricalCtlModule m_highPowerElectricalCtlModule;
  42. void Main::onRceivePacket(CanPacketRxBuffer *rxbuf, uint8_t *packet, size_t len) {
  43. printf("can rx from %d %d,", rxbuf->id, len);
  44. for (size_t i = 0; i < len; i++) {
  45. printf("%02X ", packet[i]);
  46. }
  47. printf("\n");
  48. }
  49. void Main::run() {
  50. ZHALCORE::cfg_t oscfg = {
  51. .delayhtim = &DELAY_US_TIMER,
  52. .debuguart = &DEBUG_UART,
  53. };
  54. ZHALCORE::getInstance()->initialize(oscfg);
  55. ZLOGI(TAG, "zapp:%s", VERSION);
  56. debuglight.initAsOutput(DEBUG_LIGHT_GPIO, ZGPIO::kMode_nopull, false, false);
  57. ZHAL_CORE_REG(200, { debuglight.toggleState(); });
  58. ZCanReceiver::CFG *cfg = m_canReceiver.createCFG(DEVICE_ID);
  59. m_canReceiver.init(cfg);
  60. m_canReceiver.registerListener(this);
  61. AirCompressorCtrl1.initAsOutput(PC2, ZGPIO::kMode_nopull, true, false);
  62. AirCompressorCtrl2.initAsOutput(PC3, ZGPIO::kMode_nopull, true, false);
  63. AirBlowerCtrl1.initAsOutput(PC4, ZGPIO::kMode_nopull, true, false);
  64. AirBlowerCtrl2.initAsOutput(PC5, ZGPIO::kMode_nopull, true, false);
  65. HeatingStripCtrl1.initAsOutput(PC6, ZGPIO::kMode_nopull, true, false);
  66. HeatingStripCtrl2.initAsOutput(PC7, ZGPIO::kMode_nopull, true, false);
  67. ZHAL_CORE_REG(3000, {
  68. AirCompressorCtrl1.toggleState();
  69. AirCompressorCtrl2.toggleState();
  70. AirBlowerCtrl1.toggleState();
  71. AirBlowerCtrl2.toggleState();
  72. HeatingStripCtrl1.toggleState();
  73. HeatingStripCtrl2.toggleState();
  74. });
  75. /**
  76. * @brief
  77. */
  78. m_basicOrderModule.initialize(&m_canReceiver);
  79. m_basicOrderModule.regInputCtl([this](uint8_t id, bool &val) { return false; });
  80. m_basicOrderModule.regOutCtl([this](uint8_t id, bool val) {
  81. ZLOGI(TAG, "set io %d %d", id, val);
  82. if (id == 0) {
  83. AirCompressorCtrl1.setState(val);
  84. return true;
  85. }
  86. if (id == 1) {
  87. AirCompressorCtrl2.setState(val);
  88. return true;
  89. }
  90. if (id == 2) {
  91. AirBlowerCtrl1.setState(val);
  92. return true;
  93. }
  94. if (id == 3) {
  95. AirBlowerCtrl2.setState(val);
  96. return true;
  97. }
  98. if (id == 4) {
  99. HeatingStripCtrl1.setState(val);
  100. return true;
  101. }
  102. if (id == 5) {
  103. HeatingStripCtrl2.setState(val);
  104. return true;
  105. }
  106. return false;
  107. });
  108. m_basicOrderModule.regReadAdcVal([this](uint8_t id, int32_t &val) {
  109. if (id == 0) {
  110. val = 1;
  111. return true;
  112. }
  113. if (id == 1) {
  114. val = 2;
  115. return true;
  116. }
  117. if (id == 2) {
  118. val = 3;
  119. return true;
  120. }
  121. return false;
  122. });
  123. ZLOGI(TAG, "init done");
  124. while (1) {
  125. ZHALCORE::getInstance()->loop();
  126. }
  127. }