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.

116 lines
4.3 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
  1. #include "main.hpp"
  2. #include <stddef.h>
  3. #include <stdio.h>
  4. #include "main.h"
  5. #include "project.hpp"
  6. //
  7. #include "one_dimensional_code_laser_scanner.hpp"
  8. // #include "sdk/components/single_axis_motor_control_v2/single_axis_motor_control_v2.hpp"
  9. #include "sdk/components/iflytop_can_slave_modules/idcard_reader_service.hpp"
  10. #include "sdk/components/single_axis_motor_control/single_axis_motor_control.hpp"
  11. #include "sdk/hal/zhal.hpp"
  12. #include "sdk\components\iflytop_can_slave_modules\io_control_service.hpp"
  13. #include "sdk\components\iflytop_can_slave_v1\iflytop_can_slave.hpp"
  14. #include "sdk\components\m3078\m3078_code_scaner.hpp"
  15. #include "sdk\components\tmc\ic\ztmc4361A.hpp"
  16. #include "sdk\components\tmc\ic\ztmc5130.hpp"
  17. #define TAG "main"
  18. namespace iflytop {
  19. Main gmain;
  20. };
  21. using namespace iflytop;
  22. IflytopCanProtocolStackProcesser m_protocolStack;
  23. TMC5130 m_tj_motor;
  24. TMC5130 m_py_motor;
  25. ZGPIO debuglight;
  26. ZGPIO io_fybh_read1;
  27. ZGPIO io_fybh_read2;
  28. ZGPIO io_fybh_read3;
  29. ZGPIO io_fybh_read4;
  30. ZGPIO io_fybh_read5;
  31. ZGPIO io_fybh_read6;
  32. ZGPIO io_fybjl_sensor8;
  33. ZGPIO io_fybjl_sensor7;
  34. ZGPIO io_fybjl_sensor6;
  35. ZGPIO io_fybjl_sensor5;
  36. ZGPIO io_fybjl_sensor4;
  37. ZGPIO io_fybjl_sensor3;
  38. ZGPIO io_fybjl_sensor2;
  39. ZGPIO io_fybjl_sensor1;
  40. ZGPIO io_fybjl_sensor0;
  41. M3078CodeScanner m_m3078CodeScanner;
  42. DeviceBaseControlService m_deviceBaseControlService;
  43. IOControlService m_ioControlService;
  44. SingleAxisMotorControler m_pyMotorControlService; // 平移电机
  45. SingleAxisMotorControler m_tjMotorControlService; // 推进电机
  46. OneDimensionalCodeLaserScanner m_oneDimensionalCodeLaserScanner;
  47. IDCardReaderService m_idCardReaderService;
  48. ZCanReceiver m_canReceiver;
  49. void input_sensors_init() {
  50. io_fybh_read1.initAsInput(FYBH_READ1, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, false /*mirror*/);
  51. io_fybh_read2.initAsInput(FYBH_READ2, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, false /*mirror*/);
  52. io_fybh_read3.initAsInput(FYBH_READ3, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, false /*mirror*/);
  53. io_fybh_read4.initAsInput(FYBH_READ4, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, false /*mirror*/);
  54. io_fybh_read5.initAsInput(FYBH_READ5, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, false /*mirror*/);
  55. io_fybh_read6.initAsInput(FYBH_READ6, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, false /*mirror*/);
  56. io_fybjl_sensor8.initAsInput(FYBJL_SENSOR8, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true /*mirror*/);
  57. io_fybjl_sensor7.initAsInput(FYBJL_SENSOR7, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true /*mirror*/);
  58. io_fybjl_sensor6.initAsInput(FYBJL_SENSOR6, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true /*mirror*/);
  59. io_fybjl_sensor5.initAsInput(FYBJL_SENSOR5, ZGPIO::kMode_nopull, ZGPIO::kIRQ_risingAndFallingIrq, true /*mirror*/);
  60. io_fybjl_sensor4.initAsInput(FYBJL_SENSOR4, ZGPIO::kMode_nopull, ZGPIO::kIRQ_risingAndFallingIrq, true /*mirror*/);
  61. io_fybjl_sensor3.initAsInput(FYBJL_SENSOR3, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true /*mirror*/);
  62. io_fybjl_sensor2.initAsInput(FYBJL_SENSOR2, ZGPIO::kMode_nopull, ZGPIO::kIRQ_risingAndFallingIrq, true /*mirror*/);
  63. io_fybjl_sensor1.initAsInput(FYBJL_SENSOR1, ZGPIO::kMode_nopull, ZGPIO::kIRQ_risingAndFallingIrq, true /*mirror*/);
  64. io_fybjl_sensor0.initAsInput(FYBJL_SENSOR0, ZGPIO::kMode_nopull, ZGPIO::kIRQ_risingAndFallingIrq, true /*mirror*/);
  65. }
  66. void Main::onRceivePacket(CanPacketRxBuffer *rxbuf, uint8_t *packet, size_t len) {
  67. ZLOGI(TAG, "onRceivePacket from %d %d", rxbuf->id, len);
  68. for (size_t i = 0; i < len; i++) {
  69. printf("%02X ", packet[i]);
  70. }
  71. printf("\n");
  72. }
  73. void Main::run() {
  74. ZHALCORE::cfg_t oscfg = {
  75. .delayhtim = &DELAY_US_TIMER,
  76. .debuguart = &DEBUG_UART,
  77. };
  78. ZHALCORE::getInstance()->initialize(oscfg);
  79. ZLOGI(TAG, "zapp:%s", VERSION);
  80. printf("int32_t %d int %d longint %d\n", sizeof(int32_t), sizeof(int), sizeof(long int));
  81. debuglight.initAsOutput(DEBUG_LIGHT_GPIO, ZGPIO::kMode_nopull, false, false);
  82. ZHAL_CORE_REG(200, { debuglight.toggleState(); });
  83. ZCanReceiver::CFG *cfg = m_canReceiver.createCFG(DEVICE_ID);
  84. m_canReceiver.init(cfg);
  85. m_canReceiver.registerListener(this);
  86. // uint8_t packet[255];
  87. // for (int i = 0; i < 255; i++) {
  88. // packet[i] = i;
  89. // }
  90. // ZHAL_CORE_REG(200, { m_canReceiver.sendPacket(packet, 255); });
  91. ZLOGI(TAG, "init done");
  92. while (1) {
  93. ZHALCORE::getInstance()->loop();
  94. }
  95. }