Browse Source

feat:添加遥控手柄状态

master
白凤吉 4 days ago
parent
commit
11c77cd55b
  1. 5
      src/main/java/com/iflytop/handacid/app/command/control/SolutionAddStartCommand.java
  2. 4
      src/main/java/com/iflytop/handacid/app/core/listener/BleGamepadEventListener.java
  3. 6
      src/main/java/com/iflytop/handacid/app/core/state/DeviceState.java
  4. 27
      src/main/java/com/iflytop/handacid/app/core/state/RemoteControlState.java
  5. 6
      src/main/java/com/iflytop/handacid/app/service/DeviceInitService.java

5
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.common.annotation.CommandMapping;
import com.iflytop.handacid.app.core.command.BaseCommandHandler; 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.model.dto.CommandDTO;
import com.iflytop.handacid.app.service.ChannelCtrlService; import com.iflytop.handacid.app.service.ChannelCtrlService;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
@ -11,7 +12,7 @@ import org.springframework.stereotype.Component;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
/** /**
* 开始加液(废弃)
* 开始加液
*/ */
@Slf4j @Slf4j
@Component @Component
@ -19,9 +20,11 @@ import java.util.concurrent.CompletableFuture;
@CommandMapping("solution_add_start") @CommandMapping("solution_add_start")
public class SolutionAddStartCommand extends BaseCommandHandler { public class SolutionAddStartCommand extends BaseCommandHandler {
private final ChannelCtrlService channelCtrlService; private final ChannelCtrlService channelCtrlService;
private final DeviceState deviceState;
@Override @Override
public CompletableFuture<Void> handle(CommandDTO commandDTO) { public CompletableFuture<Void> handle(CommandDTO commandDTO) {
return runAsync(() -> { return runAsync(() -> {
channelCtrlService.solutionAddStart(); channelCtrlService.solutionAddStart();
}); });

4
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)) { } else if (CmdId.event_ble_gamepad_connected.equals(cmdId)) {
log.info("蓝牙手柄 连接成功"); log.info("蓝牙手柄 连接成功");
deviceState.setBluetoothConnected(true);
deviceState.getRemoteControlState().setConnected(true);
} else if (CmdId.event_ble_gamepad_disconnected.equals(cmdId)) { } else if (CmdId.event_ble_gamepad_disconnected.equals(cmdId)) {
log.info("蓝牙手柄 连接断开"); log.info("蓝牙手柄 连接断开");
deviceState.setBluetoothConnected(false);
deviceState.getRemoteControlState().setConnected(false);
} }
} }

6
src/main/java/com/iflytop/handacid/app/core/state/DeviceState.java

@ -40,8 +40,8 @@ public class DeviceState {
@Schema(description = "是否是急停状态,true为急停") @Schema(description = "是否是急停状态,true为急停")
private volatile boolean emergencyStop = false; private volatile boolean emergencyStop = false;
@Schema(description = "蓝牙是否连接")
private volatile boolean bluetoothConnected = false;
@Schema(description = "遥控器状态")
private volatile RemoteControlState remoteControlState;
@Schema(description = "当前登录用户") @Schema(description = "当前登录用户")
private volatile User currentUser; private volatile User currentUser;
@ -54,7 +54,7 @@ public class DeviceState {
json.putOnce("virtual", virtual); json.putOnce("virtual", virtual);
json.putOnce("initComplete", initComplete); json.putOnce("initComplete", initComplete);
json.putOnce("emergencyStop", emergencyStop); json.putOnce("emergencyStop", emergencyStop);
json.putOnce("bluetoothConnected", bluetoothConnected);
json.putOnce("remoteControlState", remoteControlState);
json.putOnce("currentUser", currentUser); json.putOnce("currentUser", currentUser);
return json; return json;
} }

27
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;
}

6
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.command.DeviceCommandGenerator;
import com.iflytop.handacid.app.core.state.ChannelState; import com.iflytop.handacid.app.core.state.ChannelState;
import com.iflytop.handacid.app.core.state.DeviceState; 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.bo.DeviceInitializationData;
import com.iflytop.handacid.common.model.entity.Channel; import com.iflytop.handacid.common.model.entity.Channel;
import com.iflytop.handacid.common.model.entity.DeviceParamConfig; import com.iflytop.handacid.common.model.entity.DeviceParamConfig;
@ -38,6 +39,7 @@ public class DeviceInitService {
private boolean isLink = false; private boolean isLink = false;
private final DeviceState deviceState; private final DeviceState deviceState;
private final ObjectProvider<ChannelState> channelStateObjectProvider; private final ObjectProvider<ChannelState> channelStateObjectProvider;
private final ObjectProvider<RemoteControlState> remoteControlStateObjectProvider;
private final ChannelService channelService; private final ChannelService channelService;
private final DeviceCommandService deviceCommandService; private final DeviceCommandService deviceCommandService;
private final DeviceParamConfigService deviceParamConfigService; 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()); ChannelState channelState = channelStateObjectProvider.getObject(code, solution.getId(), solution.getName(), channel.getConcentration(), channel.getTargetVolume(), channel.getReceivedVolume(), channel.getCurrentVolume());
deviceState.getChannelStateMap().put(code, channelState); 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完毕"); log.info("初始化 initDeviceState完毕");
} }

Loading…
Cancel
Save