#include "main.hpp" #include #include #include "main.h" #include "project.hpp" // // #include "sdk/components/single_axis_motor_control_v2/single_axis_motor_control_v2.hpp" #include "sdk/components/iflytop_can_slave_modules/idcard_reader_service.hpp" #include "sdk/components/single_axis_motor_control/single_axis_motor_control.hpp" #include "sdk/hal/zhal.hpp" #include "sdk\components\iflytop_can_slave_modules\io_control_service.hpp" #include "sdk\components\iflytop_can_slave_v1\iflytop_can_slave.hpp" #include "sdk\components\m3078\m3078_code_scaner.hpp" #include "sdk\components\tmc\ic\ztmc4361A.hpp" #include "sdk\components\tmc\ic\ztmc5130.hpp" // #include "sdk\components\huacheng_sensor\dp600_pressure_sensor.hpp" #include "sdk\components\zcan_module\huacheng_pressure_sensor.hpp" #include "sdk\components\zcan_module\zcan_basic_order_module.hpp" #include "sdk\components\zcan_module\zcan_pump_ctrl_module.hpp" #include "sdk\components\zcan_module\zcan_trigle_warning_light_ctl_module.hpp" // #include "sdk\components\zcan_module\zcan_high_power_electrical_ctl_module.hpp" #define TAG "main" namespace iflytop { Main gmain; }; using namespace iflytop; IflytopCanProtocolStackProcesser m_protocolStack; // TMC5130 m_motor1; // TMC5130 m_motor2; ZGPIO debuglight; ZGPIO AirCompressorCtrl1; ZGPIO AirCompressorCtrl2; ZGPIO AirBlowerCtrl1; ZGPIO AirBlowerCtrl2; ZGPIO HeatingStripCtrl1; ZGPIO HeatingStripCtrl2; ZCanReceiver m_canReceiver; ZCanBasicOrderModule m_basicOrderModule; ZCanHighPowerElectricalCtlModule m_highPowerElectricalCtlModule; void Main::onRceivePacket(CanPacketRxBuffer *rxbuf, uint8_t *packet, size_t len) { printf("can rx from %d %d,", rxbuf->id, len); for (size_t i = 0; i < len; i++) { printf("%02X ", packet[i]); } printf("\n"); } void Main::run() { ZHALCORE::cfg_t oscfg = { .delayhtim = &DELAY_US_TIMER, .debuguart = &DEBUG_UART, }; ZHALCORE::getInstance()->initialize(oscfg); ZLOGI(TAG, "zapp:%s", VERSION); debuglight.initAsOutput(DEBUG_LIGHT_GPIO, ZGPIO::kMode_nopull, false, false); ZHAL_CORE_REG(200, { debuglight.toggleState(); }); ZCanReceiver::CFG *cfg = m_canReceiver.createCFG(DEVICE_ID); m_canReceiver.init(cfg); m_canReceiver.registerListener(this); AirCompressorCtrl1.initAsOutput(PC2, ZGPIO::kMode_nopull, true, false); AirCompressorCtrl2.initAsOutput(PC3, ZGPIO::kMode_nopull, true, false); AirBlowerCtrl1.initAsOutput(PC4, ZGPIO::kMode_nopull, true, false); AirBlowerCtrl2.initAsOutput(PC5, ZGPIO::kMode_nopull, true, false); HeatingStripCtrl1.initAsOutput(PC6, ZGPIO::kMode_nopull, true, false); HeatingStripCtrl2.initAsOutput(PC7, ZGPIO::kMode_nopull, true, false); ZHAL_CORE_REG(3000, { AirCompressorCtrl1.toggleState(); AirCompressorCtrl2.toggleState(); AirBlowerCtrl1.toggleState(); AirBlowerCtrl2.toggleState(); HeatingStripCtrl1.toggleState(); HeatingStripCtrl2.toggleState(); }); /** * @brief 基础模块 */ m_basicOrderModule.initialize(&m_canReceiver); m_basicOrderModule.regInputCtl([this](uint8_t id, bool &val) { return false; }); m_basicOrderModule.regOutCtl([this](uint8_t id, bool val) { ZLOGI(TAG, "set io %d %d", id, val); if (id == 0) { AirCompressorCtrl1.setState(val); return true; } if (id == 1) { AirCompressorCtrl2.setState(val); return true; } if (id == 2) { AirBlowerCtrl1.setState(val); return true; } if (id == 3) { AirBlowerCtrl2.setState(val); return true; } if (id == 4) { HeatingStripCtrl1.setState(val); return true; } if (id == 5) { HeatingStripCtrl2.setState(val); return true; } return false; }); m_basicOrderModule.regReadAdcVal([this](uint8_t id, int32_t &val) { if (id == 0) { val = 1; return true; } if (id == 1) { val = 2; return true; } if (id == 2) { val = 3; return true; } return false; }); ZLOGI(TAG, "init done"); while (1) { ZHALCORE::getInstance()->loop(); } }