2025年05月22日09:52:18
This commit is contained in:
parent
98f2c88113
commit
0c3f951c74
@ -172,21 +172,15 @@ class Bluetooth {
|
||||
success: () => {
|
||||
this.deviceInfo.state = true;
|
||||
this.getBLEDeviceServices();
|
||||
// this.getBLEDeviceCharacteristics();
|
||||
},
|
||||
fail: (res) => {
|
||||
this.linkFlag = false;
|
||||
console.log(res, this.deviceInfo, "连接错误");
|
||||
this.callBack({ ...this.deviceInfo, errCode: 10003 });
|
||||
if (!this.deviceInfo.deviceId) return this.timeout && this.clearTimeoutFn("timeout");
|
||||
if (this.timeout) return;
|
||||
if (res.errno == "1509007") {
|
||||
this.closeBluetoothAdapter();
|
||||
} else {
|
||||
this.timeout = setTimeout(() => {
|
||||
this.timeout && this.clearTimeoutFn("timeout");
|
||||
this.createBleConnection();
|
||||
}, 10000);
|
||||
this.timeoutBleConnection()
|
||||
}
|
||||
},
|
||||
});
|
||||
@ -196,8 +190,7 @@ class Bluetooth {
|
||||
getBLEDeviceServices() {
|
||||
Taro.getBLEDeviceServices({
|
||||
deviceId: this.deviceInfo.deviceId,
|
||||
success: (res) => {
|
||||
console.log(JSON.stringify(res), 'JSON.stringify(res)');
|
||||
success: () => {
|
||||
this.getBLEDeviceCharacteristics();
|
||||
},
|
||||
fail: (err) => this.fail(err),
|
||||
@ -269,15 +262,18 @@ class Bluetooth {
|
||||
console.log(res, "蓝牙断开");
|
||||
this.deviceInfo.state = res.connected;
|
||||
this.callBack(this.deviceInfo);
|
||||
this.linkFlag = false;
|
||||
if (!this.available || this.timeout || !this.isInit || !this.deviceInfo.deviceId) return;
|
||||
this.timeout = setTimeout(() => {
|
||||
this.timeout && this.clearTimeoutFn("timeout");
|
||||
this.createBleConnection();
|
||||
}, 3000);
|
||||
this.timeoutBleConnection()
|
||||
}
|
||||
});
|
||||
}
|
||||
timeoutBleConnection() {
|
||||
this.linkFlag = false;
|
||||
if (!this.available || !this.isInit || !this.deviceInfo.deviceId) return;
|
||||
this.timeout = setTimeout(() => {
|
||||
this.timeout && this.clearTimeoutFn("timeout");
|
||||
this.createBleConnection();
|
||||
}, 3000);
|
||||
}
|
||||
//停止搜寻附近的蓝牙外围设备
|
||||
stopBluetoothDevicesDiscovery() {
|
||||
Taro.stopBluetoothDevicesDiscovery();
|
||||
|
Loading…
x
Reference in New Issue
Block a user