From a796f5c582eef8b06107d7558b3dfafe6be0f639 Mon Sep 17 00:00:00 2001 From: zhaohe Date: Sun, 15 Oct 2023 20:07:04 +0800 Subject: [PATCH] update --- components/step_motor_45/script_cmder_step_motor_45.cpp | 1 + components/step_motor_45/step_motor_45.cpp | 8 +++++++- components/step_motor_45/step_motor_45.hpp | 7 +++++-- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/components/step_motor_45/script_cmder_step_motor_45.cpp b/components/step_motor_45/script_cmder_step_motor_45.cpp index dad93a2..c6188a3 100644 --- a/components/step_motor_45/script_cmder_step_motor_45.cpp +++ b/components/step_motor_45/script_cmder_step_motor_45.cpp @@ -46,6 +46,7 @@ void ScriptCmderStepMotor45::regcmd() { REG_CMD___NO_ACK(PREFIX, zero_calibration, "(id)", 1); REG_CMD_WITH_ACK(PREFIX, get_pos, "(id)", 1, int32_t, ack); REG_CMD___NO_ACK(PREFIX, set_pos, "(id,pos)", 2, con->getInt(2)); + REG_CMD_WITH_ACK(PREFIX, get_zero_pin_state, "(id,pos)", 1, int32_t, ack); // REG_CMD___NO_ACK(PREFIX, initialize, "(id,driverPin1,driverPin2,driverPin3,driverPin4,zeroPin)", 6, con->getInt(2), con->getInt(3), con->getInt(4), con->getInt(5), con->getInt(6), con->getInt(7)); } \ No newline at end of file diff --git a/components/step_motor_45/step_motor_45.cpp b/components/step_motor_45/step_motor_45.cpp index f732a46..538aa2e 100644 --- a/components/step_motor_45/step_motor_45.cpp +++ b/components/step_motor_45/step_motor_45.cpp @@ -51,7 +51,7 @@ void StepMotor45::initialize(StepMotor45Scheduler* scheduler, cfg_t cfg) { if (cfg.zeroPin != PinNull) { m_zeroPinZGPIO = new ZGPIO(); ZASSERT(m_zeroPinZGPIO != NULL); - m_zeroPinZGPIO->initAsInput(cfg.zeroPin, ZGPIO::kMode_pullup, ZGPIO::kIRQ_noIrq, cfg.zeroPinMirror); + m_zeroPinZGPIO->initAsInput(cfg.zeroPin, cfg.ioPollType, ZGPIO::kIRQ_noIrq, cfg.zeroPinMirror); } setdriverpinstate(1, 1, 1, 1); scheduler->addMotor(this); @@ -101,6 +101,12 @@ void StepMotor45::onTimIRQ1ms() { schedule(); } +int32_t StepMotor45::get_zero_pin_state(int32_t& state) { + CriticalContext cc; + state = getzeropinstate(); + return (int32_t)0; +} + void StepMotor45::schedule() { /** * @brief 执行零点校准逻辑 diff --git a/components/step_motor_45/step_motor_45.hpp b/components/step_motor_45/step_motor_45.hpp index 42ecaa3..e848274 100644 --- a/components/step_motor_45/step_motor_45.hpp +++ b/components/step_motor_45/step_motor_45.hpp @@ -25,8 +25,9 @@ class StepMotor45 { bool enable_max_pos_limit = false; // 是否启用最大位置限位 bool mirror = false; // 是否镜像 - Pin_t zeroPin = PinNull; - bool zeroPinMirror = false; + Pin_t zeroPin = PinNull; + ZGPIO::GPIOMode_t ioPollType = ZGPIO::kMode_nopull; + bool zeroPinMirror = false; Pin_t driverPin[4] = {PinNull, PinNull, PinNull, PinNull}; bool driverPinMirror = false; @@ -79,6 +80,8 @@ class StepMotor45 { int32_t zero_calibration(); int32_t set_pos(int32_t pos) { m_pos = pos; } + int32_t get_zero_pin_state(int32_t &state); + int32_t get_pos(int32_t &pos) { pos = m_pos; return (int32_t)0;