Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/networking/executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,9 @@ ParseResult parse_gamepad_state(const char *data, size_t len)
<< "\nLeft thumbstick x: " << result.reading.left_thumbstick_x
<< "\nLeft thumbstick y: " << result.reading.left_thumbstick_y
<< "\nRight thumbstick x: " << result.reading.right_thumbstick_x
<< "\nRight thumbstick y: " << result.reading.right_thumbstick_y;
<< "\nRight thumbstick y: " << result.reading.right_thumbstick_y
<< "\nPitch: " << result.reading.pitch
<< "\nRoll: " << result.reading.roll;
#endif

return result;
Expand Down Expand Up @@ -432,6 +434,7 @@ bool GamepadExecutor::inject_gamepad_state(vgp_data_exchange_gamepad_reading con
m_injector.setThumbsticks(reading.left_thumbstick_x, -reading.left_thumbstick_y,
reading.right_thumbstick_x, -reading.right_thumbstick_y);
m_injector.setTriggers(reading.left_trigger, reading.right_trigger);
m_injector.setOrientation(reading.pitch, reading.roll);

// Handle button presses (mapping from our buttons to Linux input codes)
if (reading.buttons_down & GamepadButtons_Menu)
Expand Down
8 changes: 8 additions & 0 deletions src/simulation/gamepadSim.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,14 @@ class GamepadInjector
*/
void setTriggers(float leftTrigger, float rightTrigger);

/**
* @brief Sets orientation as axis value (Linux)
*
* @param pitch pitch (-PI/2 to PI)
* @param roll roll (-PI to PI)
*/
void setOrientation(float pitch, float roll);

/**
* @brief Press a gamepad button (Linux).
*
Expand Down
21 changes: 21 additions & 0 deletions src/simulation/linux/gamepadSim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,16 @@
libevdev_enable_event_code(dev.get(), EV_ABS, ABS_HAT2X, &absinfo); // Left trigger
libevdev_enable_event_code(dev.get(), EV_ABS, ABS_HAT2Y, &absinfo); // Right trigger

// Orientation
absinfo.minimum = static_cast<int>(-std::numbers::pi / 2 * 20000);
absinfo.maximum = static_cast<int>(std::numbers::pi / 2 * 20000);
absinfo.fuzz = 0;
absinfo.flat = 0;
libevdev_enable_event_code(dev.get(), EV_ABS, ABS_HAT3X, &absinfo); // Pitch
absinfo.minimum = static_cast<int>(-std::numbers::pi * 10000);
absinfo.maximum = static_cast<int>(std::numbers::pi * 10000);
libevdev_enable_event_code(dev.get(), EV_ABS, ABS_HAT3Y, &absinfo); // Roll

// Create uinput device
libevdev_uinput *rawUidev;
int ret =
Expand Down Expand Up @@ -153,6 +163,17 @@
libevdev_uinput_write_event(uidev.get(), EV_ABS, ABS_HAT2Y, rightInt);
}

void GamepadInjector::setOrientation(float pitch, float roll)
{
qInfo() << pitch << "\n";
// Convert from [-PI/2..PI/2] to int range defined earlier with libevdev_enable_event_code for this axis
int evdevPitch = static_cast<int>(pitch * 20000);

Check warning on line 170 in src/simulation/linux/gamepadSim.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Replace the redundant type with "auto".

See more on https://sonarcloud.io/project/issues?id=kitswas_VirtualGamePad-PC&issues=AZ1Jz-yGZbWaBRLAfW9V&open=AZ1Jz-yGZbWaBRLAfW9V&pullRequest=32
// Convert from [-PI..PI] to int range defined earlier with libevdev_enable_event_code for this axis
int evdevRoll = static_cast<int>(roll * 10000);

Check warning on line 172 in src/simulation/linux/gamepadSim.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Replace the redundant type with "auto".

See more on https://sonarcloud.io/project/issues?id=kitswas_VirtualGamePad-PC&issues=AZ1Jz-yGZbWaBRLAfW9W&open=AZ1Jz-yGZbWaBRLAfW9W&pullRequest=32
libevdev_uinput_write_event(uidev.get(), EV_ABS, ABS_HAT3X, evdevPitch);
libevdev_uinput_write_event(uidev.get(), EV_ABS, ABS_HAT3Y, evdevRoll);
}

void GamepadInjector::pressButton(int buttonCode)
{
libevdev_uinput_write_event(uidev.get(), EV_KEY, buttonCode, 1);
Expand Down