Browse Source

挡位优化+增加鸣笛效果
Signed-off-by: caner <5658514@qq.com>

caner 3 years ago
parent
commit
b0b94dc030
3 changed files with 34 additions and 25 deletions
  1. 5 2
      README.md
  2. 25 23
      src/App.vue
  3. 4 0
      src/components/gauge.vue

+ 5 - 2
README.md

@@ -22,5 +22,8 @@
 4. A键是2档
 5. B键是1档
 6. R2是语音(按住说话)
-7. L2是静音
-```
+7. X3是静音
+8. Y2是鸣笛
+```
+## TODO:
+4. 电量采集优化(准确性)

+ 25 - 23
src/App.vue

@@ -84,9 +84,9 @@ export default {
       contrlState: false,
       audioState: false,
       mutedState: true,
+      warnAudio: false,// 鸣笛
       speed: 1, //1低速档 | 2 高速档
       muted: true,// 是否静音
-      audioPlay:false,
       signalValue: 0,
       SpeedValue: 0,
       iceServers: [
@@ -99,8 +99,7 @@ export default {
           credential: "123456",
         },
       ],
-      num: 0,
-      num2:0
+      num: 0
     };
   },
   methods: {
@@ -136,6 +135,7 @@ export default {
             console.log("track", evt);
             this.remoteVideo = document.getElementById("v2");
             this.remoteVideo.srcObject = evt.streams[0];
+            if (evt.track.kind === 'audio') this.remoteAudioTrak = evt.streams[0]
           };
 
           // listen changestate
@@ -179,7 +179,7 @@ export default {
           console.log("电量", data);
         } else if (data.type === "signal") {
           const v = data.data <= 20 ? Math.floor(data.data / 4) : 5
-          this.signalValue = v
+          this.signalValue = v || 1
         } else if (data.type === 'speed') {
           const v = Math.floor(data.data)
           this.SpeedValue = v
@@ -203,11 +203,11 @@ export default {
       if (db.buttons[0].touched) this.speed = 1;
       // 语音按键R2
       this.audioState = db.buttons[7].touched
-      // 静音L2
-      this.mutedState = db.buttons[6].touched
-      // 播放警笛X3
-
-      console.log(db.buttons);
+      // 静音X3
+      this.mutedState = db.buttons[3].touched
+      // 播放警笛Y2
+      this.warnAudio = db.buttons[2].touched
+      // console.log(db.buttons);
       const params = {
         v0: Math.floor(db.axes[0] * 128 + 128),
         v1: Math.floor(db.axes[1] * 128 + 128),
@@ -215,9 +215,7 @@ export default {
         v3: this.Gear(this.speed, Math.floor(db.axes[3] * 128 + 128)),
       };
 
-      if (this.socket.connected) {
-        this.socket.emit("msg", { type: "conctrl", conctrl: params });
-      }
+      if (this.socket && this.socket.connected) this.socket.emit("msg", { type: "conctrl", conctrl: params });
       requestAnimationFrame(this.ControlData);
     },
 
@@ -230,20 +228,17 @@ export default {
       });
     },
 
-    // 鸣笛
-    playWarningAudio(){
-
-    },
-
     // 挡位
     Gear(speed, num) {
       // 低速档
       if (speed === 1) {
         if (num < 116) {
-          num = 116;
+          // 前
+          num = 120;
         } else if (num >= 120 && num <= 131) {
           num = 128;
         } else if (num > 140) {
+          // 后
           num = 140;
         }
       }
@@ -282,6 +277,8 @@ export default {
       this.showLoading = false;
       this.error = err || "";
       this.socket = null;
+      this.Peer = null
+      this.num = 0
       cancelAnimationFrame(this.ControlData);
       window.removeEventListener("gamepadconnected", this.conControl);
       window.removeEventListener("gamepaddisconnected", this.disControl);
@@ -305,11 +302,16 @@ export default {
   watch: {
     // 静音
     mutedState(v) {
-      if (v) this.num++
-      if (!this.remoteVideo) return
-      const state = this.num % 2 ? false : true
-      this.remoteVideo.muted = state
-      this.muted = state
+      if (v) {
+        this.num++
+        const state = this.num % 2 ? false : true
+        this.muted = state
+        if (this.socket && this.socket.connected) this.socket.emit("msg", { type: "contrlAudio", contrlAudio: state });
+      }
+    },
+    // 鸣笛
+    warnAudio(v) {
+      if (v && this.socket && this.socket.connected) this.socket.emit("msg", { type: "warnAudio", warnAudio: v });
     }
   }
 };

+ 4 - 0
src/components/gauge.vue

@@ -96,6 +96,10 @@ export default {
       this.option.series.data[0] = v;
       this.mychart.setOption(this.option);
     },
+    gears(v){
+      if (!this.mychart) return;
+      this.mychart.setOption(this.option);
+    }
   },
 };
 </script>