Fixed PS5 gyro & Added GUI calibration button (#78)

* Fixed PS5 gyro & Added GUI calibration button

* Change PS4/PS5 LED to the tunic color
This commit is contained in:
MelonSpeedruns 2022-03-29 22:23:02 -04:00 committed by GitHub
parent 6aa8894125
commit 98ddacef01
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 49 additions and 25 deletions

View File

@ -30,7 +30,9 @@ struct SoHConfigType {
float gyro_sensitivity = 1.0f; float gyro_sensitivity = 1.0f;
float rumble_strength = 1.0f; float rumble_strength = 1.0f;
float input_scale = 1.0f; float input_scale = 1.0f;
bool input_enabled = false; float gyroDriftX = 0.0f;
float gyroDriftY = 0.0f;
bool input_enabled = false;
} controller; } controller;
// Cheats // Cheats

View File

@ -7,12 +7,8 @@
#include "Window.h" #include "Window.h"
extern "C" uint8_t __osMaxControllers; extern "C" uint8_t __osMaxControllers;
float gyroDriftX;
float gyroDriftY;
namespace Ship { namespace Ship {
SDLController::SDLController(int32_t dwControllerNumber) : Controller(dwControllerNumber), Cont(nullptr), guid(INVALID_SDL_CONTROLLER_GUID) { SDLController::SDLController(int32_t dwControllerNumber) : Controller(dwControllerNumber), Cont(nullptr), guid(INVALID_SDL_CONTROLLER_GUID) {
} }
@ -186,31 +182,31 @@ namespace Ship {
SDL_GameControllerGetSensorData(Cont, SDL_SENSOR_GYRO, gyroData, 3); SDL_GameControllerGetSensorData(Cont, SDL_SENSOR_GYRO, gyroData, 3);
const char* contName = SDL_GameControllerName(Cont); const char* contName = SDL_GameControllerName(Cont);
const int isSpecialController = strcmp("PS5 Controller", contName); const int isSpecialController = !strcmp("PS5 Controller", contName);
const float gyroSensitivity = Game::Settings.controller.gyro_sensitivity; const float gyroSensitivity = Game::Settings.controller.gyro_sensitivity;
if (gyroDriftX == 0) { if (Game::Settings.controller.gyroDriftX == 0) {
if (isSpecialController == 0) { Game::Settings.controller.gyroDriftX = gyroData[0];
gyroDriftX = gyroData[2]; }
if (Game::Settings.controller.gyroDriftY == 0) {
if (isSpecialController == 1) {
Game::Settings.controller.gyroDriftY = gyroData[2];
} }
else { else {
gyroDriftX = gyroData[0]; Game::Settings.controller.gyroDriftY = gyroData[1];
} }
} }
if (gyroDriftY == 0) { if (isSpecialController == 1) {
gyroDriftY = gyroData[1]; wGyroX = gyroData[0] - Game::Settings.controller.gyroDriftX;
} wGyroY = -gyroData[2] - Game::Settings.controller.gyroDriftY;
if (isSpecialController == 0) {
wGyroX = gyroData[2] - gyroDriftX;
} }
else { else {
wGyroX = gyroData[0] - gyroDriftX; wGyroX = gyroData[0] - Game::Settings.controller.gyroDriftX;
wGyroY = gyroData[1] - Game::Settings.controller.gyroDriftY;
} }
wGyroY = gyroData[1] - gyroDriftY;
wGyroX *= gyroSensitivity; wGyroX *= gyroSensitivity;
wGyroY *= gyroSensitivity; wGyroY *= gyroSensitivity;
} }
@ -340,11 +336,19 @@ namespace Ship {
} }
if (SDL_GameControllerHasLED(Cont)) { if (SDL_GameControllerHasLED(Cont)) {
if (controller->ledColor == 1) { switch (controller->ledColor) {
case 0:
SDL_JoystickSetLED(SDL_GameControllerGetJoystick(Cont), 255, 0, 0); SDL_JoystickSetLED(SDL_GameControllerGetJoystick(Cont), 255, 0, 0);
} break;
else { case 1:
SDL_JoystickSetLED(SDL_GameControllerGetJoystick(Cont), 0, 255, 0); SDL_JoystickSetLED(SDL_GameControllerGetJoystick(Cont), 0x1E, 0x69, 0x1B);
break;
case 2:
SDL_JoystickSetLED(SDL_GameControllerGetJoystick(Cont), 0x64, 0x14, 0x00);
break;
case 3:
SDL_JoystickSetLED(SDL_GameControllerGetJoystick(Cont), 0x00, 0x3C, 0x64);
break;
} }
} }
} }

View File

@ -306,6 +306,14 @@ namespace SohImGui {
if (ImGui::SliderFloat("##GYROSCOPE", &Game::Settings.controller.gyro_sensitivity, 0.0f, 1.0f, "")) { if (ImGui::SliderFloat("##GYROSCOPE", &Game::Settings.controller.gyro_sensitivity, 0.0f, 1.0f, "")) {
needs_save = true; needs_save = true;
} }
if (ImGui::Button("Recalibrate Gyro")) {
Game::Settings.controller.gyroDriftX = 0;
Game::Settings.controller.gyroDriftY = 0;
}
ImGui::Separator();
ImGui::Text("Rumble Strength: %d %%", static_cast<int>(100 * Game::Settings.controller.rumble_strength)); ImGui::Text("Rumble Strength: %d %%", static_cast<int>(100 * Game::Settings.controller.rumble_strength));
if (ImGui::SliderFloat("##RUMBLE", &Game::Settings.controller.rumble_strength, 0.0f, 1.0f, "")) { if (ImGui::SliderFloat("##RUMBLE", &Game::Settings.controller.rumble_strength, 0.0f, 1.0f, "")) {
needs_save = true; needs_save = true;

View File

@ -272,9 +272,19 @@ void PadMgr_ProcessInputs(PadMgr* padMgr) {
controllerCallback.rumble = padMgr->rumbleEnable[0] > 0 ? 1 : 0; controllerCallback.rumble = padMgr->rumbleEnable[0] > 0 ? 1 : 0;
if (HealthMeter_IsCritical()) { if (HealthMeter_IsCritical()) {
controllerCallback.ledColor = 1;
} else {
controllerCallback.ledColor = 0; controllerCallback.ledColor = 0;
} else if (gGlobalCtx) {
switch (CUR_EQUIP_VALUE(EQUIP_TUNIC) - 1) {
case PLAYER_TUNIC_KOKIRI:
controllerCallback.ledColor = 1;
break;
case PLAYER_TUNIC_GORON:
controllerCallback.ledColor = 2;
break;
case PLAYER_TUNIC_ZORA:
controllerCallback.ledColor = 3;
break;
}
} }
OTRControllerCallback(&controllerCallback); OTRControllerCallback(&controllerCallback);