steam-deck-tools/SteamController/Devices/SteamControllerLizard.cs
Kamil Trzciński ecbd0407c0 Add SteamController implementation
This adds a Steam Shortcuts, Desktop Mode, and X360 Emulation
- Supports all Steam Shortcuts (including on-screen keyboard, and brightness)
- Supports Desktop mode (with a scroll on left pad and left stick), and trackpoint (on right stick)
- Supports X360 mode: hold Options for 1s to switch between Desktop and X360
- Holding Steam button enables Desktop like controls and stops passing all inputs to X360
2022-11-26 10:19:50 +01:00

74 lines
2.5 KiB
C#

using hidapi;
using PowerControl.External;
using static CommonHelpers.Log;
namespace SteamController.Devices
{
public partial class SteamController
{
public const int LizardModeUpdateInterval = 250;
public bool LizardMouse { get; set; } = true;
public bool LizardButtons { get; set; } = true;
private bool? savedLizardMouse;
private bool? savedLizardButtons;
private DateTime lizardMouseUpdated = DateTime.Now;
private DateTime lizardButtonUpdated = DateTime.Now;
private void UpdateLizardMouse()
{
if (savedLizardMouse == LizardMouse)
{
// We need to explicitly disable lizard every some time
// but don't fight enabling it, as someone else might be taking control (Steam?)
if (LizardMouse || lizardMouseUpdated.AddMilliseconds(LizardModeUpdateInterval) > DateTime.Now)
return;
}
if (LizardMouse)
{
//Enable mouse emulation
byte[] data = new byte[] { 0x8e, 0x00 };
neptuneDevice.RequestFeatureReport(data);
}
else
{
//Disable mouse emulation
byte[] data = new byte[] { 0x87, 0x03, 0x08, 0x07 };
neptuneDevice.RequestFeatureReport(data);
}
savedLizardMouse = LizardMouse;
lizardMouseUpdated = DateTime.Now;
}
private void UpdateLizardButtons()
{
if (savedLizardButtons == LizardButtons)
{
// We need to explicitly disable lizard every some time
// but don't fight enabling it, as someone else might be taking control (Steam?)
if (LizardButtons || lizardButtonUpdated.AddMilliseconds(LizardModeUpdateInterval) > DateTime.Now)
return;
}
if (LizardButtons)
{
//Enable keyboard/mouse button emulation
byte[] data = new byte[] { 0x85, 0x00 };
neptuneDevice.RequestFeatureReport(data);
}
else
{
//Disable keyboard/mouse button emulation
byte[] data = new byte[] { 0x81, 0x00 };
neptuneDevice.RequestFeatureReport(data);
}
savedLizardButtons = LizardButtons;
lizardButtonUpdated = DateTime.Now;
}
}
}