|
@@ -728,21 +728,24 @@ object BleConnectionManager {
|
|
|
withContext(Dispatchers.IO) {
|
|
withContext(Dispatchers.IO) {
|
|
|
// -------- 第二次尝试:先开电,再连 --------
|
|
// -------- 第二次尝试:先开电,再连 --------
|
|
|
// 开电,并等待回调
|
|
// 开电,并等待回调
|
|
|
- suspendCoroutine<Unit> { unitCont ->
|
|
|
|
|
- HardwareMode.getCurrentHardwareMode().controlKeyCharge(false, mac) {
|
|
|
|
|
- logger.info("接收到消息,关闭充电")
|
|
|
|
|
- ThreadUtils.runOnIO {
|
|
|
|
|
- delay(500)
|
|
|
|
|
- HardwareMode.getCurrentHardwareMode().controlKeyCharge(true, mac) {
|
|
|
|
|
- logger.info("接收到消息,打开")
|
|
|
|
|
- unitCont.resume(Unit)
|
|
|
|
|
|
|
+ val isConnect = if (isSend) {
|
|
|
|
|
+ BleSendDispatcher.isConnected(mac)
|
|
|
|
|
+ } else {
|
|
|
|
|
+ BleReturnDispatcher.isConnected(mac)
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!isConnect){
|
|
|
|
|
+ suspendCoroutine<Unit> { unitCont ->
|
|
|
|
|
+ HardwareMode.getCurrentHardwareMode().controlKeyCharge(false, mac) {
|
|
|
|
|
+ logger.info("接收到消息,关闭充电")
|
|
|
|
|
+ ThreadUtils.runOnIO {
|
|
|
|
|
+ HardwareMode.getCurrentHardwareMode().controlKeyCharge(true, mac) {
|
|
|
|
|
+ logger.info("接收到消息,打开")
|
|
|
|
|
+ unitCont.resume(Unit)
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- logger.debug("蓝牙连接-开启充电并等待1500ms")
|
|
|
|
|
- // 等 500ms 保证硬件电源稳定
|
|
|
|
|
- delay(1500)
|
|
|
|
|
|
|
|
|
|
// 再次注册连接监听
|
|
// 再次注册连接监听
|
|
|
val secondTry = suspendCancellableCoroutine<Boolean> { cont ->
|
|
val secondTry = suspendCancellableCoroutine<Boolean> { cont ->
|