Pārlūkot izejas kodu

添加了扫码蓝牙小振动
添加了蓝牙与手机的信号强度识别

yerong 4 gadi atpakaļ
vecāks
revīzija
bce2a683a5

+ 2 - 1
src/app.json

@@ -25,7 +25,8 @@
     "pages/agent/settlement_center/index/main",
     "pages/agent/settlement_center/withdraw/detail/main",
     "pages/agent/settlement_center/withdraw/list/main",
-    "pages/only_pay/main"
+    "pages/only_pay/main",
+    "pages/test/main"
   ],
   "window": {
     "backgroundTextStyle": "light",

+ 21 - 3
src/components/device/connected.vue

@@ -18,7 +18,6 @@
       </van-col>
       <van-col span="5" offset="0">
         <div class="device_bg flex flex-direction align-center justify-center">
-          <!--          <text>{{ device_power }}%</text>-->
           <img src="https://img.shuimuai.com/web/sign_green.png" alt="" class="sign_green" v-if="device_bg == true">
           <img src="https://img.shuimuai.com/web/sign_red.png" class="sign_green" alt="" v-else>
           <img src="https://img.shuimuai.com/web/brain.png" alt="" class="device_brain">
@@ -54,7 +53,7 @@
 <script>
 export default {
   name: "connected",
-  props: ['device_bg', 'device_power'],
+  props: ['device_bg', 'device_power', 'rssi'],
   methods: {
     open_choose_toy() {
       this.$emit('open_choose_toy')
@@ -66,9 +65,28 @@ export default {
 }
 </script>
 
-<style scoped>
+<style>
 .cut_text {
   padding: 0px 5px;
   font-size: 11px;
 }
+
+/*电量显示*/
+.elc_power_container {
+  width: 23px;
+  border: #9A95B7 1 rpx solid;
+  border-radius: 5px;
+  height: 12px;
+  position: absolute;
+  left: 200px;
+  bottom: 152px;
+}
+
+
+.device_elc {
+  height: 10 rpx;
+  border-radius: 5 rpx;
+  bottom: 3 rpx;
+}
+
 </style>

+ 7 - 2
src/components/device/device.vue

@@ -39,6 +39,7 @@
             @change_brain_status="change_device_status"
             :device_bg="device_bg"
             :device_power="device_power"
+            :rssi="rssi"
           ></device_connected>
         </div>
       </div>
@@ -153,6 +154,7 @@ export default {
   },
   data() {
     return {
+      rssi:0,
       //设备状态 0为未连接,1:连接中,2:已连接 3:连接失败
       device_status: 0,
       // device_status: 2,
@@ -194,6 +196,10 @@ export default {
       wx.scanCode({
         onlyFromCamera: true,
         success: (res) => {
+          wx.vibrateShort({
+            type:"heavy"
+          })
+
           let $data = res;
           if ($data.result) {
             let url = decodeURIComponent($data.result);
@@ -326,8 +332,7 @@ export default {
       console.log("打开蓝牙搜索");
       try {
         setTimeout(() => {
-          if (!$this.device.deviceId) {
-            wx.offBluetoothDeviceFound();
+          if (!$this._deviceId) {
             wx.stopBluetoothDevicesDiscovery();
             $this.change_device_status(0);
             Toast.fail("未连接到设备");

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

@@ -224,6 +224,7 @@ export default {
               })
             }, 800)
 
+
           } else {
             Toast.fail($data.errmsg)
           }

+ 8 - 2
src/pages/game_record/index.vue

@@ -30,7 +30,9 @@
                     :value="item.play_time"
                     v-for="(item,index) in items"
                     :key="index"
-                    @click="to_report(item.game_record_id)"/>
+                    @click="to_report(item.game_record_id)"
+          />
+
         </div>
       </van-cell-group>
     </div>
@@ -99,7 +101,11 @@ export default {
           let $res = res.data;
           $this.items = $res.data.list
           $this.items.forEach(($val, $index) => {
-            $val['play_time'] = formatSeconds($val['play_time'])
+            if ($val['play_time']) {
+              $val['play_time'] = formatSeconds($val['play_time'])
+            } else {
+              $val.splice($index, 1)
+            }
           })
           $this.total = formatSeconds($res.data.total)
         },

+ 29 - 60
src/pages/start/index.vue

@@ -43,15 +43,22 @@
         </van-col>
         <van-col span="10">
           <div class="flex flex-direction align-center justify-center">
-            <van-row class="elc_power_container text-center">
-              <van-col v-for="(item,index) in elc_power/25" :key="index" span="6">
-                <img src="https://img.shuimuai.com/web/dianchi_3.png" alt="" class="device_elc">
-              </van-col>
-            </van-row>
-            <text class="text-default">{{ elc_power }}%</text>
+            <view class="elc_power_container">
+              <img src="https://img.shuimuai.com/web/dianchi_3.png" alt="" :style="{width:device_power+'%'}"
+                   class="device_elc">
+            </view>
+            <text class="text-default">{{ device_power }}%</text>
             <text class="text-default">设备电量</text>
           </div>
         </van-col>
+<!--        <van-col span="2">-->
+<!--          <view>-->
+<!--            <text>{{ rssi }}</text>-->
+<!--          </view>-->
+<!--          <view>-->
+<!--            <text>信号强度</text>-->
+<!--          </view>-->
+<!--        </van-col>-->
       </van-row>
     </div>
 
@@ -177,7 +184,7 @@ export default {
 
       timeData: {},
       mode_item: {},
-      elc_power: 100,
+      device_power: 100,
       // 折线图
       echarts,
       attCharts: initAttChart,
@@ -212,7 +219,10 @@ export default {
       played_time_text: "",
 
       //  检测佩戴是否正确
-      device_ok: true
+      device_ok: true,
+
+      //  蓝牙信号强度
+      rssi: 0
     }
   },
   methods: {
@@ -271,54 +281,8 @@ export default {
       })
     },
     start_game() {
-      //设置屏幕常亮
-      wx.setKeepScreenOn({
-        keepScreenOn: true
-      })
-      wx.onBLECharacteristicValueChange((characteristic) => {
-        // console.log("收到" + $this.ab2hex(characteristic.value));
-        let hexStr = $this.ab2hex(characteristic.value)
-        let $data = bluetooth.get_big_data(hexStr)
-
-        //监听脑环是否带好
-        if (hexStr.substr(0, 6) == '555520') {
-          //当s1为 00时 数据有效
-          let $s1 = hexStr.substr(8, 2)
-          // console.log("游戏中监听脑环是否带正:", $s1 == '00')
-          $this.device_ok = ($s1 == '00')
-        }
-
-        //连接玩具
-        if ($data) {
-          $this.do_datas($data)
-
-
-          //通过专注放松度 画图
-          let $option = util.getLineOption($this.att_list, $this.med_list)
-          att_charts.setOption($option)
-
-          //通过基本脑波发送数据
-          let $base_option = util.getBaseOption($this.delta_list, $this.theta_list, $this.alpha_list, $this.beta_list)
-          med_charts.setOption($base_option)
-        }
-        //获取设备电量
-        let $power = bluetooth.get_device_elc(hexStr)
-        if ($power) {
-          $this.elc_power = $power
-          //电量低于20就提示 电量不足
-          if ($power < 20 && $power > 0) {
-            wx.showModal({
-              content: "脑环电量不足",
-              showCancel: false,
-              success() {
-                $this.game_finished()
-              }
-            })
-          }
-        }
-        bluetooth.sendControl($this._deviceId, $this._serviceId, $this._characteristicId)
-      })
-
+      bluetooth.watchingDevice($this)
+      bluetooth.sendControl($this._deviceId, $this._serviceId, $this._characteristicId)
     },
 
     // ArrayBuffer转16进度字符串示例
@@ -391,7 +355,7 @@ export default {
       let $params = {
         game_record_id: game_store.getters.getGameRecordId(),
         type: $this.mode,
-        play_time: $this.played_time
+        play_time: Math.abs($this.played_time)
       }
       console.log("结束游戏参数", $params)
       //
@@ -429,6 +393,13 @@ export default {
       $this.attList.push($data['att'])
       $this.medList.push($data['med'])
 
+      //通过专注放松度 画图
+      let $option = util.getLineOption($this.att_list, $this.med_list)
+      att_charts.setOption($option)
+
+      //通过基本脑波发送数据
+      let $base_option = util.getBaseOption($this.delta_list, $this.theta_list, $this.alpha_list, $this.beta_list)
+      med_charts.setOption($base_option)
     },
     //计算游玩时间
     calThePlayedTime() {
@@ -470,7 +441,6 @@ export default {
   }
   ,
   mounted() {
-
     let $deviceId = $this._deviceId = game_store.getters.getDeviceId()
     let $serviceId = $this._serviceId = game_store.getters.getServiceId()
     let $cId = $this._characteristicId = game_store.getters.getCharacterId()
@@ -597,8 +567,7 @@ export default {
 }
 
 .device_elc {
-  height: 22px;
-  width: 4px;
+  height: 18px;
 }
 
 /* 节标题  */

+ 59 - 0
src/pages/test/index.vue

@@ -0,0 +1,59 @@
+<template>
+  <div id="playing_container">
+    <div class="flex flex-direction align-center justify-center">
+      <view class="elc_power_container">
+        <img src="https://img.shuimuai.com/web/dianchi_3.png" alt="" :style="{width:device_power+'%'}" class="device_elc">
+      </view>
+      <text class="text-default">{{ device_power }}%</text>
+      <text class="text-default">设备电量</text>
+    </div>
+    			<button class="cu-btn" @click="device_power++">+</button>
+			<button class="cu-btn" @click="device_power--">-</button>
+
+  </div>
+</template>
+
+<script>
+
+export default {
+  name: "index_container",
+  data() {
+    return {
+      device_power: 100,
+    }
+  },
+  methods: {}
+  ,
+  mounted() {
+  },
+}
+</script>
+
+<style scoped>
+#playing_container {
+  width: 100%;
+  background: linear-gradient(0deg, rgba(40, 157, 206, 0.51), rgba(135, 145, 226, 0.26));
+  background-color: #46425E;
+  padding: 5px;
+  height: 750px;
+
+}
+
+
+.text-default {
+  color: #9A95B7;
+  font-size: 10px;
+}
+
+/*电量显示*/
+.elc_power_container {
+  width: 28px;
+  border: #9A95B7 3px solid;
+  border-radius: 5px;
+  height: 22px;
+}
+
+.device_elc {
+  height: 16px;
+}
+</style>

+ 12 - 0
src/pages/test/main.js

@@ -0,0 +1,12 @@
+import Vue from 'vue'
+import App from './index'
+
+// add this to handle exception
+Vue.config.errorHandler = function (err) {
+  if (console && console.error) {
+    console.error(err)
+  }
+}
+
+const app = new Vue(App)
+app.$mount()

+ 10 - 0
src/pages/test/main.json

@@ -0,0 +1,10 @@
+{
+  "usingComponents": {
+    "van-row": "../../static/vant/row/index",
+    "van-col": "../../static/vant/col/index",
+    "van-toast": "../../static/vant/toast/index",
+    "van-popup": "../../static/vant/popup/index",
+    "van-count-down": "../../static/vant/count-down/index",
+    "van-dialog": "../../static/vant/dialog/index"
+  }
+}

+ 17 - 3
src/utils/bluetooth.js

@@ -600,15 +600,20 @@ export default {
     wx.onBLECharacteristicValueChange(
       (characteristic) => {
         let hexStr = that.ab2hex(characteristic.value)
-        console.log(hexStr)
+        let $data = that.get_big_data(hexStr)
+        wx.getBLEDeviceRSSI({
+          deviceId: characteristic.deviceId,
+          success(res) {
+            $this.rssi = Math.abs(res['RSSI'])
+            console.log('信号强度:',$this.rssi)
+          }
+        })
         if (hexStr.substr(0, 6) == '555520') {
           //当s1为 00时 数据有效
           let $s1 = hexStr.substr(8, 2)
           // console.log("监听脑环是否带正:", $s1 == '00')
 
           $this.device_bg = ($s1 == '00')
-          console.log($s1)
-          console.log(parseInt('0x'+$s1))
         }
 
         //  监听脑环电量
@@ -627,6 +632,15 @@ export default {
           })
         }
 
+        let $game_status = game_store.getters.getGameStatus()
+        if ($game_status == 1 && $data) {
+          try {
+            $this.do_datas($data)
+          } catch (e) {
+            console.log('调用方法失败', e)
+          }
+        }
+
       }
     )
   }