diff --git a/components/pipette_module/pipette_ctrl_module.cpp b/components/pipette_module/pipette_ctrl_module.cpp index 494fdf3..a246d49 100644 --- a/components/pipette_module/pipette_ctrl_module.cpp +++ b/components/pipette_module/pipette_ctrl_module.cpp @@ -11,42 +11,62 @@ void PipetteModule::initialize(SMTP2 *smtp2, // int32_t PipetteModule::enable(u8 enable) { // m_stepMotor->enable(enable); + return 0; } int32_t PipetteModule::stop(u8 stop_type) { m_stepMotor->stop(0); m_smtp2->stop(); + return 0; } int32_t PipetteModule::zero_pos_calibrate(function exec_complete_cb) { - /** - * @brief - */ - m_thread.stop(); m_thread.start([this, exec_complete_cb]() { - // 移液枪复位 - // 移液枪复位完成后,开始进行零点校准 - // m_stepMotor->move_to_zero_with_calibrate(); + action_cb_status_t action_status = {0}; + + int32_t exec_ret = m_stepMotor->move_to_zero_with_calibrate(0, [&](I_StepMotorCtrlModule::move_to_zero_with_calibrate_cb_status_t &status) { + action_status.exec_status = status.exec_status; + if (exec_complete_cb) exec_complete_cb(action_status); + }); + + if (exec_ret != 0) { + ZLOGE(TAG, "move_to_zero_with_calibrate fail, exec_ret = %d", exec_ret); + m_stepMotor->stop(0); + action_status.exec_status = exec_ret; + if (exec_complete_cb) exec_complete_cb(action_status); + return; + } + + while (!m_thread.getExitFlag()) { + ZLOGI(TAG, "Waiting for SMTP2 to complete the reset"); + if (!m_stepMotor->isbusy()) break; + m_thread.sleep(1000); + } + + ZLOGI(TAG, "zero_pos_calibrate complete"); + m_stepMotor->stop(0); }); + return 0; } int32_t PipetteModule::reset_device(function exec_complete_cb) { - /** - * @brief - */ - m_thread.stop(); m_thread.start([this, exec_complete_cb]() { action_cb_status_t report_status = {0}; + + /******************************************************************************* + * m_smtp2 * + *******************************************************************************/ // 移液枪复位 int ret = m_smtp2->init_device(); if (ret != 0) { ZLOGE(TAG, "init_device fail"); report_status.exec_status = ret; if (exec_complete_cb) exec_complete_cb(report_status); + return; } // 等待移液枪复位完成 - while (true && !m_thread.getExitFlag()) { + while (!m_thread.getExitFlag()) { int32_t state = m_smtp2->getState(); if (state == 0) { break; @@ -54,9 +74,42 @@ int32_t PipetteModule::reset_device(function ex m_thread.sleep(1000); ZLOGI(TAG, "Waiting for SMTP2 to complete the reset"); } - + m_smtp2->stop(); + ZLOGI(TAG, "SMTP2 reset complete"); + if (m_thread.getExitFlag()) { + ZLOGW(TAG, "break reset_device"); + return; + } + + /******************************************************************************* + * m_stepMotor * + *******************************************************************************/ + ret = m_stepMotor->move_to_zero_with_calibrate(0, [&](I_StepMotorCtrlModule::move_to_zero_with_calibrate_cb_status_t &status) { // + ret = status.exec_status; + }); + + while (!m_thread.getExitFlag()) { + if (!m_stepMotor->isbusy()) break; + m_thread.sleep(1000); + ZLOGI(TAG, "Waiting for Z axis to complete the reset"); + } + m_stepMotor->stop(0); + if (m_thread.getExitFlag()) { + ZLOGW(TAG, "break reset_device"); + return; + } + + if (ret != 0) { + ZLOGE(TAG, "move_to_zero_with_calibrate fail, ret = %d", ret); + report_status.exec_status = ret; + if (exec_complete_cb) exec_complete_cb(report_status); + return; + } - // 移液枪复位完成后,开始进行零点校准 + ZLOGI(TAG, "Z axis reset complete"); + report_status.exec_status = 0; + if (exec_complete_cb) exec_complete_cb(report_status); }); + return 0; } \ No newline at end of file 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 7045893..c92558b 100644 --- a/components/step_motor_ctrl_module/step_motor_ctrl_module.cpp +++ b/components/step_motor_ctrl_module/step_motor_ctrl_module.cpp @@ -26,6 +26,9 @@ void StepMotorCtrlModule::initialize(int id, IStepperMotor* stepM, ZGPIO* zero_g set_run_to_zero_param(run_to_zero_param); set_warning_limit_param(warning_limit_param); } + +bool StepMotorCtrlModule::isbusy() { return m_thread.isworking(); } + int32_t StepMotorCtrlModule::move_to(int32_t tox, function status_cb) { // zlock_guard lock(m_lock); diff --git a/components/step_motor_ctrl_module/step_motor_ctrl_module.hpp b/components/step_motor_ctrl_module/step_motor_ctrl_module.hpp index 699175d..9ca9aa9 100644 --- a/components/step_motor_ctrl_module/step_motor_ctrl_module.hpp +++ b/components/step_motor_ctrl_module/step_motor_ctrl_module.hpp @@ -47,6 +47,8 @@ class StepMotorCtrlModule : public I_StepMotorCtrlModule { public: void initialize(int id, IStepperMotor* stepM, ZGPIO* zero_gpio, ZGPIO* end_gpio); + virtual bool isbusy() override; + virtual int32_t move_to(int32_t x, function status_cb) override; virtual int32_t move_by(int32_t dx, function status_cb) override; virtual int32_t move_to_zero(function status_cb) override; diff --git a/components/zprotocols/zcancmder b/components/zprotocols/zcancmder index 40bae4b..ce0623d 160000 --- a/components/zprotocols/zcancmder +++ b/components/zprotocols/zcancmder @@ -1 +1 @@ -Subproject commit 40bae4b887cc873eea0d37ba581669363fdc6f27 +Subproject commit ce0623df5d4dd3ab8ffe1e068fa7af86e8d8c44a