Przeglądaj źródła

兼容一代脑机连接使用

chaooo 1 rok temu
rodzic
commit
a7d40c06e5

+ 2 - 1
src/App.vue

@@ -12,10 +12,11 @@ export default {
   },
   onHide(){
   },
-  created() {
+  onLaunch(){
     // 版本自动更新代码
     checkUpdateVersion();
   },
+  created() {},
   log() {
     console.log(`log at:${Date.now()}`)
   }

+ 2 - 2
src/components/connection/brains/connecting.vue

@@ -3,7 +3,6 @@ import ble_store from "@/store/bluetooth";
 import Dialog from "../../../../static/vant/dialog/dialog";
 import Toast from "../../../../static/vant/toast/toast";
 import WechatLog from "@/utils/wechat_log";
-import game_store from "../../../store/game";
 
 let $this;
 export default {
@@ -55,6 +54,7 @@ export default {
      *
      */
     getBluetoothState() {
+      WechatLog.info(process.env.NODE_ENV, "开始连接手机蓝牙");
       // 获取本机蓝牙适配器状态
       wx.getBluetoothAdapterState({
         success: function(res) {
@@ -164,7 +164,7 @@ export default {
           $this.setDeviceStatus(2);
           // 记录日志
           $this.code = ble_store.getters.getDeviceSn();
-          WechatLog.info("脑机蓝牙连接成功:", $this.code);
+          WechatLog.info(process.env.NODE_ENV, "脑机蓝牙连接成功:", $this.code);
         },
         fail(err) {
           //连接脑机蓝牙失败

+ 9 - 6
src/components/connection/brains/scan.vue

@@ -2,6 +2,7 @@
 import ble_store from "@/store/bluetooth";
 import Dialog from "../../../../static/vant/dialog/dialog";
 import Toast from "../../../../static/vant/toast/toast";
+import WechatLog from "@/utils/wechat_log";
 
 let $this;
 export default {
@@ -75,23 +76,24 @@ export default {
             if (scan.scanType === "QR_CODE") {
               // 二维码
               $code = url.substring(url.indexOf("AI"));
+              if($code.indexOf("AI") === -1){
+                // 兼容一代脑机
+                $code = url.substring(url.toUpperCase().indexOf("JELLYFISH"));
+              }
             } else {
               // 一维码
               $code = scan.result.toUpperCase();
             }
             ble_store.setters.setDeviceSn($code);
+            WechatLog.info(process.env.NODE_ENV, "扫码得到头环SN码:", $code);
             console.log("扫码得到头环SN码:", $code);
             // 检查微信蓝牙权限
             this.openWechatBluetooth();
           }
         },
         fail(err) {
-          console.log(JSON.stringify(err));
-          // setTimeout(() => {
-          //   Toast.fail({
-          //     message: err["errMsg"],
-          //   });
-          // }, 3000);
+          console.log("扫码错误", JSON.stringify(err));
+          WechatLog.error(process.env.NODE_ENV, "扫码错误", JSON.stringify(err));
         },
       });
     },
@@ -102,6 +104,7 @@ export default {
       // 获取系统信息
       wx.getSystemInfo({
         success(res) {
+          WechatLog.info(process.env.NODE_ENV, "获取手机系统信息:", JSON.stringify(res));
           // 判断ios
           if (res.platform === "ios") {
             // 初始化蓝牙模块。iOS上开启主机central/从机peripheral(外围设备)模式时需分别调用一次,并指定对应的 mode

+ 1 - 1
src/pages/games/start/index.vue

@@ -339,7 +339,7 @@ export default {
 
         $this.game_over();
 
-        WechatLog.info("结束训练,game_record_id:", game_store.getters.getGameRecordId());
+        WechatLog.info(process.env.NODE_ENV, "结束训练,game_record_id:", game_store.getters.getGameRecordId());
 
         Toast.loading({
           forbidClick: true,

+ 32 - 8
src/utils/connection.js

@@ -12,6 +12,15 @@ function getDeviceWriteInfo() {
 }
 
 /**
+ * 判断一代脑机
+ */
+function isJELLYFISH() {
+  let $code = ble_store.getters.getDeviceSn();
+  return $code.indexOf("JELLYFISH") >= 0;
+}
+
+
+/**
  *  ArrayBuffer转16进度字符串示例
  * @param buffer
  * @returns {string}
@@ -235,6 +244,12 @@ export default {
       that.SendOrder('09');
       ble_store.setters.setCurrentToyId("00");
     },1000);
+    //如果是一代脑机则发送00教具
+    if (isJELLYFISH()) {
+      setTimeout(()=>{
+        that.sendConnectOneToMore('00');
+      },1500);
+    }
   },
   /**
    * todo 写入buffer
@@ -266,10 +281,11 @@ export default {
         characteristicId: characteristicWriteId,
         value: buffer,
         success: function (res) {
-          console.log($hex + "写入成功,时间:" + that.getNowTime())
+          WechatLog.info(process.env.NODE_ENV, "写入指令失败:",$hex, that.getNowTime());
         },
         fail: function (err) {
-          console.log($hex + "写入失败", err);
+          console.log("写入指令失败:", $hex, err);
+          WechatLog.error(process.env.NODE_ENV, "写入指令失败:", $hex, err);
         },
       });
     }
@@ -325,7 +341,9 @@ export default {
         if (hexStr.toUpperCase().indexOf("AADD0A") >= 0) {
           //没连接上教具
           if (hexStr.toUpperCase().indexOf("AADD0A0000") >= 0) {
-            $this.connect_toy = 3;
+            if(!isJELLYFISH()){
+              $this.connect_toy = 3;
+            }
             return false;
           }
           let $baseIndex = hexStr.toUpperCase().indexOf("AADD0A");
@@ -335,11 +353,17 @@ export default {
           console.log("教具", $toy_id)
           // 连接上教具
           if (new RegExp("00").test($hex_index) === true) {
-            console.log("一对多")
-            // 发送一对一连接 03 00 ${$toy_id} 01 0A
-            that.sendConnectOneToOne($toy_id);
-            ble_store.setters.setCurrentToyId($toy_id);
-            // current_toy_id = $toy_id;
+            if (isJELLYFISH()){
+              // 一代脑机
+              $this.connect_toy = 2;
+              wx.showToast({title: "已连接到" + $this.toy_item.name });
+            } else {
+              console.log("一对多")
+              // 发送一对一连接 03 00 ${$toy_id} 01 0A
+              that.sendConnectOneToOne($toy_id);
+              ble_store.setters.setCurrentToyId($toy_id);
+              // current_toy_id = $toy_id;
+            }
           }
           if (new RegExp("01").test($hex_index) === true) {
             console.log("一对一")