|
@@ -35,6 +35,14 @@ class bleManager {
|
|
/// 监控蓝牙打开状态
|
|
/// 监控蓝牙打开状态
|
|
initBluetoothAdapter() {
|
|
initBluetoothAdapter() {
|
|
var that = this;
|
|
var that = this;
|
|
|
|
+ wx.openBluetoothAdapter({
|
|
|
|
+ success: (res) => {
|
|
|
|
+ that.isAvailable = true;
|
|
|
|
+ },
|
|
|
|
+ fail: (err) => {
|
|
|
|
+ that.isAvailable = false;
|
|
|
|
+ }
|
|
|
|
+ });
|
|
wx.onBluetoothAdapterStateChange(function (res) {
|
|
wx.onBluetoothAdapterStateChange(function (res) {
|
|
that.isAvailable = res.available;
|
|
that.isAvailable = res.available;
|
|
})
|
|
})
|
|
@@ -149,8 +157,6 @@ class bleManager {
|
|
return new Promise(resolve => setTimeout(resolve, ms));
|
|
return new Promise(resolve => setTimeout(resolve, ms));
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
-
|
|
|
|
// 开始搜索蓝牙设备
|
|
// 开始搜索蓝牙设备
|
|
async startScan(connectWillDevice, boolean, callBackConnect) {
|
|
async startScan(connectWillDevice, boolean, callBackConnect) {
|
|
var that = this;
|
|
var that = this;
|
|
@@ -163,6 +169,17 @@ class bleManager {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ if (!that.isAvailable) {
|
|
|
|
+ if (lastPageRoute == connectBleRoot) {
|
|
|
|
+ wx.showToast({
|
|
|
|
+ title: '蓝牙未打开',
|
|
|
|
+ icon: "none",
|
|
|
|
+ duration: 2000
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
///蓝牙连接 做限制
|
|
///蓝牙连接 做限制
|
|
if (lastPageRoute == indexRoot) {
|
|
if (lastPageRoute == indexRoot) {
|
|
if (that.doStartScaning == true) {
|
|
if (that.doStartScaning == true) {
|
|
@@ -188,6 +205,27 @@ class bleManager {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ // wx.startBluetoothDevicesDiscovery({
|
|
|
|
+ // allowDuplicatesKey: true,
|
|
|
|
+ // success: function (res) {
|
|
|
|
+ // 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);
|
|
|
|
+ // }
|
|
|
|
+ // },
|
|
|
|
+ // })
|
|
|
|
+
|
|
wx.closeBluetoothAdapter({
|
|
wx.closeBluetoothAdapter({
|
|
complete: function (res) {
|
|
complete: function (res) {
|
|
wx.openBluetoothAdapter({
|
|
wx.openBluetoothAdapter({
|
|
@@ -195,9 +233,11 @@ class bleManager {
|
|
wx.getBluetoothAdapterState({
|
|
wx.getBluetoothAdapterState({
|
|
success: function (res) {
|
|
success: function (res) {
|
|
that.doStartScaning = false;
|
|
that.doStartScaning = false;
|
|
|
|
+ console.log("gadsfasdfqwerqwerqwerqr==xxx==" + JSON.stringify(res));
|
|
},
|
|
},
|
|
fail(err) {
|
|
fail(err) {
|
|
that.doStartScaning = false;
|
|
that.doStartScaning = false;
|
|
|
|
+ console.log("gadsfasdfqwerqwerqwerqr==yyyy==" + JSON.stringify(res));
|
|
if (boolean != null) {
|
|
if (boolean != null) {
|
|
boolean(false);
|
|
boolean(false);
|
|
}
|
|
}
|
|
@@ -206,6 +246,7 @@ class bleManager {
|
|
wx.startBluetoothDevicesDiscovery({
|
|
wx.startBluetoothDevicesDiscovery({
|
|
allowDuplicatesKey: false,
|
|
allowDuplicatesKey: false,
|
|
success: function (res) {
|
|
success: function (res) {
|
|
|
|
+ console.log("gadsfasdfqwerqwerqwerqr==mmmm==" + JSON.stringify(res));
|
|
that.doStartScaning = false;
|
|
that.doStartScaning = false;
|
|
that.requestBlueTime = that.getCurrentMills();
|
|
that.requestBlueTime = that.getCurrentMills();
|
|
if (boolean != null) {
|
|
if (boolean != null) {
|
|
@@ -216,6 +257,7 @@ class bleManager {
|
|
that.compareList = [];
|
|
that.compareList = [];
|
|
},
|
|
},
|
|
fail(err) {
|
|
fail(err) {
|
|
|
|
+ console.log("gadsfasdfqwerqwerqwerqr==nnnn==" + JSON.stringify(err));
|
|
that.doStartScaning = false;
|
|
that.doStartScaning = false;
|
|
that.requestBlueTime = that.getCurrentMills();
|
|
that.requestBlueTime = that.getCurrentMills();
|
|
if (boolean != null) {
|
|
if (boolean != null) {
|