Bläddra i källkod

修改了,收到打开脑控的应答后才跳转游戏开始

叶振荣 3 år sedan
förälder
incheckning
c64ae9260e
3 ändrade filer med 57 tillägg och 31 borttagningar
  1. 13 12
      src/components/device/toy/connecting.vue
  2. 2 0
      src/pages/start/index.vue
  3. 42 19
      src/utils/bluetooth.js

+ 13 - 12
src/components/device/toy/connecting.vue

@@ -342,7 +342,7 @@ export default {
             // 设置游戏模式
             game_store.setters.setMode($event);
             // 设置游戏状态为游戏中
-            game_store.setters.setGameStatus(1);
+            // game_store.setters.setGameStatus(1);
             // 设置游戏记录id
             game_store.setters.setGameRecordId($res["game_record_id"]);
 
@@ -350,17 +350,18 @@ export default {
             $this.$bluetooth.sendControl();
 
             Toast.success($data.errmsg);
-            setTimeout(() => {
-              mpvue.navigateTo({
-                url: "/pages/start/main",
-                success() {
-                  // 记录消费方式 选择时间卡还是次卡
-                  game_store.setters.setPlayTime($res["play_time"]);
-                  game_store.setters.setOverPlayTime($res["play_time"]);
-                  $this.$emit("gameStart", true);
-                },
-              });
-            }, 800);
+            game_store.setters.setPlayTime($res["play_time"]);
+            game_store.setters.setOverPlayTime($res["play_time"]);
+            // setTimeout(() => {
+            //   mpvue.navigateTo({
+            //     url: "/pages/start/main",
+            //     success() {
+            //       // 记录消费方式 选择时间卡还是次卡
+                  
+            //       $this.$emit("gameStart", true);
+            //     },
+            //   });
+            // }, 800);
           } else {
             Toast.fail($data.errmsg);
           }

+ 2 - 0
src/pages/start/index.vue

@@ -447,6 +447,8 @@ export default {
       });
 
       $this.$bluetooth.watchingDevice($this);
+      $this.$bluetooth.SendOrder('8a')
+
       // $this.$bluetooth.sendControl();
       // setTimeout(() => {
         $this.$bluetooth.sendToyPower_CheckReconected()

+ 42 - 19
src/utils/bluetooth.js

@@ -77,14 +77,6 @@ export default {
   sendControl() {
     let that = this;
     that.SendOrder('07')
-
-    // let $SendControlIntv = setInterval(() => {
-    //   if (FlagOpenControl) {
-    //     clearInterval($SendControlIntv)
-    //   } else {
-    //     that.SendOrder('07')
-    //   }
-    // }, 1000);
   },
   // 关闭脑控
   sendControlClose() {
@@ -127,7 +119,6 @@ export default {
         that.SendOrder('8a')
         // connect_toy = false
         // }
-
         //3次获取不到电量则重新连接
         // if ($connect_false_count == 3) {
         //   wx.showToast({
@@ -142,7 +133,7 @@ export default {
         //   clearInterval(toy_intv)
         // }
       }
-    }, 10000)
+    }, 3000)
   },
 
   //  获取大包数据 进行绘制图表
@@ -244,6 +235,7 @@ export default {
           // 结束状态更改为1
         } else {
           //关闭脑控
+          that.sendControlClose();
           game_store.setters.setGameStatus(0);
           // 清空链接得设备 三值
           game_store.setters.clearDeviceToy();
@@ -395,9 +387,25 @@ export default {
     wx.onBLECharacteristicValueChange((characteristic) => {
       let hexStr = that.ab2hex(characteristic.value);
 
-      if (hexStr.toUpperCase().indexOf("AADD") != -1) {
+      // 教具断链
+      if (hexStr.toUpperCase().indexOf("AAEE70") != -1) {
+        wx.showToast({
+          title: "教具已断开",
+          icon: "error"
+        })
+        //重连机制
+        that.SendOrder("09")
+        setTimeout(() => {
+          that.ReconnectToy()
+        }, 1500)
+      }
+      if (hexStr.toUpperCase().indexOf("AAEE07") != -1) {
+        that.sendControl();
+      }
+
+      if (hexStr.toUpperCase().indexOf("AADD") != -1 || hexStr.toUpperCase().indexOf("AAEE") != -1) {
         let nowTime = Math.round(new Date() / 1000);
-        console.log(`${(nowTime - logTime)}s`)
+        console.log(`应答耗时:${(nowTime - logTime)}秒`)
         console.log(hexStr);
       }
       let $data = that.get_big_data(hexStr);
@@ -447,11 +455,13 @@ export default {
       //2021年11月23日10:39:49
       // 获取教具名称
       if (hexStr.toUpperCase().indexOf("AADD87") != -1) {
-          let $datas = that.DoAnalysis(hexStr, 10)
-          console.log($datas)
-          $this.toy_sn = $datas;
-          //获取教具电量
-          that.SendOrder('8a')
+        let $datas = that.DoAnalysis(hexStr, 10)
+        let $number = $datas.match(/\d+/)
+        let toy_list_pre= {'01': "SW",'02': "KL",'04': "SC",'05': "PP",'06': "SU",'09': "UF"}
+        let $sn = toy_list_pre[current_toy_id] + $number;
+        $this.toy_sn = $sn;
+        //获取教具电量
+        that.SendOrder('8a')
       }
 
       //2021年10月21日16:30:07
@@ -497,8 +507,8 @@ export default {
       // 收到一次UUID就发送一次获取教具的电量
       // 读取教具UUID
       if (hexStr.toUpperCase().indexOf("AADD84") != -1) {//接收UUID 5个字节
-        let $_hexStr = hexStr.substr(6);
-        let $datas = $_hexStr.substr(0, 10);
+        let $hex_index = hexStr.toUpperCase().indexOf("AADD84") + 6;
+        let $datas = hexStr.substr($hex_index, 10);
         if ($datas != "0000000000") {
           console.log("以获取UUID:" + $datas)
           current_toy_UUID = $datas;
@@ -566,6 +576,19 @@ export default {
       // 处理打开脑控的应答
       if (hexStr.toUpperCase().indexOf("AADD07") != -1) {
         FlagOpenControl = true;
+        console.log($game_status)
+        if($game_status != 1){
+           setTimeout(() => {
+              mpvue.navigateTo({
+                url: "/pages/start/main",
+                success() {
+                  // 设置游戏状态为游戏中
+                  game_store.setters.setGameStatus(1);
+                  $this.gameStart();
+                },
+              });
+            }, 800);
+        }
       }