mirror of
https://github.com/ayufan/steam-deck-tools.git
synced 2026-04-05 06:15:26 +00:00
Do not send repeated haptic if disabled
This commit is contained in:
parent
7c559e58f7
commit
e52459d02d
3 changed files with 18 additions and 3 deletions
|
|
@ -8,7 +8,9 @@ namespace SteamController.Devices
|
|||
{
|
||||
public partial class SteamController
|
||||
{
|
||||
public bool SetHaptic(byte position, ushort amplitude, ushort period, ushort count = 0)
|
||||
private bool[] hapticEnabled = new bool[byte.MaxValue];
|
||||
|
||||
private bool sendHaptic(byte position, ushort amplitude, ushort period, ushort count = 0)
|
||||
{
|
||||
var haptic = new SDCHapticPacket()
|
||||
{
|
||||
|
|
@ -20,6 +22,9 @@ namespace SteamController.Devices
|
|||
count = count
|
||||
};
|
||||
|
||||
Log.TraceLine("STEAM: Haptic: pos={0}, amplitude={1}, period={2}, count={3}",
|
||||
position, amplitude, period, count);
|
||||
|
||||
var bytes = new byte[Marshal.SizeOf<SDCHapticPacket>()];
|
||||
var handle = GCHandle.Alloc(bytes, GCHandleType.Pinned);
|
||||
try
|
||||
|
|
@ -34,5 +39,16 @@ namespace SteamController.Devices
|
|||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public bool SetHaptic(byte position, ushort amplitude, ushort period, ushort count = 0)
|
||||
{
|
||||
// do not send repeated haptic queries if was disabled
|
||||
bool enabled = amplitude != 0 && period != 0;
|
||||
if (!hapticEnabled[position] && !enabled)
|
||||
return false;
|
||||
hapticEnabled[position] = enabled;
|
||||
|
||||
return sendHaptic(position, amplitude, period, count);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue