feat:增加32bit设备uuid判断、增加android机型下的mtu设置
This commit is contained in:
parent
8f214456d0
commit
b5605e8025
31
uni/basic.js
31
uni/basic.js
@ -49,6 +49,18 @@ export function searchAndConnectDevice(name, reset = true) {
|
||||
}
|
||||
break
|
||||
}
|
||||
if (uuid && uuid.slice(0, 2) === '75') {
|
||||
await stopBluetoothDevicesDiscovery()
|
||||
clearTimeout(timeoutTimer)
|
||||
clearInterval(timer)
|
||||
if (uuid.slice(4, 6) === '00' && reset) {
|
||||
resolve(Result.DeviceHasBeenReset)
|
||||
} else {
|
||||
const connectResult = await createBLEConnection(deviceList[i].deviceId)
|
||||
resolve(connectResult)
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@ -177,6 +189,25 @@ export function createBLEConnection(deviceId, reconnectNumber = 0) {
|
||||
res.data.serviceId,
|
||||
res.data.notifyCharacteristicId
|
||||
)
|
||||
// 使用同步方法获取系统信息
|
||||
const systemInfo = uni.getSystemInfoSync();
|
||||
|
||||
if (systemInfo.platform === 'android') {
|
||||
// 如果是Android机型,则设置BLE MTU
|
||||
uni.setBLEMTU({
|
||||
deviceId: deviceId,
|
||||
mtu: 512,
|
||||
fail: res => {
|
||||
console.log('mtu fail', res);
|
||||
},
|
||||
success: res => {
|
||||
console.log('mtu success', res);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
// 对于非Android设备,可以在这里添加其他逻辑或者直接忽略
|
||||
console.log('当前设备不是Android,跳过设置BLE MTU');
|
||||
}
|
||||
resolve(res)
|
||||
},
|
||||
async fail(err) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user