Skip to content

Commit 253c75a

Browse files
committed
Fix support for Lizard Mode
1 parent deee7fa commit 253c75a

File tree

1 file changed

+49
-14
lines changed

1 file changed

+49
-14
lines changed

SteamController/Devices/SteamControllerLizard.cs

Lines changed: 49 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,22 @@ namespace SteamController.Devices
66
{
77
public partial class SteamController
88
{
9+
// Based on: https://github.com/torvalds/linux/blob/master/drivers/hid/hid-steam.c
10+
public const byte ID_SET_DIGITAL_MAPPINGS = 0x80;
11+
public const byte ID_CLEAR_DIGITAL_MAPPINGS = 0x81;
12+
public const byte ID_SET_DEFAULT_DIGITAL_MAPPINGS = 0x85;
13+
public const byte ID_FACTORY_RESET = 0x86;
14+
public const byte ID_SET_SETTINGS_VALUES = 0x87;
15+
public const byte ID_DEFAULT_MAPPINGS = 0x8e;
16+
17+
public const byte SETTING_LEFT_TRACKPAD_MODE = 7;
18+
public const byte SETTING_RIGHT_TRACKPAD_MODE = 8;
19+
public const byte SETTING_LEFT_TRACKPAD_CLICK_PRESSURE = 52;
20+
public const byte SETTING_RIGHT_TRACKPAD_CLICK_PRESSURE = 53;
21+
public const byte SETTING_STEAM_WATCHDOG_ENABLE = 71;
22+
23+
public const ushort TRACKPAD_NONE = 7;
24+
925
private const int LizardModeUpdateInterval = 250;
1026

1127
public bool LizardMouse { get; set; } = true;
@@ -29,17 +45,20 @@ private void UpdateLizardMouse()
2945
savedLizardMouse = LizardMouse;
3046
lizardMouseUpdated = DateTime.Now;
3147

48+
// Enable or disable mouse emulation
3249
if (LizardMouse)
3350
{
34-
//Enable mouse emulation
35-
byte[] data = new byte[] { 0x8e, 0x00 };
36-
neptuneDevice.RequestFeatureReport(data);
51+
SendFeatureByte(ID_DEFAULT_MAPPINGS);
3752
}
3853
else
3954
{
40-
//Disable mouse emulation
41-
byte[] data = new byte[] { 0x87, 0x03, 0x08, 0x07 };
42-
neptuneDevice.RequestFeatureReport(data);
55+
SendSettings(
56+
(SETTING_LEFT_TRACKPAD_MODE, TRACKPAD_NONE), // disable mouse
57+
(SETTING_RIGHT_TRACKPAD_MODE, TRACKPAD_NONE), // disable mouse
58+
(SETTING_LEFT_TRACKPAD_CLICK_PRESSURE, 0xFFFF), // disable haptic click
59+
(SETTING_RIGHT_TRACKPAD_CLICK_PRESSURE, 0xFFFF), // disable haptic click
60+
(SETTING_STEAM_WATCHDOG_ENABLE, 0) // disable watchdog that tests if Steam is active
61+
);
4362
}
4463
}
4564

@@ -56,18 +75,34 @@ private void UpdateLizardButtons()
5675
savedLizardButtons = LizardButtons;
5776
lizardButtonUpdated = DateTime.Now;
5877

78+
// Enable / Disable esc, enter, cursors
5979
if (LizardButtons)
60-
{
61-
//Enable keyboard/mouse button emulation
62-
byte[] data = new byte[] { 0x85, 0x00 };
63-
neptuneDevice.RequestFeatureReport(data);
64-
}
80+
SendFeatureByte(ID_SET_DEFAULT_DIGITAL_MAPPINGS);
6581
else
82+
SendFeatureByte(ID_CLEAR_DIGITAL_MAPPINGS);
83+
}
84+
85+
private void SendFeatureByte(byte b)
86+
{
87+
neptuneDevice.RequestFeatureReport(new byte[] { b, 0 });
88+
}
89+
90+
private void SendSettings(params (byte setting, ushort val)[] settings)
91+
{
92+
// Format: 0x87 len (reg valLo valHi)*
93+
byte[] cmd = new byte[2 + settings.Length * 3];
94+
cmd[0] = ID_SET_SETTINGS_VALUES;
95+
cmd[1] = (byte)(settings.Length * 3); // length
96+
97+
int length = 2;
98+
foreach (var (setting, val) in settings)
6699
{
67-
//Disable keyboard/mouse button emulation
68-
byte[] data = new byte[] { 0x81, 0x00 };
69-
neptuneDevice.RequestFeatureReport(data);
100+
cmd[length++] = (byte)setting;
101+
cmd[length++] = (byte)(val & 0xFF);
102+
cmd[length++] = (byte)(val >> 8);
70103
}
104+
105+
neptuneDevice.RequestFeatureReport(cmd);
71106
}
72107
}
73108
}

0 commit comments

Comments
 (0)