Skip to content

Commit 874cf6f

Browse files
committed
PowerControl: Add Charge Limit
1 parent b47c5fa commit 874cf6f

File tree

4 files changed

+61
-3
lines changed

4 files changed

+61
-3
lines changed

CommonHelpers/Vlv0100.cs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public class Vlv0100 : IDisposable
1515
static IntPtr PDFV = new IntPtr(0xFE700C00 + 0x4C);
1616
static IntPtr XBID = new IntPtr(0xFE700300 + 0xBD);
1717
static IntPtr PDCT = new IntPtr(0xFE700C00 + 0x01);
18+
static IntPtr MCBL = new IntPtr(0xFE700B00 + 0x9F);
1819
static ushort IO6C = 0x6C;
1920

2021
public const ushort MAX_FAN_RPM = 0x1C84;
@@ -26,6 +27,7 @@ public struct DeviceVersion
2627
public byte PDCS { get; set; }
2728

2829
public bool BatteryTempLE { get; set; }
30+
public bool MaxBatteryCharge { get; set; }
2931

3032
public bool IsSupported(ushort deviceFirmware, byte deviceBoardID, byte devicePDCS)
3133
{
@@ -42,11 +44,11 @@ public bool IsSupported(ushort deviceFirmware, byte deviceBoardID, byte devicePD
4244
private static readonly DeviceVersion[] deviceVersions = {
4345
// Steam Deck - LCD version
4446
new DeviceVersion() { Firmware = 0xB030, BoardID = 0x6, PDCS = 0 /* 0x2B */, BatteryTempLE = false },
45-
new DeviceVersion() { Firmware = 0xB030, BoardID = 0xA, PDCS = 0 /* 0x2B */, BatteryTempLE = false },
47+
new DeviceVersion() { Firmware = 0xB030, BoardID = 0xA, PDCS = 0 /* 0x2B */, BatteryTempLE = false, MaxBatteryCharge = true },
4648

4749
// Steam Deck - OLED version
4850
// new DeviceVersion() { Firmware = 0x1030, BoardID = 0x5, PDCS = 0 /* 0x2F */, BatteryTempLE = true },
49-
new DeviceVersion() { Firmware = 0x1050, BoardID = 0x5, PDCS = 0 /* 0x2F */, BatteryTempLE = true }
51+
new DeviceVersion() { Firmware = 0x1050, BoardID = 0x5, PDCS = 0 /* 0x2F */, BatteryTempLE = true, MaxBatteryCharge = true }
5052
};
5153

5254
public static Vlv0100 Instance = new Vlv0100();
@@ -178,6 +180,27 @@ public float GetBattTemperature()
178180
return (float)(value - 0x0AAC) / 10.0f;
179181
}
180182

183+
public int? GetMaxBatteryCharge()
184+
{
185+
if (SupportedDevice?.MaxBatteryCharge != true)
186+
return null;
187+
var data = inpOut?.ReadMemory(MCBL, 1);
188+
if (data is null)
189+
return null;
190+
if (data[0] > 100)
191+
return null;
192+
return data[0];
193+
}
194+
public void SetMaxBatteryCharge(int chargeLimit)
195+
{
196+
if (SupportedDevice?.MaxBatteryCharge != true)
197+
return;
198+
if (chargeLimit < 0 || chargeLimit > 100)
199+
return;
200+
byte[] data = BitConverter.GetBytes(chargeLimit);
201+
inpOut?.WriteMemory(MCBL, data);
202+
}
203+
181204
private void SetGain(ushort gain)
182205
{
183206
byte[] data = BitConverter.GetBytes(gain);

PowerControl/MenuStack.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ internal class MenuStack
3636
Options.PerformanceOverlay.ModeInstance,
3737
Options.PerformanceOverlay.KernelDriversInstance,
3838
Options.FanControl.Instance,
39-
Options.SteamController.Instance
39+
Options.SteamController.Instance,
40+
Options.BatteryChargeLimit.Instance
4041
}
4142
};
4243

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using CommonHelpers;
2+
3+
namespace PowerControl.Options
4+
{
5+
public static class BatteryChargeLimit
6+
{
7+
public static Menu.MenuItemWithOptions Instance = new Menu.MenuItemWithOptions()
8+
{
9+
Name = "Charge Limit",
10+
ApplyDelay = 1000,
11+
Options = { "70%", "80%", "90%", "100%" },
12+
ActiveOption = "?",
13+
ApplyValue = (selected) =>
14+
{
15+
var value = int.Parse(selected.ToString().TrimEnd('%'));
16+
17+
using (var vlv0100 = new Vlv0100())
18+
{
19+
if (!vlv0100.Open())
20+
return null;
21+
22+
vlv0100.SetMaxBatteryCharge(value);
23+
24+
var newValue = vlv0100.GetMaxBatteryCharge();
25+
if (newValue is null)
26+
return null;
27+
return newValue.ToString() + "%";
28+
}
29+
}
30+
};
31+
}
32+
}

RELEASE.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
## #{GIT_TAG_NAME}
88

9+
- PowerControl: Add Charge Limit (70%, 80%, 90%, 100%)
10+
911
## 0.7.1
1012

1113
- SteamDeck OLED: Support BIOS 107 with temperature readings

0 commit comments

Comments
 (0)