|
@@ -139,6 +139,27 @@ class bleManager {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+ ///获取已连接的设备
|
|
|
+ getConnectedDevices() {
|
|
|
+ wx.getBluetoothDevices({
|
|
|
+ success: (res) => {
|
|
|
+ if (res.devices && res.devices.length > 0) {
|
|
|
+ for (var i = 0; i < res.devices.length; i++) {
|
|
|
+ var temp = res.devices[i];
|
|
|
+ if (that.connectWillDevice != null && temp.name == that.connectWillDevice.clientType) {
|
|
|
+ temp.advertisData = temp.advertisData ? that.buf2hex(temp.advertisData) : '';
|
|
|
+ that.callBackConnect(temp);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ fail: (err) => {
|
|
|
+ console.error('获取蓝牙设备列表失败', err);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
///获取数据
|
|
|
buf2hex(buffer) {
|
|
|
return Array.prototype.map.call(new Uint8Array(buffer), x => ('00' + x.toString(16)).slice(-2)).join('');
|
|
@@ -196,15 +217,53 @@ class bleManager {
|
|
|
waitMills = delayMiliis - reduce;
|
|
|
}
|
|
|
|
|
|
- if (waitMills > 0) {
|
|
|
- await that.delay(waitMills);
|
|
|
- }
|
|
|
+ // if (waitMills > 0) {
|
|
|
+ // await that.delay(waitMills);
|
|
|
+ // }
|
|
|
|
|
|
if (callBackConnect == null && lastPageRoute == connectBleRoot) {
|
|
|
that.doStartScaning = false;
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
+ wx.stopBluetoothDevicesDiscovery({
|
|
|
+ success: (res) => {
|
|
|
+ wx.startBluetoothDevicesDiscovery({
|
|
|
+ allowDuplicatesKey: true,
|
|
|
+ success: function (res) {
|
|
|
+ that.getConnectedDevices();
|
|
|
+ that.doStartScaning = false;
|
|
|
+ that.requestBlueTime = that.getCurrentMills();
|
|
|
+ if (boolean != null) {
|
|
|
+ boolean(true);
|
|
|
+ }
|
|
|
+ that.setConnectWillDevice(connectWillDevice);
|
|
|
+ that.setCallBackConnect(callBackConnect);
|
|
|
+ that.compareList = [];
|
|
|
+ },
|
|
|
+ fail(err) {
|
|
|
+ that.doStartScaning = false;
|
|
|
+ that.requestBlueTime = that.getCurrentMills();
|
|
|
+ if (boolean != null) {
|
|
|
+ boolean(false);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ })
|
|
|
+ },
|
|
|
+ fail: (err) => {
|
|
|
+ wx.showModal({
|
|
|
+ title: '提示',
|
|
|
+ content: '请检查手机蓝牙是否打开',
|
|
|
+ showCancel: false,
|
|
|
+ success: function (res) {}
|
|
|
+ });
|
|
|
+ that.doStartScaning = false;
|
|
|
+ if (boolean != null) {
|
|
|
+ boolean(false);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
// wx.startBluetoothDevicesDiscovery({
|
|
|
// allowDuplicatesKey: true,
|
|
|
// success: function (res) {
|
|
@@ -226,61 +285,61 @@ class bleManager {
|
|
|
// },
|
|
|
// })
|
|
|
|
|
|
- wx.closeBluetoothAdapter({
|
|
|
- complete: function (res) {
|
|
|
- wx.openBluetoothAdapter({
|
|
|
- success: function (res) {
|
|
|
- wx.getBluetoothAdapterState({
|
|
|
- success: function (res) {
|
|
|
- that.doStartScaning = false;
|
|
|
- console.log("gadsfasdfqwerqwerqwerqr==xxx==" + JSON.stringify(res));
|
|
|
- },
|
|
|
- fail(err) {
|
|
|
- that.doStartScaning = false;
|
|
|
- console.log("gadsfasdfqwerqwerqwerqr==yyyy==" + JSON.stringify(res));
|
|
|
- if (boolean != null) {
|
|
|
- boolean(false);
|
|
|
- }
|
|
|
- },
|
|
|
- })
|
|
|
- wx.startBluetoothDevicesDiscovery({
|
|
|
- allowDuplicatesKey: false,
|
|
|
- success: function (res) {
|
|
|
- console.log("gadsfasdfqwerqwerqwerqr==mmmm==" + JSON.stringify(res));
|
|
|
- that.doStartScaning = false;
|
|
|
- that.requestBlueTime = that.getCurrentMills();
|
|
|
- if (boolean != null) {
|
|
|
- boolean(true);
|
|
|
- }
|
|
|
- that.setConnectWillDevice(connectWillDevice);
|
|
|
- that.setCallBackConnect(callBackConnect);
|
|
|
- that.compareList = [];
|
|
|
- },
|
|
|
- fail(err) {
|
|
|
- console.log("gadsfasdfqwerqwerqwerqr==nnnn==" + JSON.stringify(err));
|
|
|
- that.doStartScaning = false;
|
|
|
- that.requestBlueTime = that.getCurrentMills();
|
|
|
- if (boolean != null) {
|
|
|
- boolean(false);
|
|
|
- }
|
|
|
- },
|
|
|
- })
|
|
|
- },
|
|
|
- fail: function (res) {
|
|
|
- wx.showModal({
|
|
|
- title: '提示',
|
|
|
- content: '请检查手机蓝牙是否打开',
|
|
|
- showCancel: false,
|
|
|
- success: function (res) {}
|
|
|
- });
|
|
|
- that.doStartScaning = false;
|
|
|
- if (boolean != null) {
|
|
|
- boolean(false);
|
|
|
- }
|
|
|
- }
|
|
|
- })
|
|
|
- }
|
|
|
- })
|
|
|
+ // wx.closeBluetoothAdapter({
|
|
|
+ // complete: function (res) {
|
|
|
+ // wx.openBluetoothAdapter({
|
|
|
+ // success: function (res) {
|
|
|
+ // wx.getBluetoothAdapterState({
|
|
|
+ // success: function (res) {
|
|
|
+ // that.doStartScaning = false;
|
|
|
+ // console.log("gadsfasdfqwerqwerqwerqr==xxx==" + JSON.stringify(res));
|
|
|
+ // },
|
|
|
+ // fail(err) {
|
|
|
+ // that.doStartScaning = false;
|
|
|
+ // console.log("gadsfasdfqwerqwerqwerqr==yyyy==" + JSON.stringify(res));
|
|
|
+ // if (boolean != null) {
|
|
|
+ // boolean(false);
|
|
|
+ // }
|
|
|
+ // },
|
|
|
+ // })
|
|
|
+ // wx.startBluetoothDevicesDiscovery({
|
|
|
+ // allowDuplicatesKey: false,
|
|
|
+ // success: function (res) {
|
|
|
+ // console.log("gadsfasdfqwerqwerqwerqr==mmmm==" + JSON.stringify(res));
|
|
|
+ // that.doStartScaning = false;
|
|
|
+ // that.requestBlueTime = that.getCurrentMills();
|
|
|
+ // if (boolean != null) {
|
|
|
+ // boolean(true);
|
|
|
+ // }
|
|
|
+ // that.setConnectWillDevice(connectWillDevice);
|
|
|
+ // that.setCallBackConnect(callBackConnect);
|
|
|
+ // that.compareList = [];
|
|
|
+ // },
|
|
|
+ // fail(err) {
|
|
|
+ // console.log("gadsfasdfqwerqwerqwerqr==nnnn==" + JSON.stringify(err));
|
|
|
+ // that.doStartScaning = false;
|
|
|
+ // that.requestBlueTime = that.getCurrentMills();
|
|
|
+ // if (boolean != null) {
|
|
|
+ // boolean(false);
|
|
|
+ // }
|
|
|
+ // },
|
|
|
+ // })
|
|
|
+ // },
|
|
|
+ // fail: function (res) {
|
|
|
+ // wx.showModal({
|
|
|
+ // title: '提示',
|
|
|
+ // content: '请检查手机蓝牙是否打开',
|
|
|
+ // showCancel: false,
|
|
|
+ // success: function (res) {}
|
|
|
+ // });
|
|
|
+ // that.doStartScaning = false;
|
|
|
+ // if (boolean != null) {
|
|
|
+ // boolean(false);
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // })
|
|
|
+ // }
|
|
|
+ // })
|
|
|
}
|
|
|
|
|
|
// 停止搜索
|