diff options
| author | 2022-12-23 08:32:02 -0600 | |
|---|---|---|
| committer | 2023-01-19 18:05:22 -0600 | |
| commit | e1a3bda4d9881cb99c36b64733b814a3bb437f13 (patch) | |
| tree | a9c0d864b023a810f48c129bb8bd6e84afb2ed2b /src/input_common/helpers/joycon_protocol/rumble.cpp | |
| parent | core: hid: Fix input regressions (diff) | |
| download | yuzu-e1a3bda4d9881cb99c36b64733b814a3bb437f13.tar.gz yuzu-e1a3bda4d9881cb99c36b64733b814a3bb437f13.tar.xz yuzu-e1a3bda4d9881cb99c36b64733b814a3bb437f13.zip | |
Address review comments
Diffstat (limited to 'src/input_common/helpers/joycon_protocol/rumble.cpp')
| -rw-r--r-- | src/input_common/helpers/joycon_protocol/rumble.cpp | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/src/input_common/helpers/joycon_protocol/rumble.cpp b/src/input_common/helpers/joycon_protocol/rumble.cpp index 17ee38863..fad67a94b 100644 --- a/src/input_common/helpers/joycon_protocol/rumble.cpp +++ b/src/input_common/helpers/joycon_protocol/rumble.cpp | |||
| @@ -1,17 +1,20 @@ | |||
| 1 | // SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project | 1 | // SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project |
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later | 2 | // SPDX-License-Identifier: GPL-2.0-or-later |
| 3 | 3 | ||
| 4 | #include <algorithm> | ||
| 5 | #include <cmath> | ||
| 6 | |||
| 4 | #include "common/logging/log.h" | 7 | #include "common/logging/log.h" |
| 5 | #include "input_common/helpers/joycon_protocol/rumble.h" | 8 | #include "input_common/helpers/joycon_protocol/rumble.h" |
| 6 | 9 | ||
| 7 | namespace InputCommon::Joycon { | 10 | namespace InputCommon::Joycon { |
| 8 | 11 | ||
| 9 | RumbleProtocol::RumbleProtocol(std::shared_ptr<JoyconHandle> handle) | 12 | RumbleProtocol::RumbleProtocol(std::shared_ptr<JoyconHandle> handle) |
| 10 | : JoyconCommonProtocol(handle) {} | 13 | : JoyconCommonProtocol(std::move(handle)) {} |
| 11 | 14 | ||
| 12 | DriverResult RumbleProtocol::EnableRumble(bool is_enabled) { | 15 | DriverResult RumbleProtocol::EnableRumble(bool is_enabled) { |
| 13 | LOG_DEBUG(Input, "Enable Rumble"); | 16 | LOG_DEBUG(Input, "Enable Rumble"); |
| 14 | const std::vector<u8> buffer{static_cast<u8>(is_enabled ? 1 : 0)}; | 17 | const std::array<u8, 1> buffer{static_cast<u8>(is_enabled ? 1 : 0)}; |
| 15 | std::vector<u8> output; | 18 | std::vector<u8> output; |
| 16 | SetBlocking(); | 19 | SetBlocking(); |
| 17 | const auto result = SendSubCommand(SubCommand::ENABLE_VIBRATION, buffer, output); | 20 | const auto result = SendSubCommand(SubCommand::ENABLE_VIBRATION, buffer, output); |
| @@ -20,7 +23,7 @@ DriverResult RumbleProtocol::EnableRumble(bool is_enabled) { | |||
| 20 | } | 23 | } |
| 21 | 24 | ||
| 22 | DriverResult RumbleProtocol::SendVibration(const VibrationValue& vibration) { | 25 | DriverResult RumbleProtocol::SendVibration(const VibrationValue& vibration) { |
| 23 | std::vector<u8> buffer(sizeof(DefaultVibrationBuffer)); | 26 | std::array<u8, sizeof(DefaultVibrationBuffer)> buffer{}; |
| 24 | 27 | ||
| 25 | if (vibration.high_amplitude <= 0.0f && vibration.low_amplitude <= 0.0f) { | 28 | if (vibration.high_amplitude <= 0.0f && vibration.low_amplitude <= 0.0f) { |
| 26 | return SendVibrationReport(DefaultVibrationBuffer); | 29 | return SendVibrationReport(DefaultVibrationBuffer); |
| @@ -66,7 +69,7 @@ u8 RumbleProtocol::EncodeHighAmplitude(f32 amplitude) const { | |||
| 66 | /* More information about these values can be found here: | 69 | /* More information about these values can be found here: |
| 67 | * https://github.com/dekuNukem/Nintendo_Switch_Reverse_Engineering/blob/master/rumble_data_table.md | 70 | * https://github.com/dekuNukem/Nintendo_Switch_Reverse_Engineering/blob/master/rumble_data_table.md |
| 68 | */ | 71 | */ |
| 69 | constexpr std::array<std::pair<f32, int>, 101> high_fequency_amplitude{ | 72 | static constexpr std::array<std::pair<f32, int>, 101> high_fequency_amplitude{ |
| 70 | std::pair<f32, int>{0.0f, 0x0}, | 73 | std::pair<f32, int>{0.0f, 0x0}, |
| 71 | {0.01f, 0x2}, | 74 | {0.01f, 0x2}, |
| 72 | {0.012f, 0x4}, | 75 | {0.012f, 0x4}, |
| @@ -183,7 +186,7 @@ u16 RumbleProtocol::EncodeLowAmplitude(f32 amplitude) const { | |||
| 183 | /* More information about these values can be found here: | 186 | /* More information about these values can be found here: |
| 184 | * https://github.com/dekuNukem/Nintendo_Switch_Reverse_Engineering/blob/master/rumble_data_table.md | 187 | * https://github.com/dekuNukem/Nintendo_Switch_Reverse_Engineering/blob/master/rumble_data_table.md |
| 185 | */ | 188 | */ |
| 186 | constexpr std::array<std::pair<f32, int>, 101> high_fequency_amplitude{ | 189 | static constexpr std::array<std::pair<f32, int>, 101> high_fequency_amplitude{ |
| 187 | std::pair<f32, int>{0.0f, 0x0040}, | 190 | std::pair<f32, int>{0.0f, 0x0040}, |
| 188 | {0.01f, 0x8040}, | 191 | {0.01f, 0x8040}, |
| 189 | {0.012f, 0x0041}, | 192 | {0.012f, 0x0041}, |