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