summaryrefslogtreecommitdiffstats
path: root/src/hid_core/resources/vibration/gc_vibration_device.cpp
diff options
context:
space:
mode:
authorgerman77 <juangerman-13@hotmail.com>2024-01-07 16:05:12 +0100
committerNarr the Reg <juangerman-13@hotmail.com>2024-01-12 02:35:04 +0100
commitb5dac5f525e8d5884506ebd98a530e237b518480 (patch)
tree6ceee925ba897dc3450bdad209982f0be4bc3f7a /src/hid_core/resources/vibration/gc_vibration_device.cpp
parentMerge pull request #12653 from liamwhite/once-more (diff)
downloadyuzu-b5dac5f525e8d5884506ebd98a530e237b518480.tar
yuzu-b5dac5f525e8d5884506ebd98a530e237b518480.tar.gz
yuzu-b5dac5f525e8d5884506ebd98a530e237b518480.tar.bz2
yuzu-b5dac5f525e8d5884506ebd98a530e237b518480.tar.lz
yuzu-b5dac5f525e8d5884506ebd98a530e237b518480.tar.xz
yuzu-b5dac5f525e8d5884506ebd98a530e237b518480.tar.zst
yuzu-b5dac5f525e8d5884506ebd98a530e237b518480.zip
Diffstat (limited to 'src/hid_core/resources/vibration/gc_vibration_device.cpp')
-rw-r--r--src/hid_core/resources/vibration/gc_vibration_device.cpp106
1 files changed, 106 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 @@
+// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
+// SPDX-License-Identifier: GPL-3.0-or-later
+
+#include "hid_core/hid_result.h"
+#include "hid_core/resources/npad/npad_types.h"
+#include "hid_core/resources/npad/npad_vibration.h"
+#include "hid_core/resources/vibration/gc_vibration_device.h"
+
+namespace Service::HID {
+
+NpadGcVibrationDevice::NpadGcVibrationDevice() {}
+
+Result NpadGcVibrationDevice::IncrementRefCounter() {
+ if (ref_counter == 0 && is_mounted) {
+ f32 volume = 1.0f;
+ const auto result = vibration_handler->GetVibrationVolume(volume);
+ if (result.IsSuccess()) {
+ // TODO: SendVibrationGcErmCommand
+ }
+ }
+ ref_counter++;
+ return ResultSuccess;
+}
+
+Result NpadGcVibrationDevice::DecrementRefCounter() {
+ if (ref_counter == 1 && !is_mounted) {
+ f32 volume = 1.0f;
+ const auto result = vibration_handler->GetVibrationVolume(volume);
+ if (result.IsSuccess()) {
+ // TODO: SendVibrationGcErmCommand
+ }
+ }
+
+ if (ref_counter > 0) {
+ ref_counter--;
+ }
+
+ return ResultSuccess;
+}
+
+Result NpadGcVibrationDevice::SendVibrationGcErmCommand(Core::HID::VibrationGcErmCommand command) {
+ if (!is_mounted) {
+ return ResultSuccess;
+ }
+ f32 volume = 1.0f;
+ const auto result = vibration_handler->GetVibrationVolume(volume);
+ if (result.IsError()) {
+ return result;
+ }
+ if (volume == 0.0) {
+ command = Core::HID::VibrationGcErmCommand::Stop;
+ } else {
+ if (command > Core::HID::VibrationGcErmCommand::StopHard) {
+ // Abort
+ return ResultSuccess;
+ }
+ }
+ // TODO: SendVibrationGcErmCommand
+ return ResultSuccess;
+}
+
+Result NpadGcVibrationDevice::GetActualVibrationGcErmCommand(
+ Core::HID::VibrationGcErmCommand& out_command) {
+ if (!is_mounted) {
+ out_command = Core::HID::VibrationGcErmCommand::Stop;
+ return ResultSuccess;
+ }
+
+ f32 volume = 1.0f;
+ const auto result = vibration_handler->GetVibrationVolume(volume);
+ if (result.IsError()) {
+ return result;
+ }
+ if (volume == 0.0f) {
+ out_command = Core::HID::VibrationGcErmCommand::Stop;
+ return ResultSuccess;
+ }
+
+ // TODO: GetActualVibrationGcErmCommand
+ return ResultSuccess;
+}
+
+Result NpadGcVibrationDevice::SendVibrationNotificationPattern(
+ Core::HID::VibrationGcErmCommand command) {
+ if (!is_mounted) {
+ return ResultSuccess;
+ }
+
+ f32 volume = 1.0f;
+ const auto result = vibration_handler->GetVibrationVolume(volume);
+ if (result.IsError()) {
+ return result;
+ }
+ if (volume <= 0.0f) {
+ command = Core::HID::VibrationGcErmCommand::Stop;
+ }
+ if (command > Core::HID::VibrationGcErmCommand::StopHard) {
+ // Abort
+ return ResultSuccess;
+ }
+
+ // TODO: SendVibrationNotificationPattern
+ return ResultSuccess;
+}
+
+} // namespace Service::HID