diff --git a/src/main/java/com/iflytop/handacid/app/command/control/SolutionAddStartCommand.java b/src/main/java/com/iflytop/handacid/app/command/control/SolutionAddStartCommand.java index 132a75e..882bc08 100644 --- a/src/main/java/com/iflytop/handacid/app/command/control/SolutionAddStartCommand.java +++ b/src/main/java/com/iflytop/handacid/app/command/control/SolutionAddStartCommand.java @@ -2,6 +2,7 @@ package com.iflytop.handacid.app.command.control; import com.iflytop.handacid.app.common.annotation.CommandMapping; import com.iflytop.handacid.app.core.command.BaseCommandHandler; +import com.iflytop.handacid.app.core.state.DeviceState; import com.iflytop.handacid.app.model.dto.CommandDTO; import com.iflytop.handacid.app.service.ChannelCtrlService; import lombok.RequiredArgsConstructor; @@ -11,7 +12,7 @@ import org.springframework.stereotype.Component; import java.util.concurrent.CompletableFuture; /** - * 开始加液(废弃) + * 开始加液 */ @Slf4j @Component @@ -19,9 +20,11 @@ import java.util.concurrent.CompletableFuture; @CommandMapping("solution_add_start") public class SolutionAddStartCommand extends BaseCommandHandler { private final ChannelCtrlService channelCtrlService; + private final DeviceState deviceState; @Override public CompletableFuture handle(CommandDTO commandDTO) { + return runAsync(() -> { channelCtrlService.solutionAddStart(); }); diff --git a/src/main/java/com/iflytop/handacid/app/core/listener/BleGamepadEventListener.java b/src/main/java/com/iflytop/handacid/app/core/listener/BleGamepadEventListener.java index 63d742b..a75b34d 100644 --- a/src/main/java/com/iflytop/handacid/app/core/listener/BleGamepadEventListener.java +++ b/src/main/java/com/iflytop/handacid/app/core/listener/BleGamepadEventListener.java @@ -55,10 +55,10 @@ public class BleGamepadEventListener { } } else if (CmdId.event_ble_gamepad_connected.equals(cmdId)) { log.info("蓝牙手柄 连接成功"); - deviceState.setBluetoothConnected(true); + deviceState.getRemoteControlState().setConnected(true); } else if (CmdId.event_ble_gamepad_disconnected.equals(cmdId)) { log.info("蓝牙手柄 连接断开"); - deviceState.setBluetoothConnected(false); + deviceState.getRemoteControlState().setConnected(false); } } diff --git a/src/main/java/com/iflytop/handacid/app/core/state/DeviceState.java b/src/main/java/com/iflytop/handacid/app/core/state/DeviceState.java index 54863dc..b4555a0 100644 --- a/src/main/java/com/iflytop/handacid/app/core/state/DeviceState.java +++ b/src/main/java/com/iflytop/handacid/app/core/state/DeviceState.java @@ -40,8 +40,8 @@ public class DeviceState { @Schema(description = "是否是急停状态,true为急停") private volatile boolean emergencyStop = false; - @Schema(description = "蓝牙是否连接") - private volatile boolean bluetoothConnected = false; + @Schema(description = "遥控器状态") + private volatile RemoteControlState remoteControlState; @Schema(description = "当前登录用户") private volatile User currentUser; @@ -54,7 +54,7 @@ public class DeviceState { json.putOnce("virtual", virtual); json.putOnce("initComplete", initComplete); json.putOnce("emergencyStop", emergencyStop); - json.putOnce("bluetoothConnected", bluetoothConnected); + json.putOnce("remoteControlState", remoteControlState); json.putOnce("currentUser", currentUser); return json; } diff --git a/src/main/java/com/iflytop/handacid/app/core/state/RemoteControlState.java b/src/main/java/com/iflytop/handacid/app/core/state/RemoteControlState.java new file mode 100644 index 0000000..17c55bc --- /dev/null +++ b/src/main/java/com/iflytop/handacid/app/core/state/RemoteControlState.java @@ -0,0 +1,27 @@ +package com.iflytop.handacid.app.core.state; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import lombok.RequiredArgsConstructor; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Component; + +@Schema(description = "遥控器状态") +@Data +@Component +@Scope("prototype") +@RequiredArgsConstructor +@JsonIgnoreProperties(value = {"advisors", "frozen", "preFiltered", "proxyTargetClass", "targetSource", "exposeProxy", "advisorCount", "proxiedInterfaces", "targetClass"}) +public class RemoteControlState { + + @Schema(description = "遥控器是否连接") + private volatile boolean connected = false; + + @Schema(description = "当前电量(0-100%)") + private volatile int batteryLevel = 0; + + @Schema(description = "是否正在充电") + private volatile boolean charging = false; + +} diff --git a/src/main/java/com/iflytop/handacid/app/service/DeviceInitService.java b/src/main/java/com/iflytop/handacid/app/service/DeviceInitService.java index 9a93d24..cb029e7 100644 --- a/src/main/java/com/iflytop/handacid/app/service/DeviceInitService.java +++ b/src/main/java/com/iflytop/handacid/app/service/DeviceInitService.java @@ -8,6 +8,7 @@ import com.iflytop.handacid.app.core.command.DeviceCommand; import com.iflytop.handacid.app.core.command.DeviceCommandGenerator; import com.iflytop.handacid.app.core.state.ChannelState; import com.iflytop.handacid.app.core.state.DeviceState; +import com.iflytop.handacid.app.core.state.RemoteControlState; import com.iflytop.handacid.common.model.bo.DeviceInitializationData; import com.iflytop.handacid.common.model.entity.Channel; import com.iflytop.handacid.common.model.entity.DeviceParamConfig; @@ -38,6 +39,7 @@ public class DeviceInitService { private boolean isLink = false; private final DeviceState deviceState; private final ObjectProvider channelStateObjectProvider; + private final ObjectProvider remoteControlStateObjectProvider; private final ChannelService channelService; private final DeviceCommandService deviceCommandService; private final DeviceParamConfigService deviceParamConfigService; @@ -99,8 +101,8 @@ public class DeviceInitService { ChannelState channelState = channelStateObjectProvider.getObject(code, solution.getId(), solution.getName(), channel.getConcentration(), channel.getTargetVolume(), channel.getReceivedVolume(), channel.getCurrentVolume()); deviceState.getChannelStateMap().put(code, channelState); } - SolutionAddMode mode = SolutionAddMode.valueOf(systemConfigService.getValueByKey(SystemConfigKey.SOLUTION_ADD_MODE)); - deviceState.setMode(mode); + deviceState.setMode(SolutionAddMode.valueOf(systemConfigService.getValueByKey(SystemConfigKey.SOLUTION_ADD_MODE))); + deviceState.setRemoteControlState(remoteControlStateObjectProvider.getObject()); log.info("初始化 initDeviceState完毕"); }