Skip to content
This repository has been archived by the owner on Nov 24, 2024. It is now read-only.

Commit

Permalink
Added support for the DualSense gyroscope, including a combined Yaw/P…
Browse files Browse the repository at this point in the history
…itch axis designed for easy gyro aiming using EnhancedInput.
  • Loading branch information
Jamie Greunbaum committed Nov 11, 2023
1 parent c1d81fd commit ac946e8
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Config/Input.ini
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[InputPlatformSettings_Windows InputPlatformSettings]
+HardwareDevices=(InputClassName="DsInputDevice",HardwareDeviceIdentifier="DualSense",PrimaryDeviceType=Gamepad,SupportedFeaturesMask=462)
+HardwareDevices=(InputClassName="DsInputDevice",HardwareDeviceIdentifier="DualSense",PrimaryDeviceType=Gamepad,SupportedFeaturesMask=8654)
5 changes: 5 additions & 0 deletions Source/FabulousDualSense/Private/DsConstants.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ const FKey DsConstants::Touch2AxisXKey{FName{TEXTVIEW("DsTouch2AxisX")}};
const FKey DsConstants::Touch2AxisYKey{FName{TEXTVIEW("DsTouch2AxisY")}};
const FKey DsConstants::Touch2AxisXYKey{FName{TEXTVIEW("DsTouch2AxisXY")}};

const FKey DsConstants::GyroscopeAxisRollKey{ FName{TEXTVIEW("DsGyroscopeRoll")}};
const FKey DsConstants::GyroscopeAxisPitchKey{ FName{TEXTVIEW("DsGyroscopePitch")}};
const FKey DsConstants::GyroscopeAxisYawKey{ FName{TEXTVIEW("DsGyroscopeYaw")}};
const FKey DsConstants::GyroscopeAxisYawPitchKey{ FName{TEXTVIEW("DsGyroscopeYawPitch")}};

const TMap<FGamepadKeyNames::Type, uint32>& DsConstants::GetRegularButtons()
{
static const TMap<FGamepadKeyNames::Type, uint32> Buttons{
Expand Down
23 changes: 23 additions & 0 deletions Source/FabulousDualSense/Private/DsInputDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,29 @@ void FDsInputDevice::SendControllerEvents()
Input.rightTrigger / static_cast<float>(TNumericLimits<uint8>::Max()));
}

// Gyroscope.

// Gyroscope X represents Unreal Engine's pitch axis
if (PreviousInput.gyroscope.x != Input.gyroscope.x)
{
MessageHandler->OnControllerAnalog(DsConstants::GyroscopeAxisPitchKey.GetFName(), PlatformUserId, InputDeviceId,
Input.gyroscope.x * 0.0001);
}

// Gyroscope Y represents Unreal Engine's yaw axis
if (PreviousInput.gyroscope.y != Input.gyroscope.y)
{
MessageHandler->OnControllerAnalog(DsConstants::GyroscopeAxisYawKey.GetFName(), PlatformUserId, InputDeviceId,
Input.gyroscope.y * 0.0001);
}

// Gyroscope Z represents Unreal Engine's roll axis
if (PreviousInput.gyroscope.z != Input.gyroscope.z)
{
MessageHandler->OnControllerAnalog(DsConstants::GyroscopeAxisRollKey.GetFName(), PlatformUserId, InputDeviceId,
Input.gyroscope.z * 0.0001);
}

// Regular buttons.

auto ButtonIndex{0};
Expand Down
22 changes: 22 additions & 0 deletions Source/FabulousDualSense/Private/FabulousDualSenseModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,28 @@ void FFabulousDualSenseModule::StartupModule()
FKeyDetails::GamepadKey | FKeyDetails::Touch | FKeyDetails::Axis2D | FKeyDetails::UpdateAxisWithoutSamples,
CategoryName
}, DsConstants::Touch2AxisXKey, DsConstants::Touch2AxisYKey);

// Gyroscope.

EKeys::AddKey({
DsConstants::GyroscopeAxisRollKey, LOCTEXT("GyroscopeAxisRollKey", "DualSense Gyroscope Roll Axis"),
FKeyDetails::GamepadKey | FKeyDetails::Axis1D | FKeyDetails::UpdateAxisWithoutSamples, CategoryName
});

EKeys::AddKey({
DsConstants::GyroscopeAxisPitchKey, LOCTEXT("GyroscopeAxisPitchKey", "DualSense Gyroscope Pitch Axis"),
FKeyDetails::GamepadKey | FKeyDetails::Axis1D | FKeyDetails::UpdateAxisWithoutSamples, CategoryName
});

EKeys::AddKey({
DsConstants::GyroscopeAxisYawKey, LOCTEXT("GyroscopeAxisYawKey", "DualSense Gyroscope Yaw Axis"),
FKeyDetails::GamepadKey | FKeyDetails::Axis1D | FKeyDetails::UpdateAxisWithoutSamples, CategoryName
});

EKeys::AddPairedKey({
DsConstants::GyroscopeAxisYawPitchKey, LOCTEXT("GyroscopeAxisYawPitchKey", "DualSense Gyroscope Yaw/Pitch Axis"),
FKeyDetails::GamepadKey | FKeyDetails::Axis2D | FKeyDetails::UpdateAxisWithoutSamples, CategoryName
}, DsConstants::GyroscopeAxisYawKey, DsConstants::GyroscopeAxisPitchKey);
}

TSharedPtr<IInputDevice> FFabulousDualSenseModule::CreateInputDevice(const TSharedRef<FGenericApplicationMessageHandler>& MessageHandler)
Expand Down
5 changes: 5 additions & 0 deletions Source/FabulousDualSense/Public/DsConstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,10 @@ namespace DsConstants
FABULOUSDUALSENSE_API extern const FKey Touch2AxisYKey;
FABULOUSDUALSENSE_API extern const FKey Touch2AxisXYKey;

FABULOUSDUALSENSE_API extern const FKey GyroscopeAxisRollKey;
FABULOUSDUALSENSE_API extern const FKey GyroscopeAxisPitchKey;
FABULOUSDUALSENSE_API extern const FKey GyroscopeAxisYawKey;
FABULOUSDUALSENSE_API extern const FKey GyroscopeAxisYawPitchKey;

FABULOUSDUALSENSE_API const TMap<FGamepadKeyNames::Type, uint32>& GetRegularButtons();
}

0 comments on commit ac946e8

Please sign in to comment.