diff --git a/components/xy_robot_ctrl_module/xy_robot_ctrl_module.cpp b/components/xy_robot_ctrl_module/xy_robot_ctrl_module.cpp index a052a92..0c5b063 100644 --- a/components/xy_robot_ctrl_module/xy_robot_ctrl_module.cpp +++ b/components/xy_robot_ctrl_module/xy_robot_ctrl_module.cpp @@ -7,14 +7,16 @@ using namespace iflytop; using namespace std; #define TAG "XYRobotCtrlModule" -void XYRobotCtrlModule::initialize(IStepperMotor* stepM1, // - IStepperMotor* stepM2, // - ZGPIO* Xgpio, // - ZGPIO* Ygpio, const char* flashmark) { - m_stepM1 = stepM1; - m_stepM2 = stepM2; - m_Xgpio = Xgpio; - m_Ygpio = Ygpio; +void XYRobotCtrlModule::initialize(IStepperMotor* stepM1, // + IStepperMotor* stepM2, // + ZGPIO* gpiotable, // + int ngpio, const char* flashmark) { + m_stepM1 = stepM1; + m_stepM2 = stepM2; + m_Xgpio = &gpiotable[0]; + m_Ygpio = &gpiotable[1]; + m_gpiotable = gpiotable; + m_ngpio = ngpio; ZASSERT(m_stepM1); ZASSERT(m_stepM2); ZASSERT(m_Xgpio); @@ -263,18 +265,26 @@ int32_t XYRobotCtrlModule::read_version(version_t& version) { } int32_t XYRobotCtrlModule::read_status(status_t& status) { zlock_guard lock(m_lock); - status = {0}; - status.status = m_thread.isworking() ? 0x01 : 0x00; - if (m_Xgpio) status.iostate |= m_Xgpio->getState() ? 0x01 : 0x00; - if (m_Ygpio) status.iostate |= m_Ygpio->getState() ? 0x02 : 0x00; + status = {0}; + status.status = m_thread.isworking() ? 0x01 : 0x00; + status.iostate = 0xff; + for (int i = 0; i < m_ngpio; i++) { + if (i > 7) break; + if (!m_gpiotable[i].getState()) status.iostate &= ~(1 << i); + } + getnowpos(status.x, status.y); return 0; } int32_t XYRobotCtrlModule::read_detailed_status(detailed_status_t& debug_info) { zlock_guard lock(m_lock); debug_info = {0}; - if (m_Xgpio) debug_info.iostate |= m_Xgpio->getState() ? 0x01 : 0x00; - if (m_Ygpio) debug_info.iostate |= m_Ygpio->getState() ? 0x02 : 0x00; + + debug_info.iostate = 0xff; + for (int i = 0; i < m_ngpio; i++) { + if (i > 7) break; + if (!m_gpiotable[i].getState()) debug_info.iostate &= ~(1 << i); + } debug_info.status = m_thread.isworking() ? 0x01 : 0x00; getnowpos(debug_info.x, debug_info.y); @@ -566,8 +576,8 @@ void XYRobotCtrlModule::forward_kinematics(int32_t x, int32_t y, int32_t& m1pos, m1pos = ((x + y) / 2); m2pos = ((y - x) / 2); } else { - m1pos = (x - y) / 2; - m2pos = (x + y) / 2; + m1pos = (x + y) / 2; + m2pos = (x - y) / 2; } } diff --git a/components/xy_robot_ctrl_module/xy_robot_ctrl_module.hpp b/components/xy_robot_ctrl_module/xy_robot_ctrl_module.hpp index 4a00c48..2b893ab 100644 --- a/components/xy_robot_ctrl_module/xy_robot_ctrl_module.hpp +++ b/components/xy_robot_ctrl_module/xy_robot_ctrl_module.hpp @@ -15,6 +15,9 @@ class XYRobotCtrlModule : public I_XYRobotCtrlModule { ZGPIO* m_Xgpio; ZGPIO* m_Ygpio; + ZGPIO* m_gpiotable; + int m_ngpio; + ZThread m_thread; int m_x = 0; @@ -37,7 +40,7 @@ class XYRobotCtrlModule : public I_XYRobotCtrlModule { void initialize(IStepperMotor* stepM1, // IStepperMotor* stepM2, // ZGPIO* Xgpio, // - ZGPIO* Ygpio, const char* flashmark); + int ngpio, const char* flashmark); virtual int32_t move_to(int32_t x, int32_t y, int speed, action_cb_status_t status_cb) override; virtual int32_t move_by(int32_t dx, int32_t dy, int speed, action_cb_status_t status_cb) override; diff --git a/components/zprotocols/zcancmder b/components/zprotocols/zcancmder index d73af8a..9f0c021 160000 --- a/components/zprotocols/zcancmder +++ b/components/zprotocols/zcancmder @@ -1 +1 @@ -Subproject commit d73af8aeff6f7e6dd1dc38c4742f181c4cd9c87d +Subproject commit 9f0c021c41d1d410ccea7cc8a3d3c80c767e854d