|
@@ -209,59 +209,39 @@ class bleManager {
|
|
// 开始搜索蓝牙设备
|
|
// 开始搜索蓝牙设备
|
|
async startScan(connectWillDevice, boolean, callBackConnect) {
|
|
async startScan(connectWillDevice, boolean, callBackConnect) {
|
|
var that = this;
|
|
var that = this;
|
|
- if (that.doStartScaning == true) {
|
|
|
|
- that.doStartScaning = false;
|
|
|
|
- if (boolean != null) {
|
|
|
|
- boolean(false);
|
|
|
|
- }
|
|
|
|
|
|
+ const route_util = require('../utils/route_util');
|
|
|
|
+ const route_constant = require('../utils/route_constant');
|
|
|
|
+ const indexRoot = route_constant.indexRoot;
|
|
|
|
+ const connectBleRoot = route_constant.connectBleRoot;
|
|
|
|
+ var lastPageRoute = route_util.getLastPageRoute();
|
|
|
|
+ if (lastPageRoute != indexRoot && lastPageRoute != connectBleRoot) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
- that.doStartScaning = true;
|
|
|
|
-
|
|
|
|
- // const route_util = require('../utils/route_util');
|
|
|
|
- // const route_constant = require('../utils/route_constant');
|
|
|
|
- // const indexRoot = route_constant.indexRoot;
|
|
|
|
- // const connectBleRoot = route_constant.connectBleRoot;
|
|
|
|
- // var lastPageRoute = route_util.getLastPageRoute();
|
|
|
|
- // if (lastPageRoute != indexRoot && lastPageRoute != connectBleRoot) {
|
|
|
|
- // return;
|
|
|
|
- // }
|
|
|
|
-
|
|
|
|
- // if (!that.isAvailable) {
|
|
|
|
- // if (lastPageRoute == connectBleRoot) {
|
|
|
|
- // wx.showToast({
|
|
|
|
- // title: '蓝牙未打开',
|
|
|
|
- // icon: "none",
|
|
|
|
- // duration: 2000
|
|
|
|
- // })
|
|
|
|
- // }
|
|
|
|
- // return;
|
|
|
|
- // }
|
|
|
|
|
|
|
|
///蓝牙连接 做限制
|
|
///蓝牙连接 做限制
|
|
- // if (lastPageRoute == indexRoot) {
|
|
|
|
- // if (that.doStartScaning == true) {
|
|
|
|
- // return;
|
|
|
|
- // }
|
|
|
|
- // }
|
|
|
|
|
|
+ if (lastPageRoute == indexRoot) {
|
|
|
|
+ if (that.doStartScaning == true) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
- // that.doStartScaning = true;
|
|
|
|
- // var currentMill = that.getCurrentMills();
|
|
|
|
- // var waitMills = 0;
|
|
|
|
- // var reduce = currentMill - that.requestBlueTime;
|
|
|
|
- // const delayMiliis = 5 * 1000;
|
|
|
|
- // if (reduce > 0 && reduce < delayMiliis) {
|
|
|
|
- // waitMills = delayMiliis - reduce;
|
|
|
|
- // }
|
|
|
|
|
|
+ that.doStartScaning = true;
|
|
|
|
+ var currentMill = that.getCurrentMills();
|
|
|
|
+ var waitMills = 0;
|
|
|
|
+ var reduce = currentMill - that.requestBlueTime;
|
|
|
|
+ const delayMiliis = 5 * 1000;
|
|
|
|
+ if (reduce > 0 && reduce < delayMiliis) {
|
|
|
|
+ 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;
|
|
|
|
- // }
|
|
|
|
|
|
+ if (callBackConnect == null && lastPageRoute == connectBleRoot) {
|
|
|
|
+ that.doStartScaning = false;
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
|
|
wx.openBluetoothAdapter({
|
|
wx.openBluetoothAdapter({
|
|
success: function (res) {
|
|
success: function (res) {
|
|
@@ -271,6 +251,7 @@ class bleManager {
|
|
},
|
|
},
|
|
fail: (err) => {
|
|
fail: (err) => {
|
|
that.doStartScaning = false;
|
|
that.doStartScaning = false;
|
|
|
|
+ that.requestBlueTime = that.getCurrentMills();
|
|
if (boolean != null) {
|
|
if (boolean != null) {
|
|
boolean(false);
|
|
boolean(false);
|
|
}
|
|
}
|
|
@@ -299,6 +280,7 @@ class bleManager {
|
|
allowDuplicatesKey: true,
|
|
allowDuplicatesKey: true,
|
|
success: function (res) {
|
|
success: function (res) {
|
|
that.getConnectedDevices();
|
|
that.getConnectedDevices();
|
|
|
|
+
|
|
that.doStartScaning = false;
|
|
that.doStartScaning = false;
|
|
that.requestBlueTime = that.getCurrentMills();
|
|
that.requestBlueTime = that.getCurrentMills();
|
|
if (boolean != null) {
|
|
if (boolean != null) {
|
|
@@ -309,7 +291,6 @@ class bleManager {
|
|
that.compareList = [];
|
|
that.compareList = [];
|
|
},
|
|
},
|
|
fail(err) {
|
|
fail(err) {
|
|
- console.log("gadsfqwerqewrqrqr===" + JSON.stringify(err));
|
|
|
|
that.doStartScaning = false;
|
|
that.doStartScaning = false;
|
|
that.requestBlueTime = that.getCurrentMills();
|
|
that.requestBlueTime = that.getCurrentMills();
|
|
if (boolean != null) {
|
|
if (boolean != null) {
|