Kaynağa Gözat

feature: 处理连续处理

Damon 7 ay önce
ebeveyn
işleme
e7087a65fb
2 değiştirilmiş dosya ile 27 ekleme ve 14 silme
  1. 20 1
      devices/ble_manager.js
  2. 7 13
      pages/index/index.js

+ 20 - 1
devices/ble_manager.js

@@ -150,7 +150,7 @@ class bleManager {
     var that = this;
     wx.getBluetoothDevices({
       success: (res) => {
-        if (res.devices && res.devices.length > 0) {
+        if (that.callBackConnect != null) {
           for (var i = 0; i < res.devices.length; i++) {
             var temp = res.devices[i];
             if (that.connectWillDevice != null && temp.name == that.connectWillDevice.clientType) {
@@ -161,6 +161,25 @@ class bleManager {
               break;
             }
           }
+        } else {
+          for (var i = 0; i < res.devices.length; i++) {
+            if (that.compareList.length > 0) {
+              var has = false;
+              for (var j = 0; j < that.compareList.length; j++) {
+                if (res.devices[i].name != "") {
+                  if (res.devices[i].deviceId == that.compareList[j].deviceId) {
+                    has = true;
+                    break;
+                  }
+                }
+              }
+              if (!has) {
+                that.compareList.push(res.devices[i]);
+              }
+            } else {
+              that.compareList.push(res.devices[i]);
+            }
+          }
         }
       },
       fail: (err) => {

+ 7 - 13
pages/index/index.js

@@ -121,7 +121,7 @@ Page({
               that.addConnectBlueDevice(connectDevice);
             }
           })
-        } else { }
+        } else {}
       })
     }
   },
@@ -140,23 +140,18 @@ Page({
     BtHelper.getInstance().getBluetoothDevices();
     ///3秒去处理一下
     BtHelper.getInstance().startScan(null, null, null);
-    ///先接收数据
-    // var isFirst = true;
-    // setTimeout(() => {
-    //   that.compareList();
-    //   ///再秒再对比一次
-    //   that.data.intervalId = setInterval(async function () {
-    //     isFirst = false;
-    //     that.compareList();
-    //   }, isFirst ? 10 * 1000 : 20 * 1000);
-    // }, 3 * 1000);
+    var isFirst = true;
+    ///再秒再对比一次
+    that.data.intervalId = setInterval(async function () {
+      isFirst = false;
+      that.compareList();
+    }, isFirst ? 3 * 1000 : 20 * 1000);
   },
 
   async compareList() {
     var that = this;
     if (BtHelper.getInstance().getCallBackConnect() == null) {
       var compareList = BtHelper.getInstance().getCompareList();
-      console.log("gadsfasdfqwerqwerqwerqr==000==" + compareList.length);
       if (compareList.length > 0) {
         ///对比在线的蓝牙设备
         var isChanged = false;
@@ -170,7 +165,6 @@ Page({
                 // "state":"online" "offline"
                 if (tempItem.deviceId === compareList[j].deviceId) {
                   has = true;
-                  console.log("gadsfasdfqwerqwerqwerqr==111==" + JSON.stringify(tempItem));
                   break;
                 }
               }