From 30ce97a35da999f80daf983c493202edb0d40a1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20Trzci=C5=84ski?= Date: Sat, 1 Apr 2023 13:11:12 +0200 Subject: [PATCH 1/5] PowerControl: Improve support for SessionProfile --- CommonHelpers/BaseSettings.cs | 53 +++++++--- PowerControl/Options/Profiles.cs | 8 +- PowerControl/ProfilesController.cs | 152 +++++++++++++---------------- RELEASE.md | 1 + 4 files changed, 112 insertions(+), 102 deletions(-) diff --git a/CommonHelpers/BaseSettings.cs b/CommonHelpers/BaseSettings.cs index 1ec9454..6fd0cbe 100644 --- a/CommonHelpers/BaseSettings.cs +++ b/CommonHelpers/BaseSettings.cs @@ -16,6 +16,12 @@ namespace CommonHelpers [Browsable(false)] public bool TouchSettings { get; set; } + [Browsable(false)] + public bool UseMemoryCache { get; set; } = true; + + [Browsable(false)] + public bool UseConfigFile { get; set; } = true; + [Browsable(false)] public String SettingsKey { get; protected set; } @@ -34,7 +40,7 @@ namespace CommonHelpers [Browsable(false)] public bool Exists { - get { return File.Exists(this.ConfigFile); } + get { return !this.UseConfigFile || File.Exists(this.ConfigFile); } } public override string ToString() @@ -61,7 +67,7 @@ namespace CommonHelpers return false; SettingChanging(key); - if (!SetProfileString(key, valueString)) + if (this.UseConfigFile && !SetProfileString(key, valueString)) return false; cachedValues[key] = value; @@ -71,8 +77,11 @@ namespace CommonHelpers protected T Get(string key, T defaultValue, bool touchSettings = false) { - if (cachedValues.TryGetValue(key, out var cachedValue)) - return ((T?)cachedValue) ?? defaultValue; + if (this.UseMemoryCache) + { + if (cachedValues.TryGetValue(key, out var cachedValue)) + return ((T?)cachedValue) ?? defaultValue; + } var typeConverter = TypeDescriptor.GetConverter(typeof(T)); var defaultString = typeConverter.ConvertToString(defaultValue); @@ -82,6 +91,12 @@ namespace CommonHelpers return defaultValue; } + if (!this.UseConfigFile) + { + cachedValues[key] = defaultValue; + return defaultValue; + } + try { var valueString = GetProfileString(key, defaultString); @@ -131,7 +146,12 @@ namespace CommonHelpers lock (this) { cachedValues.Remove(key); - return WritePrivateProfileString(SettingsKey, key, null, ConfigFile); + + if (this.UseConfigFile) + { + return WritePrivateProfileString(SettingsKey, key, null, ConfigFile); + } + return true; } } @@ -140,7 +160,12 @@ namespace CommonHelpers lock (this) { cachedValues.Clear(); - return WritePrivateProfileString(SettingsKey, null, null, ConfigFile); + + if (this.UseConfigFile) + { + return WritePrivateProfileString(SettingsKey, null, null, ConfigFile); + } + return true; } } @@ -148,10 +173,10 @@ namespace CommonHelpers { lock (this) { - if (Exists) - return; - - using (File.Create(ConfigFile)) { } + if (this.UseConfigFile && Exists) + { + using (File.Create(ConfigFile)) { } + } } } @@ -160,8 +185,12 @@ namespace CommonHelpers lock (this) { cachedValues.Clear(); - try { File.Delete(ConfigFile); } - catch (DirectoryNotFoundException) { } + + if (this.UseConfigFile) + { + try { File.Delete(ConfigFile); } + catch (DirectoryNotFoundException) { } + } } } diff --git a/PowerControl/Options/Profiles.cs b/PowerControl/Options/Profiles.cs index 545dde0..dfc3d42 100644 --- a/PowerControl/Options/Profiles.cs +++ b/PowerControl/Options/Profiles.cs @@ -10,7 +10,7 @@ namespace PowerControl.Options ApplyDelay = 500, OptionsValues = delegate () { - var currentProfileSettings = Controller?.CurrentProfileSettings; + var currentProfileSettings = Controller?.GameProfileSettings; if (currentProfileSettings == null) return null; @@ -34,7 +34,7 @@ namespace PowerControl.Options CycleOptions = false, CurrentValue = delegate () { - var currentProfileSettings = Controller?.CurrentProfileSettings; + var currentProfileSettings = Controller?.GameProfileSettings; if (currentProfileSettings == null) return null; @@ -53,11 +53,11 @@ namespace PowerControl.Options case "Create New": Controller?.CreateProfile(false); - return Controller?.CurrentProfileSettings?.ProfileName; + return Controller?.GameProfileSettings?.ProfileName; case "Save All": Controller?.CreateProfile(true); - return Controller?.CurrentProfileSettings?.ProfileName; + return Controller?.GameProfileSettings?.ProfileName; default: return selected; diff --git a/PowerControl/ProfilesController.cs b/PowerControl/ProfilesController.cs index 4d5a63a..32efe8a 100644 --- a/PowerControl/ProfilesController.cs +++ b/PowerControl/ProfilesController.cs @@ -10,10 +10,8 @@ namespace PowerControl { public const bool AutoCreateProfiles = true; public const int ApplyProfileDelayMs = 500; - public const int ResetProfileDelayMs = 500; private Dictionary watchedProcesses = new Dictionary(); - private Dictionary? changedSettings; private CancellationTokenSource? changeTask; private System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer() @@ -30,7 +28,9 @@ namespace PowerControl } } - public ProfileSettings? CurrentProfileSettings { get; private set; } + public ProfileSettings? GameProfileSettings { get; private set; } + + public ProfileSettings? SessionProfileSettings { get; private set; } public ProfilesController() { @@ -92,12 +92,12 @@ namespace PowerControl if (!watchedProcesses.TryGetValue(processId, out var profileSettings)) return false; - if (CurrentProfileSettings != profileSettings) + if (GameProfileSettings != profileSettings) { Log.TraceLine("ProfilesController: Foreground changed: {0} => {1}", - CurrentProfileSettings?.ProfileName, profileSettings.ProfileName); - CurrentProfileSettings = profileSettings; - ProfileChanged(); + GameProfileSettings?.ProfileName, profileSettings.ProfileName); + GameProfileSettings = profileSettings; + ProfileChanged(profileSettings); } return true; } @@ -106,12 +106,18 @@ namespace PowerControl { Log.TraceLine("ProfilesController: New Process: {0}/{1}", processId, processName); - if (changedSettings == null) - changedSettings = new Dictionary(); - var profileSettings = new ProfileSettings(processName); watchedProcesses.Add(processId, profileSettings); + // Create memory only SessionProfileSettings + if (SessionProfileSettings is null) + { + SessionProfileSettings = new ProfileSettings("Session:" + processName) { UseConfigFile = false }; + SaveProfile(SessionProfileSettings); + } + + GameProfileSettings = profileSettings; + ProfileChanged(profileSettings); ApplyProfile(profileSettings); } @@ -120,8 +126,8 @@ namespace PowerControl if (!watchedProcesses.Remove(processId, out var profileSettings)) return; - if (CurrentProfileSettings == profileSettings) - CurrentProfileSettings = null; + if (GameProfileSettings == profileSettings) + GameProfileSettings = null; Log.TraceLine("ProfilesController: Removed Process: {0}", processId); @@ -136,79 +142,77 @@ namespace PowerControl if (options.PersistentKey is null) return; - if (oldValue is not null) - { - if (changedSettings?.TryAdd(options, oldValue) == true) - { - Log.TraceLine("ProfilesController: Saved change: {0} from {1}", options.PersistentKey, oldValue); - } - } + // No active profile, cannot persist + if (GameProfileSettings is null) + return; - // If profile exists persist value - if (CurrentProfileSettings != null && (CurrentProfileSettings.Exists || AutoCreateProfiles)) - { - CurrentProfileSettings.SetValue(options.PersistentKey, newValue); - options.ProfileOption = newValue; + // Do not auto-create profile unless requested + if (!GameProfileSettings.Exists && !AutoCreateProfiles) + return; - Log.TraceLine("ProfilesController: Stored: {0} {1} = {2}", - CurrentProfileSettings.ProfileName, options.PersistentKey, newValue); - } + GameProfileSettings.SetValue(options.PersistentKey, newValue); + options.ProfileOption = newValue; + + Log.TraceLine("ProfilesController: Stored: {0} {1} = {2}", + GameProfileSettings.ProfileName, options.PersistentKey, newValue); } - private void ProfileChanged() + private void ProfileChanged(ProfileSettings? profileSettings) { foreach (var menuItem in PersistableOptions()) { - menuItem.ProfileOption = CurrentProfileSettings?.GetValue(menuItem.PersistentKey ?? ""); + menuItem.ProfileOption = profileSettings?.GetValue(menuItem.PersistentKey ?? ""); } } public void CreateProfile(bool saveAll = true) { - var profileSettings = CurrentProfileSettings; - - profileSettings?.TouchFile(); - - Log.TraceLine("ProfilesController: Created Profile: {0}, SaveAll={1}", - profileSettings?.ProfileName, saveAll); - - if (!saveAll) + var profileSettings = GameProfileSettings; + if (profileSettings is null) return; - foreach (var menuItem in PersistableOptions()) - { - if (menuItem.ActiveOption is null || !menuItem.PersistOnCreate) - continue; - profileSettings?.SetValue(menuItem.PersistentKey ?? "", menuItem.ActiveOption); - } + profileSettings.TouchFile(); - ProfileChanged(); + Log.TraceLine("ProfilesController: Created Profile: {0}, SaveAll={1}", + profileSettings.ProfileName, saveAll); + + if (saveAll) + SaveProfile(profileSettings); + + ProfileChanged(profileSettings); } public void DeleteProfile() { - CurrentProfileSettings?.DeleteFile(); - ProfileChanged(); + GameProfileSettings?.DeleteFile(); + ProfileChanged(GameProfileSettings); - Log.TraceLine("ProfilesController: Deleted Profile: {0}", CurrentProfileSettings?.ProfileName); + Log.TraceLine("ProfilesController: Deleted Profile: {0}", GameProfileSettings?.ProfileName); + } + + private void SaveProfile(ProfileSettings profileSettings, bool force = false) + { + foreach (var menuItem in PersistableOptions()) + { + if (menuItem.ActiveOption is null || !menuItem.PersistOnCreate && !force) + continue; + profileSettings?.SetValue(menuItem.PersistentKey ?? "", menuItem.ActiveOption); + } } private void ApplyProfile(ProfileSettings profileSettings) { - CurrentProfileSettings = profileSettings; - ProfileChanged(); - - if (CurrentProfileSettings is null || CurrentProfileSettings?.Exists != true) + if (profileSettings is null || profileSettings?.Exists != true) return; - int delay = CurrentProfileSettings.GetInt("ApplyDelay", ApplyProfileDelayMs); + int delay = profileSettings.GetInt("ApplyDelay", ApplyProfileDelayMs); changeTask?.Cancel(); changeTask = Dispatcher.RunWithDelay(delay, () => { foreach (var menuItem in PersistableOptions()) { - var persistedValue = CurrentProfileSettings.GetValue(menuItem.PersistentKey ?? ""); + var persistedValue = profileSettings.GetValue(menuItem.PersistentKey ?? ""); if (persistedValue is null) continue; @@ -217,14 +221,14 @@ namespace PowerControl menuItem.Set(persistedValue, true, false); Log.TraceLine("ProfilesController: Applied from Profile: {0}: {1} = {2}", - CurrentProfileSettings.ProfileName, menuItem.PersistentKey, persistedValue); + profileSettings.ProfileName, menuItem.PersistentKey, persistedValue); } catch (Exception e) { Log.TraceLine("ProfilesController: Exception Profile: {0}: {1} = {2} => {3}", - CurrentProfileSettings.ProfileName, menuItem.PersistentKey, persistedValue, e); + profileSettings.ProfileName, menuItem.PersistentKey, persistedValue, e); - CurrentProfileSettings.DeleteKey(menuItem.PersistentKey ?? ""); + profileSettings.DeleteKey(menuItem.PersistentKey ?? ""); menuItem.ProfileOption = null; } } @@ -233,38 +237,14 @@ namespace PowerControl private void ResetProfile() { - CurrentProfileSettings = null; - ProfileChanged(); + GameProfileSettings = null; + ProfileChanged(null); - if (changedSettings is null) - return; - - // Revert all changes made to original value - var appliedSettings = changedSettings; - changedSettings = null; - - changeTask?.Cancel(); - changeTask = Dispatcher.RunWithDelay(ResetProfileDelayMs, () => + if (SessionProfileSettings is not null) { - foreach (var menuItem in PersistableOptions()) - { - if (!appliedSettings.TryGetValue(menuItem, out var setting)) - continue; - - try - { - menuItem.Set(setting, true, true); - - Log.TraceLine("ProfilesController: Reset: {0} = {1}", - menuItem.PersistentKey, setting); - } - catch (Exception e) - { - Log.TraceLine("ProfilesController: Reset Exception: {0} = {1} => {2}", - menuItem.PersistentKey, setting, e); - } - } - }); + ApplyProfile(SessionProfileSettings); + SessionProfileSettings = null; + } } private IEnumerable PersistableOptions() diff --git a/RELEASE.md b/RELEASE.md index 8fff653..9527bd7 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -31,6 +31,7 @@ ## 0.6.16 +- PowerControl: Improve handling of restoring DesktopProfile - All: Support [unofficial APU drivers](https://sourceforge.net/projects/amernimezone/files/Release%20Polaris-Vega-Navi/AMD%20SOC%20Driver%20Variant/) that present themselves as `AMD Radeon 670M` - PowerControl: Show Game Profiles menu item From acd33f2cb2e63b6cb7712475b1ba1c56af7aa9a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20Trzci=C5=84ski?= Date: Sat, 1 Apr 2023 13:17:08 +0200 Subject: [PATCH 2/5] PowerControl: Show Game Profiles menu item --- RELEASE.md | 1 + 1 file changed, 1 insertion(+) diff --git a/RELEASE.md b/RELEASE.md index 9527bd7..00c1c1b 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -31,6 +31,7 @@ ## 0.6.16 +- PowerControl: Show Game Profiles menu item - PowerControl: Improve handling of restoring DesktopProfile - All: Support [unofficial APU drivers](https://sourceforge.net/projects/amernimezone/files/Release%20Polaris-Vega-Navi/AMD%20SOC%20Driver%20Variant/) that present themselves as `AMD Radeon 670M` - PowerControl: Show Game Profiles menu item From cf0de0ad8fc0908f31b4ac0f6edfbb218517b791 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20Trzci=C5=84ski?= Date: Sat, 1 Apr 2023 13:41:53 +0200 Subject: [PATCH 3/5] PowerControl: Allow to set Autostart Profile Settings --- PowerControl/Helpers/ProfileSettings.cs | 4 +-- PowerControl/Menu/MenuItemWithOptions.cs | 40 ++++++++++++++++++++++++ PowerControl/ProfilesController.cs | 10 ++++-- RELEASE.md | 1 + 4 files changed, 51 insertions(+), 4 deletions(-) diff --git a/PowerControl/Helpers/ProfileSettings.cs b/PowerControl/Helpers/ProfileSettings.cs index 98b821e..c9ead61 100644 --- a/PowerControl/Helpers/ProfileSettings.cs +++ b/PowerControl/Helpers/ProfileSettings.cs @@ -26,10 +26,10 @@ namespace PowerControl.Helper public String ProfileName { get; } - public ProfileSettings(string profileName) : base("PersistentSettings") + public ProfileSettings(string prefix, string profileName) : base("PersistentSettings") { this.ProfileName = profileName; - this.ConfigFile = Path.Combine(UserProfilesPath, String.Format("PowerControl.Process.{0}.ini", profileName)); + this.ConfigFile = Path.Combine(UserProfilesPath, String.Format("{0}.{1}.ini", prefix, profileName)); this.SettingChanging += delegate { }; this.SettingChanged += delegate { }; diff --git a/PowerControl/Menu/MenuItemWithOptions.cs b/PowerControl/Menu/MenuItemWithOptions.cs index 5a8485a..73ef0f1 100644 --- a/PowerControl/Menu/MenuItemWithOptions.cs +++ b/PowerControl/Menu/MenuItemWithOptions.cs @@ -155,10 +155,50 @@ namespace PowerControl.Menu toolStripItem.DropDownItems.Add(item); } + AddMenuItemsToModifyProfile( + PowerControl.Options.Profiles.Controller?.AutostartProfileSettings, + toolStripItem.DropDownItems + ); + toolStripItem.Visible = Visible && Options.Count > 0; }; } + private void AddMenuItemsToModifyProfile(Helper.ProfileSettings? profileSettings, ToolStripItemCollection dropDownItems) + { + if (profileSettings is null || PersistentKey is null) + return; + + dropDownItems.Add(new ToolStripSeparator()); + + var headingItem = new ToolStripMenuItem(profileSettings.ProfileName + ": "); + dropDownItems.Add(headingItem); + + var persistedValue = profileSettings.GetValue(PersistentKey); + + foreach (var option in Options) + { + var item = new ToolStripMenuItem("Set: " + option); + item.Checked = option == persistedValue; + item.Click += delegate { profileSettings.SetValue(PersistentKey, option); }; + headingItem.DropDownItems.Add(item); + } + + if (persistedValue is not null) + { + headingItem.Text += persistedValue; + headingItem.Checked = true; + + headingItem.DropDownItems.Add(new ToolStripSeparator()); + var unsetItem = headingItem.DropDownItems.Add("Unset"); + unsetItem.Click += delegate { profileSettings.DeleteKey(PersistentKey); }; + } + else + { + headingItem.Text += "Not set"; + } + } + private void SelectIndex(int index) { if (Options.Count == 0) diff --git a/PowerControl/ProfilesController.cs b/PowerControl/ProfilesController.cs index 32efe8a..30e8b2e 100644 --- a/PowerControl/ProfilesController.cs +++ b/PowerControl/ProfilesController.cs @@ -31,14 +31,20 @@ namespace PowerControl public ProfileSettings? GameProfileSettings { get; private set; } public ProfileSettings? SessionProfileSettings { get; private set; } + public ProfileSettings AutostartProfileSettings { get; private set; } public ProfilesController() { PowerControl.Options.Profiles.Controller = this; MenuStack.Root.ValueChanged += Root_OnOptionValueChange; + AutostartProfileSettings = new ProfileSettings("PowerControl", "Autostart"); + timer.Start(); timer.Tick += Timer_Tick; + + ProfileChanged(null); + ApplyProfile(AutostartProfileSettings); } ~ProfilesController() @@ -106,13 +112,13 @@ namespace PowerControl { Log.TraceLine("ProfilesController: New Process: {0}/{1}", processId, processName); - var profileSettings = new ProfileSettings(processName); + var profileSettings = new ProfileSettings("PowerControl.Process", processName); watchedProcesses.Add(processId, profileSettings); // Create memory only SessionProfileSettings if (SessionProfileSettings is null) { - SessionProfileSettings = new ProfileSettings("Session:" + processName) { UseConfigFile = false }; + SessionProfileSettings = new ProfileSettings("PowerControl.Session", "Session." + processName) { UseConfigFile = false }; SaveProfile(SessionProfileSettings); } diff --git a/RELEASE.md b/RELEASE.md index 00c1c1b..4f1d0e3 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -31,6 +31,7 @@ ## 0.6.16 +- PowerControl: Allow to set Autostart Profile Settings - PowerControl: Show Game Profiles menu item - PowerControl: Improve handling of restoring DesktopProfile - All: Support [unofficial APU drivers](https://sourceforge.net/projects/amernimezone/files/Release%20Polaris-Vega-Navi/AMD%20SOC%20Driver%20Variant/) that present themselves as `AMD Radeon 670M` From 91d46d801b964a5129265ddae249c873302a0420 Mon Sep 17 00:00:00 2001 From: diesel-dogg <106082199+diesel-dogg@users.noreply.github.com> Date: Sat, 2 Sep 2023 14:59:19 +0530 Subject: [PATCH 4/5] SteamController: Attempted fix for joystick snapping to cardinal directions in gamepad mode (#143) * Update SteamButtons.cs removed deadzone and min change * Update SteamButtons.cs Adjusted deadzones to minimise snapping to cardinals in xinput mode while attempting to simultaneously avoid drifting of the mouse cursor or scroll in the desktop mode --- SteamController/Devices/SteamButtons.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/SteamController/Devices/SteamButtons.cs b/SteamController/Devices/SteamButtons.cs index 1a5704f..dfeef23 100644 --- a/SteamController/Devices/SteamButtons.cs +++ b/SteamController/Devices/SteamButtons.cs @@ -52,10 +52,10 @@ namespace SteamController.Devices public readonly SteamAxis GyroYaw = new SteamAxis(0x22); public readonly SteamAxis LeftTrigger = new SteamAxis(0x2C); public readonly SteamAxis RightTrigger = new SteamAxis(0x2E); - public readonly SteamAxis LeftThumbX = new SteamAxis(0x30) { Deadzone = 5000, MinChange = 10, DeltaValueMode = Devices.DeltaValueMode.AbsoluteTime }; - public readonly SteamAxis LeftThumbY = new SteamAxis(0x32) { Deadzone = 5000, MinChange = 10, DeltaValueMode = Devices.DeltaValueMode.AbsoluteTime }; - public readonly SteamAxis RightThumbX = new SteamAxis(0x34) { Deadzone = 5000, MinChange = 10, DeltaValueMode = Devices.DeltaValueMode.AbsoluteTime }; - public readonly SteamAxis RightThumbY = new SteamAxis(0x36) { Deadzone = 5000, MinChange = 10, DeltaValueMode = Devices.DeltaValueMode.AbsoluteTime }; + public readonly SteamAxis LeftThumbX = new SteamAxis(0x30) { Deadzone = 1400, MinChange = 0, DeltaValueMode = Devices.DeltaValueMode.AbsoluteTime }; + public readonly SteamAxis LeftThumbY = new SteamAxis(0x32) { Deadzone = 1400, MinChange = 0, DeltaValueMode = Devices.DeltaValueMode.AbsoluteTime }; + public readonly SteamAxis RightThumbX = new SteamAxis(0x34) { Deadzone = 1400, MinChange = 0, DeltaValueMode = Devices.DeltaValueMode.AbsoluteTime }; + public readonly SteamAxis RightThumbY = new SteamAxis(0x36) { Deadzone = 1400, MinChange = 0, DeltaValueMode = Devices.DeltaValueMode.AbsoluteTime }; public readonly SteamAxis LPadPressure = new SteamAxis(0x38); public readonly SteamAxis RPadPressure = new SteamAxis(0x38); From 525b7d53e276879e9a32d666fdb922c284efa4fe Mon Sep 17 00:00:00 2001 From: Adravil <39429872+Adravil@users.noreply.github.com> Date: Sat, 2 Sep 2023 12:29:32 +0300 Subject: [PATCH 5/5] FanControl: Add Silent fan profile (#141) --- CommonHelpers/GlobalConfig.cs | 1 + FanControl/FanControllerSensors.cs | 62 ++++++++++++++++++++++++++---- FanControl/FanSensor.cs | 18 +++++---- 3 files changed, 67 insertions(+), 14 deletions(-) diff --git a/CommonHelpers/GlobalConfig.cs b/CommonHelpers/GlobalConfig.cs index 22cbf92..83161ed 100644 --- a/CommonHelpers/GlobalConfig.cs +++ b/CommonHelpers/GlobalConfig.cs @@ -10,6 +10,7 @@ namespace CommonHelpers public enum FanMode : uint { Default = 17374, + Silent, SteamOS, Max } diff --git a/FanControl/FanControllerSensors.cs b/FanControl/FanControllerSensors.cs index d7d823d..d5df406 100644 --- a/FanControl/FanControllerSensors.cs +++ b/FanControl/FanControllerSensors.cs @@ -1,11 +1,6 @@ using CommonHelpers; using LibreHardwareMonitor.Hardware; -using System; -using System.Collections.Generic; using System.ComponentModel; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace FanControl { @@ -40,6 +35,13 @@ namespace FanControl MinRPM = 1500 } }, + { + FanMode.Silent, new FanSensor.Profile() + { + Type = FanSensor.Profile.ProfileType.Constant, + MinRPM = 1500 + } + }, } } }, @@ -64,7 +66,18 @@ namespace FanControl B = -188.6f, C = 5457.0f } - } + }, + { + FanMode.Silent, new FanSensor.Profile() + { + Type = FanSensor.Profile.ProfileType.Exponential, + MinInput = 55, + MaxInput = 93, + A = 1.28f, + B = 60f, + C = 3000f + } + }, } } }, @@ -89,7 +102,18 @@ namespace FanControl B = -188.6f, C = 5457.0f } - } + }, + { + FanMode.Silent, new FanSensor.Profile() + { + Type = FanSensor.Profile.ProfileType.Exponential, + MinInput = 55, + MaxInput = 93, + A = 1.28f, + B = 60f, + C = 3000f + } + }, } } }, @@ -114,6 +138,19 @@ namespace FanControl Ki = -20, Kd = 0 } + }, + { + FanMode.Silent, new FanSensor.Profile() + { + Type = FanSensor.Profile.ProfileType.Pid, + MinInput = 30, + MaxInput = 70, + MaxRPM = 3000, + PidSetPoint = 70, + Kp = 0, + Ki = -20, + Kd = 0 + } } } } @@ -137,6 +174,17 @@ namespace FanControl MinRPM = 0, MaxRPM = 2000, } + }, + { + FanMode.Silent, new FanSensor.Profile() + { + // If battery goes over 40oC require 2kRPM + Type = FanSensor.Profile.ProfileType.Constant, + MinInput = 0, + MaxInput = 40, + MinRPM = 0, + MaxRPM = 2000, + } } } } diff --git a/FanControl/FanSensor.cs b/FanControl/FanSensor.cs index 6392187..8683b20 100644 --- a/FanControl/FanSensor.cs +++ b/FanControl/FanSensor.cs @@ -1,12 +1,6 @@ using CommonHelpers; using LibreHardwareMonitor.Hardware; -using System; -using System.Collections.Generic; using System.ComponentModel; -using System.Linq; -using System.Security.Policy; -using System.Text; -using System.Threading.Tasks; namespace FanControl { @@ -36,7 +30,8 @@ namespace FanControl { Constant, Quadratic, - Pid + Pid, + Exponential } public ProfileType Type { get; set; } @@ -78,6 +73,10 @@ namespace FanControl case ProfileType.Pid: rpm = calculatePidRPM(input); break; + + case ProfileType.Exponential: + rpm = calculateExponentialRPM(input); + break; } if (input < MinInput) @@ -119,6 +118,11 @@ namespace FanControl return pidP + pidI + pidD; } + + private float calculateExponentialRPM(float input) + { + return (float)(Math.Pow(A, input - B) + C); + } } public void Reset()