Browse Source
Merge remote-tracking branch 'origin/master'
Merge remote-tracking branch 'origin/master'
# Conflicts: # src/main/java/com/iflytop/handacid/hardware/drivers/BleGamepadDriver.javamaster
10 changed files with 117 additions and 42 deletions
-
5src/main/java/com/iflytop/handacid/app/command/control/SolutionAddStartCommand.java
-
4src/main/java/com/iflytop/handacid/app/command/control/SolutionAddStopCommand.java
-
5src/main/java/com/iflytop/handacid/app/core/listener/BleGamepadEventListener.java
-
11src/main/java/com/iflytop/handacid/app/core/state/DeviceState.java
-
27src/main/java/com/iflytop/handacid/app/core/state/RemoteControlState.java
-
39src/main/java/com/iflytop/handacid/app/scheduled/BleGamepadStateScheduledTask.java
-
1src/main/java/com/iflytop/handacid/app/service/ChannelCtrlService.java
-
9src/main/java/com/iflytop/handacid/app/service/DeviceInitService.java
-
53src/main/java/com/iflytop/handacid/hardware/comm/can/A8kCanBusConnection.java
-
5src/main/java/com/iflytop/handacid/hardware/service/AppEventBusService.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; |
|||
|
|||
} |
@ -0,0 +1,39 @@ |
|||
package com.iflytop.handacid.app.scheduled; |
|||
|
|||
import com.iflytop.handacid.app.core.state.DeviceState; |
|||
import com.iflytop.handacid.hardware.drivers.BleGamepadDriver; |
|||
import com.iflytop.handacid.hardware.type.BleGamepadMid; |
|||
import lombok.RequiredArgsConstructor; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.scheduling.annotation.Scheduled; |
|||
import org.springframework.stereotype.Service; |
|||
|
|||
/** |
|||
* 定时采集蓝牙的连接状态和电量 |
|||
*/ |
|||
@Slf4j |
|||
@Service |
|||
@RequiredArgsConstructor |
|||
public class BleGamepadStateScheduledTask { |
|||
private final BleGamepadDriver bleGamepadDriver; |
|||
private final DeviceState deviceState; |
|||
|
|||
@Scheduled(fixedRate = 30 * 1000) |
|||
public void fetchTrayState() { |
|||
try { |
|||
|
|||
if (!deviceState.isVirtual()) { |
|||
boolean is_connect = bleGamepadDriver.is_connected(BleGamepadMid.BleGamePad); |
|||
deviceState.getRemoteControlState().setConnected(is_connect); |
|||
if (is_connect) { |
|||
Integer[] power_state = bleGamepadDriver.get_power_state(BleGamepadMid.BleGamePad); |
|||
deviceState.getRemoteControlState().setBatteryLevel(power_state[0]); |
|||
deviceState.getRemoteControlState().setCharging(power_state[1] != 0); |
|||
} |
|||
} |
|||
} catch (Exception e) { |
|||
log.error("定时采集蓝牙的连接状态和电量错误", e); |
|||
} |
|||
|
|||
} |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue