Fury 3 jaren geleden
bovenliggende
commit
183936c1fb

+ 1 - 1
src/components/device/device.vue

@@ -398,7 +398,7 @@ export default {
 
       $this.$bluetooth.sendConnectOneToMore($hex);
 
-      //设置5秒后是否已经连接
+      //2022-5-25 09:07:59 设置10秒后是否已经连接
       setTimeout(() => {
         if ($this.toy_connected == false) {
           $this.change_toy_connect_status(3);

+ 9 - 0
src/components/device/toy/connecting.vue

@@ -334,6 +334,15 @@ export default {
             Toast.success($data.errmsg);
             game_store.setters.setPlayTime($res["play_time"]);
             game_store.setters.setOverPlayTime($res["play_time"]);
+            setTimeout(() => {
+              mpvue.navigateTo({
+                url: "/pages/start/main",
+                success() {
+                  // 设置游戏状态为游戏中
+                  game_store.setters.setGameStatus(1);
+                },
+              });
+            }, 800);
             
           } else {
             $this.is_started = false;

+ 3 - 3
src/pages/index/index.vue

@@ -184,9 +184,9 @@ export default {
   onHide() {
   },
   onLoad($option) {
-    // if (process.env.NODE_ENV == "development") {
-    //   wx.setStorageSync('token',"uWBC1UDZ4GciXkBkuGFTJ914xOoyMmvk")
-    // }
+    if (process.env.NODE_ENV == "development") {
+      wx.setStorageSync('token',"uWBC1UDZ4GciXkBkuGFTJ914xOoyMmvk")
+    }
     if (game_store.getters.getGameStatus() == 1) {
       Dialog.alert({
         title: "系统提示",

+ 8 - 4
src/pages/start/index.vue

@@ -273,7 +273,7 @@ function initMedChart(canvas, width, height) {
   med_charts.setOption(option);
   return med_charts; // 返回 chart 后可以自动绑定触摸操作
 }
-
+var $timeout;
 export default {
   name: "index_container",
   components: {
@@ -423,11 +423,12 @@ export default {
         keepScreenOn: true,
       });
 
-      $this.$bluetooth.watchingDevice($this);
-      $this.$bluetooth.SendOrder('8a')
+      $this.$bluetooth.sendAutoConnectRf(true,Math.round($this.played_time/60));
 
+      $this.$bluetooth.watchingDevice($this);
       // 开始倒计时
-      let $timeout = setInterval(()=>{
+      clearInterval($timeout)
+      $timeout = setInterval(()=>{
             if ($this.played_time > 0) {
             //自定义定时器
             $this.played_time -= 1;
@@ -445,6 +446,9 @@ export default {
             clearInterval($timeout)
           }
       },1000)
+
+
+      
     },
 
     // ArrayBuffer转16进度字符串示例

+ 44 - 21
src/utils/bluetooth.js

@@ -152,7 +152,9 @@ export default {
         if (connect_toy) {
           that.SendOrder('8a')
         }else{
-          clearInterval(toy_intv)
+          if ($game_status!=1) {
+            clearInterval(toy_intv)
+          }
         }
       }, 3000)
     } else {
@@ -293,14 +295,14 @@ export default {
     //重连的次数
     let $connect_count = 0;
     let $rec = setInterval(() => {
-      $connect_count += 1;
       let $game_status = game_store.getters.getGameStatus();
       if ($game_status == 1) {
         wx.createBLEConnection({
           deviceId: $deviceInfo.deviceId,
           success(res) {
+            clearInterval($rec)
             Notify({ type: 'success', message: `第${$connect_count}次重新连接成功` });
-            LogInDb(`${that.getNowTime} 第${$connect_count}次重新连接成功`)
+            LogInDb(`${that.getNowTime()} 第${$connect_count}次重新连接成功`)
             let $system = wx.getSystemInfoSync()
             if ($system.platform == 'ios') {
               that.getBLEDeviceServices($deviceInfo.deviceId)
@@ -309,9 +311,8 @@ export default {
               that.openNotify($this)
               that.watch_bluetooth_status($this);
             }
-            that.sendToyPower();
+            // that.sendToyPower();
 
-            clearInterval($rec)
           },
           fail(res) {
             Notify({ type: 'danger', message: `第${$connect_count}次重新连接失败` });
@@ -322,10 +323,11 @@ export default {
           $this.game_finished();
           clearInterval($rec)
         }
+        $connect_count += 1;
       } else {
         clearInterval($rec)
       }
-    }, 5000)
+    }, 7000)
 
   },
 
@@ -412,7 +414,6 @@ export default {
       state: true,
       success() {
         that.watchingDevice($this)
-        that.sendOpenBigData();
       }
     });
   },
@@ -483,6 +484,11 @@ export default {
         that.SendOrder("8a")
       }
 
+      //防止在首页 连接的时候重复 选择教具 产生了发送多个教具电量
+      // if(hexStr.toUpperCase().indexOf("AAEE8A000000FF76") != -1){
+      //   that.connect_toy = false;
+      // }
+
       if (hexStr.toUpperCase().indexOf("AAEE07") != -1) {
         that.sendControl();
       }
@@ -523,9 +529,18 @@ export default {
           });
           $this.toy_connected = true;
           connect_toy = true;
+
           $this.change_toy_connect_status(2);
           //连接成功后 获取一次教具名称
-          that.SendOrder('87')
+          
+
+          //TODO 2022-5-25 08:51:15 延迟发送教具UUID
+          //2022年5月25日17:21:57 从2秒更换到3秒
+          setTimeout(()=>{
+            that.SendOrder('87')
+          },3000)
+
+
         }
 
         if (new RegExp("02").test($hex_index) == true) {
@@ -536,7 +551,7 @@ export default {
             title: "教具重连成功"
           })
           that.sendControl()
-          that.sendToyPower();
+          // that.sendToyPower();
         }
       }
 
@@ -629,18 +644,6 @@ export default {
       if (hexStr.toUpperCase().indexOf("AADD07") != -1) {
         ble_store.setters.setBluetoothLinkStatus(true)
         FlagOpenControl = true;
-        if ($game_status != 1) {
-          setTimeout(() => {
-            mpvue.navigateTo({
-              url: "/pages/start/main",
-              success() {
-                // 设置游戏状态为游戏中
-                game_store.setters.setGameStatus(1);
-                $this.gameStart();
-              },
-            });
-          }, 800);
-        }
       }
 
 
@@ -945,5 +948,25 @@ export default {
     const millSeconds = date.getMilliseconds();
 
     return `${year}/${month}/${day} ${hour}:${minutes}:${seconds}.${millSeconds}`;
+  },
+
+  /**
+   * 自动发送RF重连
+   * @param  {Boolean} isOn    是否打开重连功能
+   * @param  {[type]}  timeOut 有效时间
+   * @return {[type]}          [description]
+   * AA CC 03 00 01 0a d0 21
+   */ 
+  sendAutoConnectRf(isOn,timeOut){
+    let that = this;
+    let onVal = isOn?'01':'00';
+    let mTimeOut = timeOut.toString(16);
+
+    if (mTimeOut.length==1) {
+      mTimeOut = `0${mTimeOut}`
+    }
+
+    let $hexStr = `03 00 ${onVal} ${mTimeOut} d0`;
+    this.WriteBufferInBle($hexStr)
   }
 };