Skip to content

Commit

Permalink
Power plan / freq update independent with registry
Browse files Browse the repository at this point in the history
  • Loading branch information
simonchen committed Apr 22, 2024
1 parent daa95a2 commit c917067
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 4 deletions.
16 changes: 15 additions & 1 deletion LenovoFanManagementApp/DellFanManagementGuiForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 31 additions & 2 deletions LenovoFanManagementApp/DellFanManagementGuiForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ public partial class DellFanManagementGuiForm : Form
private int _prevStartChargeIndex;
private int _prevStopChargeIndex;

private Guid _activePlan;

/// <summary>
/// Constructor. Get everything set up before the window is displayed.
/// </summary>
Expand Down Expand Up @@ -455,9 +457,7 @@ private void ApplyConfiguration()
DCCpuFreqTextBox.Text = DCCpuFreq.ToString();
}

// Power schemes
/*
Guid activePlan = PowerManager.GetActivePlan();
List<Guid> plans = PowerManager.ListPlans();
for (int i = 0; i < plans.Count; i++)
{
Expand Down Expand Up @@ -845,6 +845,23 @@ public void UpdateForm()
}
}

// Power schemes (Always monitoring current actived power scheme)
Guid activePlan = PowerManager.GetActivePlan();
if (activePlan != _activePlan)
{
_activePlan = activePlan;
activePowerPlanLabel.Text = "(当前电源计划:" + PowerManager.GetPlanName(activePlan) + ")";
uint acFreqMax = PowerManager.GetPlanSetting(activePlan, SettingSubgroup.PROCESSOR_SETTINGS_SUBGROUP, Setting.PROCFREQMAX, PowerMode.AC);
uint dcFreqMax = PowerManager.GetPlanSetting(activePlan, SettingSubgroup.PROCESSOR_SETTINGS_SUBGROUP, Setting.PROCFREQMAX, PowerMode.DC);
uint acFreqMax1 = PowerManager.GetPlanSetting(activePlan, SettingSubgroup.PROCESSOR_SETTINGS_SUBGROUP, Setting.PROCFREQMAX1, PowerMode.AC);
uint dcFreqMax1 = PowerManager.GetPlanSetting(activePlan, SettingSubgroup.PROCESSOR_SETTINGS_SUBGROUP, Setting.PROCFREQMAX1, PowerMode.DC);

ACCpuFreqTextBox.Text = acFreqMax.ToString();
ACCpuFreq1TextBox.Text = acFreqMax1.ToString();
DCCpuFreqTextBox.Text = dcFreqMax.ToString();
DCCpuFreq1TextBox.Text = dcFreqMax1.ToString();
}

_state.Release();

if (bringBackAudioDevice != null)
Expand Down Expand Up @@ -1279,6 +1296,7 @@ private void ApplyCpuFreqButtonClickedEventHandler(Object sender, EventArgs e)
try
{
// P-cores
/*
Process p = new Process();
p.StartInfo.FileName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "powercfg.exe");
p.StartInfo.Arguments = " /setDCvalueindex scheme_current SUB_PROCESSOR PROCFREQMAX1 " + (DCCpuFreq1TextBox.Text == "" ? "0" : DCCpuFreq1TextBox.Text);
Expand Down Expand Up @@ -1311,6 +1329,17 @@ private void ApplyCpuFreqButtonClickedEventHandler(Object sender, EventArgs e)
p.Start();
p.WaitForExit();
p.Close();
*/
Guid activePlan = PowerManager.GetActivePlan();
uint acFreq1 = (ACCpuFreq1TextBox.Text == "") ? 0 : uint.Parse(ACCpuFreq1TextBox.Text);
uint dcFreq1 = (DCCpuFreq1TextBox.Text == "") ? 0 : uint.Parse(DCCpuFreq1TextBox.Text);
uint acFreq = (ACCpuFreqTextBox.Text == "") ? 0 : uint.Parse(ACCpuFreqTextBox.Text);
uint dcFreq = (DCCpuFreqTextBox.Text == "") ? 0 : uint.Parse(DCCpuFreqTextBox.Text);
PowerManager.SetPlanSetting(activePlan, SettingSubgroup.PROCESSOR_SETTINGS_SUBGROUP, Setting.PROCFREQMAX1, PowerMode.AC, acFreq1);
PowerManager.SetPlanSetting(activePlan, SettingSubgroup.PROCESSOR_SETTINGS_SUBGROUP, Setting.PROCFREQMAX1, PowerMode.DC, dcFreq1);
PowerManager.SetPlanSetting(activePlan, SettingSubgroup.PROCESSOR_SETTINGS_SUBGROUP, Setting.PROCFREQMAX, PowerMode.AC, acFreq);
PowerManager.SetPlanSetting(activePlan, SettingSubgroup.PROCESSOR_SETTINGS_SUBGROUP, Setting.PROCFREQMAX, PowerMode.DC, dcFreq);
PowerManager.SetActivePlan(activePlan);

bool success = int.TryParse(ACCpuFreq1TextBox.Text, out int ACCpuFreq1);
//if (success)
Expand Down
4 changes: 3 additions & 1 deletion PowerManagerAPI/SettingIdLookup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public enum Setting
DISKIDLE,
ASPM,
PROCFREQMAX,
PROCFREQMAX1,
PROCTHROTTLEMAX,
PROCTHROTTLEMIN,
SYSCOOLPOL,
Expand Down Expand Up @@ -83,7 +84,8 @@ public static class SettingIdLookup
{ Setting.UIBUTTON_ACTION, new Guid("a7066653-8d6c-40a8-910e-a1f54b84c7e5") },
{ Setting.DISKIDLE, new Guid("6738e2c4-e8a5-4a42-b16a-e040e769756e") },
{ Setting.ASPM, new Guid("ee12f906-d277-404b-b6da-e5fa1a576df5") },
{ Setting.PROCFREQMAX, new Guid("75b0ae3f-bce0-45a7-8c89-c9611c25e100") },
{ Setting.PROCFREQMAX, new Guid("75b0ae3f-bce0-45a7-8c89-c9611c25e100") }, // E-Core
{ Setting.PROCFREQMAX1, new Guid("75b0ae3f-bce0-45a7-8c89-c9611c25e101") }, // P-Core
{ Setting.PROCTHROTTLEMAX, new Guid("bc5038f7-23e0-4960-96da-33abaf5935ec") },
{ Setting.PROCTHROTTLEMIN, new Guid("893dee8e-2bef-41e0-89c6-b55d0929964c") },
{ Setting.SYSCOOLPOL, new Guid("94d3a615-a899-4ac5-ae2b-e4d8f634367f") },
Expand Down

0 comments on commit c917067

Please sign in to comment.