Przeglądaj źródła

feature: 解决连接之后会有一段时间显示离线,先添加进去就不会了

Damon 7 miesięcy temu
rodzic
commit
2b463a6231
3 zmienionych plików z 32 dodań i 12 usunięć
  1. 12 6
      devices/ble_manager.js
  2. 15 0
      devices/bt_helper.js
  3. 5 6
      pages/connectBle/connectBle.js

+ 12 - 6
devices/ble_manager.js

@@ -21,6 +21,10 @@ class bleManager {
     return this.compareList;
   }
 
+  setCompareList(compareList) {
+    this.compareList = compareList;
+  }
+
   getDissmissDevice() {
     return this.dissmissDevice;
   }
@@ -90,9 +94,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 +214,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;
@@ -581,6 +585,8 @@ class bleManager {
     });
   }
 
+  connect() {}
+
   // 发现特征值 read / write
   discoverCharacteristics(deviceId, serviceId) {
     var that = this;

+ 15 - 0
devices/bt_helper.js

@@ -385,6 +385,7 @@ class BtHelper {
       }
       return
     }
+
     const serviceId = await that.bleManager.discoverServices(device.deviceId);
     if (serviceId == "") {
       console.log("连接失败")
@@ -426,6 +427,20 @@ class BtHelper {
         setTimeout(() => {
           that._connectSuccess()
         }, 100);
+
+        ///解决连接之后会有一段时间显示离线,先添加进去就不会了
+        var has = false;
+        var compareList = that.bleManager.getCompareList();
+        for (var j = 0; j < compareList.length; j++) {
+          if (compareList[j].deviceId == device.deviceId) {
+            has = true;
+          }
+        }
+        if (!has) {
+          compareList.unshift(device);
+          that.bleManager.setCompareList(compareList);
+        }
+
         if (onChanged) {
           onChanged(true)
         }

+ 5 - 6
pages/connectBle/connectBle.js

@@ -73,12 +73,11 @@ Page({
       wx.hideLoading();
       that.setStatus(data ? 3 : 4)
       if (data) {
-        setTimeout(() => {
-          that.data.connectDevice.connectType = 1;
-          that.data.connectDevice.state = 'online';
-          getCurrentPages()[0].addConnectBlueDevice(that.data.connectDevice);
-          route_util.goBackRoute(route_constant.indexRoot);
-        }, 200);
+        this.compareList
+        that.data.connectDevice.connectType = 1;
+        that.data.connectDevice.state = 'online';
+        getCurrentPages()[0].addConnectBlueDevice(that.data.connectDevice);
+        route_util.goBackRoute(route_constant.indexRoot);
       }
     });
   },