|
|
@ -1,8 +1,11 @@ |
|
|
|
package iflytop.app.page; |
|
|
|
|
|
|
|
import com.fasterxml.jackson.databind.JsonNode; |
|
|
|
import iflytop.app.hardware.driver.LeisaiServoDriver; |
|
|
|
import iflytop.app.hardware.type.LeisaiRegIndex; |
|
|
|
import iflytop.app.hardware.type.LeisaiServoMId; |
|
|
|
import iflytop.app.hardware.type.LeisaiServoSpeedLevel; |
|
|
|
import iflytop.app.hardware.type.MiniServoRegIndex; |
|
|
|
import iflytop.app.type.exception.HardwareException; |
|
|
|
import iflytop.app.utils.ZJsonNode; |
|
|
|
import iflytop.extui.mgr.ExtApiPageMgr; |
|
|
@ -50,6 +53,11 @@ public class LeisaiServoPage { |
|
|
|
driver.enable(id, 0); |
|
|
|
} |
|
|
|
|
|
|
|
public void stop() throws Exception { |
|
|
|
log.info("stop called"); |
|
|
|
driver.moduleStop(id); |
|
|
|
} |
|
|
|
|
|
|
|
public Integer readPosition() throws Exception { |
|
|
|
log.info("readPosition called"); |
|
|
|
return driver.readPosition(id); |
|
|
@ -93,6 +101,22 @@ public class LeisaiServoPage { |
|
|
|
return node.get(); |
|
|
|
} |
|
|
|
|
|
|
|
public void setReg(LeisaiRegIndex reg, Integer val) throws HardwareException { |
|
|
|
driver.setReg(id, reg, val); |
|
|
|
} |
|
|
|
|
|
|
|
public JsonNode getAllReg() { |
|
|
|
ZJsonNode jsonNode = new ZJsonNode(); |
|
|
|
for (LeisaiRegIndex reg : LeisaiRegIndex.values()) { |
|
|
|
try { |
|
|
|
jsonNode.get(reg.name()).set(driver.getReg(id, reg)); |
|
|
|
} catch (HardwareException e) { |
|
|
|
jsonNode.get(reg.name()).set("error"); |
|
|
|
} |
|
|
|
} //enable |
|
|
|
return jsonNode.get(); |
|
|
|
} |
|
|
|
|
|
|
|
@PostConstruct |
|
|
|
void init() { |
|
|
|
var page = extApiPageMgr.newPage(this); |
|
|
@ -105,6 +129,7 @@ public class LeisaiServoPage { |
|
|
|
page.addFunction("使能伺服", this::enableServo); |
|
|
|
page.addFunction("失能伺服", this::disableServo); |
|
|
|
page.addFunction("归零", this::moveToZero); |
|
|
|
page.addFunction("停止", this::stop); |
|
|
|
|
|
|
|
page.newGroup("相对移动"); |
|
|
|
page.addFunction("设置相对移动距离", this::setLeisaiServoDpos).setParamVal("dpos", () -> dpos); |
|
|
@ -118,6 +143,10 @@ public class LeisaiServoPage { |
|
|
|
page.addFunction("顺时针旋转", this::rotateForward); |
|
|
|
page.addFunction("逆时针旋转", this::rotateBackward); |
|
|
|
|
|
|
|
page.newGroup("寄存器"); |
|
|
|
page.addFunction("设置寄存器", this::setReg); |
|
|
|
page.addFunction("读取所有寄存器", this::getAllReg); |
|
|
|
|
|
|
|
page.newGroup("状态"); |
|
|
|
page.addFunction("读取位置", this::readPosition); |
|
|
|
page.addFunction("读取IO", this::readIOState); |
|
|
|