From c3ecf599ad779361a44d2dd6b6823a8c1a6f93da Mon Sep 17 00:00:00 2001 From: kalaposfos13 <153381648+kalaposfos13@users.noreply.github.com> Date: Tue, 7 Jan 2025 10:50:54 +0100 Subject: [PATCH] Add motion controls toggle (#2029) * Add motion controls toggle * clang --- src/common/config.cpp | 11 +++++++++++ src/common/config.h | 4 +++- src/input/controller.cpp | 31 +++++++++++++++---------------- src/qt_gui/settings_dialog.cpp | 3 +++ src/qt_gui/settings_dialog.ui | 7 +++++++ 5 files changed, 39 insertions(+), 17 deletions(-) diff --git a/src/common/config.cpp b/src/common/config.cpp index 9e2cc002..1838f35f 100644 --- a/src/common/config.cpp +++ b/src/common/config.cpp @@ -47,6 +47,7 @@ static std::string updateChannel; static std::string backButtonBehavior = "left"; static bool useSpecialPad = false; static int specialPadClass = 1; +static bool isMotionControlsEnabled = true; static bool isDebugDump = false; static bool isShaderDebug = false; static bool isShowSplash = false; @@ -172,6 +173,10 @@ int getSpecialPadClass() { return specialPadClass; } +bool getIsMotionControlsEnabled() { + return isMotionControlsEnabled; +} + bool debugDump() { return isDebugDump; } @@ -368,6 +373,10 @@ void setSpecialPadClass(int type) { specialPadClass = type; } +void setIsMotionControlsEnabled(bool use) { + isMotionControlsEnabled = use; +} + void setSeparateUpdateEnabled(bool use) { separateupdatefolder = use; } @@ -594,6 +603,7 @@ void load(const std::filesystem::path& path) { backButtonBehavior = toml::find_or(input, "backButtonBehavior", "left"); useSpecialPad = toml::find_or(input, "useSpecialPad", false); specialPadClass = toml::find_or(input, "specialPadClass", 1); + isMotionControlsEnabled = toml::find_or(input, "isMotionControlsEnabled", true); } if (data.contains("GPU")) { @@ -709,6 +719,7 @@ void save(const std::filesystem::path& path) { data["Input"]["backButtonBehavior"] = backButtonBehavior; data["Input"]["useSpecialPad"] = useSpecialPad; data["Input"]["specialPadClass"] = specialPadClass; + data["Input"]["isMotionControlsEnabled"] = isMotionControlsEnabled; data["GPU"]["screenWidth"] = screenWidth; data["GPU"]["screenHeight"] = screenHeight; data["GPU"]["nullGpu"] = isNullGpu; diff --git a/src/common/config.h b/src/common/config.h index 2b9a3544..d2860bec 100644 --- a/src/common/config.h +++ b/src/common/config.h @@ -38,6 +38,7 @@ int getCursorHideTimeout(); std::string getBackButtonBehavior(); bool getUseSpecialPad(); int getSpecialPadClass(); +bool getIsMotionControlsEnabled(); u32 getScreenWidth(); u32 getScreenHeight(); @@ -84,6 +85,7 @@ void setCursorHideTimeout(int newcursorHideTimeout); void setBackButtonBehavior(const std::string& type); void setUseSpecialPad(bool use); void setSpecialPadClass(int type); +void setIsMotionControlsEnabled(bool use); void setLogType(const std::string& type); void setLogFilter(const std::string& type); @@ -139,4 +141,4 @@ void setDefaultValues(); // settings u32 GetLanguage(); -}; // namespace Config \ No newline at end of file +}; // namespace Config diff --git a/src/input/controller.cpp b/src/input/controller.cpp index 366d80f8..eb43e6ad 100644 --- a/src/input/controller.cpp +++ b/src/input/controller.cpp @@ -2,6 +2,7 @@ // SPDX-License-Identifier: GPL-2.0-or-later #include +#include "common/config.h" #include "common/logging/log.h" #include "core/libraries/kernel/time.h" #include "core/libraries/pad/pad.h" @@ -189,11 +190,6 @@ void GameController::CalculateOrientation(Libraries::Pad::OrbisFVector3& acceler gz += Kp * ez + Ki * eInt[2]; //// Integrate rate of change of quaternion - // float pa = q2, pb = q3, pc = q4; - // q1 += (-q2 * gx - q3 * gy - q4 * gz) * (0.5f * deltaTime); - // q2 += (pa * gx + pb * gz - pc * gy) * (0.5f * deltaTime); - // q3 += (pb * gy - pa * gz + pc * gx) * (0.5f * deltaTime); - // q4 += (pc * gz + pa * gy - pb * gx) * (0.5f * deltaTime); q1 += (-q2 * gx - q3 * gy - q4 * gz) * (0.5f * deltaTime); q2 += (q1 * gx + q3 * gz - q4 * gy) * (0.5f * deltaTime); q3 += (q1 * gy - q2 * gz + q4 * gx) * (0.5f * deltaTime); @@ -247,18 +243,21 @@ void GameController::TryOpenSDLController() { int gamepad_count; SDL_JoystickID* gamepads = SDL_GetGamepads(&gamepad_count); m_sdl_gamepad = gamepad_count > 0 ? SDL_OpenGamepad(gamepads[0]) : nullptr; - if (SDL_SetGamepadSensorEnabled(m_sdl_gamepad, SDL_SENSOR_GYRO, true)) { - gyro_poll_rate = SDL_GetGamepadSensorDataRate(m_sdl_gamepad, SDL_SENSOR_GYRO); - LOG_INFO(Input, "Gyro initialized, poll rate: {}", gyro_poll_rate); - } else { - LOG_ERROR(Input, "Failed to initialize gyro controls for gamepad"); - } - if (SDL_SetGamepadSensorEnabled(m_sdl_gamepad, SDL_SENSOR_ACCEL, true)) { - accel_poll_rate = SDL_GetGamepadSensorDataRate(m_sdl_gamepad, SDL_SENSOR_ACCEL); - LOG_INFO(Input, "Accel initialized, poll rate: {}", accel_poll_rate); - } else { - LOG_ERROR(Input, "Failed to initialize accel controls for gamepad"); + if (Config::getIsMotionControlsEnabled()) { + if (SDL_SetGamepadSensorEnabled(m_sdl_gamepad, SDL_SENSOR_GYRO, true)) { + gyro_poll_rate = SDL_GetGamepadSensorDataRate(m_sdl_gamepad, SDL_SENSOR_GYRO); + LOG_INFO(Input, "Gyro initialized, poll rate: {}", gyro_poll_rate); + } else { + LOG_ERROR(Input, "Failed to initialize gyro controls for gamepad"); + } + if (SDL_SetGamepadSensorEnabled(m_sdl_gamepad, SDL_SENSOR_ACCEL, true)) { + accel_poll_rate = SDL_GetGamepadSensorDataRate(m_sdl_gamepad, SDL_SENSOR_ACCEL); + LOG_INFO(Input, "Accel initialized, poll rate: {}", accel_poll_rate); + } else { + LOG_ERROR(Input, "Failed to initialize accel controls for gamepad"); + } } + SDL_free(gamepads); SetLightBarRGB(0, 0, 255); diff --git a/src/qt_gui/settings_dialog.cpp b/src/qt_gui/settings_dialog.cpp index 6d76a531..1a03345e 100644 --- a/src/qt_gui/settings_dialog.cpp +++ b/src/qt_gui/settings_dialog.cpp @@ -339,6 +339,8 @@ void SettingsDialog::LoadValuesFromConfig() { toml::find_or(data, "Input", "backButtonBehavior", "left")); int index = ui->backButtonBehaviorComboBox->findData(backButtonBehavior); ui->backButtonBehaviorComboBox->setCurrentIndex(index != -1 ? index : 0); + ui->motionControlsCheckBox->setChecked( + toml::find_or(data, "Input", "isMotionControlsEnabled", true)); ui->removeFolderButton->setEnabled(!ui->gameFoldersListWidget->selectedItems().isEmpty()); ResetInstallFolders(); @@ -532,6 +534,7 @@ void SettingsDialog::UpdateSettings() { const QVector TouchPadIndex = {"left", "center", "right", "none"}; Config::setBackButtonBehavior(TouchPadIndex[ui->backButtonBehaviorComboBox->currentIndex()]); + Config::setIsMotionControlsEnabled(ui->motionControlsCheckBox->isChecked()); Config::setFullscreenMode(ui->fullscreenCheckBox->isChecked()); Config::setisTrophyPopupDisabled(ui->disableTrophycheckBox->isChecked()); Config::setPlayBGM(ui->playBGMCheckBox->isChecked()); diff --git a/src/qt_gui/settings_dialog.ui b/src/qt_gui/settings_dialog.ui index 2e7e3db3..cefe1f7c 100644 --- a/src/qt_gui/settings_dialog.ui +++ b/src/qt_gui/settings_dialog.ui @@ -815,6 +815,13 @@ + + + + Enable Motion Controls + + +