mirror of
https://github.com/ayufan/steam-deck-tools.git
synced 2025-12-06 07:12:01 +01:00
SteamController: Fix PS button and Gyro support for DS4
Make DS4 fields be readonly and optimise DS4 packets.
This commit is contained in:
parent
eed1453daf
commit
00a30cbf5c
|
|
@ -1,6 +1,6 @@
|
||||||
namespace CommonHelpers
|
namespace CommonHelpers
|
||||||
{
|
{
|
||||||
public class TimedValue<T> where T : struct
|
public struct TimedValue<T> where T : struct
|
||||||
{
|
{
|
||||||
public T Value { get; }
|
public T Value { get; }
|
||||||
public DateTime ExpiryDate { get; }
|
public DateTime ExpiryDate { get; }
|
||||||
|
|
@ -32,9 +32,19 @@ namespace CommonHelpers
|
||||||
return Valid;
|
return Valid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public T? GetValue()
|
||||||
|
{
|
||||||
|
return Valid ? Value : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public T GetValueOrDefault(T defaultValue)
|
||||||
|
{
|
||||||
|
return Valid ? Value : defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
public static implicit operator T?(TimedValue<T> tv)
|
public static implicit operator T?(TimedValue<T> tv)
|
||||||
{
|
{
|
||||||
return tv.Valid ? tv.Value : null;
|
return tv.GetValue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@
|
||||||
|
|
||||||
## 0.6.x
|
## 0.6.x
|
||||||
|
|
||||||
- SteamController: Add initial `DS4` support (with Gyro, Accel, Trackpads and Haptics)
|
- SteamController: Add `DS4` support (with Gyro, Accel, Trackpads and Haptics)
|
||||||
- SteamController: Move `KeepX360AlwaysConnected` to `Settings`
|
- SteamController: Move `KeepX360AlwaysConnected` to `Settings`
|
||||||
- PowerControl: Install custom resolutions (EDID) (experimental feature)
|
- PowerControl: Install custom resolutions (EDID) (experimental feature)
|
||||||
- All: Show `Missing RTSS` button to install RTSS
|
- All: Show `Missing RTSS` button to install RTSS
|
||||||
|
|
|
||||||
|
|
@ -94,19 +94,14 @@ namespace SteamController.Devices
|
||||||
public struct DualShock4Sensor
|
public struct DualShock4Sensor
|
||||||
{
|
{
|
||||||
public int Offset { get; }
|
public int Offset { get; }
|
||||||
public bool Invert { get; }
|
|
||||||
|
|
||||||
public DualShock4Sensor(int offset, bool invert)
|
public DualShock4Sensor(int offset)
|
||||||
{
|
{
|
||||||
Offset = offset;
|
Offset = offset;
|
||||||
Invert = invert;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void Set(byte[] report, short value)
|
internal void Set(byte[] report, short value)
|
||||||
{
|
{
|
||||||
if (Invert)
|
|
||||||
value = (short)Math.Clamp(-value, short.MinValue, short.MaxValue);
|
|
||||||
|
|
||||||
BitConverter.GetBytes(value).CopyTo(report, Offset);
|
BitConverter.GetBytes(value).CopyTo(report, Offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -155,8 +150,9 @@ namespace SteamController.Devices
|
||||||
if ((currentValue & 0xFFFFFF80) == (calculatedValue & 0xFFFFFF80))
|
if ((currentValue & 0xFFFFFF80) == (calculatedValue & 0xFFFFFF80))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// increment packet number
|
// increment packet number (if it changed since the last packet)
|
||||||
report[33] = (byte)(report[33] + 1);
|
if (report[33] == report[42])
|
||||||
|
report[33] = (byte)(report[33] + 1);
|
||||||
BitConverter.GetBytes(calculatedValue).CopyTo(report, Offset);
|
BitConverter.GetBytes(calculatedValue).CopyTo(report, Offset);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -166,47 +162,47 @@ namespace SteamController.Devices
|
||||||
public readonly static DualShock4Axis RightThumbX = new DualShock4Axis(2, false);
|
public readonly static DualShock4Axis RightThumbX = new DualShock4Axis(2, false);
|
||||||
public readonly static DualShock4Axis RightThumbY = new DualShock4Axis(3, true);
|
public readonly static DualShock4Axis RightThumbY = new DualShock4Axis(3, true);
|
||||||
|
|
||||||
public static DualShock4Slider LeftTrigger = new DualShock4Slider(7);
|
public readonly static DualShock4Slider LeftTrigger = new DualShock4Slider(7);
|
||||||
public static DualShock4Slider RightTrigger = new DualShock4Slider(8);
|
public readonly static DualShock4Slider RightTrigger = new DualShock4Slider(8);
|
||||||
|
|
||||||
public static DualShock4Button ThumbRight = new DualShock4Button(5, 7);
|
public readonly static DualShock4Button ThumbRight = new DualShock4Button(5, 7);
|
||||||
public static DualShock4Button ThumbLeft = new DualShock4Button(5, 6);
|
public readonly static DualShock4Button ThumbLeft = new DualShock4Button(5, 6);
|
||||||
public static DualShock4Button Options = new DualShock4Button(5, 5);
|
public readonly static DualShock4Button Options = new DualShock4Button(5, 5);
|
||||||
public static DualShock4Button Share = new DualShock4Button(5, 4);
|
public readonly static DualShock4Button Share = new DualShock4Button(5, 4);
|
||||||
public static DualShock4Button TriggerRight = new DualShock4Button(5, 3);
|
public readonly static DualShock4Button TriggerRight = new DualShock4Button(5, 3);
|
||||||
public static DualShock4Button TriggerLeft = new DualShock4Button(5, 2);
|
public readonly static DualShock4Button TriggerLeft = new DualShock4Button(5, 2);
|
||||||
public static DualShock4Button ShoulderRight = new DualShock4Button(5, 1);
|
public readonly static DualShock4Button ShoulderRight = new DualShock4Button(5, 1);
|
||||||
public static DualShock4Button ShoulderLeft = new DualShock4Button(5, 0);
|
public readonly static DualShock4Button ShoulderLeft = new DualShock4Button(5, 0);
|
||||||
public static DualShock4Button Triangle = new DualShock4Button(4, 7);
|
public readonly static DualShock4Button Triangle = new DualShock4Button(4, 7);
|
||||||
public static DualShock4Button Circle = new DualShock4Button(4, 6);
|
public readonly static DualShock4Button Circle = new DualShock4Button(4, 6);
|
||||||
public static DualShock4Button Cross = new DualShock4Button(4, 5);
|
public readonly static DualShock4Button Cross = new DualShock4Button(4, 5);
|
||||||
public static DualShock4Button Square = new DualShock4Button(4, 4);
|
public readonly static DualShock4Button Square = new DualShock4Button(4, 4);
|
||||||
|
|
||||||
public static DualShock4Button TPadClick = new DualShock4Button(6, 1);
|
public readonly static DualShock4Button TPadClick = new DualShock4Button(6, 1);
|
||||||
public static DualShock4Button PS = new DualShock4Button(6, 0);
|
public readonly static DualShock4Button PS = new DualShock4Button(6, 0);
|
||||||
|
|
||||||
private static DualShock4Sensor Timestamp = new DualShock4Sensor(9, false);
|
private readonly static DualShock4Sensor Timestamp = new DualShock4Sensor(9);
|
||||||
private static DualShock4Slider BatteryLevel = new DualShock4Slider(11);
|
private readonly static DualShock4Slider BatteryLevel = new DualShock4Slider(11);
|
||||||
private static DualShock4Slider Counter = new DualShock4Slider(6);
|
private readonly static DualShock4Slider Counter = new DualShock4Slider(6);
|
||||||
|
|
||||||
public static DualShock4Sensor GyroX = new DualShock4Sensor(12, false);
|
public readonly static DualShock4Sensor GyroX = new DualShock4Sensor(12);
|
||||||
public static DualShock4Sensor GyroY = new DualShock4Sensor(14, true);
|
public readonly static DualShock4Sensor GyroY = new DualShock4Sensor(14);
|
||||||
public static DualShock4Sensor GyroZ = new DualShock4Sensor(16, false);
|
public readonly static DualShock4Sensor GyroZ = new DualShock4Sensor(16);
|
||||||
public static DualShock4Sensor AccelX = new DualShock4Sensor(18, false);
|
public readonly static DualShock4Sensor AccelX = new DualShock4Sensor(18);
|
||||||
public static DualShock4Sensor AccelY = new DualShock4Sensor(20, true);
|
public readonly static DualShock4Sensor AccelY = new DualShock4Sensor(20);
|
||||||
public static DualShock4Sensor AccelZ = new DualShock4Sensor(22, false);
|
public readonly static DualShock4Sensor AccelZ = new DualShock4Sensor(22);
|
||||||
|
|
||||||
public static DualShock4DPadDirection DPadReleased = new DualShock4DPadDirection(4, 8, 15);
|
public readonly static DualShock4DPadDirection DPadReleased = new DualShock4DPadDirection(4, 8, 15);
|
||||||
public static DualShock4DPadDirection DPadNorthwest = new DualShock4DPadDirection(4, 7, 15);
|
public readonly static DualShock4DPadDirection DPadNorthwest = new DualShock4DPadDirection(4, 7, 15);
|
||||||
public static DualShock4DPadDirection DPadWest = new DualShock4DPadDirection(4, 6, 15);
|
public readonly static DualShock4DPadDirection DPadWest = new DualShock4DPadDirection(4, 6, 15);
|
||||||
public static DualShock4DPadDirection DPadSouthwest = new DualShock4DPadDirection(4, 5, 15);
|
public readonly static DualShock4DPadDirection DPadSouthwest = new DualShock4DPadDirection(4, 5, 15);
|
||||||
public static DualShock4DPadDirection DPadSouth = new DualShock4DPadDirection(4, 4, 15);
|
public readonly static DualShock4DPadDirection DPadSouth = new DualShock4DPadDirection(4, 4, 15);
|
||||||
public static DualShock4DPadDirection DPadSoutheast = new DualShock4DPadDirection(4, 3, 15);
|
public readonly static DualShock4DPadDirection DPadSoutheast = new DualShock4DPadDirection(4, 3, 15);
|
||||||
public static DualShock4DPadDirection DPadEast = new DualShock4DPadDirection(4, 2, 15);
|
public readonly static DualShock4DPadDirection DPadEast = new DualShock4DPadDirection(4, 2, 15);
|
||||||
public static DualShock4DPadDirection DPadNortheast = new DualShock4DPadDirection(4, 1, 15);
|
public readonly static DualShock4DPadDirection DPadNortheast = new DualShock4DPadDirection(4, 1, 15);
|
||||||
public static DualShock4DPadDirection DPadNorth = new DualShock4DPadDirection(4, 0, 15);
|
public readonly static DualShock4DPadDirection DPadNorth = new DualShock4DPadDirection(4, 0, 15);
|
||||||
|
|
||||||
public static DualShock4Finger LeftFinger = new DualShock4Finger(0);
|
public readonly static DualShock4Finger LeftFinger = new DualShock4Finger(0);
|
||||||
public static DualShock4Finger RightFinger = new DualShock4Finger(1);
|
public readonly static DualShock4Finger RightFinger = new DualShock4Finger(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -48,8 +48,8 @@ namespace SteamController.Devices
|
||||||
public readonly SteamAxis AccelY = new SteamAxis(0x1A);
|
public readonly SteamAxis AccelY = new SteamAxis(0x1A);
|
||||||
public readonly SteamAxis AccelZ = new SteamAxis(0x1C);
|
public readonly SteamAxis AccelZ = new SteamAxis(0x1C);
|
||||||
public readonly SteamAxis GyroPitch = new SteamAxis(0x1E);
|
public readonly SteamAxis GyroPitch = new SteamAxis(0x1E);
|
||||||
public readonly SteamAxis GyroYaw = new SteamAxis(0x20);
|
public readonly SteamAxis GyroRoll = new SteamAxis(0x20);
|
||||||
public readonly SteamAxis GyroRoll = new SteamAxis(0x22);
|
public readonly SteamAxis GyroYaw = new SteamAxis(0x22);
|
||||||
public readonly SteamAxis LeftTrigger = new SteamAxis(0x2C);
|
public readonly SteamAxis LeftTrigger = new SteamAxis(0x2C);
|
||||||
public readonly SteamAxis RightTrigger = new SteamAxis(0x2E);
|
public readonly SteamAxis RightTrigger = new SteamAxis(0x2E);
|
||||||
public readonly SteamAxis LeftThumbX = new SteamAxis(0x30) { Deadzone = 5000, MinChange = 10, DeltaValueMode = Devices.DeltaValueMode.AbsoluteTime };
|
public readonly SteamAxis LeftThumbX = new SteamAxis(0x30) { Deadzone = 5000, MinChange = 10, DeltaValueMode = Devices.DeltaValueMode.AbsoluteTime };
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
using Nefarius.ViGEm.Client.Targets.Xbox360;
|
using CommonHelpers;
|
||||||
using SteamController.Devices;
|
using SteamController.Devices;
|
||||||
using SteamController.ProfilesSettings;
|
|
||||||
|
|
||||||
namespace SteamController.Profiles.Predefined
|
namespace SteamController.Profiles.Predefined
|
||||||
{
|
{
|
||||||
|
|
@ -27,14 +26,20 @@ namespace SteamController.Profiles.Predefined
|
||||||
get { return ProfilesSettings.DS4BackPanelSettings.Default; }
|
get { return ProfilesSettings.DS4BackPanelSettings.Default; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private TimedValue<bool> btnSteamPressed;
|
||||||
|
|
||||||
public override Status Run(Context context)
|
public override Status Run(Context context)
|
||||||
{
|
{
|
||||||
context.Steam.LizardButtons = false;
|
context.Steam.LizardButtons = false;
|
||||||
context.Steam.LizardMouse = false;
|
context.Steam.LizardMouse = false;
|
||||||
context.DS4.Connected = true;
|
context.DS4.Connected = true;
|
||||||
|
|
||||||
|
// Lock BtnSteam
|
||||||
|
if (context.Steam.BtnSteam.Pressed())
|
||||||
|
btnSteamPressed = new TimedValue<bool>(true, 100);
|
||||||
|
|
||||||
// Controls
|
// Controls
|
||||||
context.DS4.Overwrite(DS4Controller.PS, context.Steam.BtnSteam.Pressed(), 100);
|
context.DS4[DS4Controller.PS] = btnSteamPressed.GetValueOrDefault(false);
|
||||||
context.DS4[DS4Controller.Share] = context.Steam.BtnMenu;
|
context.DS4[DS4Controller.Share] = context.Steam.BtnMenu;
|
||||||
context.DS4[DS4Controller.Options] = context.Steam.BtnOptions;
|
context.DS4[DS4Controller.Options] = context.Steam.BtnOptions;
|
||||||
|
|
||||||
|
|
@ -85,8 +90,8 @@ namespace SteamController.Profiles.Predefined
|
||||||
|
|
||||||
// Accel & Gyro
|
// Accel & Gyro
|
||||||
context.DS4[DS4Controller.GyroX] = context.Steam.GyroPitch;
|
context.DS4[DS4Controller.GyroX] = context.Steam.GyroPitch;
|
||||||
context.DS4[DS4Controller.GyroY] = context.Steam.GyroRoll;
|
context.DS4[DS4Controller.GyroY] = context.Steam.GyroYaw;
|
||||||
context.DS4[DS4Controller.GyroZ] = context.Steam.GyroYaw;
|
context.DS4[DS4Controller.GyroZ] = context.Steam.GyroRoll;
|
||||||
context.DS4[DS4Controller.AccelX] = context.Steam.AccelX;
|
context.DS4[DS4Controller.AccelX] = context.Steam.AccelX;
|
||||||
context.DS4[DS4Controller.AccelY] = context.Steam.AccelY;
|
context.DS4[DS4Controller.AccelY] = context.Steam.AccelY;
|
||||||
context.DS4[DS4Controller.AccelZ] = context.Steam.AccelZ;
|
context.DS4[DS4Controller.AccelZ] = context.Steam.AccelZ;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue