蓝牙断开连接变成异步操作
This commit is contained in:
@ -398,11 +398,11 @@
|
|||||||
ble = BleTool.getBleTool();
|
ble = BleTool.getBleTool();
|
||||||
|
|
||||||
|
|
||||||
ble.addReceiveCallback(these.bleValueNotify, pagePath);
|
ble.addReceiveCallback(this.bleValueNotify, pagePath);
|
||||||
ble.addStateBreakCallback(these.bleStateBreak, pagePath);
|
ble.addStateBreakCallback(this.bleStateBreak, pagePath);
|
||||||
ble.addStateRecoveryCallback(these.bleStateRecovry, pagePath);
|
ble.addStateRecoveryCallback(this.bleStateRecovry, pagePath);
|
||||||
ble.addDisposeCallback(these.deviceDispose, pagePath);
|
ble.addDisposeCallback(this.deviceDispose, pagePath);
|
||||||
ble.addRecoveryCallback(these.deviceRecovry, pagePath);
|
ble.addRecoveryCallback(this.deviceRecovry, pagePath);
|
||||||
|
|
||||||
|
|
||||||
let eventChannel = this.getOpenerEventChannel();
|
let eventChannel = this.getOpenerEventChannel();
|
||||||
|
|||||||
@ -172,7 +172,7 @@ class BleHelper {
|
|||||||
//连接所有已连接过的设备
|
//连接所有已连接过的设备
|
||||||
linkAllDevices() {
|
linkAllDevices() {
|
||||||
// console.log("模块启动时,自动连接已连接过的设备", this.data.LinkedList);
|
// console.log("模块启动时,自动连接已连接过的设备", this.data.LinkedList);
|
||||||
if(this.data.platform=='web'){
|
if (this.data.platform == 'web') {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (this.data.LinkedList && this.data.LinkedList.length > 0) {
|
if (this.data.LinkedList && this.data.LinkedList.length > 0) {
|
||||||
@ -1405,7 +1405,7 @@ class BleHelper {
|
|||||||
|
|
||||||
//连接某个设备
|
//连接某个设备
|
||||||
LinkBlue(deviceId, targetServiceId, writeCharId, notifyCharId, maxRetries) {
|
LinkBlue(deviceId, targetServiceId, writeCharId, notifyCharId, maxRetries) {
|
||||||
if(this.data.platform=='web'){
|
if (this.data.platform == 'web') {
|
||||||
return Promise.resolve(true);
|
return Promise.resolve(true);
|
||||||
}
|
}
|
||||||
if (maxRetries === undefined) {
|
if (maxRetries === undefined) {
|
||||||
@ -1595,7 +1595,7 @@ class BleHelper {
|
|||||||
}
|
}
|
||||||
//断开连接
|
//断开连接
|
||||||
disconnectDevice(deviceId) {
|
disconnectDevice(deviceId) {
|
||||||
if(this.data.platform=='web'){
|
if (this.data.platform == 'web') {
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
}
|
}
|
||||||
var disconnect = (id) => {
|
var disconnect = (id) => {
|
||||||
@ -1616,16 +1616,7 @@ class BleHelper {
|
|||||||
|
|
||||||
}
|
}
|
||||||
if (deviceId) {
|
if (deviceId) {
|
||||||
disconnect(deviceId);
|
return disconnect(deviceId);
|
||||||
|
|
||||||
this.data.LinkedList.find(v => {
|
|
||||||
if (v.deviceId === deviceId) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.data.LinkedList.length > 0) {
|
if (this.data.LinkedList.length > 0) {
|
||||||
@ -1637,10 +1628,8 @@ class BleHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
if (arr.length == 0) {
|
if (arr.length) {
|
||||||
return;
|
return new Promise((_succ, _err) => {
|
||||||
}
|
|
||||||
|
|
||||||
Promise.allSettled(arr).then((results) => {
|
Promise.allSettled(arr).then((results) => {
|
||||||
results.forEach((result, index) => {
|
results.forEach((result, index) => {
|
||||||
if (result.status === 'fulfilled') {
|
if (result.status === 'fulfilled') {
|
||||||
@ -1649,12 +1638,17 @@ class BleHelper {
|
|||||||
////console.log(`第${index + 1}个Promise失败:`, result.reason.message);
|
////console.log(`第${index + 1}个Promise失败:`, result.reason.message);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
_succ()
|
||||||
|
}).catch((ex) => {
|
||||||
|
_err();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
} else {
|
|
||||||
////console.log("无已连接设备");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return Promise.resolve();
|
||||||
|
|
||||||
|
}
|
||||||
//向蓝牙设备发送一个字符串的ASCII码
|
//向蓝牙设备发送一个字符串的ASCII码
|
||||||
sendString(deviceid, str, writeServiceId, wirteCharactId, ms) {
|
sendString(deviceid, str, writeServiceId, wirteCharactId, ms) {
|
||||||
if (str && typeof(str) == 'object') {
|
if (str && typeof(str) == 'object') {
|
||||||
|
|||||||
Reference in New Issue
Block a user