Forráskód Böngészése

feature: 蓝牙搜索处理

Damon 7 hónapja
szülő
commit
0b4f80835b
2 módosított fájl, 43 hozzáadás és 109 törlés
  1. 43 108
      devices/ble_manager.js
  2. 0 1
      pages/connectBle/connectBle.js

+ 43 - 108
devices/ble_manager.js

@@ -85,9 +85,6 @@ class bleManager {
         if (that.callBackConnect != null) {
           for (var i = 0; i < res.devices.length; i++) {
             var temp = res.devices[i];
-            if (devices.devices[i].name == "MW-SR1(4G_WIFI)") {
-              console.log("gadsfqwerqeddsafdafwqr==111==" + JSON.stringify(devices.devices[i]));
-            }
             if (that.connectWillDevice != null && temp.name == that.connectWillDevice.clientType) {
               temp.advertisData = temp.advertisData ? that.buf2hex(temp.advertisData) : '';
               if (that.callBackConnect != null) {
@@ -156,9 +153,6 @@ class bleManager {
         if (res.devices && res.devices.length > 0) {
           for (var i = 0; i < res.devices.length; i++) {
             var temp = res.devices[i];
-            if (res.devices[i].name == "MW-SR1(4G_WIFI)") {
-              console.log("gadsfqwerqeddsafdafwqr==000==" + JSON.stringify(res.devices[i]));
-            }
             if (that.connectWillDevice != null && temp.name == that.connectWillDevice.clientType) {
               temp.advertisData = temp.advertisData ? that.buf2hex(temp.advertisData) : '';
               if (that.callBackConnect != null) {
@@ -197,6 +191,7 @@ class bleManager {
   async startScan(connectWillDevice, boolean, callBackConnect) {
     var that = this;
     if (that.doStartScaning == true) {
+      that.doStartScaning = false;
       if (boolean != null) {
         boolean(false);
       }
@@ -249,120 +244,60 @@ class bleManager {
     //   return;
     // }
 
-    wx.stopBluetoothDevicesDiscovery({
-      success: (res) => {
-        wx.startBluetoothDevicesDiscovery({
-          allowDuplicatesKey: true,
-          success: function (res) {
-            that.getConnectedDevices();
-            that.doStartScaning = false;
-            that.requestBlueTime = that.getCurrentMills();
-            if (boolean != null) {
-              boolean(true);
-            }
-            that.setConnectWillDevice(connectWillDevice);
-            that.setCallBackConnect(callBackConnect);
-            that.compareList = [];
+    wx.openBluetoothAdapter({
+      success: function (res) {
+        wx.stopBluetoothDevicesDiscovery({
+          success: (res) => {
+            that.search(connectWillDevice, boolean, callBackConnect);
           },
-          fail(err) {
+          fail: (err) => {
             that.doStartScaning = false;
-            that.requestBlueTime = that.getCurrentMills();
             if (boolean != null) {
               boolean(false);
             }
-          },
-        })
-      },
-      fail: (err) => {
-        wx.showModal({
-          title: '提示',
-          content: '请检查手机蓝牙是否打开',
-          showCancel: false,
-          success: function (res) {}
+          }
         });
+      },
+      fail: function (res) {
+        // wx.showModal({
+        //   title: '提示',
+        //   content: '请检查手机蓝牙是否打开',
+        //   showCancel: false,
+        //   success: function (res) {}
+        // });
         that.doStartScaning = false;
+        that.requestBlueTime = that.getCurrentMills();
         if (boolean != null) {
           boolean(false);
         }
       }
-    });
+    })
+  }
 
-    // wx.startBluetoothDevicesDiscovery({
-    //   allowDuplicatesKey: true,
-    //   success: function (res) {
-    //     that.doStartScaning = false;
-    //     that.requestBlueTime = that.getCurrentMills();
-    //     if (boolean != null) {
-    //       boolean(true);
-    //     }
-    //     that.setConnectWillDevice(connectWillDevice);
-    //     that.setCallBackConnect(callBackConnect);
-    //     that.compareList = [];
-    //   },
-    //   fail(err) {
-    //     that.doStartScaning = false;
-    //     that.requestBlueTime = that.getCurrentMills();
-    //     if (boolean != null) {
-    //       boolean(false);
-    //     }
-    //   },
-    // })
-
-    // wx.closeBluetoothAdapter({
-    //   complete: function (res) {
-    //     wx.openBluetoothAdapter({
-    //       success: function (res) {
-    //         wx.getBluetoothAdapterState({
-    //           success: function (res) {
-    //             that.doStartScaning = false;
-    //             console.log("gadsfasdfqwerqwerqwerqr==xxx==" + JSON.stringify(res));
-    //           },
-    //           fail(err) {
-    //             that.doStartScaning = false;
-    //             console.log("gadsfasdfqwerqwerqwerqr==yyyy==" + JSON.stringify(res));
-    //             if (boolean != null) {
-    //               boolean(false);
-    //             }
-    //           },
-    //         })
-    //         wx.startBluetoothDevicesDiscovery({
-    //           allowDuplicatesKey: false,
-    //           success: function (res) {
-    //             console.log("gadsfasdfqwerqwerqwerqr==mmmm==" + JSON.stringify(res));
-    //             that.doStartScaning = false;
-    //             that.requestBlueTime = that.getCurrentMills();
-    //             if (boolean != null) {
-    //               boolean(true);
-    //             }
-    //             that.setConnectWillDevice(connectWillDevice);
-    //             that.setCallBackConnect(callBackConnect);
-    //             that.compareList = [];
-    //           },
-    //           fail(err) {
-    //             console.log("gadsfasdfqwerqwerqwerqr==nnnn==" + JSON.stringify(err));
-    //             that.doStartScaning = false;
-    //             that.requestBlueTime = that.getCurrentMills();
-    //             if (boolean != null) {
-    //               boolean(false);
-    //             }
-    //           },
-    //         })
-    //       },
-    //       fail: function (res) {
-    //         wx.showModal({
-    //           title: '提示',
-    //           content: '请检查手机蓝牙是否打开',
-    //           showCancel: false,
-    //           success: function (res) {}
-    //         });
-    //         that.doStartScaning = false;
-    //         if (boolean != null) {
-    //           boolean(false);
-    //         }
-    //       }
-    //     })
-    //   }
-    // })
+  search(connectWillDevice, boolean, callBackConnect) {
+    var that = this;
+    wx.startBluetoothDevicesDiscovery({
+      allowDuplicatesKey: true,
+      success: function (res) {
+        that.getConnectedDevices();
+        that.doStartScaning = false;
+        that.requestBlueTime = that.getCurrentMills();
+        if (boolean != null) {
+          boolean(true);
+        }
+        that.setConnectWillDevice(connectWillDevice);
+        that.setCallBackConnect(callBackConnect);
+        that.compareList = [];
+      },
+      fail(err) {
+        console.log("gadsfqwerqewrqrqr===" + JSON.stringify(err));
+        that.doStartScaning = false;
+        that.requestBlueTime = that.getCurrentMills();
+        if (boolean != null) {
+          boolean(false);
+        }
+      },
+    })
   }
 
   // 停止搜索

+ 0 - 1
pages/connectBle/connectBle.js

@@ -41,7 +41,6 @@ Page({
       that.data.connectDevice,
       async function (b) {
           if (!b) {
-            await BtHelper.getInstance().stopSearch();
             that.setStatus(1);
           }
         },