Selaa lähdekoodia

feature: 加上在线蓝牙对比

Damon 8 kuukautta sitten
vanhempi
commit
942419b294
3 muutettua tiedostoa jossa 29 lisäystä ja 8 poistoa
  1. 1 1
      devices/ble_manager.js
  2. 3 3
      pages/connectBle/connectBle.js
  3. 25 4
      pages/index/index.js

+ 1 - 1
devices/ble_manager.js

@@ -107,7 +107,7 @@ class bleManager {
     wx.getBluetoothDevices({
       success: (res) => {
         if (res && res.devices.length > 0) {
-          callBack(res);
+          callBack(res.devices);
         }
         setTimeout(() => {
           that.getAllOnlineDevices();

+ 3 - 3
pages/connectBle/connectBle.js

@@ -59,11 +59,11 @@ Page({
   async startSearch() {
     var that = this;
     that.setStatus(0)
-    that.data.btHelper.search(
+    BtHelper.getInstance().search(
       async function (c) {
           console.log("gadfadfqwerqewqr==111==" + JSON.stringify(c));
           that.setStatus(2);
-          that.data.btHelper.stopSearch();
+          BtHelper.getInstance().stopSearch();
           that.data.connectDevice.deviceId = c.deviceId;
           that.data.connectDevice.connectable = c.connectable;
         },
@@ -81,7 +81,7 @@ Page({
     toastUtil.show("开始连接设备")
     var that = this;
     //  搜索到
-    that.data.btHelper.connect(that.data.connectDevice, function (data) {
+    BtHelper.getInstance().connect(that.data.connectDevice, function (data) {
       console.log("连接成功:", data)
       that.setStatus(data ? 3 : 4)
       if (data) {

+ 25 - 4
pages/index/index.js

@@ -8,7 +8,9 @@ import timeUtil from '../../utils/time_util.js';
 import strings from '../../utils/strings.js';
 import route_constant from '../../utils/route_constant.js';
 import route_util from '../../utils/route_util.js';
-import { BtHelper } from '../../devices/bt_helper.js';
+import {
+  BtHelper
+} from '../../devices/bt_helper.js';
 
 Page({
   data: {
@@ -117,8 +119,7 @@ Page({
               that.addConnectBlueDevice(connectDevice);
             }
           })
-        } else {
-        }
+        } else {}
       })
     }
   },
@@ -127,10 +128,30 @@ Page({
     var devicelist = wx.getStorageSync("devicelist") || "";
     if (!strings.isEmpty(devicelist)) {
       var list = JSON.parse(devicelist);
-
       that.updateDeviceList(list, true);
       that.tryConnectBle()
 
+      ///对比在线的蓝牙设备
+      var tempList = that.data.devicelist;
+      var isChanged = false;
+      BtHelper.getInstance().getAllOnlineDevices(function (devices) {
+        for (var i = 0; i < tempList.length; i++) {
+          var tempItem = tempList[i];
+          if (tempItem.connectType != 3) {
+            for (var j = 0; j < devices.length; j++) {
+              // "state":"online"
+              if (tempItem.deviceId === devices[j].deviceId) {
+                isChanged = true;
+                tempItem.state = "online";
+                break;
+              }
+            }
+          }
+        }
+      });
+      if (isChanged) {
+        that.updateDeviceList(list, false);
+      }
     }
   },