8 changed files with 77 additions and 36 deletions
-
4src/main/java/com/iflytop/handacid/app/command/control/SolutionAddStopCommand.java
-
1src/main/java/com/iflytop/handacid/app/core/listener/BleGamepadEventListener.java
-
39src/main/java/com/iflytop/handacid/app/scheduled/BleGamepadStateScheduledTask.java
-
1src/main/java/com/iflytop/handacid/app/service/ChannelCtrlService.java
-
3src/main/java/com/iflytop/handacid/app/service/DeviceInitService.java
-
53src/main/java/com/iflytop/handacid/hardware/comm/can/A8kCanBusConnection.java
-
7src/main/java/com/iflytop/handacid/hardware/drivers/BleGamepadDriver.java
-
5src/main/java/com/iflytop/handacid/hardware/service/AppEventBusService.java
@ -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