diff options
| author | 2024-01-07 09:05:12 -0600 | |
|---|---|---|
| committer | 2024-01-11 19:35:04 -0600 | |
| commit | b5dac5f525e8d5884506ebd98a530e237b518480 (patch) | |
| tree | 6ceee925ba897dc3450bdad209982f0be4bc3f7a /src/hid_core/resources/vibration | |
| parent | Merge pull request #12653 from liamwhite/once-more (diff) | |
| download | yuzu-b5dac5f525e8d5884506ebd98a530e237b518480.tar.gz yuzu-b5dac5f525e8d5884506ebd98a530e237b518480.tar.xz yuzu-b5dac5f525e8d5884506ebd98a530e237b518480.zip | |
service: hid: Create abstracted pad structure
Diffstat (limited to 'src/hid_core/resources/vibration')
8 files changed, 423 insertions, 0 deletions
diff --git a/src/hid_core/resources/vibration/gc_vibration_device.cpp b/src/hid_core/resources/vibration/gc_vibration_device.cpp new file mode 100644 index 000000000..f01f81b9a --- /dev/null +++ b/src/hid_core/resources/vibration/gc_vibration_device.cpp | |||
| @@ -0,0 +1,106 @@ | |||
| 1 | // SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project | ||
| 2 | // SPDX-License-Identifier: GPL-3.0-or-later | ||
| 3 | |||
| 4 | #include "hid_core/hid_result.h" | ||
| 5 | #include "hid_core/resources/npad/npad_types.h" | ||
| 6 | #include "hid_core/resources/npad/npad_vibration.h" | ||
| 7 | #include "hid_core/resources/vibration/gc_vibration_device.h" | ||
| 8 | |||
| 9 | namespace Service::HID { | ||
| 10 | |||
| 11 | NpadGcVibrationDevice::NpadGcVibrationDevice() {} | ||
| 12 | |||
| 13 | Result NpadGcVibrationDevice::IncrementRefCounter() { | ||
| 14 | if (ref_counter == 0 && is_mounted) { | ||
| 15 | f32 volume = 1.0f; | ||
| 16 | const auto result = vibration_handler->GetVibrationVolume(volume); | ||
| 17 | if (result.IsSuccess()) { | ||
| 18 | // TODO: SendVibrationGcErmCommand | ||
| 19 | } | ||
| 20 | } | ||
| 21 | ref_counter++; | ||
| 22 | return ResultSuccess; | ||
| 23 | } | ||
| 24 | |||
| 25 | Result NpadGcVibrationDevice::DecrementRefCounter() { | ||
| 26 | if (ref_counter == 1 && !is_mounted) { | ||
| 27 | f32 volume = 1.0f; | ||
| 28 | const auto result = vibration_handler->GetVibrationVolume(volume); | ||
| 29 | if (result.IsSuccess()) { | ||
| 30 | // TODO: SendVibrationGcErmCommand | ||
| 31 | } | ||
| 32 | } | ||
| 33 | |||
| 34 | if (ref_counter > 0) { | ||
| 35 | ref_counter--; | ||
| 36 | } | ||
| 37 | |||
| 38 | return ResultSuccess; | ||
| 39 | } | ||
| 40 | |||
| 41 | Result NpadGcVibrationDevice::SendVibrationGcErmCommand(Core::HID::VibrationGcErmCommand command) { | ||
| 42 | if (!is_mounted) { | ||
| 43 | return ResultSuccess; | ||
| 44 | } | ||
| 45 | f32 volume = 1.0f; | ||
| 46 | const auto result = vibration_handler->GetVibrationVolume(volume); | ||
| 47 | if (result.IsError()) { | ||
| 48 | return result; | ||
| 49 | } | ||
| 50 | if (volume == 0.0) { | ||
| 51 | command = Core::HID::VibrationGcErmCommand::Stop; | ||
| 52 | } else { | ||
| 53 | if (command > Core::HID::VibrationGcErmCommand::StopHard) { | ||
| 54 | // Abort | ||
| 55 | return ResultSuccess; | ||
| 56 | } | ||
| 57 | } | ||
| 58 | // TODO: SendVibrationGcErmCommand | ||
| 59 | return ResultSuccess; | ||
| 60 | } | ||
| 61 | |||
| 62 | Result NpadGcVibrationDevice::GetActualVibrationGcErmCommand( | ||
| 63 | Core::HID::VibrationGcErmCommand& out_command) { | ||
| 64 | if (!is_mounted) { | ||
| 65 | out_command = Core::HID::VibrationGcErmCommand::Stop; | ||
| 66 | return ResultSuccess; | ||
| 67 | } | ||
| 68 | |||
| 69 | f32 volume = 1.0f; | ||
| 70 | const auto result = vibration_handler->GetVibrationVolume(volume); | ||
| 71 | if (result.IsError()) { | ||
| 72 | return result; | ||
| 73 | } | ||
| 74 | if (volume == 0.0f) { | ||
| 75 | out_command = Core::HID::VibrationGcErmCommand::Stop; | ||
| 76 | return ResultSuccess; | ||
| 77 | } | ||
| 78 | |||
| 79 | // TODO: GetActualVibrationGcErmCommand | ||
| 80 | return ResultSuccess; | ||
| 81 | } | ||
| 82 | |||
| 83 | Result NpadGcVibrationDevice::SendVibrationNotificationPattern( | ||
| 84 | Core::HID::VibrationGcErmCommand command) { | ||
| 85 | if (!is_mounted) { | ||
| 86 | return ResultSuccess; | ||
| 87 | } | ||
| 88 | |||
| 89 | f32 volume = 1.0f; | ||
| 90 | const auto result = vibration_handler->GetVibrationVolume(volume); | ||
| 91 | if (result.IsError()) { | ||
| 92 | return result; | ||
| 93 | } | ||
| 94 | if (volume <= 0.0f) { | ||
| 95 | command = Core::HID::VibrationGcErmCommand::Stop; | ||
| 96 | } | ||
| 97 | if (command > Core::HID::VibrationGcErmCommand::StopHard) { | ||
| 98 | // Abort | ||
| 99 | return ResultSuccess; | ||
| 100 | } | ||
| 101 | |||
| 102 | // TODO: SendVibrationNotificationPattern | ||
| 103 | return ResultSuccess; | ||
| 104 | } | ||
| 105 | |||
| 106 | } // namespace Service::HID | ||
diff --git a/src/hid_core/resources/vibration/gc_vibration_device.h b/src/hid_core/resources/vibration/gc_vibration_device.h new file mode 100644 index 000000000..87abca57d --- /dev/null +++ b/src/hid_core/resources/vibration/gc_vibration_device.h | |||
| @@ -0,0 +1,31 @@ | |||
| 1 | // SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project | ||
| 2 | // SPDX-License-Identifier: GPL-3.0-or-later | ||
| 3 | |||
| 4 | #pragma once | ||
| 5 | |||
| 6 | #include <array> | ||
| 7 | #include <mutex> | ||
| 8 | |||
| 9 | #include "common/common_types.h" | ||
| 10 | #include "core/hle/result.h" | ||
| 11 | #include "hid_core/hid_types.h" | ||
| 12 | #include "hid_core/resources/npad/npad_types.h" | ||
| 13 | #include "hid_core/resources/vibration/vibration_base.h" | ||
| 14 | |||
| 15 | namespace Service::HID { | ||
| 16 | class NpadVibration; | ||
| 17 | |||
| 18 | /// Handles Npad request from HID interfaces | ||
| 19 | class NpadGcVibrationDevice final : public NpadVibrationBase { | ||
| 20 | public: | ||
| 21 | explicit NpadGcVibrationDevice(); | ||
| 22 | |||
| 23 | Result IncrementRefCounter() override; | ||
| 24 | Result DecrementRefCounter() override; | ||
| 25 | |||
| 26 | Result SendVibrationGcErmCommand(Core::HID::VibrationGcErmCommand command); | ||
| 27 | |||
| 28 | Result GetActualVibrationGcErmCommand(Core::HID::VibrationGcErmCommand& out_command); | ||
| 29 | Result SendVibrationNotificationPattern(Core::HID::VibrationGcErmCommand command); | ||
| 30 | }; | ||
| 31 | } // namespace Service::HID | ||
diff --git a/src/hid_core/resources/vibration/n64_vibration_device.cpp b/src/hid_core/resources/vibration/n64_vibration_device.cpp new file mode 100644 index 000000000..639f87abf --- /dev/null +++ b/src/hid_core/resources/vibration/n64_vibration_device.cpp | |||
| @@ -0,0 +1,80 @@ | |||
| 1 | // SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project | ||
| 2 | // SPDX-License-Identifier: GPL-3.0-or-later | ||
| 3 | |||
| 4 | #include "hid_core/hid_result.h" | ||
| 5 | #include "hid_core/resources/npad/npad_types.h" | ||
| 6 | #include "hid_core/resources/npad/npad_vibration.h" | ||
| 7 | #include "hid_core/resources/vibration/n64_vibration_device.h" | ||
| 8 | |||
| 9 | namespace Service::HID { | ||
| 10 | |||
| 11 | NpadN64VibrationDevice::NpadN64VibrationDevice() {} | ||
| 12 | |||
| 13 | Result NpadN64VibrationDevice::IncrementRefCounter() { | ||
| 14 | if (ref_counter == 0 && is_mounted) { | ||
| 15 | f32 volume = 1.0f; | ||
| 16 | const auto result = vibration_handler->GetVibrationVolume(volume); | ||
| 17 | if (result.IsSuccess()) { | ||
| 18 | // TODO: SendVibrationInBool | ||
| 19 | } | ||
| 20 | } | ||
| 21 | |||
| 22 | ref_counter++; | ||
| 23 | return ResultSuccess; | ||
| 24 | } | ||
| 25 | |||
| 26 | Result NpadN64VibrationDevice::DecrementRefCounter() { | ||
| 27 | if (ref_counter == 1) { | ||
| 28 | if (!is_mounted) { | ||
| 29 | ref_counter = 0; | ||
| 30 | if (is_mounted != false) { | ||
| 31 | // TODO: SendVibrationInBool | ||
| 32 | } | ||
| 33 | return ResultSuccess; | ||
| 34 | } | ||
| 35 | f32 volume = 1.0f; | ||
| 36 | const auto result = vibration_handler->GetVibrationVolume(volume); | ||
| 37 | if (result.IsSuccess()) { | ||
| 38 | // TODO | ||
| 39 | } | ||
| 40 | } | ||
| 41 | |||
| 42 | if (ref_counter > 0) { | ||
| 43 | ref_counter--; | ||
| 44 | } | ||
| 45 | |||
| 46 | return ResultSuccess; | ||
| 47 | } | ||
| 48 | |||
| 49 | Result NpadN64VibrationDevice::SendValueInBool(bool is_vibrating) { | ||
| 50 | if (ref_counter < 1) { | ||
| 51 | return ResultVibrationNotInitialized; | ||
| 52 | } | ||
| 53 | if (is_mounted) { | ||
| 54 | f32 volume = 1.0f; | ||
| 55 | const auto result = vibration_handler->GetVibrationVolume(volume); | ||
| 56 | if (result.IsError()) { | ||
| 57 | return result; | ||
| 58 | } | ||
| 59 | // TODO: SendVibrationInBool | ||
| 60 | } | ||
| 61 | return ResultSuccess; | ||
| 62 | } | ||
| 63 | |||
| 64 | Result NpadN64VibrationDevice::SendVibrationNotificationPattern([[maybe_unused]] u32 pattern) { | ||
| 65 | if (!is_mounted) { | ||
| 66 | return ResultSuccess; | ||
| 67 | } | ||
| 68 | f32 volume = 1.0f; | ||
| 69 | const auto result = vibration_handler->GetVibrationVolume(volume); | ||
| 70 | if (result.IsError()) { | ||
| 71 | return result; | ||
| 72 | } | ||
| 73 | if (volume <= 0.0) { | ||
| 74 | pattern = 0; | ||
| 75 | } | ||
| 76 | // TODO: SendVibrationNotificationPattern | ||
| 77 | return ResultSuccess; | ||
| 78 | } | ||
| 79 | |||
| 80 | } // namespace Service::HID | ||
diff --git a/src/hid_core/resources/vibration/n64_vibration_device.h b/src/hid_core/resources/vibration/n64_vibration_device.h new file mode 100644 index 000000000..54e6efc1a --- /dev/null +++ b/src/hid_core/resources/vibration/n64_vibration_device.h | |||
| @@ -0,0 +1,29 @@ | |||
| 1 | // SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project | ||
| 2 | // SPDX-License-Identifier: GPL-3.0-or-later | ||
| 3 | |||
| 4 | #pragma once | ||
| 5 | |||
| 6 | #include <array> | ||
| 7 | #include <mutex> | ||
| 8 | |||
| 9 | #include "common/common_types.h" | ||
| 10 | #include "core/hle/result.h" | ||
| 11 | #include "hid_core/hid_types.h" | ||
| 12 | #include "hid_core/resources/npad/npad_types.h" | ||
| 13 | #include "hid_core/resources/vibration/vibration_base.h" | ||
| 14 | |||
| 15 | namespace Service::HID { | ||
| 16 | class NpadVibration; | ||
| 17 | |||
| 18 | /// Handles Npad request from HID interfaces | ||
| 19 | class NpadN64VibrationDevice final : public NpadVibrationBase { | ||
| 20 | public: | ||
| 21 | explicit NpadN64VibrationDevice(); | ||
| 22 | |||
| 23 | Result IncrementRefCounter() override; | ||
| 24 | Result DecrementRefCounter() override; | ||
| 25 | |||
| 26 | Result SendValueInBool(bool is_vibrating); | ||
| 27 | Result SendVibrationNotificationPattern(u32 pattern); | ||
| 28 | }; | ||
| 29 | } // namespace Service::HID | ||
diff --git a/src/hid_core/resources/vibration/vibration_base.cpp b/src/hid_core/resources/vibration/vibration_base.cpp new file mode 100644 index 000000000..350f349c2 --- /dev/null +++ b/src/hid_core/resources/vibration/vibration_base.cpp | |||
| @@ -0,0 +1,30 @@ | |||
| 1 | // SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project | ||
| 2 | // SPDX-License-Identifier: GPL-3.0-or-later | ||
| 3 | |||
| 4 | #include "hid_core/hid_result.h" | ||
| 5 | #include "hid_core/resources/npad/npad_types.h" | ||
| 6 | #include "hid_core/resources/npad/npad_vibration.h" | ||
| 7 | #include "hid_core/resources/vibration/vibration_base.h" | ||
| 8 | |||
| 9 | namespace Service::HID { | ||
| 10 | |||
| 11 | NpadVibrationBase::NpadVibrationBase() {} | ||
| 12 | |||
| 13 | Result NpadVibrationBase::IncrementRefCounter() { | ||
| 14 | ref_counter++; | ||
| 15 | return ResultSuccess; | ||
| 16 | } | ||
| 17 | |||
| 18 | Result NpadVibrationBase::DecrementRefCounter() { | ||
| 19 | if (ref_counter > 0) { | ||
| 20 | ref_counter--; | ||
| 21 | } | ||
| 22 | |||
| 23 | return ResultSuccess; | ||
| 24 | } | ||
| 25 | |||
| 26 | bool NpadVibrationBase::IsVibrationMounted() const { | ||
| 27 | return is_mounted; | ||
| 28 | } | ||
| 29 | |||
| 30 | } // namespace Service::HID | ||
diff --git a/src/hid_core/resources/vibration/vibration_base.h b/src/hid_core/resources/vibration/vibration_base.h new file mode 100644 index 000000000..c6c5fc4d9 --- /dev/null +++ b/src/hid_core/resources/vibration/vibration_base.h | |||
| @@ -0,0 +1,28 @@ | |||
| 1 | // SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project | ||
| 2 | // SPDX-License-Identifier: GPL-3.0-or-later | ||
| 3 | |||
| 4 | #pragma once | ||
| 5 | |||
| 6 | #include "common/common_types.h" | ||
| 7 | #include "core/hle/result.h" | ||
| 8 | |||
| 9 | namespace Service::HID { | ||
| 10 | class NpadVibration; | ||
| 11 | |||
| 12 | /// Handles Npad request from HID interfaces | ||
| 13 | class NpadVibrationBase { | ||
| 14 | public: | ||
| 15 | explicit NpadVibrationBase(); | ||
| 16 | |||
| 17 | virtual Result IncrementRefCounter(); | ||
| 18 | virtual Result DecrementRefCounter(); | ||
| 19 | |||
| 20 | bool IsVibrationMounted() const; | ||
| 21 | |||
| 22 | protected: | ||
| 23 | u64 xcd_handle{}; | ||
| 24 | s32 ref_counter{}; | ||
| 25 | bool is_mounted{}; | ||
| 26 | NpadVibration* vibration_handler{nullptr}; | ||
| 27 | }; | ||
| 28 | } // namespace Service::HID | ||
diff --git a/src/hid_core/resources/vibration/vibration_device.cpp b/src/hid_core/resources/vibration/vibration_device.cpp new file mode 100644 index 000000000..888c3a7ed --- /dev/null +++ b/src/hid_core/resources/vibration/vibration_device.cpp | |||
| @@ -0,0 +1,84 @@ | |||
| 1 | // SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project | ||
| 2 | // SPDX-License-Identifier: GPL-3.0-or-later | ||
| 3 | |||
| 4 | #include "hid_core/hid_result.h" | ||
| 5 | #include "hid_core/resources/npad/npad_types.h" | ||
| 6 | #include "hid_core/resources/npad/npad_vibration.h" | ||
| 7 | #include "hid_core/resources/vibration/vibration_device.h" | ||
| 8 | |||
| 9 | namespace Service::HID { | ||
| 10 | |||
| 11 | NpadVibrationDevice::NpadVibrationDevice() {} | ||
| 12 | |||
| 13 | Result NpadVibrationDevice::IncrementRefCounter() { | ||
| 14 | ref_counter++; | ||
| 15 | return ResultSuccess; | ||
| 16 | } | ||
| 17 | |||
| 18 | Result NpadVibrationDevice::DecrementRefCounter() { | ||
| 19 | if (ref_counter > 0) { | ||
| 20 | ref_counter--; | ||
| 21 | } | ||
| 22 | |||
| 23 | return ResultSuccess; | ||
| 24 | } | ||
| 25 | |||
| 26 | Result NpadVibrationDevice::SendVibrationValue(const Core::HID::VibrationValue& value) { | ||
| 27 | if (ref_counter == 0) { | ||
| 28 | return ResultVibrationNotInitialized; | ||
| 29 | } | ||
| 30 | if (!is_mounted) { | ||
| 31 | return ResultSuccess; | ||
| 32 | } | ||
| 33 | |||
| 34 | f32 volume = 1.0f; | ||
| 35 | const auto result = vibration_handler->GetVibrationVolume(volume); | ||
| 36 | if (result.IsError()) { | ||
| 37 | return result; | ||
| 38 | } | ||
| 39 | if (volume <= 0.0f) { | ||
| 40 | // TODO: SendVibrationValue | ||
| 41 | return ResultSuccess; | ||
| 42 | } | ||
| 43 | |||
| 44 | Core::HID::VibrationValue vibration_value = value; | ||
| 45 | vibration_value.high_amplitude *= volume; | ||
| 46 | vibration_value.low_amplitude *= volume; | ||
| 47 | |||
| 48 | // TODO: SendVibrationValue | ||
| 49 | return ResultSuccess; | ||
| 50 | } | ||
| 51 | |||
| 52 | Result NpadVibrationDevice::SendVibrationNotificationPattern([[maybe_unused]] u32 pattern) { | ||
| 53 | if (!is_mounted) { | ||
| 54 | return ResultSuccess; | ||
| 55 | } | ||
| 56 | |||
| 57 | f32 volume = 1.0f; | ||
| 58 | const auto result = vibration_handler->GetVibrationVolume(volume); | ||
| 59 | if (result.IsError()) { | ||
| 60 | return result; | ||
| 61 | } | ||
| 62 | if (volume <= 0.0) { | ||
| 63 | pattern = 0; | ||
| 64 | } | ||
| 65 | |||
| 66 | // return xcd_handle->SendVibrationNotificationPattern(pattern); | ||
| 67 | return ResultSuccess; | ||
| 68 | } | ||
| 69 | |||
| 70 | Result NpadVibrationDevice::GetActualVibrationValue(Core::HID::VibrationValue& out_value) { | ||
| 71 | if (ref_counter < 1) { | ||
| 72 | return ResultVibrationNotInitialized; | ||
| 73 | } | ||
| 74 | |||
| 75 | out_value = Core::HID::DEFAULT_VIBRATION_VALUE; | ||
| 76 | if (!is_mounted) { | ||
| 77 | return ResultSuccess; | ||
| 78 | } | ||
| 79 | |||
| 80 | // TODO: SendVibrationValue | ||
| 81 | return ResultSuccess; | ||
| 82 | } | ||
| 83 | |||
| 84 | } // namespace Service::HID | ||
diff --git a/src/hid_core/resources/vibration/vibration_device.h b/src/hid_core/resources/vibration/vibration_device.h new file mode 100644 index 000000000..3574ad60b --- /dev/null +++ b/src/hid_core/resources/vibration/vibration_device.h | |||
| @@ -0,0 +1,35 @@ | |||
| 1 | // SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project | ||
| 2 | // SPDX-License-Identifier: GPL-3.0-or-later | ||
| 3 | |||
| 4 | #pragma once | ||
| 5 | |||
| 6 | #include <array> | ||
| 7 | #include <mutex> | ||
| 8 | |||
| 9 | #include "common/common_types.h" | ||
| 10 | #include "core/hle/result.h" | ||
| 11 | #include "hid_core/hid_types.h" | ||
| 12 | #include "hid_core/resources/npad/npad_types.h" | ||
| 13 | #include "hid_core/resources/vibration/vibration_base.h" | ||
| 14 | |||
| 15 | namespace Service::HID { | ||
| 16 | class NpadVibration; | ||
| 17 | |||
| 18 | /// Handles Npad request from HID interfaces | ||
| 19 | class NpadVibrationDevice final : public NpadVibrationBase { | ||
| 20 | public: | ||
| 21 | explicit NpadVibrationDevice(); | ||
| 22 | |||
| 23 | Result IncrementRefCounter(); | ||
| 24 | Result DecrementRefCounter(); | ||
| 25 | |||
| 26 | Result SendVibrationValue(const Core::HID::VibrationValue& value); | ||
| 27 | Result SendVibrationNotificationPattern(u32 pattern); | ||
| 28 | |||
| 29 | Result GetActualVibrationValue(Core::HID::VibrationValue& out_value); | ||
| 30 | |||
| 31 | private: | ||
| 32 | u32 device_index{}; | ||
| 33 | }; | ||
| 34 | |||
| 35 | } // namespace Service::HID | ||