Browse Source

update

sunlight
zhaohe 11 months ago
parent
commit
aa98fd3d44
  1. 10
      uappbase/service/gstate_mgr.cpp
  2. 2
      uappbase/service/gstate_mgr.hpp
  3. 2
      usrc/service/page/Page_main.cpp
  4. 110
      usrc/service/pump_ctrl_service.cpp
  5. 5
      usrc/service/remote_controler_event_processer.cpp
  6. 45
      usrc/service/valve_state_ctrl_service.cpp
  7. 1
      usrc/service/valve_state_ctrl_service.hpp

10
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; }

2
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

2
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

110
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() {

5
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) {

45
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();
}

1
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);

Loading…
Cancel
Save