diff --git a/uappbase/service/gstate_mgr.cpp b/uappbase/service/gstate_mgr.cpp index dd3eaab..fb6578b 100644 --- a/uappbase/service/gstate_mgr.cpp +++ b/uappbase/service/gstate_mgr.cpp @@ -85,5 +85,15 @@ bool GStateMgr::getPumpSelectState(int32_t index) { zlock_guard l(m_mutex); return pumpSelectState[index]; } +bool GStateMgr::isHasPumpSelect() { + zlock_guard l(m_mutex); + for (int i = 0; i < 4; i++) { + if (pumpSelectState[i]) { + return true; + } + } + return false; +} + void GStateMgr::setMenuPage(int32_t page) { m_menuPage = page; } int32_t GStateMgr::getMenuPage() { return m_menuPage; } diff --git a/uappbase/service/gstate_mgr.hpp b/uappbase/service/gstate_mgr.hpp index 3ed775a..e5c3127 100644 --- a/uappbase/service/gstate_mgr.hpp +++ b/uappbase/service/gstate_mgr.hpp @@ -54,6 +54,8 @@ class GStateMgr { void setPumpSelectState(int32_t index, bool state); bool getPumpSelectState(int32_t index); + + bool isHasPumpSelect(); }; } // namespace iflytop \ No newline at end of file diff --git a/usrc/service/page/Page_main.cpp b/usrc/service/page/Page_main.cpp index aaffca7..bc9a1b7 100644 --- a/usrc/service/page/Page_main.cpp +++ b/usrc/service/page/Page_main.cpp @@ -1,4 +1,6 @@ #include "Page_main.hpp" + +#include "service\pump_ctrl_service.hpp" using namespace iflytop; #define PAGE pg_main diff --git a/usrc/service/pump_ctrl_service.cpp b/usrc/service/pump_ctrl_service.cpp index 18bd35e..f3dd79d 100644 --- a/usrc/service/pump_ctrl_service.cpp +++ b/usrc/service/pump_ctrl_service.cpp @@ -1,6 +1,7 @@ #include "pump_ctrl_service.hpp" #include "remote_controler.hpp" +#include "valve_state_ctrl_service.hpp" using namespace iflytop; #define TAG "PumpCtrlService" @@ -79,66 +80,75 @@ void PumpCtrlService::reflux() { ZLOGI(TAG, "reflux"); if (m_pumpCfgUpdateFlag) updateMotorSetting(); - m_thread.start([this]() { - int32_t pipeLenML = getCfgInt(kcfg_pipeLengthML); - int32_t vel = getCfgInt(config_index_t(kcfg_pumpDefVel)); - - for (size_t i = 0; i < PUMP_NUM; i++) { - TMC51X0* cur_motor = m_motors[i]; - cur_motor->stop(); - cur_motor->setXACTUAL(0); - ZLOGI(TAG, "pump %d move %f ml", i, -pipeLenML); - cur_motor->moveBy((int32_t)-pipeLenML * 1000, vel); - } + m_thread.start( + [this]() { + ValveStateSyncService::ins()->setValveState(1); + int32_t pipeLenML = getCfgInt(kcfg_pipeLengthML); + int32_t vel = getCfgInt(config_index_t(kcfg_pumpDefVel)); + + for (size_t i = 0; i < PUMP_NUM; i++) { + TMC51X0* cur_motor = m_motors[i]; + cur_motor->stop(); + cur_motor->setXACTUAL(0); + ZLOGI(TAG, "pump %d move %f ml", i, -pipeLenML); + cur_motor->moveBy((int32_t)-pipeLenML * 1000, vel); + } - while (!m_thread.getExitFlag()) { - if (isAllReachTarget()) { - break; - } - osDelay(10); - } + while (!m_thread.getExitFlag()) { + if (isAllReachTarget()) { + break; + } + osDelay(10); + } - stopAll(); - ZLOGI(TAG, "reflux end"); - }); + stopAll(); + ZLOGI(TAG, "reflux end"); + }, + []() { + ValveStateSyncService::ins()->setValveState(0); + }); } void PumpCtrlService::acidPrefilling() { ZLOGI(TAG, "acidPrefilling"); if (m_pumpCfgUpdateFlag) updateMotorSetting(); - m_thread.start([this]() { - int32_t pipeLenML = getCfgInt(kcfg_pipeLengthML); - int32_t vel = getCfgInt(config_index_t(kcfg_pumpDefVel)); - - for (size_t i = 0; i < PUMP_NUM; i++) { - TMC51X0* cur_motor = m_motors[i]; - cur_motor->stop(); - cur_motor->setXACTUAL(0); - ZLOGI(TAG, "pump %d move %f ml", i, pipeLenML); - cur_motor->moveBy((int32_t)pipeLenML * 1000, vel); - } + m_thread.start( + [this]() { + ValveStateSyncService::ins()->setValveState(1); - while (!m_thread.getExitFlag()) { - if (isAllReachTarget()) { - break; - } - osDelay(10); - } + int32_t pipeLenML = getCfgInt(kcfg_pipeLengthML); + int32_t vel = getCfgInt(config_index_t(kcfg_pumpDefVel)); - // 短回流 - for (size_t i = 0; i < PUMP_NUM; i++) { - int32_t vel = getCfgInt(kcfg_pumpDefVel); - TMC51X0* cur_motor = m_motors[i]; - cur_motor->moveBy(-(int32_t)(APPEND_ML) * 1000, vel); - } + for (size_t i = 0; i < PUMP_NUM; i++) { + TMC51X0* cur_motor = m_motors[i]; + cur_motor->stop(); + cur_motor->setXACTUAL(0); + ZLOGI(TAG, "pump %d move %f ml", i, pipeLenML); + cur_motor->moveBy((int32_t)pipeLenML * 1000, vel); + } - while (!isAllReachTarget()) { - osDelay(10); - } + while (!m_thread.getExitFlag()) { + if (isAllReachTarget()) { + break; + } + osDelay(10); + } - stopAll(); - ZLOGI(TAG, "acidPrefilling end"); - }); + // 短回流 + for (size_t i = 0; i < PUMP_NUM; i++) { + int32_t vel = getCfgInt(kcfg_pumpDefVel); + TMC51X0* cur_motor = m_motors[i]; + cur_motor->moveBy(-(int32_t)(APPEND_ML) * 1000, vel); + } + + while (!isAllReachTarget()) { + osDelay(10); + } + + stopAll(); + ZLOGI(TAG, "acidPrefilling end"); + }, + []() { ValveStateSyncService::ins()->setValveState(0); }); } void PumpCtrlService::autoMoveMutiTimes() { @@ -180,6 +190,7 @@ bool PumpCtrlService::isWorking() { return m_thread.isworking(); } void PumpCtrlService::doMoveOnce() { // ZLOGI(TAG, "do moveOnce ..."); + ValveStateSyncService::ins()->setValveState(1); for (size_t i = 0; i < PUMP_NUM; i++) { bool pumpselect = GSM->getPumpSelectState(i); @@ -218,6 +229,7 @@ void PumpCtrlService::doMoveOnce() { ZLOGI(TAG, "do moveOnce finish"); stopAll(); + ValveStateSyncService::ins()->setValveState(0); } bool PumpCtrlService::isAllReachTarget() { diff --git a/usrc/service/remote_controler_event_processer.cpp b/usrc/service/remote_controler_event_processer.cpp index a0fc128..00f63a1 100644 --- a/usrc/service/remote_controler_event_processer.cpp +++ b/usrc/service/remote_controler_event_processer.cpp @@ -98,6 +98,11 @@ void RemoteControlerEventProcesser::processKeyEventFromRemoter(hand_acid_remoter } else { if (keyEvent == hand_acid_remoter_kevent_add_liquid) { // + if (!GSM->isHasPumpSelect()) { + UIS->alert("请至少选中一个泵机"); + return; + } + if (GSM->getRunMode() == khand_acid_m_jog_mode) { PUMPCS->moveOnce(); } else if (GSM->getRunMode() == khand_acid_m_continuous_mode) { diff --git a/usrc/service/valve_state_ctrl_service.cpp b/usrc/service/valve_state_ctrl_service.cpp index 37e54cf..171c036 100644 --- a/usrc/service/valve_state_ctrl_service.cpp +++ b/usrc/service/valve_state_ctrl_service.cpp @@ -16,28 +16,51 @@ void ValveStateSyncService::startSync() { while (true) { m_thread.sleep(300); { - zlock_guard l(lock); - valve_ctrl_msg_t msg = {0}; - msg.output0 = output0state; - msg.output1 = output1state; - msg.rgbw = rgbwstate; - ZCAN1::ins()->txMsgNoError(kvalve_ctrl_msg, (uint8_t*)&msg, sizeof(msg), 30); + { + zlock_guard l(lock); + msg.output0 = output0state; + msg.output1 = output1state; + msg.rgbw = rgbwstate; + ZCAN1::ins()->txMsgNoError(kvalve_ctrl_msg, (uint8_t*)&msg, sizeof(msg), 10); + forceupdate = false; + } } } }); } +void ValveStateSyncService::setValveState(bool state) { + { + zlock_guard l(lock); + output0state = (output0state & ~(1 << 0)) | (state << 0); + output0state = (output0state & ~(1 << 1)) | (state << 1); + output0state = (output0state & ~(1 << 2)) | (state << 2); + output0state = (output0state & ~(1 << 3)) | (state << 3); + forceupdate = true; + } -void ValveStateSyncService::setValveState(int valveIndex, bool state) { - zlock_guard l(lock); + m_thread.wake(); + while (!forceupdate) { + osDelay(2); + } +} +void ValveStateSyncService::setValveState(int valveIndex, bool state) { if (valveIndex >= 4) { ZLOGW(TAG, "valveIndex %d out of range", valveIndex); return; } - output0state = (output0state & ~(1 << valveIndex)) | (state << valveIndex); - forceupdate = true; + + { + zlock_guard l(lock); + output0state = (output0state & ~(1 << valveIndex)) | (state << valveIndex); + forceupdate = true; + } + m_thread.wake(); + while (!forceupdate) { + osDelay(2); + } } #define SETBIT(byte, off, valve) (byte = (byte & ~(1 << off)) | (valve << off)) @@ -50,13 +73,11 @@ void ValveStateSyncService::setRGBState(bool r, bool g, bool b) { SETBIT(rgbwstate, 0, r); SETBIT(rgbwstate, 1, g); SETBIT(rgbwstate, 2, b); - forceupdate = true; m_thread.wake(); } void ValveStateSyncService::setWarningState(bool warning) { zlock_guard l(lock); SETBIT(rgbwstate, 3, warning); - forceupdate = true; m_thread.wake(); } diff --git a/usrc/service/valve_state_ctrl_service.hpp b/usrc/service/valve_state_ctrl_service.hpp index e281116..d8206e2 100644 --- a/usrc/service/valve_state_ctrl_service.hpp +++ b/usrc/service/valve_state_ctrl_service.hpp @@ -29,6 +29,7 @@ class ValveStateSyncService { void startSync(); void setValveState(int valveIndex, bool state); + void setValveState(bool state); void setRGBState(bool r, bool g, bool b); void setWarningState(bool warning);