电动门能力
介绍
通过 API 可以控制电动门的开关,以及查询电动门的状态。API 需要使用 10.1 及以上的release 库
打开或者关闭电动门
RobotApi.getInstance().startControlElectricDoor(0, doorCmd, new ActionListener() {
@Override
public void onResult(int result, String message, String extraData) {
Log.d(TAG, "startControlElectricDoor result:" + result + " message:" + message);
LogTools.info("startControlElectricDoor result:" + result + " message:" + message);
if (result == Definition.RESULT_OK) {
//控制成功
Log.d(TAG, "startControlElectricDoor success");
} else {
//控制失败
Log.d(TAG, "startControlElectricDoor failed");
}
}
@Override
public void onError(int errorCode, String errorString, String extraData) {
Log.d(TAG, "startControlElectricDoor onError: errorCode:" + errorCode + " errorString:" + errorString);
if (errorCode == Definition.ERROR_ELECTRIC_DOOR_BLOCK) {
//上下门被堵(夹手或者其他被夹)
Log.d(TAG, "startControlElectricDoor onError: electric door block");
} else if (errorCode == Definition.ERROR_ELECTRIC_DOOR_UPPER_BLOCK) {
//上门被堵(上面门夹手或者其他)
Log.d(TAG, "startControlElectricDoor onError: electric door upper block");
} else if (errorCode == Definition.ERROR_ELECTRIC_DOOR_LOWER_BLOCK) {
//下门被堵(上面门夹手或者其他)
Log.d(TAG, "startControlElectricDoor onError: electric door lower block");
} else if (errorCode == Definition.ERROR_ELECTRIC_DOOR_TIMEOUT) {
//控制门指令超时
Log.d(TAG, "startControlElectricDoor onError: electric door timeout");
}
}
@Override
public void onStatusUpdate(int status, String data, String extraData) {
Log.d(TAG, "onStatusUpdate: status:" + status + " data:" + data);
if (status == Definition.STATUS_ELECTRIC_DOOR_BLOCK) {
//上下门被堵(夹手或者其他被夹),可以做夹手提示
Log.d(TAG, "onStatusUpdate: electric door block");
} else if (status == Definition.STATUS_ELECTRIC_DOOR_UPPER_BLOCK) {
//上门被堵(上面门夹手或者其他),可以做夹手提示
Log.d(TAG, "onStatusUpdate: electric door upper block");
} else if (status == Definition.STATUS_ELECTRIC_DOOR_LOWER_BLOCK) {
//下门被堵(上面门夹手或者其他),可以做夹手提示
Log.d(TAG, "onStatusUpdate: electric door lower block");
}
}
});
doorCmd参数:
Definition.CAN_DOOR_DOOR1_DOOR2_OPEN 打开上面仓门
Definition.CAN_DOOR_DOOR1_DOOR2_CLOSE 关闭上面仓门
Definition.CAN_DOOR_DOOR3_DOOR4_OPEN 打开下面仓门
Definition.CAN_DOOR_DOOR3_DOOR4_CLOSE 关闭下面仓门
Definition.CAN_DOOR_ALL_OPEN 打开所有仓门
Definition.CAN_DOOR_ALL_CLOSE 关闭所有仓门
注册仓门状态监听
注册电动门状态监听,获取电动门状态,根据自己业务在需要地方注册
当电动门状态发生变化时,会回调onStatusUpdate方法,例如调用开门、关门指令后,电动门状态会发生变化
如果需要在任意时机获取电动门状态,可以调用getElectricDoorStatus方法
//listener 的处理,参考getElectricDoorStatus方法中处理 RobotApi.getInstance().registerStatusListener(Definition.STATUS_CAN_ELECTRIC_DOOR_CTRL, statusListener);
移除仓门监听
在不需要电门状态时候,移除监听,防止内存泄漏
RobotApi.getInstance().unregisterStatusListener(statusListener);
主动查询仓门状态
在任意时机都可以调用该方法查询仓门状态
RobotApi.getInstance().getElectricDoorStatus(0, new CommandListener() {
@Override
public void onResult(int result, String message, String extraData) {
super.onResult(result, message, extraData);
Log.d(TAG, "getElectricDoorStatus result:" + result + " message:" + message);
if (result == 1 && !TextUtils.isEmpty(message)) {
CanElectricDoorBean doorBean = GsonUtil.fromJson(message, CanElectricDoorBean.class);
//door1和 door2是上面的两扇仓门,door3和door4是下面的两扇仓门
//上仓门的状态
if (doorBean.getDoor1() == Definition.CAN_DOOR_STATUS_RUNNING || doorBean.getDoor2() == Definition.CAN_DOOR_STATUS_RUNNING) {
Log.d(TAG, "upper door is running");
//当仓门正在运动时,不要执行开关门指令
}
if (doorBean.getDoor1() == Definition.CAN_DOOR_STATUS_OPEN && doorBean.getDoor2() == Definition.CAN_DOOR_STATUS_OPEN) {
Log.d(TAG, "upper door is open");
}
if (doorBean.getDoor1() == Definition.CAN_DOOR_STATUS_CLOSE && doorBean.getDoor2() == Definition.CAN_DOOR_STATUS_CLOSE) {
Log.d(TAG, "upper door is close");
}
//下仓门的状态
if (doorBean.getDoor3() == Definition.CAN_DOOR_STATUS_RUNNING || doorBean.getDoor4() == Definition.CAN_DOOR_STATUS_RUNNING) {
Log.d(TAG, "lower door is running");
//当仓门正在运动时,不要执行开关门指令
}
if (doorBean.getDoor3() == Definition.CAN_DOOR_STATUS_OPEN && doorBean.getDoor4() == Definition.CAN_DOOR_STATUS_OPEN) {
Log.d(TAG, "lower door is open");
}
if (doorBean.getDoor3() == Definition.CAN_DOOR_STATUS_CLOSE && doorBean.getDoor4() == Definition.CAN_DOOR_STATUS_CLOSE) {
Log.d(TAG, "lower door is close");
}
//门的堵转状态,开门、关门时可能会出现堵转
//关门时,被堵
if (doorBean.getUpStatus() == Definition.CAN_DOOR_STATUS_BLOCK_AND_BOUNCE) {
Log.d(TAG, "upper door is block and bounce");
}
if (doorBean.getDownStatus() == Definition.CAN_DOOR_STATUS_BLOCK_AND_BOUNCE) {
Log.d(TAG, "lower door is block and bounce");
}
//开门时,被堵
if (doorBean.getUpStatus() == Definition.CAN_DOOR_STATUS_BLOCKING_STOP) {
Log.d(TAG, "upper door is blocking stop");
}
if (doorBean.getDownStatus() == Definition.CAN_DOOR_STATUS_BLOCKING_STOP) {
Log.d(TAG, "lower door is blocking stop");
}
} else {
Log.d(TAG, "getElectricDoorStatus onResult: Failure to get status");
}
}
});
状态说明:
Definition.CAN_DOOR_STATUS_RUNNING:电动门正在执行任务
Definition.CAN_DOOR_STATUS_OPEN:仓门打开
Definition.CAN_DOOR_STATUS_CLOSE:仓门关闭
Definition.CAN_DOOR_STATUS_BLOCK_AND_BOUNCE:关门时候被堵(出现该情况,移除阻挡物后重试)
Definition.CAN_DOOR_STATUS_BLOCKING_STOP:开门时候被堵(出现该情况,移除阻挡物后重试)
使用说明:
上仓门分为两扇门,返回为 door1 和 door2;下仓门为两扇门,返回 door3 和 door4。
查询上仓门状态可以同时判断 door1 和 door2 状态,查询下仓门状态可以同时判断 door3 和 door4 状态;
在使用打开或者关闭仓门命令后,立即去查询,此时仓门正在打开或者关闭,得不到预期的已经打开或者已经关闭状态,需要延迟一定时间查询。
具体使用参考 Demo
豹小秘 | 豹小秘2 | mini | 招财豹 | 招财豹Pro | 豹小秘DP | 豹小递Pro |
否 | 否 | 否 | 否 | 否 | 否 | 是 |