浏览代码

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

Damon 7 月之前
父节点
当前提交
1d99491d4b
共有 2 个文件被更改,包括 22 次插入20 次删除
  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) {
         if (that.callBackConnect != null) {
           for (var i = 0; i < res.devices.length; i++) {
           for (var i = 0; i < res.devices.length; i++) {
             var temp = res.devices[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) {
             if (that.connectWillDevice != null && temp.name == that.connectWillDevice.clientType) {
               temp.mac = temp.advertisData ? that.buf2hex(temp.advertisData) : '';
               temp.mac = temp.advertisData ? that.buf2hex(temp.advertisData) : '';
               if (that.callBackConnect != null) {
               if (that.callBackConnect != null) {
@@ -210,9 +210,9 @@ class bleManager {
               var has = false;
               var has = false;
               for (var j = 0; j < that.compareList.length; j++) {
               for (var j = 0; j < that.compareList.length; j++) {
                 if (res.devices[i].name != "") {
                 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) {
                   if (res.devices[i].deviceId == that.compareList[j].deviceId) {
                     has = true;
                     has = true;
                     break;
                     break;

+ 16 - 14
pages/connectBle/connectBle.js

@@ -40,17 +40,17 @@ Page({
     BtHelper.getInstance().startScan(
     BtHelper.getInstance().startScan(
       that.data.connectDevice,
       that.data.connectDevice,
       async function (b) {
       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();
       wx.hideLoading();
       that.setStatus(data ? 3 : 4)
       that.setStatus(data ? 3 : 4)
       if (data) {
       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);
       }
       }
     });
     });
   },
   },