From cf680265cdb94e6f4fe836e2c592cef06b4426ed Mon Sep 17 00:00:00 2001 From: ABeltramo Date: Sat, 25 May 2024 10:45:31 +0100 Subject: [PATCH] fix: inverted y values on PS5 joypad --- src/uhid/joypad_ps5.cpp | 4 ++-- tests/testCAPI.cpp | 3 ++- tests/testJoypads.cpp | 9 +++++++-- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/uhid/joypad_ps5.cpp b/src/uhid/joypad_ps5.cpp index 56bc1c7..4020bfa 100644 --- a/src/uhid/joypad_ps5.cpp +++ b/src/uhid/joypad_ps5.cpp @@ -321,13 +321,13 @@ void PS5Joypad::set_stick(Joypad::STICK_POSITION stick_type, short x, short y) { switch (stick_type) { case RS: { this->_state->current_state.rx = scale_value(x, -32768, 32767, uhid::PS5_AXIS_MIN, uhid::PS5_AXIS_MAX); - this->_state->current_state.ry = scale_value(y, -32768, 32767, uhid::PS5_AXIS_MIN, uhid::PS5_AXIS_MAX); + this->_state->current_state.ry = scale_value(-y, -32768, 32767, uhid::PS5_AXIS_MIN, uhid::PS5_AXIS_MAX); send_report(*this->_state); break; } case LS: { this->_state->current_state.x = scale_value(x, -32768, 32767, uhid::PS5_AXIS_MIN, uhid::PS5_AXIS_MAX); - this->_state->current_state.y = scale_value(y, -32768, 32767, uhid::PS5_AXIS_MIN, uhid::PS5_AXIS_MAX); + this->_state->current_state.y = scale_value(-y, -32768, 32767, uhid::PS5_AXIS_MIN, uhid::PS5_AXIS_MAX); send_report(*this->_state); break; } diff --git a/tests/testCAPI.cpp b/tests/testCAPI.cpp index 2c06e26..874ac94 100644 --- a/tests/testCAPI.cpp +++ b/tests/testCAPI.cpp @@ -1,6 +1,7 @@ #include "catch2/catch_all.hpp" #include #include +#include TEST_CASE("C Mouse API", "[C-API]") { InputtinoErrorHandler error_handler = {.eh = [](const char *message, void *_data) { FAIL(message); }, @@ -187,7 +188,7 @@ TEST_CASE("C PS5 API", "[C-API]") { .version = 0x8111}; auto ps_pad = inputtino_joypad_ps5_create(&def, &error_handler); REQUIRE(ps_pad != nullptr); - + std::this_thread::sleep_for(std::chrono::milliseconds(50)); int num_nodes = 0; auto nodes = inputtino_joypad_ps5_get_nodes(ps_pad, &num_nodes); REQUIRE(num_nodes == 5); diff --git a/tests/testJoypads.cpp b/tests/testJoypads.cpp index 049d9d6..6619d85 100644 --- a/tests/testJoypads.cpp +++ b/tests/testJoypads.cpp @@ -163,12 +163,17 @@ TEST_CASE_METHOD(SDLTestsFixture, "PS Joypad", "[SDL]") { joypad.set_stick(Joypad::LS, 1000, 2000); flush_sdl_events(); REQUIRE(SDL_GameControllerGetAxis(gc, SDL_CONTROLLER_AXIS_LEFTX) == 899); - REQUIRE(SDL_GameControllerGetAxis(gc, SDL_CONTROLLER_AXIS_LEFTY) == 1927); + REQUIRE(SDL_GameControllerGetAxis(gc, SDL_CONTROLLER_AXIS_LEFTY) == -1928); + + joypad.set_stick(Joypad::RS, 1000, 2000); + flush_sdl_events(); + REQUIRE(SDL_GameControllerGetAxis(gc, SDL_CONTROLLER_AXIS_LEFTX) == 899); + REQUIRE(SDL_GameControllerGetAxis(gc, SDL_CONTROLLER_AXIS_LEFTY) == -1928); joypad.set_stick(Joypad::RS, -16384, -32768); flush_sdl_events(); REQUIRE(SDL_GameControllerGetAxis(gc, SDL_CONTROLLER_AXIS_RIGHTX) == -16320); - REQUIRE(SDL_GameControllerGetAxis(gc, SDL_CONTROLLER_AXIS_RIGHTY) == -32768); + REQUIRE(SDL_GameControllerGetAxis(gc, SDL_CONTROLLER_AXIS_RIGHTY) == 32767); joypad.set_triggers(125, 255); flush_sdl_events();