Add haptic style setting (disabled, weak, strong)

This commit is contained in:
Kamil Trzciński 2022-12-05 18:35:25 +01:00
parent 0e92640085
commit d4b8a09395
4 changed files with 49 additions and 20 deletions

View file

@ -27,3 +27,4 @@ It does help this project on being supported.
- Allow to select between touch keyboard or CTRL+WIN+O
- Fix haptics not being fired both sides
- Scale haptic intensity
- Add haptic style setting (disabled, weak, strong)

View file

@ -51,43 +51,62 @@ namespace SteamController.Devices
{
public byte packet_type = 0xea;
public byte len = 0xd;
public byte position = 0x00;
public byte amplitude = 0x2; //
public HapticPad position = HapticPad.Left;
public HapticStyle style = HapticStyle.Strong; //
public byte unsure2 = 0x0;
public sbyte intensity = 0x00; // -7..5 => -2dB..10dB
public byte unsure3 = 0x4;
public int tsA = 0; // timestamp?
public int tsB = 0;
public SDCHapticPacket2() { }
public SDCHapticPacket2()
{
var ts = Random.Shared.Next();
this.tsA = ts;
this.tsB = ts;
}
public SDCHapticPacket2(HapticPad position, HapticStyle style, sbyte intensityDB) : this()
{
this.position = position;
this.style = style;
this.intensity = (sbyte)(intensityDB - 5); // convert from dB to values
}
}
private Task?[] hapticTask = new Task?[byte.MaxValue];
private Dictionary<HapticPad, Task?> hapticTasks = new Dictionary<HapticPad, Task?>();
public bool SendHaptic(byte position, sbyte intensity)
public enum HapticPad : byte
{
if (hapticTask[position]?.IsCompleted == false)
Left,
Right
};
public enum HapticStyle : byte
{
Disabled = 0,
Weak = 1,
Strong = 2
};
public bool SendHaptic(HapticPad position, HapticStyle style, sbyte intensityDB)
{
if (hapticTasks.GetValueOrDefault(position)?.IsCompleted == false)
return false;
if (style == HapticStyle.Disabled)
return true;
var ts = Random.Shared.Next();
var haptic = new SDCHapticPacket2(position, style, intensityDB);
var haptic = new SDCHapticPacket2()
{
position = position,
intensity = (sbyte)(intensity - 5), // convert from dB to values
tsA = ts,
tsB = ts
};
Log.TraceLine("STEAM: Haptic: pos={0}, intensity={1}",
position, intensity);
Log.TraceLine("STEAM: Haptic: position={0}, style={1}, intensity={2}",
position, style, intensityDB);
var bytes = new byte[Marshal.SizeOf<SDCHapticPacket2>()];
var handle = GCHandle.Alloc(bytes, GCHandleType.Pinned);
try
{
Marshal.StructureToPtr(haptic, handle.AddrOfPinnedObject(), false);
hapticTask[position] = neptuneDevice.RequestFeatureReportAsync(bytes);
hapticTasks[position] = neptuneDevice.RequestFeatureReportAsync(bytes);
return true;
}
catch (Exception e)

View file

@ -1,4 +1,5 @@
using SteamController.ProfilesSettings;
using HapticPad = SteamController.Devices.SteamController.HapticPad;
namespace SteamController.Profiles
{
@ -15,10 +16,10 @@ namespace SteamController.Profiles
return Status.Done;
if (GetHapticIntensity(context.X360.FeedbackLargeMotor, HapticSettings.LeftIntensity, out var leftIntensity))
context.Steam.SendHaptic(1, leftIntensity);
context.Steam.SendHaptic(HapticPad.Right, HapticSettings.HapticStyle, leftIntensity);
if (GetHapticIntensity(context.X360.FeedbackSmallMotor, HapticSettings.RightIntensity, out var rightIntensity))
context.Steam.SendHaptic(0, rightIntensity);
context.Steam.SendHaptic(HapticPad.Left, HapticSettings.HapticStyle, rightIntensity);
context.X360.ResetFeedback();

View file

@ -17,6 +17,14 @@ namespace SteamController.ProfilesSettings
{
}
[UserScopedSettingAttribute()]
[DefaultSettingValueAttribute("Weak")]
public Devices.SteamController.HapticStyle HapticStyle
{
get { return ((Devices.SteamController.HapticStyle)(this["HapticStyle"])); }
set { this["HapticStyle"] = value; }
}
[UserScopedSettingAttribute()]
[DefaultSettingValueAttribute("5")]
[Description("Haptic intensity between -2dB and 10dB")]