diff --git a/components/step_motor_ctrl_module/step_motor_ctrl_module.cpp b/components/step_motor_ctrl_module/step_motor_ctrl_module.cpp index 6ad0fc1..306ff35 100644 --- a/components/step_motor_ctrl_module/step_motor_ctrl_module.cpp +++ b/components/step_motor_ctrl_module/step_motor_ctrl_module.cpp @@ -390,8 +390,10 @@ int32_t StepMotorCtrlModule::step_motor_easy_move_to_zero() { return err::kstep_motor_ioindex_out_of_range; } - if(m_iotable[0].getHalPin()) - + if (m_iotable[0].isNull()) { + return err::kstep_motor_ioindex_out_of_range; + } + return do_step_motor_easy_move_to_zero(); } int32_t StepMotorCtrlModule::step_motor_easy_move_to_io(int32_t ioindex, int32_t direction) { @@ -413,6 +415,9 @@ int32_t StepMotorCtrlModule::step_motor_easy_move_to_end_point() { if (m_nio <= 1) { return err::kstep_motor_ioindex_out_of_range; } + if (m_iotable[1].isNull()) { + return err::kstep_motor_ioindex_out_of_range; + } return do_step_motor_easy_move_to_end_point(); } @@ -492,6 +497,13 @@ int32_t StepMotorCtrlModule::do_step_motor_easy_move_to_zero() { } int32_t StepMotorCtrlModule::do_step_motor_easy_move_to_io(int32_t ioindex, int32_t direction) { + if (ioindex < 0 || ioindex >= m_nio) { + return err::kstep_motor_ioindex_out_of_range; + } + if (m_iotable[ioindex].isNull()) { + return err::kstep_motor_ioindex_out_of_range; + } + m_thread.stop(); m_thread.start( [this, ioindex, direction]() {