Skip to content

Commit

Permalink
fix: inverted y values on PS5 joypad
Browse files Browse the repository at this point in the history
  • Loading branch information
ABeltramo committed May 25, 2024
1 parent 96d1045 commit cf68026
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/uhid/joypad_ps5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
3 changes: 2 additions & 1 deletion tests/testCAPI.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "catch2/catch_all.hpp"
#include <filesystem>
#include <inputtino/input.h>
#include <thread>

TEST_CASE("C Mouse API", "[C-API]") {
InputtinoErrorHandler error_handler = {.eh = [](const char *message, void *_data) { FAIL(message); },
Expand Down Expand Up @@ -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);
Expand Down
9 changes: 7 additions & 2 deletions tests/testJoypads.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit cf68026

Please sign in to comment.