diff options
author | Narr the Reg <juangerman-13@hotmail.com> | 2024-02-22 18:58:52 +0100 |
---|---|---|
committer | Narr the Reg <juangerman-13@hotmail.com> | 2024-02-24 00:49:02 +0100 |
commit | d08f201e0c0e6d36176983f9673a89550705952b (patch) | |
tree | 93229a986e75f1962d0665dd05a8d2813a8c9ce7 /src/core/hle/service/hid/active_vibration_device_list.cpp | |
parent | Merge pull request #13141 from liamwhite/swap (diff) | |
download | yuzu-d08f201e0c0e6d36176983f9673a89550705952b.tar yuzu-d08f201e0c0e6d36176983f9673a89550705952b.tar.gz yuzu-d08f201e0c0e6d36176983f9673a89550705952b.tar.bz2 yuzu-d08f201e0c0e6d36176983f9673a89550705952b.tar.lz yuzu-d08f201e0c0e6d36176983f9673a89550705952b.tar.xz yuzu-d08f201e0c0e6d36176983f9673a89550705952b.tar.zst yuzu-d08f201e0c0e6d36176983f9673a89550705952b.zip |
Diffstat (limited to '')
-rw-r--r-- | src/core/hle/service/hid/active_vibration_device_list.cpp | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/src/core/hle/service/hid/active_vibration_device_list.cpp b/src/core/hle/service/hid/active_vibration_device_list.cpp new file mode 100644 index 000000000..c440f8382 --- /dev/null +++ b/src/core/hle/service/hid/active_vibration_device_list.cpp @@ -0,0 +1,53 @@ +// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project +// SPDX-License-Identifier: GPL-3.0-or-later + +#include "common/logging/log.h" +#include "core/hle/service/cmif_serialization.h" +#include "core/hle/service/hid/active_vibration_device_list.h" +#include "hid_core/hid_result.h" +#include "hid_core/hid_util.h" +#include "hid_core/resource_manager.h" +#include "hid_core/resources/vibration/vibration_device.h" + +namespace Service::HID { + +IActiveVibrationDeviceList::IActiveVibrationDeviceList(Core::System& system_, + std::shared_ptr<ResourceManager> resource) + : ServiceFramework{system_, "IActiveVibrationDeviceList"}, resource_manager(resource) { + // clang-format off + static const FunctionInfo functions[] = { + {0, C<&IActiveVibrationDeviceList::ActivateVibrationDevice>, "ActivateVibrationDevice"}, + }; + // clang-format on + + RegisterHandlers(functions); +} + +IActiveVibrationDeviceList::~IActiveVibrationDeviceList() = default; + +Result IActiveVibrationDeviceList::ActivateVibrationDevice( + Core::HID::VibrationDeviceHandle vibration_device_handle) { + LOG_DEBUG(Service_HID, "called, npad_type={}, npad_id={}, device_index={}", + vibration_device_handle.npad_type, vibration_device_handle.npad_id, + vibration_device_handle.device_index); + + std::scoped_lock lock{mutex}; + + R_TRY(IsVibrationHandleValid(vibration_device_handle)); + + for (std::size_t i = 0; i < list_size; i++) { + if (vibration_device_handle.device_index == vibration_device_list[i].device_index && + vibration_device_handle.npad_id == vibration_device_list[i].npad_id && + vibration_device_handle.npad_type == vibration_device_list[i].npad_type) { + R_SUCCEED(); + } + } + + R_UNLESS(list_size < MaxVibrationDevicesHandles, ResultVibrationDeviceIndexOutOfRange); + R_TRY(resource_manager->GetVibrationDevice(vibration_device_handle)->Activate()); + + vibration_device_list[list_size++] = vibration_device_handle; + R_SUCCEED(); +} + +} // namespace Service::HID |