diff options
author | german77 <juangerman-13@hotmail.com> | 2022-12-23 15:32:02 +0100 |
---|---|---|
committer | Narr the Reg <juangerman-13@hotmail.com> | 2023-01-20 01:05:22 +0100 |
commit | e1a3bda4d9881cb99c36b64733b814a3bb437f13 (patch) | |
tree | a9c0d864b023a810f48c129bb8bd6e84afb2ed2b /src/input_common/helpers/joycon_protocol | |
parent | core: hid: Fix input regressions (diff) | |
download | yuzu-e1a3bda4d9881cb99c36b64733b814a3bb437f13.tar yuzu-e1a3bda4d9881cb99c36b64733b814a3bb437f13.tar.gz yuzu-e1a3bda4d9881cb99c36b64733b814a3bb437f13.tar.bz2 yuzu-e1a3bda4d9881cb99c36b64733b814a3bb437f13.tar.lz yuzu-e1a3bda4d9881cb99c36b64733b814a3bb437f13.tar.xz yuzu-e1a3bda4d9881cb99c36b64733b814a3bb437f13.tar.zst yuzu-e1a3bda4d9881cb99c36b64733b814a3bb437f13.zip |
Diffstat (limited to 'src/input_common/helpers/joycon_protocol')
11 files changed, 40 insertions, 40 deletions
diff --git a/src/input_common/helpers/joycon_protocol/calibration.cpp b/src/input_common/helpers/joycon_protocol/calibration.cpp index ce1ff7061..cd30ab869 100644 --- a/src/input_common/helpers/joycon_protocol/calibration.cpp +++ b/src/input_common/helpers/joycon_protocol/calibration.cpp @@ -9,7 +9,7 @@ namespace InputCommon::Joycon { CalibrationProtocol::CalibrationProtocol(std::shared_ptr<JoyconHandle> handle) - : JoyconCommonProtocol(handle) {} + : JoyconCommonProtocol(std::move(handle)) {} DriverResult CalibrationProtocol::GetLeftJoyStickCalibration(JoyStickCalibration& calibration) { std::vector<u8> buffer; @@ -136,12 +136,8 @@ DriverResult CalibrationProtocol::GetRingCalibration(RingCalibration& calibratio ring_data_min = current_value - 800; ring_data_default = current_value; } - if (ring_data_max < current_value) { - ring_data_max = current_value; - } - if (ring_data_min > current_value) { - ring_data_min = current_value; - } + ring_data_max = std::max(ring_data_max, current_value); + ring_data_min = std::min(ring_data_min, current_value); calibration = { .default_value = ring_data_default, .max_value = ring_data_max, diff --git a/src/input_common/helpers/joycon_protocol/calibration.h b/src/input_common/helpers/joycon_protocol/calibration.h index 32ddef4b8..afb52a36a 100644 --- a/src/input_common/helpers/joycon_protocol/calibration.h +++ b/src/input_common/helpers/joycon_protocol/calibration.h @@ -24,7 +24,7 @@ namespace InputCommon::Joycon { /// Driver functions related to retrieving calibration data from the device class CalibrationProtocol final : private JoyconCommonProtocol { public: - CalibrationProtocol(std::shared_ptr<JoyconHandle> handle); + explicit CalibrationProtocol(std::shared_ptr<JoyconHandle> handle); /** * Sends a request to obtain the left stick calibration from memory diff --git a/src/input_common/helpers/joycon_protocol/common_protocol.cpp b/src/input_common/helpers/joycon_protocol/common_protocol.cpp index 43a036e02..a4d08fdaf 100644 --- a/src/input_common/helpers/joycon_protocol/common_protocol.cpp +++ b/src/input_common/helpers/joycon_protocol/common_protocol.cpp @@ -6,7 +6,7 @@ namespace InputCommon::Joycon { JoyconCommonProtocol::JoyconCommonProtocol(std::shared_ptr<JoyconHandle> hidapi_handle_) - : hidapi_handle{hidapi_handle_} {} + : hidapi_handle{std::move(hidapi_handle_)} {} u8 JoyconCommonProtocol::GetCounter() { hidapi_handle->packet_counter = (hidapi_handle->packet_counter + 1) & 0x0F; @@ -256,7 +256,7 @@ DriverResult JoyconCommonProtocol::WaitSetMCUMode(ReportMode report_mode, MCUMod } // crc-8-ccitt / polynomial 0x07 look up table -static constexpr uint8_t mcu_crc8_table[256] = { +constexpr std::array<u8, 256> mcu_crc8_table = { 0x00, 0x07, 0x0E, 0x09, 0x1C, 0x1B, 0x12, 0x15, 0x38, 0x3F, 0x36, 0x31, 0x24, 0x23, 0x2A, 0x2D, 0x70, 0x77, 0x7E, 0x79, 0x6C, 0x6B, 0x62, 0x65, 0x48, 0x4F, 0x46, 0x41, 0x54, 0x53, 0x5A, 0x5D, 0xE0, 0xE7, 0xEE, 0xE9, 0xFC, 0xFB, 0xF2, 0xF5, 0xD8, 0xDF, 0xD6, 0xD1, 0xC4, 0xC3, 0xCA, 0xCD, @@ -278,7 +278,7 @@ u8 JoyconCommonProtocol::CalculateMCU_CRC8(u8* buffer, u8 size) const { u8 crc8 = 0x0; for (int i = 0; i < size; ++i) { - crc8 = mcu_crc8_table[(u8)(crc8 ^ buffer[i])]; + crc8 = mcu_crc8_table[static_cast<u8>(crc8 ^ buffer[i])]; } return crc8; } diff --git a/src/input_common/helpers/joycon_protocol/generic_functions.cpp b/src/input_common/helpers/joycon_protocol/generic_functions.cpp index 829f7625d..cbd9ff4f8 100644 --- a/src/input_common/helpers/joycon_protocol/generic_functions.cpp +++ b/src/input_common/helpers/joycon_protocol/generic_functions.cpp @@ -7,7 +7,7 @@ namespace InputCommon::Joycon { GenericProtocol::GenericProtocol(std::shared_ptr<JoyconHandle> handle) - : JoyconCommonProtocol(handle) {} + : JoyconCommonProtocol(std::move(handle)) {} DriverResult GenericProtocol::EnablePassiveMode() { SetBlocking(); @@ -43,7 +43,7 @@ DriverResult GenericProtocol::GetControllerType(ControllerType& controller_type) } DriverResult GenericProtocol::EnableImu(bool enable) { - const std::vector<u8> buffer{static_cast<u8>(enable ? 1 : 0)}; + const std::array<u8, 1> buffer{static_cast<u8>(enable ? 1 : 0)}; std::vector<u8> output; SetBlocking(); const auto result = SendSubCommand(SubCommand::ENABLE_IMU, buffer, output); @@ -54,8 +54,8 @@ DriverResult GenericProtocol::EnableImu(bool enable) { DriverResult GenericProtocol::SetImuConfig(GyroSensitivity gsen, GyroPerformance gfrec, AccelerometerSensitivity asen, AccelerometerPerformance afrec) { - const std::vector<u8> buffer{static_cast<u8>(gsen), static_cast<u8>(asen), - static_cast<u8>(gfrec), static_cast<u8>(afrec)}; + const std::array<u8, 4> buffer{static_cast<u8>(gsen), static_cast<u8>(asen), + static_cast<u8>(gfrec), static_cast<u8>(afrec)}; std::vector<u8> output; SetBlocking(); const auto result = SendSubCommand(SubCommand::SET_IMU_SENSITIVITY, buffer, output); @@ -115,7 +115,7 @@ DriverResult GenericProtocol::GetVersionNumber(FirmwareVersion& version) { } DriverResult GenericProtocol::SetHomeLight() { - const std::vector<u8> buffer{0x0f, 0xf0, 0x00}; + static constexpr std::array<u8, 3> buffer{0x0f, 0xf0, 0x00}; std::vector<u8> output; SetBlocking(); @@ -130,7 +130,7 @@ DriverResult GenericProtocol::SetLedBusy() { } DriverResult GenericProtocol::SetLedPattern(u8 leds) { - const std::vector<u8> buffer{leds}; + const std::array<u8, 1> buffer{leds}; std::vector<u8> output; SetBlocking(); diff --git a/src/input_common/helpers/joycon_protocol/generic_functions.h b/src/input_common/helpers/joycon_protocol/generic_functions.h index c3e2ccadc..239bb7dbf 100644 --- a/src/input_common/helpers/joycon_protocol/generic_functions.h +++ b/src/input_common/helpers/joycon_protocol/generic_functions.h @@ -16,7 +16,7 @@ namespace InputCommon::Joycon { /// Joycon driver functions that easily implemented class GenericProtocol final : private JoyconCommonProtocol { public: - GenericProtocol(std::shared_ptr<JoyconHandle> handle); + explicit GenericProtocol(std::shared_ptr<JoyconHandle> handle); /// Enables passive mode. This mode only sends button data on change. Sticks will return digital /// data instead of analog. Motion will be disabled diff --git a/src/input_common/helpers/joycon_protocol/nfc.cpp b/src/input_common/helpers/joycon_protocol/nfc.cpp index 69b2bfe05..8755e310b 100644 --- a/src/input_common/helpers/joycon_protocol/nfc.cpp +++ b/src/input_common/helpers/joycon_protocol/nfc.cpp @@ -7,7 +7,8 @@ namespace InputCommon::Joycon { -NfcProtocol::NfcProtocol(std::shared_ptr<JoyconHandle> handle) : JoyconCommonProtocol(handle) {} +NfcProtocol::NfcProtocol(std::shared_ptr<JoyconHandle> handle) + : JoyconCommonProtocol(std::move(handle)) {} DriverResult NfcProtocol::EnableNfc() { LOG_INFO(Input, "Enable NFC"); @@ -160,9 +161,9 @@ DriverResult NfcProtocol::ReadTag(const TagFoundData& data) { std::vector<u8> output; std::size_t tries = 0; - std::string uuid_string = ""; + std::string uuid_string; for (auto& content : data.uuid) { - uuid_string += " " + fmt::format("{:02x}", content); + uuid_string += fmt::format(" {:02x}", content); } LOG_INFO(Input, "Tag detected, type={}, uuid={}", data.type, uuid_string); @@ -407,7 +408,7 @@ NFCReadBlockCommand NfcProtocol::GetReadBlockCommand(std::size_t pages) const { return {}; } -bool NfcProtocol::IsEnabled() { +bool NfcProtocol::IsEnabled() const { return is_enabled; } diff --git a/src/input_common/helpers/joycon_protocol/nfc.h b/src/input_common/helpers/joycon_protocol/nfc.h index 0ede03d50..5cb0e5a65 100644 --- a/src/input_common/helpers/joycon_protocol/nfc.h +++ b/src/input_common/helpers/joycon_protocol/nfc.h @@ -17,7 +17,7 @@ namespace InputCommon::Joycon { class NfcProtocol final : private JoyconCommonProtocol { public: - NfcProtocol(std::shared_ptr<JoyconHandle> handle); + explicit NfcProtocol(std::shared_ptr<JoyconHandle> handle); DriverResult EnableNfc(); @@ -29,7 +29,7 @@ public: bool HasAmiibo(); - bool IsEnabled(); + bool IsEnabled() const; private: struct TagFoundData { diff --git a/src/input_common/helpers/joycon_protocol/ringcon.cpp b/src/input_common/helpers/joycon_protocol/ringcon.cpp index 47769f344..8adad57dd 100644 --- a/src/input_common/helpers/joycon_protocol/ringcon.cpp +++ b/src/input_common/helpers/joycon_protocol/ringcon.cpp @@ -7,7 +7,7 @@ namespace InputCommon::Joycon { RingConProtocol::RingConProtocol(std::shared_ptr<JoyconHandle> handle) - : JoyconCommonProtocol(handle) {} + : JoyconCommonProtocol(std::move(handle)) {} DriverResult RingConProtocol::EnableRingCon() { LOG_DEBUG(Input, "Enable Ringcon"); @@ -78,7 +78,7 @@ DriverResult RingConProtocol::IsRingConnected(bool& is_connected) { is_connected = false; do { - std::vector<u8> empty_data(0); + std::array<u8, 1> empty_data{}; const auto result = SendSubCommand(SubCommand::UNKNOWN_RINGCON, empty_data, output); if (result != DriverResult::Success) { @@ -101,11 +101,11 @@ DriverResult RingConProtocol::ConfigureRing() { std::vector<u8> output; std::size_t tries = 0; + static constexpr std::array<u8, 37> ring_config{ + 0x06, 0x03, 0x25, 0x06, 0x00, 0x00, 0x00, 0x00, 0x1C, 0x16, 0xED, 0x34, 0x36, + 0x00, 0x00, 0x00, 0x0A, 0x64, 0x0B, 0xE6, 0xA9, 0x22, 0x00, 0x00, 0x04, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x90, 0xA8, 0xE1, 0x34, 0x36}; do { - std::vector<u8> ring_config{0x06, 0x03, 0x25, 0x06, 0x00, 0x00, 0x00, 0x00, 0x1C, 0x16, - 0xED, 0x34, 0x36, 0x00, 0x00, 0x00, 0x0A, 0x64, 0x0B, 0xE6, - 0xA9, 0x22, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x90, 0xA8, 0xE1, 0x34, 0x36}; result = SendSubCommand(SubCommand::UNKNOWN_RINGCON3, ring_config, output); if (result != DriverResult::Success) { @@ -116,13 +116,13 @@ DriverResult RingConProtocol::ConfigureRing() { } } while (output[14] != 0x5C); - std::vector<u8> ringcon_data{0x04, 0x01, 0x01, 0x02}; + static constexpr std::array<u8, 4> ringcon_data{0x04, 0x01, 0x01, 0x02}; result = SendSubCommand(SubCommand::UNKNOWN_RINGCON2, ringcon_data, output); return result; } -bool RingConProtocol::IsEnabled() { +bool RingConProtocol::IsEnabled() const { return is_enabled; } diff --git a/src/input_common/helpers/joycon_protocol/ringcon.h b/src/input_common/helpers/joycon_protocol/ringcon.h index 0c25de23e..6e858f3fc 100644 --- a/src/input_common/helpers/joycon_protocol/ringcon.h +++ b/src/input_common/helpers/joycon_protocol/ringcon.h @@ -17,7 +17,7 @@ namespace InputCommon::Joycon { class RingConProtocol final : private JoyconCommonProtocol { public: - RingConProtocol(std::shared_ptr<JoyconHandle> handle); + explicit RingConProtocol(std::shared_ptr<JoyconHandle> handle); DriverResult EnableRingCon(); @@ -25,7 +25,7 @@ public: DriverResult StartRingconPolling(); - bool IsEnabled(); + bool IsEnabled() const; private: DriverResult IsRingConnected(bool& is_connected); 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 @@ // SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later +#include <algorithm> +#include <cmath> + #include "common/logging/log.h" #include "input_common/helpers/joycon_protocol/rumble.h" namespace InputCommon::Joycon { RumbleProtocol::RumbleProtocol(std::shared_ptr<JoyconHandle> handle) - : JoyconCommonProtocol(handle) {} + : JoyconCommonProtocol(std::move(handle)) {} DriverResult RumbleProtocol::EnableRumble(bool is_enabled) { LOG_DEBUG(Input, "Enable Rumble"); - const std::vector<u8> buffer{static_cast<u8>(is_enabled ? 1 : 0)}; + const std::array<u8, 1> buffer{static_cast<u8>(is_enabled ? 1 : 0)}; std::vector<u8> output; SetBlocking(); const auto result = SendSubCommand(SubCommand::ENABLE_VIBRATION, buffer, output); @@ -20,7 +23,7 @@ DriverResult RumbleProtocol::EnableRumble(bool is_enabled) { } DriverResult RumbleProtocol::SendVibration(const VibrationValue& vibration) { - std::vector<u8> buffer(sizeof(DefaultVibrationBuffer)); + std::array<u8, sizeof(DefaultVibrationBuffer)> buffer{}; if (vibration.high_amplitude <= 0.0f && vibration.low_amplitude <= 0.0f) { return SendVibrationReport(DefaultVibrationBuffer); @@ -66,7 +69,7 @@ u8 RumbleProtocol::EncodeHighAmplitude(f32 amplitude) const { /* More information about these values can be found here: * https://github.com/dekuNukem/Nintendo_Switch_Reverse_Engineering/blob/master/rumble_data_table.md */ - constexpr std::array<std::pair<f32, int>, 101> high_fequency_amplitude{ + static constexpr std::array<std::pair<f32, int>, 101> high_fequency_amplitude{ std::pair<f32, int>{0.0f, 0x0}, {0.01f, 0x2}, {0.012f, 0x4}, @@ -183,7 +186,7 @@ u16 RumbleProtocol::EncodeLowAmplitude(f32 amplitude) const { /* More information about these values can be found here: * https://github.com/dekuNukem/Nintendo_Switch_Reverse_Engineering/blob/master/rumble_data_table.md */ - constexpr std::array<std::pair<f32, int>, 101> high_fequency_amplitude{ + static constexpr std::array<std::pair<f32, int>, 101> high_fequency_amplitude{ std::pair<f32, int>{0.0f, 0x0040}, {0.01f, 0x8040}, {0.012f, 0x0041}, diff --git a/src/input_common/helpers/joycon_protocol/rumble.h b/src/input_common/helpers/joycon_protocol/rumble.h index 7d0329f03..6c12b7925 100644 --- a/src/input_common/helpers/joycon_protocol/rumble.h +++ b/src/input_common/helpers/joycon_protocol/rumble.h @@ -17,7 +17,7 @@ namespace InputCommon::Joycon { class RumbleProtocol final : private JoyconCommonProtocol { public: - RumbleProtocol(std::shared_ptr<JoyconHandle> handle); + explicit RumbleProtocol(std::shared_ptr<JoyconHandle> handle); DriverResult EnableRumble(bool is_enabled); |