Browse Source

Merge branch 'master' of 192.168.1.3:p_chinagoldgroup_hand_acid/hand_acid_mainboard

sunlight
sunlight 11 months ago
parent
commit
4228875bcc
  1. 4
      .settings/language.settings.xml
  2. 10
      README.md
  3. 2
      stm32components
  4. 8
      uappbase/appcfg/appcfg.hpp
  5. 5
      uappbase/bean/config_index_enum.hpp
  6. 11
      uappbase/bean/event.hpp
  7. 12
      uappbase/service/config_index.cpp
  8. 2
      uappbase/service/config_index.hpp
  9. 4
      uappbase/service/config_service.cpp
  10. 50
      uappbase/service/config_service_utils.cpp
  11. 5
      uappbase/service/config_service_utils.hpp
  12. 8
      usrc/apphardware/apphardware.cpp
  13. 7
      usrc/service/front_end_controler.hpp
  14. 96
      usrc/service/page/Page_main.cpp
  15. 32
      usrc/service/page/submenu/Page_muSettings.cpp
  16. 300
      usrc/service/pump_ctrl_service.cpp
  17. 19
      usrc/service/pump_ctrl_service.hpp
  18. 62
      usrc/service/remote_controler_event_processer.cpp
  19. 16
      usrc/service/valve_state_ctrl_service.cpp
  20. 1
      usrc/service/valve_state_ctrl_service.hpp

4
.settings/language.settings.xml

@ -5,7 +5,7 @@
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
<provider class="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" console="false" env-hash="-980894174094061135" id="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" keep-relative-paths="false" name="MCU ARM GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<provider class="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" console="false" env-hash="1534615028576298921" id="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" keep-relative-paths="false" name="MCU ARM GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<language-scope id="org.eclipse.cdt.core.gcc"/>
<language-scope id="org.eclipse.cdt.core.g++"/>
</provider>
@ -16,7 +16,7 @@
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
<provider class="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" console="false" env-hash="-975839414090046430" id="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" keep-relative-paths="false" name="MCU ARM GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<provider class="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" console="false" env-hash="1550109261171453848" id="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" keep-relative-paths="false" name="MCU ARM GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<language-scope id="org.eclipse.cdt.core.gcc"/>
<language-scope id="org.eclipse.cdt.core.g++"/>
</provider>

10
README.md

@ -1,6 +1,13 @@
```
V101:
1. 重构加酸逻辑
2. 预充管路,改成先回流再预冲
3. 修改提示 "泵机" 为 "通道"
4. 修改预充管路,只充满选中管路
V102:
1.设备在工作时,禁止离开首页
2.设备在工作时,禁止切换模式
```
@ -10,7 +17,6 @@
TODO:
1. 输入超过10次错误密码后,弹出提示框,请等待24小时,24小时后,页面将自动切换到恢复出厂设置页面。
2. 添加恢复出厂设置按键,且恢复出厂设置按键按下后,需要根用户二次确认。
3. 转换比设置错误可能到只泵机不转
```

2
stm32components

@ -1 +1 @@
Subproject commit f45df89965564db5c5ad518c7a704571726b8a6e
Subproject commit d8826b58d64f4f69f5d867d110e5a8705b8bcdef

8
uappbase/appcfg/appcfg.hpp

@ -65,4 +65,10 @@
#define ACID_DEFAULT_NAME14 "一氯乙酸"
#define ACID_DEFAULT_NAME15 "氢氟酸"
#define PUMPDEFVEL "500" // 100r/min
#define PUMPDEFVEL "400" // 100r/min
// 通道每次小回流的液体长度
#define CH0APPENDML 0.2
#define CH1APPENDML 0.2
#define CH2APPENDML 0.1
#define CH3APPENDML 0.1

5
uappbase/bean/config_index_enum.hpp

@ -82,7 +82,10 @@ typedef enum {
/***********************************************************************************************************************
* *
***********************************************************************************************************************/
kcfg_pipeLengthML, // 酸液管路长度
kcfg_pipeLengthML0, // 酸液管路长度
kcfg_pipeLengthML1, // 酸液管路长度
kcfg_pipeLengthML2, // 酸液管路长度
kcfg_pipeLengthML3, // 酸液管路长度
kcfg_m0irun, // 电机0 irun
kcfg_m1irun, // 电机1 irun

11
uappbase/bean/event.hpp

@ -1,5 +1,7 @@
#pragma once
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <functional>
@ -9,7 +11,7 @@ using namespace std;
typedef enum {
kAppEvent_RunModeChangeEvent,
kAppEvent_RemoterConnectStateChangeEvent,
kAppEvent_PumpWorkStateChangeEvent,
kAppEvent_StateDisplayInfo,
kAppEvent_ConfigChangeEvent,
kAppEvent_BleConnectEvent,
} AppEventType_t;
@ -28,6 +30,7 @@ typedef struct {
uint32_t placeholder;
config_index_t configIndex;
char bleName[20];
char stateDisplayInfo[30];
} d;
} AppEvent_t;
@ -45,4 +48,10 @@ static inline AppEvent_t createConfigChangeEvent(config_index_t index) {
return event;
}
static inline AppEvent_t createStateDisplayInfoEvent(const char* info) {
AppEvent_t event;
event.type = kAppEvent_StateDisplayInfo;
strncpy(event.d.stateDisplayInfo, info, sizeof(event.d.stateDisplayInfo));
return event;
}
} // namespace iflytop

12
uappbase/service/config_index.cpp

@ -78,9 +78,9 @@ static cfg_iterm_info_t cfg_iterm_infos[] = {
/***********************************************************************************************************************
* *
***********************************************************************************************************************/
CFG_ITERM(kcfg_lockAcidName, kcfgt_bool, "false"), //
CFG_ITERM(kcfg_echDitrUpLi, kcfgt_int32, "99"), // 每次分配上限设定值 each distri up-limit
CFG_ITERM(kcfg_distrInterval, kcfgt_float, "1.5"), // 每次分配间隔时间
CFG_ITERM(kcfg_lockAcidName, kcfgt_bool, "false"), //
CFG_ITERM(kcfg_echDitrUpLi, kcfgt_int32, "99"), // 每次分配上限设定值 each distri up-limit
CFG_ITERM(kcfg_distrInterval, kcfgt_float, "1.5"), // 每次分配间隔时间
// CFG_ITERM(kcfg_pumpDefVel, kcfgt_int32, PUMPDEFVEL), //
CFG_ITERM(kcfg_pumpDefVel0, kcfgt_int32, PUMPDEFVEL), //
@ -98,8 +98,10 @@ static cfg_iterm_info_t cfg_iterm_infos[] = {
/***********************************************************************************************************************
* *
***********************************************************************************************************************/
CFG_ITERM(kcfg_pipeLengthML, kcfgt_float, "100"), //
CFG_ITERM(kcfg_pipeLengthML0, kcfgt_float, "14"), //
CFG_ITERM(kcfg_pipeLengthML1, kcfgt_float, "14"), //
CFG_ITERM(kcfg_pipeLengthML2, kcfgt_float, "7"), //
CFG_ITERM(kcfg_pipeLengthML3, kcfgt_float, "7"), //
};
const char *cfgName(int32_t index) {

2
uappbase/service/config_index.hpp

@ -21,7 +21,7 @@ typedef struct {
const char *initval;
} cfg_iterm_info_t;
#define CFG_MAX_INDEX 58
#define CFG_MAX_INDEX 61
const char *cfgName(int32_t index);
cfg_iterm_type_t cfgType(int32_t index);

4
uappbase/service/config_service.cpp

@ -3,7 +3,7 @@
#include "uappbase\service\app_event_bus.hpp"
//
#define CFG_HEADER 0x12345671
#define CFG_HEADER 0x12345670
/**
* @brief CFGÄÚ´æÊ¹ÓÃ
*
@ -98,7 +98,7 @@ void ConfigService::setcfgAndFlush(config_index_t index, int32_t val) {
void ConfigService::setcfgAndFlush(config_index_t index, float val) {
zlock_guard lg(mutex);
char buf[CONTENT_MAX_LEN];
snprintf(buf, CONTENT_MAX_LEN, "%.2f", val);
snprintf(buf, CONTENT_MAX_LEN, "%.3f", val);
_setcfgAndFlush(index, buf);
}

50
uappbase/service/config_service_utils.cpp

@ -1,6 +1,56 @@
#include "config_service_utils.hpp"
namespace iflytop {
float getPumpAppendMl(int chid) {
switch (chid) {
case 0:
return CH0APPENDML; //
case 1:
return CH1APPENDML;
case 2:
return CH2APPENDML;
case 3:
return CH3APPENDML;
default:
ZASSERT(0);
return 0;
}
}
float getCfgPipeLengthML(int chid) {
switch (chid) {
case 0:
return getCfgFloat(kcfg_pipeLengthML0);
case 1:
return getCfgFloat(kcfg_pipeLengthML1);
case 2:
return getCfgFloat(kcfg_pipeLengthML2);
case 3:
return getCfgFloat(kcfg_pipeLengthML3);
default:
ZASSERT(0);
return 0;
}
}
void setCfgPipeLengthML(int chid, float ml) {
switch (chid) {
case 0:
CS->setcfgAndFlush(kcfg_pipeLengthML0, ml);
break;
case 1:
CS->setcfgAndFlush(kcfg_pipeLengthML1, ml);
break;
case 2:
CS->setcfgAndFlush(kcfg_pipeLengthML2, ml);
break;
case 3:
CS->setcfgAndFlush(kcfg_pipeLengthML3, ml);
break;
default:
ZASSERT(0);
}
}
int getMxRunRPM(int32_t mid) { //
float rpm = 0;
if (mid == 0) {

5
uappbase/service/config_service_utils.hpp

@ -13,4 +13,9 @@ int32_t getMxIRun(int motorid);
const char* getPasswd(const char* usrname, CfgItermCache* cache);
const void setPasswd(const char* usrname, const char* passwd);
float getCfgPipeLengthML(int chid);
void setCfgPipeLengthML(int chid, float ml);
float getPumpAppendMl(int chid);
} // namespace iflytop

8
usrc/apphardware/apphardware.cpp

@ -41,10 +41,10 @@ void AppHardware::initialize() {
TMC51X0Cfg tmc5130cfg3 = {&MOTOR_SPI_INS, MOTO3_CSN_IO, MOTO3_DRV_ENN_IO};
TMC51X0Cfg tmc5130cfg4 = {&MOTOR_SPI_INS, MOTO4_CSN_IO, MOTO4_DRV_ENN_IO};
MOTO1.initialize(tmc5130cfg1);
MOTO2.initialize(tmc5130cfg2);
MOTO3.initialize(tmc5130cfg3);
MOTO4.initialize(tmc5130cfg4);
MOTO1.initialize(0,tmc5130cfg1);
MOTO2.initialize(1,tmc5130cfg2);
MOTO3.initialize(2,tmc5130cfg3);
MOTO4.initialize(3,tmc5130cfg4);
ZLOGI(TAG, "motor1 initialize TMC51X0:%x", MOTO1.readICVersion());
ZLOGI(TAG, "motor2 initialize TMC51X0:%x", MOTO2.readICVersion());

7
usrc/service/front_end_controler.hpp

@ -61,7 +61,6 @@ class FrontEndControler {
bool setTxt(uint8_t pid, uint8_t bid, const char* txt, ...);
bool setTxt(uint8_t bid, const char* txt) { return setTxt(m_nowPage, bid, txt); }
bool setVal(uint8_t pid, uint8_t bid, int32_t val);
bool setVal(uint8_t bid, int32_t val) { return setVal(m_nowPage, bid, val); }
@ -114,4 +113,10 @@ static inline const char* zfmt(const char* fmt, ...) {
return buf;
}
static inline const char* refmt(const char* fmt, const char* floatval) {
static char buf[128];
sprintf(buf, fmt, atof(floatval));
return buf;
}
} // namespace iflytop

96
usrc/service/page/Page_main.cpp

@ -41,7 +41,7 @@ void Page_main::updateRunModeState() {
bool Page_main::isBelongThisPage(int page) { return page == PAGE; }
void Page_main::OnPageLoad(OnPageLoadContext*cxt) {
void Page_main::OnPageLoad(OnPageLoadContext* cxt) {
// 只有管理员能够修改,酸液通道名称
if (GSM->isAdmin()) {
UIS->setTouchEnableState(ob_main_acidname0, 1);
@ -87,15 +87,65 @@ void Page_main::OnPageLoad(OnPageLoadContext*cxt) {
void Page_main::OnAppEvent(AppEvent_t* event) {
if (event->type == kAppEvent_RunModeChangeEvent) {
updateRunModeState();
UIS->setTxt(PAGE, ob_main_sysInfo, "切换模式");
}
if (event->type == kAppEvent_RemoterConnectStateChangeEvent) {
UIS->setEnumComponentState(PAGE, ob_main_RemoterS, GSM->getRemoterS());
if (GSM->getRemoterS()) {
UIS->setTxt(PAGE, ob_main_sysInfo, "连接上手柄");
} else {
UIS->setTxt(PAGE, ob_main_sysInfo, "断开手柄连接");
}
}
if (event->type == kAppEvent_StateDisplayInfo) {
UIS->setTxt(PAGE, ob_main_sysInfo, event->d.stateDisplayInfo);
}
return;
};
void Page_main::OnInputFieldContentChange(uint8_t bid, const char* text) {
/***********************************************************************************************************************
* *
***********************************************************************************************************************/
if (PumpCtrlService::ins()->isWorking()) {
UIS->alert("工作中,请稍后再操作");
return;
}
// 运行间隔设定值
if (bid == ob_main_RunModeVal) {
float distrIntervalSecond = atof(text);
if (distrIntervalSecond <= 0) {
UIS->alert("酸液间隔时间不能小于0");
return;
}
if (distrIntervalSecond > 30) {
UIS->alert("酸液间隔时间不能大于30");
return;
}
}
// 加酸设定值过滤
if (bid == ob_main_acideval0 || //
bid == ob_main_acideval1 || //
bid == ob_main_acideval2 || //
bid == ob_main_acideval3) {
float add_ml = atof(text);
if (add_ml < 0.009) {
UIS->alert("设定值不能小于0");
return;
} else if (add_ml > CS->getInt(kcfg_echDitrUpLi)) {
UIS->alert(fmt("设定值不能大于%d", CS->getInt(kcfg_echDitrUpLi)));
return;
}
}
/***********************************************************************************************************************
* *
***********************************************************************************************************************/
// 更新酸液每次分配设定值
if (bid == ob_main_acideval0) {
processAcidevalUpdateEvent(bid, text, 0, kcfg_acideval0);
@ -129,21 +179,31 @@ void Page_main::OnInputFieldContentChange(uint8_t bid, const char* text) {
// 设置加酸间隔
if (bid == ob_main_RunModeVal) {
float distrIntervalSecond = atof(text);
if (distrIntervalSecond <= 0) {
UIS->alert("酸液间隔时间不能小于0");
return;
}
if (distrIntervalSecond > 30) {
UIS->alert("酸液间隔时间不能大于30");
return;
}
UIS->setTxt(PAGE, bid, zfmt("%.1f", distrIntervalSecond));
CS->setcfgAndFlush(kcfg_distrInterval, zfmt("%.1f", distrIntervalSecond));
}
}
void Page_main::OnButton(uint8_t bid, uint8_t val) {
/***********************************************************************************************************************
* *
***********************************************************************************************************************/
if (bid == ob_main_RunMode || //
bid == ob_main_acidch0 || //
bid == ob_main_acidch1 || //
bid == ob_main_acidch2 || //
bid == ob_main_acidch3 || //
bid == ob_main_MenuButton //
) {
if (PumpCtrlService::ins()->isWorking()) {
UIS->alert("工作中,请稍后再操作");
return;
}
}
/***********************************************************************************************************************
* *
***********************************************************************************************************************/
if (bid == ob_main_RunMode) {
// 切换模式
GSM->changeToNextRunMode();
@ -169,17 +229,7 @@ void Page_main::OnButton(uint8_t bid, uint8_t val) {
}
void Page_main::processAcidevalUpdateEvent(uint8_t bid, const char* text, int ch, config_index_t cfgid) {
float add_ml = atof(text);
if (add_ml < 0) {
UIS->alert("设定值不能小于0");
return;
} else if (add_ml > CS->getInt(kcfg_echDitrUpLi)) {
UIS->alert(fmt("设定值不能大于%d", CS->getInt(kcfg_echDitrUpLi)));
return;
}
char reformattext[20];
sprintf(reformattext, "%.1f", add_ml);
ZLOGI(TAG, "set acid ch%d:%s", ch, reformattext);
UIS->setTxt(PAGE, bid, reformattext);
CS->setcfgAndFlush(cfgid, reformattext); //
ZLOGI(TAG, "set acid ch%d:%s", ch, text);
UIS->setTxt(PAGE, bid, refmt("%.1f", text));
CS->setcfgAndFlush(cfgid, refmt("%.1f", text));
}

32
usrc/service/page/submenu/Page_muSettings.cpp

@ -69,7 +69,10 @@ void Page_muSettings::updatePage() {
UIS->setTxt(PAGE, ob_muSettings_pumpCoef1, zfmt("%.4f", getMotorMLPR(1)));
UIS->setTxt(PAGE, ob_muSettings_pumpCoef2, zfmt("%.4f", getMotorMLPR(2)));
UIS->setTxt(PAGE, ob_muSettings_pumpCoef3, zfmt("%.4f", getMotorMLPR(3)));
UIS->setTxt(PAGE, ob_muSettings_pipeLen0, getCfgStr(kcfg_pipeLengthML));
UIS->setTxt(PAGE, ob_muSettings_pipeLen0, zfmt("%.2f", getCfgPipeLengthML(0)));
UIS->setTxt(PAGE, ob_muSettings_pipeLen1, zfmt("%.2f", getCfgPipeLengthML(1)));
UIS->setTxt(PAGE, ob_muSettings_pipeLen2, zfmt("%.2f", getCfgPipeLengthML(2)));
UIS->setTxt(PAGE, ob_muSettings_pipeLen3, zfmt("%.2f", getCfgPipeLengthML(3)));
// TODO:改成4个输入框
UIS->setTxt(PAGE, ob_muSettings_addAcidVel0, zitoa(getMxRunRPM(0)));
UIS->setTxt(PAGE, ob_muSettings_addAcidVel1, zitoa(getMxRunRPM(1)));
@ -138,9 +141,32 @@ void Page_muSettings::OnInputFieldContentChange(uint8_t bid, const char* text) {
* pipeLen *
***********************************************************************************************************************/
if (bid == ob_muSettings_pipeLen0 || bid == ob_muSettings_pipeLen1 || bid == ob_muSettings_pipeLen2 || bid == ob_muSettings_pipeLen3) {
float len = atof(text);
if (len < 0.1) {
UIS->alert("管道长度不能小于0.1");
return;
}
}
if (bid == ob_muSettings_pipeLen0) {
CS->setcfg(kcfg_pipeLengthML, text);
UIS->setTxt(bid, getCfgStr(kcfg_pipeLengthML));
setCfgPipeLengthML(0, atof(text));
UIS->setTxt(bid, zfmt("%.2f", getCfgPipeLengthML(0)));
}
if (bid == ob_muSettings_pipeLen1) {
setCfgPipeLengthML(1, atof(text));
UIS->setTxt(bid, zfmt("%.2f", getCfgPipeLengthML(1)));
}
if (bid == ob_muSettings_pipeLen2) {
setCfgPipeLengthML(2, atof(text));
UIS->setTxt(bid, zfmt("%.2f", getCfgPipeLengthML(2)));
}
if (bid == ob_muSettings_pipeLen3) {
setCfgPipeLengthML(3, atof(text));
UIS->setTxt(bid, zfmt("%.2f", getCfgPipeLengthML(3)));
}
/***********************************************************************************************************************

300
usrc/service/pump_ctrl_service.cpp

@ -10,9 +10,9 @@ static TMC51X0* m_motors[4];
#define PUMP_NUM 4
static CfgItermCache cfgcache;
#define APPEND_ML 10
// #define APPEND_ML 2
#define PUSH_DIS_INFO(info) AppEventBus::ins()->pushEvent(createStateDisplayInfoEvent(info))
void PumpCtrlService::initialize() {
m_motors[0] = AppHardware::ins()->getPump(0);
@ -35,6 +35,16 @@ void PumpCtrlService::initialize() {
});
}
#define WAIT_FOR_MOTOR_STOP() \
waitForMotorStop(); \
if (m_thread.getExitFlag()) { \
break; \
}
void PumpCtrlService::tryUpdateMotorSetting() {
if (m_pumpCfgUpdateFlag) updateMotorSetting();
}
void PumpCtrlService::updateMotorSetting() {
for (size_t i = 0; i < PUMP_NUM; i++) {
m_motors[i]->enable(false);
@ -70,8 +80,10 @@ void PumpCtrlService::updateMotorSetting() {
void PumpCtrlService::stop() {
ZLOGI(TAG, "stop");
stopAll();
m_thread.stop();
stopAll();
ZLOGI(TAG, "stop finish");
}
@ -80,102 +92,81 @@ void PumpCtrlService::stop() {
***********************************************************************************************************************/
void PumpCtrlService::reflux() {
ZLOGI(TAG, "reflux");
if (m_pumpCfgUpdateFlag) updateMotorSetting();
tryUpdateMotorSetting();
m_thread.start(
[this]() {
ValveStateSyncService::ins()->setValveState(1);
int32_t pipeLenML = getCfgInt(kcfg_pipeLengthML);
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, getMxRunRPM(i));
}
while (!m_thread.getExitFlag()) {
if (isAllReachTarget()) {
break;
}
osDelay(10);
}
stopAll();
ZLOGI(TAG, "reflux end");
},
[]() { ValveStateSyncService::ins()->setValveState(0); });
PUSH_DIS_INFO("开始回流");
m_thread.start([this]() {
unlockAll();
do {
doMotorsRefluxAllOnce();
WAIT_FOR_MOTOR_STOP();
} while (false);
stopAll();
lock();
ZLOGI(TAG, "reflux end");
PUSH_DIS_INFO("回流结束");
});
}
void PumpCtrlService::acidPrefilling() {
ZLOGI(TAG, "acidPrefilling");
if (m_pumpCfgUpdateFlag) updateMotorSetting();
m_thread.start(
[this]() {
ValveStateSyncService::ins()->setValveState(1);
int32_t pipeLenML = getCfgInt(kcfg_pipeLengthML);
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, getMxRunRPM(i));
}
while (!m_thread.getExitFlag()) {
if (isAllReachTarget()) {
break;
}
osDelay(10);
}
// 短回流
for (size_t i = 0; i < PUMP_NUM; i++) {
TMC51X0* cur_motor = m_motors[i];
cur_motor->moveBy(-(int32_t)(APPEND_ML) * 1000, getMxRunRPM(i));
}
while (!isAllReachTarget()) {
osDelay(10);
}
stopAll();
ZLOGI(TAG, "acidPrefilling end");
},
[]() { ValveStateSyncService::ins()->setValveState(0); });
tryUpdateMotorSetting();
PUSH_DIS_INFO("开始预充管路");
m_thread.start([this]() {
unlockAll();
do {
doMotorsRefluxAllOnce(); // 回流
WAIT_FOR_MOTOR_STOP();
doMotorsAcidPrefillingOnce(); // 预填充
WAIT_FOR_MOTOR_STOP();
doMotorsLittleRefluxOnce(); // 小回流
WAIT_FOR_MOTOR_STOP();
} while (false);
stopAll();
lock();
ZLOGI(TAG, "reflux end");
PUSH_DIS_INFO("结束预充管路");
});
}
void PumpCtrlService::autoMoveMutiTimes() {
// doMoveOnce();
ZLOGI(TAG, "autoMoveMutiTimes");
if (m_pumpCfgUpdateFlag) updateMotorSetting();
tryUpdateMotorSetting();
PUSH_DIS_INFO("开始自动加液");
m_thread.start([this]() {
float delayTime = getCfgFloat(kcfg_distrInterval);
ZLOGI(TAG, "delayTime %d", delayTime);
while (!m_thread.getExitFlag()) {
doMoveOnce();
for (size_t i = 0; i < delayTime * 1000; i++) {
osDelay(1);
if (m_thread.getExitFlag()) {
break;
}
delayTime = getCfgFloat(kcfg_distrInterval);
}
unlock();
doMotorsMoveByOnce();
WAIT_FOR_MOTOR_STOP();
doMotorsLittleRefluxOnce();
WAIT_FOR_MOTOR_STOP();
lock();
sleep(getCfgFloat(kcfg_distrInterval) * 1000);
}
stopAll();
lock();
PUSH_DIS_INFO("停止加液");
});
}
void PumpCtrlService::moveOnce() {
// doMoveOnce();
ZLOGI(TAG, "moveOnce");
if (m_pumpCfgUpdateFlag) updateMotorSetting();
tryUpdateMotorSetting();
PUSH_DIS_INFO("加一次液");
m_thread.start([this]() {
unlock();
do {
doMotorsMoveByOnce();
WAIT_FOR_MOTOR_STOP();
doMotorsLittleRefluxOnce();
WAIT_FOR_MOTOR_STOP();
} while (false);
m_thread.start([this]() { doMoveOnce(); });
stopAll();
lock();
PUSH_DIS_INFO("停止加液");
});
}
bool PumpCtrlService::isWorking() { return m_thread.isworking(); }
@ -183,52 +174,6 @@ bool PumpCtrlService::isWorking() { return m_thread.isworking(); }
/***********************************************************************************************************************
* BASIC *
***********************************************************************************************************************/
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);
float distribut_ml = getCfgFloat(config_index_t(kcfg_acideval0 + i));
TMC51X0* cur_motor = m_motors[i];
cur_motor->stop();
cur_motor->setXACTUAL(0);
if (pumpselect) {
ZLOGI(TAG, "pump %d move %f ml", i, distribut_ml);
cur_motor->moveBy((int32_t)(distribut_ml + APPEND_ML) * 1000, getMxRunRPM(i));
}
}
while (!isAllReachTarget() && !m_thread.getExitFlag()) {
// ZLOGI(TAG, "wait for motor move to target");
osDelay(10);
}
ZLOGI(TAG, "do moveOnce finish");
// 回流
for (size_t i = 0; i < PUMP_NUM; i++) {
bool pumpselect = GSM->getPumpSelectState(i);
TMC51X0* cur_motor = m_motors[i];
cur_motor->stop();
cur_motor->setXACTUAL(0);
if (pumpselect) {
cur_motor->moveBy(-(int32_t)(APPEND_ML) * 1000, getMxRunRPM(i));
}
}
while (!isAllReachTarget() && !m_thread.getExitFlag()) {
osDelay(10);
}
ZLOGI(TAG, "do moveOnce finish");
stopAll();
ValveStateSyncService::ins()->setValveState(0);
}
bool PumpCtrlService::isAllReachTarget() {
for (size_t i = 0; i < PUMP_NUM; i++) {
TMC5130RampStat state = m_motors[i]->getRampStat();
@ -284,3 +229,106 @@ double PumpCtrlService::getMotorNowPosR(int32_t mid) {
}
return m_motors[mid]->getXactualRAW() / 51200.0;
}
void PumpCtrlService::doMotorsMoveByOnce() {
int32_t step0 = int32_t((getCfgFloat(kcfg_acideval0) + getPumpAppendMl(0)) * 1000);
int32_t step1 = int32_t((getCfgFloat(kcfg_acideval1) + getPumpAppendMl(1)) * 1000);
int32_t step2 = int32_t((getCfgFloat(kcfg_acideval2) + getPumpAppendMl(2)) * 1000);
int32_t step3 = int32_t((getCfgFloat(kcfg_acideval3) + getPumpAppendMl(3)) * 1000);
step0 = GSM->getPumpSelectState(0) ? step0 : 0;
step1 = GSM->getPumpSelectState(1) ? step1 : 0;
step2 = GSM->getPumpSelectState(2) ? step2 : 0;
step3 = GSM->getPumpSelectState(3) ? step3 : 0;
ZLOGI(TAG, "doMotorsMoveByOnce, moveBy %d %d %d %d", step0, step1, step2, step3);
moveBy(step0, step1, step2, step3);
}
void PumpCtrlService::doMotorsRefluxAllOnce() {
int32_t step0 = int32_t(-(getCfgPipeLengthML(0) * 1.2) * 1000); // *1.2是为了保证液体完全回流
int32_t step1 = int32_t(-(getCfgPipeLengthML(1) * 1.2) * 1000); // *1.2是为了保证液体完全回流
int32_t step2 = int32_t(-(getCfgPipeLengthML(2) * 1.2) * 1000); // *1.2是为了保证液体完全回流
int32_t step3 = int32_t(-(getCfgPipeLengthML(3) * 1.2) * 1000); // *1.2是为了保证液体完全回流
// step0 = GSM->getPumpSelectState(0) ? step0 : 0;
// step1 = GSM->getPumpSelectState(1) ? step1 : 0;
// step2 = GSM->getPumpSelectState(2) ? step2 : 0;
// step3 = GSM->getPumpSelectState(3) ? step3 : 0;
ZLOGI(TAG, "doMotorsRefluxOnce, moveBy %d %d %d %d", step0, step1, step2, step3);
moveBy(step0, step1, step2, step3);
}
void PumpCtrlService::doMotorsAcidPrefillingOnce() {
int32_t step0 = int32_t((getCfgPipeLengthML(0)) * 1000);
int32_t step1 = int32_t((getCfgPipeLengthML(1)) * 1000);
int32_t step2 = int32_t((getCfgPipeLengthML(2)) * 1000);
int32_t step3 = int32_t((getCfgPipeLengthML(3)) * 1000);
step0 = GSM->getPumpSelectState(0) ? step0 : 0;
step1 = GSM->getPumpSelectState(1) ? step1 : 0;
step2 = GSM->getPumpSelectState(2) ? step2 : 0;
step3 = GSM->getPumpSelectState(3) ? step3 : 0;
ZLOGI(TAG, "doMotorsAcidPrefillingOnce, moveBy %d %d %d %d", step0, step1, step2, step3);
moveBy(step0, step1, step2, step3);
}
void PumpCtrlService::doMotorsLittleRefluxOnce() {
int32_t step0 = int32_t(-(getPumpAppendMl(0)) * 1000); //
int32_t step1 = int32_t(-(getPumpAppendMl(1)) * 1000); //
int32_t step2 = int32_t(-(getPumpAppendMl(2)) * 1000); //
int32_t step3 = int32_t(-(getPumpAppendMl(3)) * 1000); //
step0 = GSM->getPumpSelectState(0) ? step0 : 0;
step1 = GSM->getPumpSelectState(1) ? step1 : 0;
step2 = GSM->getPumpSelectState(2) ? step2 : 0;
step3 = GSM->getPumpSelectState(3) ? step3 : 0;
ZLOGI(TAG, "doMotorsLittleRefluxOnce, moveBy %d %d %d %d", step0, step1, step2, step3);
moveBy(step0, step1, step2, step3);
}
void PumpCtrlService::lock() {
ZLOGI(TAG, "lockAll");
ValveStateSyncService::ins()->setValveState(0);
}
void PumpCtrlService::unlock() {
bool select0 = GSM->getPumpSelectState(0);
bool select1 = GSM->getPumpSelectState(1);
bool select2 = GSM->getPumpSelectState(2);
bool select3 = GSM->getPumpSelectState(3);
ZLOGI(TAG, "unlock %d %d %d %d", select0, select1, select2, select3);
ValveStateSyncService::ins()->setValveState(select0, select1, select2, select3);
return;
}
void PumpCtrlService::unlockAll() {
ZLOGI(TAG, "unlockAll");
ValveStateSyncService::ins()->setValveState(1);
}
void PumpCtrlService::moveBy(int32_t steps0, int32_t steps1, int32_t steps2, int32_t steps3) {
m_motors[0]->moveBy(steps0, getMxRunRPM(0));
m_motors[1]->moveBy(steps1, getMxRunRPM(1));
m_motors[2]->moveBy(steps2, getMxRunRPM(2));
m_motors[3]->moveBy(steps3, getMxRunRPM(3));
}
void PumpCtrlService::waitForMotorStop() {
while (!m_thread.getExitFlag()) {
if (isAllReachTarget()) break;
osDelay(5);
}
return;
}
void PumpCtrlService::sleep(int32_t ms) {
for (size_t i = 0; i < ms;) {
if (m_thread.getExitFlag()) {
break;
}
osDelay(10);
i += 10;
}
}

19
usrc/service/pump_ctrl_service.hpp

@ -23,6 +23,7 @@ class PumpCtrlService {
void initialize();
void updateMotorSetting();
void tryUpdateMotorSetting();
public:
bool isWorking();
@ -35,14 +36,24 @@ class PumpCtrlService {
void stop();
public:
void rotate(int32_t mid, int32_t direction);
void stopRotate();
void rotate(int32_t mid, int32_t direction);
void stopRotate();
double getMotorNowPosR(int32_t mid);
private:
bool isAllReachTarget();
void doMotorsMoveByOnce();
void doMotorsRefluxAllOnce();
void doMotorsLittleRefluxOnce();
void doMotorsAcidPrefillingOnce();
void lock();
void unlock();
void unlockAll();
void moveBy(int32_t steps0, int32_t steps1, int32_t steps2, int32_t steps3);
void stopAll();
void doMoveOnce();
bool isAllReachTarget();
void waitForMotorStop();
void sleep(int32_t ms);
};
} // namespace iflytop

62
usrc/service/remote_controler_event_processer.cpp

@ -41,6 +41,7 @@ void RemoteControlerEventProcesser::initialize() {
AppEventBus::ins()->pushEvent(appevent);
} else if (packet->cmd == kzble_report_disconnect_event) {
GSM->setRemoterS(false);
PUMPCS->stop();
}
// ZLOGI(TAG, "TRACE process ble report end");
});
@ -92,6 +93,12 @@ void RemoteControlerEventProcesser::processKeyEventFromRemoter(hand_acid_remoter
* @brief
*/
if (PUMPCS->isWorking()) {
PUMPCS->stop();
RCTRL->setRemoterState(GSM->getRunMode(), PUMPCS->isWorking());
return;
}
if (UIS->getNowPage() == pg_muPumpTest) {
ZLOGW(TAG, "now page is in pump test, remote key event process by pumpTestPage");
return;
@ -102,39 +109,34 @@ void RemoteControlerEventProcesser::processKeyEventFromRemoter(hand_acid_remoter
}
if (UIS->getNowPage() != pg_main) {
UIS->alert("请先切换到首页,在控制泵机");
UIS->alert("请先切换到首页,在控制设备");
return;
}
if (PUMPCS->isWorking()) {
PUMPCS->stop();
RCTRL->setRemoterState(GSM->getRunMode(), PUMPCS->isWorking());
} 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) {
PUMPCS->autoMoveMutiTimes();
}
} else if (keyEvent == hand_acid_remoter_kevent_change_next_mode) {
// 修改工作模式
if (GSM->getRunMode() == khand_acid_m_jog_mode) {
GSM->setRunMode(khand_acid_m_continuous_mode);
} else if (GSM->getRunMode() == khand_acid_m_continuous_mode) {
GSM->setRunMode(khand_acid_m_jog_mode);
}
} else if (keyEvent == hand_acid_remoter_kevent_reflux) {
// 回流
PUMPCS->reflux();
} else if (keyEvent == hand_acid_remoter_kevent_preFilling) {
// 管路填充
PUMPCS->acidPrefilling();
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) {
PUMPCS->autoMoveMutiTimes();
}
} else if (keyEvent == hand_acid_remoter_kevent_change_next_mode) {
// 修改工作模式
if (GSM->getRunMode() == khand_acid_m_jog_mode) {
GSM->setRunMode(khand_acid_m_continuous_mode);
} else if (GSM->getRunMode() == khand_acid_m_continuous_mode) {
GSM->setRunMode(khand_acid_m_jog_mode);
}
} else if (keyEvent == hand_acid_remoter_kevent_reflux) {
// 回流
PUMPCS->reflux();
} else if (keyEvent == hand_acid_remoter_kevent_preFilling) {
// 管路填充
PUMPCS->acidPrefilling();
}
}

16
usrc/service/valve_state_ctrl_service.cpp

@ -63,6 +63,22 @@ void ValveStateSyncService::setValveState(int valveIndex, bool state) {
}
}
void ValveStateSyncService::setValveState(bool state0, bool state1, bool state2, bool state3) {
{
zlock_guard l(lock);
output0state = (output0state & ~(1 << 0)) | (state0 << 0);
output0state = (output0state & ~(1 << 1)) | (state1 << 1);
output0state = (output0state & ~(1 << 2)) | (state2 << 2);
output0state = (output0state & ~(1 << 3)) | (state3 << 3);
forceupdate = true;
}
m_thread.wake();
while (!forceupdate) {
osDelay(2);
}
}
#define SETBIT(byte, off, valve) (byte = (byte & ~(1 << off)) | (valve << off))
void ValveStateSyncService::setRGBState(bool r, bool g, bool b) {

1
usrc/service/valve_state_ctrl_service.hpp

@ -30,6 +30,7 @@ class ValveStateSyncService {
void setValveState(int valveIndex, bool state);
void setValveState(bool state);
void setValveState(bool state0, bool state1, bool state2, bool state3);
void setRGBState(bool r, bool g, bool b);
void setWarningState(bool warning);

Loading…
Cancel
Save