Browse Source

feature: 处理wifi和蓝牙连接出现短时间失去连接问题

Damon 7 tháng trước cách đây
mục cha
commit
1d99491d4b
2 tập tin đã thay đổi với 22 bổ sung20 xóa
  1. 6 6
      devices/ble_manager.js
  2. 16 14
      pages/connectBle/connectBle.js

+ 6 - 6
devices/ble_manager.js

@@ -90,9 +90,9 @@ class bleManager {
         if (that.callBackConnect != null) {
           for (var i = 0; i < res.devices.length; i++) {
             var temp = res.devices[i];
-            if (temp.name == "MW-SR1(4G_WIFI)") {
-              console.log("gadsfqewrqewrqwerqrqr==111==" + JSON.stringify(res.devices[i]));
-            }
+//            if (temp.name == "MW-SR1(4G_WIFI)") {
+//              console.log("gadsfqewrqewrqwerqrqr==111==" + JSON.stringify(res.devices[i]));
+//            }
             if (that.connectWillDevice != null && temp.name == that.connectWillDevice.clientType) {
               temp.mac = temp.advertisData ? that.buf2hex(temp.advertisData) : '';
               if (that.callBackConnect != null) {
@@ -210,9 +210,9 @@ class bleManager {
               var has = false;
               for (var j = 0; j < that.compareList.length; j++) {
                 if (res.devices[i].name != "") {
-                  if (res.devices[i].name == "MW-SR1(4G_WIFI)") {
-                    console.log("gadsfqewrqewrqwerqrqr==000==" + JSON.stringify(res.devices[i]));
-                  }
+//                  if (res.devices[i].name == "MW-SR1(4G_WIFI)") {
+//                    console.log("gadsfqewrqewrqwerqrqr==000==" + JSON.stringify(res.devices[i]));
+//                  }
                   if (res.devices[i].deviceId == that.compareList[j].deviceId) {
                     has = true;
                     break;

+ 16 - 14
pages/connectBle/connectBle.js

@@ -40,17 +40,17 @@ Page({
     BtHelper.getInstance().startScan(
       that.data.connectDevice,
       async function (b) {
-        if (!b) {
-          that.setStatus(1);
+          if (!b) {
+            that.setStatus(1);
+          }
+        },
+        async function (res) {
+          await BtHelper.getInstance().stopSearch();
+          that.setStatus(2);
+          that.data.connectDevice.deviceId = res.deviceId;
+          that.data.connectDevice.connectable = res.connectable;
+          that.data.connectDevice.mac = res.mac;
         }
-      },
-      async function (res) {
-        await BtHelper.getInstance().stopSearch();
-        that.setStatus(2);
-        that.data.connectDevice.deviceId = res.deviceId;
-        that.data.connectDevice.connectable = res.connectable;
-        that.data.connectDevice.mac = res.mac;
-      }
     );
   },
 
@@ -73,10 +73,12 @@ Page({
       wx.hideLoading();
       that.setStatus(data ? 3 : 4)
       if (data) {
-        that.data.connectDevice.connectType = 1;
-        that.data.connectDevice.state = 'online';
-        getCurrentPages()[0].addConnectBlueDevice(that.data.connectDevice);
-        route_util.goBackRoute(route_constant.indexRoot);
+        setTimeout(() => {
+          that.data.connectDevice.connectType = 1;
+          that.data.connectDevice.state = 'online';
+          getCurrentPages()[0].addConnectBlueDevice(that.data.connectDevice);
+          route_util.goBackRoute(route_constant.indexRoot);
+        }, 200);
       }
     });
   },