Skip to content

Commit c917067

Browse files
committed
Power plan / freq update independent with registry
1 parent daa95a2 commit c917067

File tree

3 files changed

+49
-4
lines changed

3 files changed

+49
-4
lines changed

LenovoFanManagementApp/DellFanManagementGuiForm.Designer.cs

Lines changed: 15 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

LenovoFanManagementApp/DellFanManagementGuiForm.cs

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ public partial class DellFanManagementGuiForm : Form
8080
private int _prevStartChargeIndex;
8181
private int _prevStopChargeIndex;
8282

83+
private Guid _activePlan;
84+
8385
/// <summary>
8486
/// Constructor. Get everything set up before the window is displayed.
8587
/// </summary>
@@ -455,9 +457,7 @@ private void ApplyConfiguration()
455457
DCCpuFreqTextBox.Text = DCCpuFreq.ToString();
456458
}
457459

458-
// Power schemes
459460
/*
460-
Guid activePlan = PowerManager.GetActivePlan();
461461
List<Guid> plans = PowerManager.ListPlans();
462462
for (int i = 0; i < plans.Count; i++)
463463
{
@@ -845,6 +845,23 @@ public void UpdateForm()
845845
}
846846
}
847847

848+
// Power schemes (Always monitoring current actived power scheme)
849+
Guid activePlan = PowerManager.GetActivePlan();
850+
if (activePlan != _activePlan)
851+
{
852+
_activePlan = activePlan;
853+
activePowerPlanLabel.Text = "(当前电源计划:" + PowerManager.GetPlanName(activePlan) + ")";
854+
uint acFreqMax = PowerManager.GetPlanSetting(activePlan, SettingSubgroup.PROCESSOR_SETTINGS_SUBGROUP, Setting.PROCFREQMAX, PowerMode.AC);
855+
uint dcFreqMax = PowerManager.GetPlanSetting(activePlan, SettingSubgroup.PROCESSOR_SETTINGS_SUBGROUP, Setting.PROCFREQMAX, PowerMode.DC);
856+
uint acFreqMax1 = PowerManager.GetPlanSetting(activePlan, SettingSubgroup.PROCESSOR_SETTINGS_SUBGROUP, Setting.PROCFREQMAX1, PowerMode.AC);
857+
uint dcFreqMax1 = PowerManager.GetPlanSetting(activePlan, SettingSubgroup.PROCESSOR_SETTINGS_SUBGROUP, Setting.PROCFREQMAX1, PowerMode.DC);
858+
859+
ACCpuFreqTextBox.Text = acFreqMax.ToString();
860+
ACCpuFreq1TextBox.Text = acFreqMax1.ToString();
861+
DCCpuFreqTextBox.Text = dcFreqMax.ToString();
862+
DCCpuFreq1TextBox.Text = dcFreqMax1.ToString();
863+
}
864+
848865
_state.Release();
849866

850867
if (bringBackAudioDevice != null)
@@ -1279,6 +1296,7 @@ private void ApplyCpuFreqButtonClickedEventHandler(Object sender, EventArgs e)
12791296
try
12801297
{
12811298
// P-cores
1299+
/*
12821300
Process p = new Process();
12831301
p.StartInfo.FileName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "powercfg.exe");
12841302
p.StartInfo.Arguments = " /setDCvalueindex scheme_current SUB_PROCESSOR PROCFREQMAX1 " + (DCCpuFreq1TextBox.Text == "" ? "0" : DCCpuFreq1TextBox.Text);
@@ -1311,6 +1329,17 @@ private void ApplyCpuFreqButtonClickedEventHandler(Object sender, EventArgs e)
13111329
p.Start();
13121330
p.WaitForExit();
13131331
p.Close();
1332+
*/
1333+
Guid activePlan = PowerManager.GetActivePlan();
1334+
uint acFreq1 = (ACCpuFreq1TextBox.Text == "") ? 0 : uint.Parse(ACCpuFreq1TextBox.Text);
1335+
uint dcFreq1 = (DCCpuFreq1TextBox.Text == "") ? 0 : uint.Parse(DCCpuFreq1TextBox.Text);
1336+
uint acFreq = (ACCpuFreqTextBox.Text == "") ? 0 : uint.Parse(ACCpuFreqTextBox.Text);
1337+
uint dcFreq = (DCCpuFreqTextBox.Text == "") ? 0 : uint.Parse(DCCpuFreqTextBox.Text);
1338+
PowerManager.SetPlanSetting(activePlan, SettingSubgroup.PROCESSOR_SETTINGS_SUBGROUP, Setting.PROCFREQMAX1, PowerMode.AC, acFreq1);
1339+
PowerManager.SetPlanSetting(activePlan, SettingSubgroup.PROCESSOR_SETTINGS_SUBGROUP, Setting.PROCFREQMAX1, PowerMode.DC, dcFreq1);
1340+
PowerManager.SetPlanSetting(activePlan, SettingSubgroup.PROCESSOR_SETTINGS_SUBGROUP, Setting.PROCFREQMAX, PowerMode.AC, acFreq);
1341+
PowerManager.SetPlanSetting(activePlan, SettingSubgroup.PROCESSOR_SETTINGS_SUBGROUP, Setting.PROCFREQMAX, PowerMode.DC, dcFreq);
1342+
PowerManager.SetActivePlan(activePlan);
13141343

13151344
bool success = int.TryParse(ACCpuFreq1TextBox.Text, out int ACCpuFreq1);
13161345
//if (success)

PowerManagerAPI/SettingIdLookup.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public enum Setting
4545
DISKIDLE,
4646
ASPM,
4747
PROCFREQMAX,
48+
PROCFREQMAX1,
4849
PROCTHROTTLEMAX,
4950
PROCTHROTTLEMIN,
5051
SYSCOOLPOL,
@@ -83,7 +84,8 @@ public static class SettingIdLookup
8384
{ Setting.UIBUTTON_ACTION, new Guid("a7066653-8d6c-40a8-910e-a1f54b84c7e5") },
8485
{ Setting.DISKIDLE, new Guid("6738e2c4-e8a5-4a42-b16a-e040e769756e") },
8586
{ Setting.ASPM, new Guid("ee12f906-d277-404b-b6da-e5fa1a576df5") },
86-
{ Setting.PROCFREQMAX, new Guid("75b0ae3f-bce0-45a7-8c89-c9611c25e100") },
87+
{ Setting.PROCFREQMAX, new Guid("75b0ae3f-bce0-45a7-8c89-c9611c25e100") }, // E-Core
88+
{ Setting.PROCFREQMAX1, new Guid("75b0ae3f-bce0-45a7-8c89-c9611c25e101") }, // P-Core
8789
{ Setting.PROCTHROTTLEMAX, new Guid("bc5038f7-23e0-4960-96da-33abaf5935ec") },
8890
{ Setting.PROCTHROTTLEMIN, new Guid("893dee8e-2bef-41e0-89c6-b55d0929964c") },
8991
{ Setting.SYSCOOLPOL, new Guid("94d3a615-a899-4ac5-ae2b-e4d8f634367f") },

0 commit comments

Comments
 (0)