From 41189f4ca60ac566567f4402fb49d165fac934cc Mon Sep 17 00:00:00 2001 From: qiin <414382190@qq.com> Date: Wed, 17 Jun 2026 11:52:49 +0800 Subject: [PATCH 1/2] fix(controller): align device events and hvigor version --- .../test/GameControllerTestView.ets | 9 ++++++++- hvigor/hvigor-config.json5 | 4 ++-- hvigor/package.json | 4 ++-- .../src/main/cpp/game_controller_native.cpp | 19 +++++++++++++++++++ 4 files changed, 31 insertions(+), 5 deletions(-) diff --git a/entry/src/main/ets/components/test/GameControllerTestView.ets b/entry/src/main/ets/components/test/GameControllerTestView.ets index 092d64d..24ec9fe 100644 --- a/entry/src/main/ets/components/test/GameControllerTestView.ets +++ b/entry/src/main/ets/components/test/GameControllerTestView.ets @@ -16,7 +16,7 @@ import { gameControllerService, GameControllerService, ButtonCode } from '../../service/input/GameControllerService'; import { GamepadManager } from '../../service/input/GamepadManager'; import { UsbDriverService } from '../../service/usbdriver'; -import { gcButtonMap, AXIS_MAX, TRIGGER_MAX } from '../../service/input/GamepadTypes'; +import { gcButtonMap, AXIS_MAX, TRIGGER_MAX, MoonlightButton } from '../../service/input/GamepadTypes'; import { AppColors } from '../../common/Theme'; // @Builder 按引用传参接口 @@ -429,6 +429,13 @@ export struct GameControllerTestView { state.rightStickX = Math.floor(x * AXIS_MAX); state.rightStickY = Math.floor(-y * AXIS_MAX); break; + case 2: // D-Pad + state.buttons &= ~MoonlightButton.DPAD_MASK; + if (y < -0.5) state.buttons |= MoonlightButton.UP; + if (y > 0.5) state.buttons |= MoonlightButton.DOWN; + if (x < -0.5) state.buttons |= MoonlightButton.LEFT; + if (x > 0.5) state.buttons |= MoonlightButton.RIGHT; + break; case 3: // 左扳机 state.leftTrigger = Math.floor(x * TRIGGER_MAX); break; diff --git a/hvigor/hvigor-config.json5 b/hvigor/hvigor-config.json5 index 4bed9e9..832e30f 100644 --- a/hvigor/hvigor-config.json5 +++ b/hvigor/hvigor-config.json5 @@ -1,8 +1,8 @@ { "modelVersion": "5.0.0", "dependencies": { - "@ohos/hvigor": "6.24.1", - "@ohos/hvigor-ohos-plugin": "6.24.1" + "@ohos/hvigor": "6.24.2", + "@ohos/hvigor-ohos-plugin": "6.24.2" }, "execution": { "daemon": true, diff --git a/hvigor/package.json b/hvigor/package.json index 9b181c3..def1300 100644 --- a/hvigor/package.json +++ b/hvigor/package.json @@ -4,7 +4,7 @@ "private": true, "description": "Hvigor dependencies for CI build", "dependencies": { - "@ohos/hvigor": "6.24.1", - "@ohos/hvigor-ohos-plugin": "6.24.1" + "@ohos/hvigor": "6.24.2", + "@ohos/hvigor-ohos-plugin": "6.24.2" } } diff --git a/nativelib/src/main/cpp/game_controller_native.cpp b/nativelib/src/main/cpp/game_controller_native.cpp index 9637ae3..80ccbbc 100644 --- a/nativelib/src/main/cpp/game_controller_native.cpp +++ b/nativelib/src/main/cpp/game_controller_native.cpp @@ -1005,6 +1005,25 @@ int GameController_StartMonitor(void) { strncpy(info.name, name, sizeof(info.name) - 1); free(name); } + + int product = 0; + OH_GameDevice_DeviceInfo_GetProduct(deviceInfo, &product); + info.product = product; + + int version = 0; + OH_GameDevice_DeviceInfo_GetVersion(deviceInfo, &version); + info.version = version; + + char* physicalAddress = nullptr; + OH_GameDevice_DeviceInfo_GetPhysicalAddress(deviceInfo, &physicalAddress); + if (physicalAddress) { + strncpy(info.physicalAddress, physicalAddress, sizeof(info.physicalAddress) - 1); + free(physicalAddress); + } + + GameDevice_DeviceType deviceType; + OH_GameDevice_DeviceInfo_GetDeviceType(deviceInfo, &deviceType); + info.deviceType = (int32_t)deviceType; info.isConnected = true; From 935b344c3233d4929d0d3f5f359befd3bf98e9ac Mon Sep 17 00:00:00 2001 From: qiin <414382190@qq.com> Date: Thu, 18 Jun 2026 14:11:01 +0800 Subject: [PATCH 2/2] fix(controller): initialize device type fallback --- nativelib/src/main/cpp/game_controller_native.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/nativelib/src/main/cpp/game_controller_native.cpp b/nativelib/src/main/cpp/game_controller_native.cpp index 80ccbbc..104e115 100644 --- a/nativelib/src/main/cpp/game_controller_native.cpp +++ b/nativelib/src/main/cpp/game_controller_native.cpp @@ -455,7 +455,7 @@ static void OnDeviceChanged(const struct GameDevice_DeviceEvent* deviceEvent) { free(physicalAddress); } - GameDevice_DeviceType deviceType; + GameDevice_DeviceType deviceType = (GameDevice_DeviceType)0; OH_GameDevice_DeviceInfo_GetDeviceType(deviceInfo, &deviceType); info.deviceType = (int32_t)deviceType; @@ -1021,7 +1021,7 @@ int GameController_StartMonitor(void) { free(physicalAddress); } - GameDevice_DeviceType deviceType; + GameDevice_DeviceType deviceType = (GameDevice_DeviceType)0; OH_GameDevice_DeviceInfo_GetDeviceType(deviceInfo, &deviceType); info.deviceType = (int32_t)deviceType; @@ -1187,7 +1187,7 @@ int GameController_RefreshDevices(void) { free(physicalAddress); } - GameDevice_DeviceType deviceType; + GameDevice_DeviceType deviceType = (GameDevice_DeviceType)0; OH_GameDevice_DeviceInfo_GetDeviceType(deviceInfo, &deviceType); info.deviceType = (int32_t)deviceType;