summaryrefslogtreecommitdiffstats
path: root/src/hid_core/resources/vibration/gc_vibration_device.cpp
blob: f01f81b9a3d6e91f8c0178051564cd11e2353a58 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
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