|
@@ -7,9 +7,9 @@ class bleManager {
|
|
|
that.hasPermission = false;
|
|
|
that.scanDevices = [];
|
|
|
that.publicDevice = null;
|
|
|
- ///用来对比列表
|
|
|
that.compareList = [];
|
|
|
- that.searching = false;
|
|
|
+ that.connectWillDevice = null;
|
|
|
+ that.callBackConnect = null;
|
|
|
}
|
|
|
|
|
|
///获取比较的数据
|
|
@@ -17,13 +17,20 @@ class bleManager {
|
|
|
return this.compareList;
|
|
|
}
|
|
|
|
|
|
- ///处理当前正在连接中,对比暂停
|
|
|
- setSearching(search) {
|
|
|
- this.searching = search;
|
|
|
+ getConnectWillDevice() {
|
|
|
+ return this.connectWillDevice;
|
|
|
}
|
|
|
|
|
|
- getSearching() {
|
|
|
- return this.searching;
|
|
|
+ setConnectWillDevice(connectWillDevice) {
|
|
|
+ this.connectWillDevice = connectWillDevice;
|
|
|
+ }
|
|
|
+
|
|
|
+ getCallBackConnect() {
|
|
|
+ return this.callBackConnect;
|
|
|
+ }
|
|
|
+
|
|
|
+ setCallBackConnect(callBackConnect) {
|
|
|
+ this.callBackConnect = callBackConnect;
|
|
|
}
|
|
|
|
|
|
/// 监控蓝牙打开状态
|
|
@@ -35,15 +42,15 @@ class bleManager {
|
|
|
}
|
|
|
|
|
|
///监听搜索设备列表
|
|
|
- getBluetoothDevices(callBack, toCompare) {
|
|
|
+ getBluetoothDevices() {
|
|
|
var that = this;
|
|
|
wx.onBluetoothDeviceFound(function (res) {
|
|
|
///第一种情况
|
|
|
if (res.deviceId) {
|
|
|
- if (!toCompare) {
|
|
|
- if (res.name == getApp().globalData.connectWillDevice.clientType) {
|
|
|
+ if (that.callBackConnect != null) {
|
|
|
+ if (that.connectWillDevice != null && res.name == that.connectWillDevice.clientType) {
|
|
|
res.advertisData = res.advertisData ? that.buf2hex(res.advertisData) : '';
|
|
|
- callBack(res);
|
|
|
+ that.callBackConnect(res);
|
|
|
}
|
|
|
} else {
|
|
|
if (res.name != "") {
|
|
@@ -66,12 +73,12 @@ class bleManager {
|
|
|
}
|
|
|
///第二种情况
|
|
|
else if (res.devices) {
|
|
|
- if (!toCompare) {
|
|
|
+ if (that.callBackConnect != null) {
|
|
|
for (var i = 0; i < res.devices.length; i++) {
|
|
|
var temp = res.devices[i];
|
|
|
- if (temp.name == getApp().globalData.connectWillDevice.clientType) {
|
|
|
+ if (that.connectWillDevice != null && temp.name == that.connectWillDevice.clientType) {
|
|
|
temp.advertisData = temp.advertisData ? that.buf2hex(temp.advertisData) : '';
|
|
|
- callBack(temp);
|
|
|
+ that.callBackConnect(temp);
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
@@ -98,10 +105,10 @@ class bleManager {
|
|
|
}
|
|
|
///第三种情况
|
|
|
else if (res[0]) {
|
|
|
- if (!toCompare) {
|
|
|
- if (res[0].name == getApp().globalData.connectWillDevice.clientType) {
|
|
|
+ if (that.callBackConnect != null) {
|
|
|
+ if (that.connectWillDevice != null && res[0].name == that.connectWillDevice.clientType) {
|
|
|
res[0].advertisData = res[0].advertisData ? that.buf2hex(res[0].advertisData) : '';
|
|
|
- callBack(res[0]);
|
|
|
+ that.callBackConnect(res[0]);
|
|
|
}
|
|
|
} else {
|
|
|
if (res[0].name != "") {
|