From ec81827a2a295d2af12c7438635cf2eb4499d391 Mon Sep 17 00:00:00 2001
From: Plasmid <22126651+PlasmidEve@users.noreply.github.com>
Date: Sun, 2 Jun 2024 01:14:41 -0500
Subject: [PATCH 1/2] Add 80% battery charge limit for Legion Go
---
HandheldCompanion/App.config | 3 ++
HandheldCompanion/Devices/Lenovo/LegionGo.cs | 30 +++++++++++++++
.../Properties/Resources.Designer.cs | 18 +++++++++
HandheldCompanion/Properties/Resources.resx | 6 +++
.../Properties/Settings.Designer.cs | 15 ++++++++
.../Properties/Settings.settings | 3 ++
HandheldCompanion/Views/Pages/AboutPage.xaml | 2 +-
HandheldCompanion/Views/Pages/DevicePage.xaml | 38 +++++++++++++++++++
.../Views/Pages/DevicePage.xaml.cs | 8 ++++
9 files changed, 122 insertions(+), 1 deletion(-)
diff --git a/HandheldCompanion/App.config b/HandheldCompanion/App.config
index 87f62a2e7..2269c726b 100644
--- a/HandheldCompanion/App.config
+++ b/HandheldCompanion/App.config
@@ -275,6 +275,9 @@
0
+
+ False
+
\ No newline at end of file
diff --git a/HandheldCompanion/Devices/Lenovo/LegionGo.cs b/HandheldCompanion/Devices/Lenovo/LegionGo.cs
index a3c5f54e0..87e4cebc6 100644
--- a/HandheldCompanion/Devices/Lenovo/LegionGo.cs
+++ b/HandheldCompanion/Devices/Lenovo/LegionGo.cs
@@ -97,6 +97,18 @@ public Task SetCPUPowerLimit(CapabilityID capabilityID, int limit) =>
{ "value", limit },
});
+ // InstantBootAc (0x03010001) controls the 80% power charge limit.
+ // https://github.com/aarron-lee/LegionGoRemapper/blob/ab823f2042fc857cca856687a385a033d68c58bf/py_modules/legion_space.py#L138
+ public Task SetBatteryChargeLimit(bool enabled) =>
+ WMI.CallAsync("root\\WMI",
+ $"SELECT * FROM LENOVO_OTHER_METHOD",
+ "SetFeatureValue",
+ new()
+ {
+ { "IDs", (int)CapabilityID.InstantBootAc },
+ { "value", enabled ? 1 : 0 },
+ });
+
public const byte INPUT_HID_ID = 0x04;
public override bool IsOpen => hidDevices.ContainsKey(INPUT_HID_ID) && hidDevices[INPUT_HID_ID].IsOpen;
@@ -211,6 +223,9 @@ public LegionGo()
DefaultLayout.ButtonLayout[ButtonFlags.B7] = new List() { new MouseActions { MouseType = MouseActionsType.ScrollUp } };
DefaultLayout.ButtonLayout[ButtonFlags.B8] = new List() { new MouseActions { MouseType = MouseActionsType.ScrollDown } };
+ SettingsManager.SettingValueChanged += SettingsManager_SettingValueChanged;
+ UpdateSettings();
+
/*
Task task = Task.Run(async () => await GetFanFullSpeedAsync());
bool FanFullSpeed = task.Result;
@@ -427,4 +442,19 @@ public override string GetGlyph(ButtonFlags button)
return defaultGlyph;
}
+
+ protected void UpdateSettings()
+ {
+ SetBatteryChargeLimit(SettingsManager.GetBoolean("LegionBatteryChargeLimit"));
+ }
+
+ private void SettingsManager_SettingValueChanged(string name, object value)
+ {
+ switch (name)
+ {
+ case "LegionBatteryChargeLimit":
+ SetBatteryChargeLimit(Convert.ToBoolean(value));
+ break;
+ }
+ }
}
\ No newline at end of file
diff --git a/HandheldCompanion/Properties/Resources.Designer.cs b/HandheldCompanion/Properties/Resources.Designer.cs
index f0db7f3b8..4dedb8854 100644
--- a/HandheldCompanion/Properties/Resources.Designer.cs
+++ b/HandheldCompanion/Properties/Resources.Designer.cs
@@ -1069,6 +1069,24 @@ public static string DevicePage_FullFanSpeedText {
}
}
+ ///
+ /// Looks up a localized string similar to 80% Battery Charge Limit.
+ ///
+ public static string DevicePage_LegionBatteryChargeLimit {
+ get {
+ return ResourceManager.GetString("DevicePage_LegionBatteryChargeLimit", resourceCulture);
+ }
+ }
+
+ ///
+ /// Looks up a localized string similar to Sets the maximum charge level of the battery to 80%.
+ ///
+ public static string DevicePage_LegionBatteryChargeLimit_Desc {
+ get {
+ return ResourceManager.GetString("DevicePage_LegionBatteryChargeLimit_Desc", resourceCulture);
+ }
+ }
+
///
/// Looks up a localized string similar to Auto Sleep Time.
///
diff --git a/HandheldCompanion/Properties/Resources.resx b/HandheldCompanion/Properties/Resources.resx
index 06b43f3df..916b23624 100644
--- a/HandheldCompanion/Properties/Resources.resx
+++ b/HandheldCompanion/Properties/Resources.resx
@@ -2994,4 +2994,10 @@ Motion input toggle: press selected button(s) to switch motion state.
The best system settings that MSI recommends.
+
+ 80% Battery Charge Limit
+
+
+ Sets the maximum charge level of the battery to 80%
+
\ No newline at end of file
diff --git a/HandheldCompanion/Properties/Settings.Designer.cs b/HandheldCompanion/Properties/Settings.Designer.cs
index 558e82dda..426c698bf 100644
--- a/HandheldCompanion/Properties/Settings.Designer.cs
+++ b/HandheldCompanion/Properties/Settings.Designer.cs
@@ -1103,5 +1103,20 @@ public int LegionControllerGyroIndex {
this["LegionControllerGyroIndex"] = value;
}
}
+
+ [global::System.Configuration.UserScopedSettingAttribute()]
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ [global::System.Configuration.DefaultSettingValueAttribute("False")]
+ public bool LegionBatteryChargeLimit
+ {
+ get
+ {
+ return ((bool)(this["LegionBatteryChargeLimit"]));
+ }
+ set
+ {
+ this["LegionBatteryChargeLimit"] = value;
+ }
+ }
}
}
diff --git a/HandheldCompanion/Properties/Settings.settings b/HandheldCompanion/Properties/Settings.settings
index b1e4ad014..97b03d5e1 100644
--- a/HandheldCompanion/Properties/Settings.settings
+++ b/HandheldCompanion/Properties/Settings.settings
@@ -272,5 +272,8 @@
0
+
+ False
+
\ No newline at end of file
diff --git a/HandheldCompanion/Views/Pages/AboutPage.xaml b/HandheldCompanion/Views/Pages/AboutPage.xaml
index abcca9358..dab6d9735 100644
--- a/HandheldCompanion/Views/Pages/AboutPage.xaml
+++ b/HandheldCompanion/Views/Pages/AboutPage.xaml
@@ -193,7 +193,7 @@
Margin="0,0,0,5"
Foreground="{DynamicResource SystemControlForegroundBaseMediumBrush}"
Style="{StaticResource BodyTextBlockStyle}"
- Text="Nefarius, CasperH2O, B-Core, Frank东, Toomy, Havner, CoryManson, MSeys, ShadowFlare, trippyone, MiguelLedesmaC, Cheng77777, thororen1234, fighterguard, micdah, Geckon01, Bagboii, MeikoMenmaHonma, cerahmed, indiesaudi, Radther, Staubgeborener, twjmy, m33ts4k0z, howanghk, Creaous, xerootg, quangmach, MrCivsteR, 0SkillAllLuck, DevL0rd, romracer, JT" />
+ Text="Nefarius, CasperH2O, B-Core, Frank东, Toomy, Havner, CoryManson, MSeys, ShadowFlare, trippyone, MiguelLedesmaC, Cheng77777, thororen1234, fighterguard, micdah, Geckon01, Bagboii, MeikoMenmaHonma, cerahmed, indiesaudi, Radther, Staubgeborener, twjmy, m33ts4k0z, howanghk, Creaous, xerootg, quangmach, MrCivsteR, 0SkillAllLuck, DevL0rd, romracer, JT, PlasmidEve" />
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Date: Tue, 4 Jun 2024 12:19:24 +0200
Subject: [PATCH 2/2] removed UpdateSettings()
not needed, SettingsManager will iterate through all settings on startup anyway
---
HandheldCompanion/Devices/Lenovo/LegionGo.cs | 11 -----------
1 file changed, 11 deletions(-)
diff --git a/HandheldCompanion/Devices/Lenovo/LegionGo.cs b/HandheldCompanion/Devices/Lenovo/LegionGo.cs
index 87e4cebc6..d968a14ca 100644
--- a/HandheldCompanion/Devices/Lenovo/LegionGo.cs
+++ b/HandheldCompanion/Devices/Lenovo/LegionGo.cs
@@ -224,12 +224,6 @@ public LegionGo()
DefaultLayout.ButtonLayout[ButtonFlags.B8] = new List() { new MouseActions { MouseType = MouseActionsType.ScrollDown } };
SettingsManager.SettingValueChanged += SettingsManager_SettingValueChanged;
- UpdateSettings();
-
- /*
- Task task = Task.Run(async () => await GetFanFullSpeedAsync());
- bool FanFullSpeed = task.Result;
- */
}
private void PowerProfileManager_Applied(PowerProfile profile, UpdateSource source)
@@ -443,11 +437,6 @@ public override string GetGlyph(ButtonFlags button)
return defaultGlyph;
}
- protected void UpdateSettings()
- {
- SetBatteryChargeLimit(SettingsManager.GetBoolean("LegionBatteryChargeLimit"));
- }
-
private void SettingsManager_SettingValueChanged(string name, object value)
{
switch (name)