update speed function
This commit is contained in:
parent
aa8f6f5c22
commit
318b57b2bf
12
protocol.c
12
protocol.c
@ -44,7 +44,7 @@ SystemStatus_t systemStatus = {
|
||||
DeviceParam_t dp = {
|
||||
.pump = {
|
||||
{"pump1", 4, 60, 100, 100,40000,0},
|
||||
{"pump2", 3, 10, 100, 100,40000,0}
|
||||
{"pump2", 3, 60, 100, 100,40000,0}
|
||||
},
|
||||
.valve = {
|
||||
{"valve1", 1, 10, 100, 100,47620,0},
|
||||
@ -448,7 +448,7 @@ static uint8_t SetPumpJogDec(uint8_t index, uint16_t dec) {
|
||||
* @return 0:成功 其他:失败
|
||||
*/
|
||||
static uint8_t SetPumpJogSpeed(uint8_t index, uint16_t speed) {
|
||||
return WritePump1Reg(dp.pump[index].id, RTU_PUMP_CMD_JS, speed*PUMP_SPEED_RPS);
|
||||
return WritePump1Reg(dp.pump[index].id, RTU_PUMP_CMD_JS, speed);
|
||||
}
|
||||
|
||||
// Jog=慢跑
|
||||
@ -508,7 +508,7 @@ static uint8_t SetPumpStepDec(uint8_t index, uint16_t dec) {
|
||||
* @return 实际速度值
|
||||
*/
|
||||
uint16_t transSpeedPercentToSpeed(uint8_t index, uint8_t speedPercent) {
|
||||
return speedPercent * dp.pump[index].fullSpeed / 100;
|
||||
return speedPercent*PUMP_SPEED_RPS * dp.pump[index].fullSpeed / 100;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -532,7 +532,7 @@ uint8_t transSpeedToSpeedPercent(uint8_t index, uint32_t speed) {
|
||||
*/
|
||||
static uint8_t SetPumpStepSpeed(uint8_t index, uint16_t speed) {
|
||||
// 速度类寄存器参数设定值单位为 1/240 rps
|
||||
speed = speed * PUMP_SPEED_RPS;
|
||||
// speed = speed * PUMP_SPEED_RPS;
|
||||
return WritePump1Reg(dp.pump[index].id, RTU_PUMP_CMD_VE, speed);
|
||||
}
|
||||
/**
|
||||
@ -1599,6 +1599,9 @@ static uint8_t HandlePumpSpeedControl(uint8_t *Buff, uint8_t len) {
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if(speedPercent == 0) {
|
||||
speedPercent = 1;
|
||||
}
|
||||
|
||||
if (speedPercent > 100) {
|
||||
log_e("泵速度设置错误");
|
||||
@ -1608,6 +1611,7 @@ static uint8_t HandlePumpSpeedControl(uint8_t *Buff, uint8_t len) {
|
||||
|
||||
// 写入指令
|
||||
uint16_t speed = transSpeedPercentToSpeed(index, speedPercent);
|
||||
log_d("泵速度设置: %d[%d], %d[%d%%]",index, dp.pump[index].id, speed,speedPercent);
|
||||
SetPumpJogSpeed(index, speed);
|
||||
SetPumpStepSpeed(index, speed);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user