This commit is contained in:
JayJiaJun 2025-02-19 21:33:57 +08:00
parent 960a08f25d
commit e3eea4bd54
2 changed files with 30 additions and 16 deletions

View File

@ -21,6 +21,7 @@ class GamepadController {
this.directionAxis0_1 = ""; this.directionAxis0_1 = "";
this.directionAxis9 = ""; this.directionAxis9 = "";
this.angle = 0; this.angle = 0;
this.rightJoystickPressed = false;
// 初始化按钮状态 // 初始化按钮状态
this.buttons = this.options.buttonsConfig.map(button => ({ this.buttons = this.options.buttonsConfig.map(button => ({
...button, ...button,
@ -104,15 +105,16 @@ class GamepadController {
const axis9 = axes[9]; const axis9 = axes[9];
const roundedAxis9 = Math.round(axis9 * 100) / 100; const roundedAxis9 = Math.round(axis9 * 100) / 100;
if (roundedAxis9 <= -0.9) { if (roundedAxis9 <= -0.9) {
this.directionAxis9 = "上"; this.directionAxis9 = 0;
} else if (roundedAxis9 >= 0.0 && roundedAxis9 <= 0.2) { } else if (roundedAxis9 >= 0.0 && roundedAxis9 <= 0.2) {
this.directionAxis9 = "下"; this.directionAxis9 = 1;
} else if (roundedAxis9 >= 0.6 && roundedAxis9 <= 0.8) { // } else if (roundedAxis9 >= 0.6 && roundedAxis9 <= 0.8) {
this.directionAxis9 = "左"; // this.directionAxis9 = "左";
} else if (roundedAxis9 >= -0.5 && roundedAxis9 <= -0.4) { // } else if (roundedAxis9 >= -0.5 && roundedAxis9 <= -0.4) {
this.directionAxis9 = "右"; // this.directionAxis9 = "右";
} else { }
this.directionAxis9 = "未定义"; else {
this.directionAxis9 = 0;
} }
} }
@ -120,6 +122,11 @@ class GamepadController {
this.buttons.forEach(button => { this.buttons.forEach(button => {
const buttonData = buttons[button.index]; const buttonData = buttons[button.index];
button.pressed = buttonData ? buttonData.value === 1 : false; button.pressed = buttonData ? buttonData.value === 1 : false;
// 特别检查 Right Joystick Press 按钮
if (button.name === "Right Joystick Press") {
this.rightJoystickPressed = button.pressed;
}
}); });
} }

View File

@ -104,7 +104,9 @@ export default {
connectionCheckInterval: null, connectionCheckInterval: null,
sendInterval: null, sendInterval: null,
lastDirection: 0, lastDirection: 0,
lastSpeed: 0 lastSpeed: 0,
platform_fun:0,
button:"",
} }
}, },
created() { created() {
@ -219,12 +221,17 @@ export default {
// //
updateGamepadData() { updateGamepadData() {
if (this.gamepadController) { if (this.gamepadController) {
// angle //
const angle = this.gamepadController.angle; const angle = this.gamepadController.angle;
console.log('当前角度:', angle); const directionAxis9 = this.gamepadController.directionAxis9;
//
this.isControlPressed = this.gamepadController.rightJoystickPressed;
//
this.lastDirection = angle; this.lastDirection = angle;
// this.platform_fun = directionAxis9;
this.lastSpeed = 0; // 0 this.lastSpeed = 0;
} }
}, },
sendCarInfo() { sendCarInfo() {
@ -290,7 +297,7 @@ export default {
"get_info": 1, "get_info": 1,
"get_attribute": 1, "get_attribute": 1,
"function": { "function": {
"platform_fun": 2, "platform_fun": this.platform_fun,
"screen_en": this.screenStatus ? 1 : 0, "screen_en": this.screenStatus ? 1 : 0,
"warn_light_en": this.warningLightStatus ? 1 : 0, "warn_light_en": this.warningLightStatus ? 1 : 0,
"follow_en": this.followStatus ? 1 : 0, "follow_en": this.followStatus ? 1 : 0,