Pārlūkot izejas kodu

脑机LED指令

chaooo 1 gadu atpakaļ
vecāks
revīzija
efdc58ef88

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

@@ -448,12 +448,16 @@ export default {
       wx.setKeepScreenOn({
         keepScreenOn: true,
       });
-
       $this.$bluetooth.sendAutoConnectRf(true, Math.round($this.played_time / 60));
-
       $this.$bluetooth.watchingDevice($this);
-      // 关闭LED
-      $this.$bluetooth.SendLedOrder("00");
+      // 获取LED灯状态并设置
+      let led_status = game_store.getters.getLED();
+      console.log("开始游戏获取LED灯状态", led_status)
+      if(led_status){
+        $this.$bluetooth.SendLedOrder("01");
+      }else{
+        $this.$bluetooth.SendLedOrder("00");
+      }
       // 开始倒计时
       clearInterval($timeout)
       $timeout = setInterval(() => {
@@ -544,6 +548,8 @@ export default {
         wx.removeStorageSync("over_play_time");
         game_store.setters.setMode(0);
       });
+      // 打开LED
+      $this.$bluetooth.SendLedOrder("01");
     },
     //  处理游戏中数据的方法
     do_datas: function ($data) {

+ 6 - 10
src/pages/user_center/index.vue

@@ -116,6 +116,7 @@
 import { reload_userinfo } from "../../utils/user";
 import game_store from "@/store/game";
 import Toast from "../../../static/vant/toast/toast";
+import {setUserLED} from "../../requests/user";
 
 var $this;
 export default {
@@ -130,18 +131,13 @@ export default {
   methods: {
     ledChange() {
       this.led_status = !this.led_status;
-      console.log("脑机LED灯:",this.led_status)
-      // let $ble_status = wx.getStorageSync("ble_link_status");
-      // if ($ble_status) {
-        //蓝牙已连接
-        if(this.led_status ){
-          $this.$bluetooth.SendLedOrder("01");
-        }else{
-          $this.$bluetooth.SendLedOrder("00");
-        }
-      // }
+      console.log("脑机LED灯:",this.led_status);
+      // 设置LED
+      game_store.setters.setLED(this.led_status);
+      console.log("设置后获取LED灯状态", game_store.getters.getLED())
       // 保存状态到数据库
       // todo
+      setUserLED(this.led_status);
     },
     to_edit() {
       mpvue.navigateTo({

+ 1 - 0
src/requests/log.js

@@ -14,6 +14,7 @@ export function LogInDb(content) {
     user_id,
     content
   }
+  console.log("记录日志:", JSON.stringify(params));
   // fly.post("log/add-log", params).then((res) => {
   //   if (res.data.code == 0) {
   //     return res.data.data;

+ 9 - 0
src/requests/user.js

@@ -26,6 +26,15 @@ export function userDetail() {
   return fly.post('user/user-detail', $params)
 }
 
+export function setUserLED(status) {
+  let $token = wx.getStorageSync('token')
+  let $params = {
+    access_token: $token,
+    status: status?1:0
+  }
+  return fly.post('user/set-up', $params)
+}
+
 //获取时间戳(10)
 export function  timestamp(){
   let outcome = Math.round(new Date().getTime()/1000).toString();

+ 2 - 9
src/utils/bluetooth.js

@@ -108,13 +108,6 @@ export default {
     let that = this;
     // 先发第一次
     that.SendOrder('07')
-    // 获取LED灯状态并设置
-    let led_status = game_store.getters.getLED();
-    if(led_status ){
-      $this.$bluetooth.SendLedOrder("01");
-    }else{
-      $this.$bluetooth.SendLedOrder("00");
-    }
     wx.showLoading({
       title: "正在启动"
     })
@@ -140,9 +133,9 @@ export default {
         // 关闭脑控
         that.SendOrder('09')
         // 打开LED
-        $this.$bluetooth.SendLedOrder("01");
+        that.SendLedOrder("01");
         // 断开教具及蓝牙连接
-        $this.$bluetooth.SendOrder("31");
+        that.SendOrder("31");
         //如果是jellyfish则发送00教具
         if (!is_new) {
           that.sendConnectOneToMore('00')

+ 2 - 2
src/utils/user.js

@@ -24,8 +24,8 @@ export function reload_userinfo($this) {
       do_logout($this)
     }
     $this.userinfo = $data.data;
-    // 设置脑机LED
-    if ($data.data.light_status * 1 === 1) {
+    // 设置LED
+    if ($this.userinfo.light_status * 1 === 1) {
       game_store.setters.setLED(true);
     } else {
       game_store.setters.setLED(false);