Add alternate axes processing for PS3 and PS4

This commit is contained in:
2025-03-17 23:35:52 -04:00
parent 5f308e7b23
commit 326ab4c8d8
2 changed files with 38 additions and 8 deletions

View File

@@ -26,6 +26,7 @@ Vector2 r_thumb;
short l_trigger;
short r_trigger;
Vector2 dpad;
jstick::ControllerType device_type;
/// Reads a joystick event from the joystick device.
@@ -83,6 +84,7 @@ int jstick::Connect(int hwid) {
}
js_connected = true;
device_type = GetDeviceTypeFromName(GetDeviceName(js_handle));
JoystickConnected.Invoke(js_handle);
return js_handle;
}
@@ -134,16 +136,41 @@ void ProcessAxisEvent(uint8_t axis, short value) {
short prev_ltrigger = l_trigger;
short prev_rtrigger = r_trigger;
if (axis == 0) l_thumb.x = value;
if (axis == 1) l_thumb.y = value;
if (axis == 2) l_trigger = value;
if (axis == 3) r_thumb.x = value;
if (axis == 4) r_thumb.y = value;
if (axis == 5) r_trigger = value;
if (axis == 6) dpad.x = value;
if (axis == 7) dpad.y = value;
if (device_type == jstick::ControllerType::XBox)
{
if (axis == 0) l_thumb.x = value;
if (axis == 1) l_thumb.y = value;
if (axis == 2) l_trigger = value;
if (axis == 3) r_thumb.x = value;
if (axis == 4) r_thumb.y = value;
if (axis == 5) r_trigger = value;
if (axis == 6) dpad.x = value;
if (axis == 7) dpad.y = value;
}
if (device_type == jstick::ControllerType::PS3) {
if (axis == 0) l_thumb.x = value;
if (axis == 1) l_thumb.y = value;
if (axis == 2) r_thumb.x = value;
if (axis == 3) r_thumb.y = value;
if (axis == 4) l_trigger = value;
if (axis == 5) r_trigger = value;
}
if (device_type == jstick::ControllerType::PS4) {
if (axis == 0) l_thumb.x = value;
if (axis == 1) l_thumb.y = value;
if (axis == 2) r_thumb.x = value;
if (axis == 3) r_thumb.y = value;
if (axis == 4) l_trigger = value;
if (axis == 5) r_trigger = value;
if (axis == 6) dpad.x = value;
if (axis == 7) dpad.y = value;
}
// TODO: Compare against the l_thumb from the last time the event was called.
if (l_thumb.DistanceSq(prev_lthumb) > 0.1f)
jstick::LeftThumbstickMoved.Invoke(l_thumb);