├── .gitignore ├── README.md ├── SysFanControl.sln ├── SysFanControl ├── App.config ├── App.xaml ├── App.xaml.cs ├── BaseNotifyPropertyChanged.cs ├── FodyWeavers.xml ├── FodyWeavers.xsd ├── HardwareNotifyPropertyChanged.cs ├── MainWindow.xaml ├── MainWindow.xaml.cs ├── Models │ ├── Fan.cs │ ├── FanCurve.cs │ ├── FanCurveJSON.cs │ ├── FanCurvePoint.cs │ ├── FanCurveSource.cs │ ├── GPU.cs │ ├── SensorEx.cs │ └── SmartFanCurvePoint.cs ├── Properties │ ├── AssemblyInfo.cs │ ├── Resources.Designer.cs │ ├── Resources.resx │ ├── Settings.Designer.cs │ └── Settings.settings ├── Resources │ └── speedfan.ico ├── SensorValueConverter.cs ├── SysFanControl.csproj ├── ViewModels │ └── MainWindowViewModel.cs ├── packages.config └── speedfan.ico └── image.png /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Mono auto generated files 17 | mono_crash.* 18 | 19 | # Build results 20 | [Dd]ebug/ 21 | [Dd]ebugPublic/ 22 | [Rr]elease/ 23 | [Rr]eleases/ 24 | x64/ 25 | x86/ 26 | [Ww][Ii][Nn]32/ 27 | [Aa][Rr][Mm]/ 28 | [Aa][Rr][Mm]64/ 29 | bld/ 30 | [Bb]in/ 31 | [Oo]bj/ 32 | [Ll]og/ 33 | [Ll]ogs/ 34 | 35 | # Visual Studio 2015/2017 cache/options directory 36 | .vs/ 37 | # Uncomment if you have tasks that create the project's static files in wwwroot 38 | #wwwroot/ 39 | 40 | # Visual Studio 2017 auto generated files 41 | Generated\ Files/ 42 | 43 | # MSTest test Results 44 | [Tt]est[Rr]esult*/ 45 | [Bb]uild[Ll]og.* 46 | 47 | # NUnit 48 | *.VisualState.xml 49 | TestResult.xml 50 | nunit-*.xml 51 | 52 | # Build Results of an ATL Project 53 | [Dd]ebugPS/ 54 | [Rr]eleasePS/ 55 | dlldata.c 56 | 57 | # Benchmark Results 58 | BenchmarkDotNet.Artifacts/ 59 | 60 | # .NET Core 61 | project.lock.json 62 | project.fragment.lock.json 63 | artifacts/ 64 | 65 | # ASP.NET Scaffolding 66 | ScaffoldingReadMe.txt 67 | 68 | # StyleCop 69 | StyleCopReport.xml 70 | 71 | # Files built by Visual Studio 72 | *_i.c 73 | *_p.c 74 | *_h.h 75 | *.ilk 76 | *.meta 77 | *.obj 78 | *.iobj 79 | *.pch 80 | *.pdb 81 | *.ipdb 82 | *.pgc 83 | *.pgd 84 | *.rsp 85 | *.sbr 86 | *.tlb 87 | *.tli 88 | *.tlh 89 | *.tmp 90 | *.tmp_proj 91 | *_wpftmp.csproj 92 | *.log 93 | *.vspscc 94 | *.vssscc 95 | .builds 96 | *.pidb 97 | *.svclog 98 | *.scc 99 | 100 | # Chutzpah Test files 101 | _Chutzpah* 102 | 103 | # Visual C++ cache files 104 | ipch/ 105 | *.aps 106 | *.ncb 107 | *.opendb 108 | *.opensdf 109 | *.sdf 110 | *.cachefile 111 | *.VC.db 112 | *.VC.VC.opendb 113 | 114 | # Visual Studio profiler 115 | *.psess 116 | *.vsp 117 | *.vspx 118 | *.sap 119 | 120 | # Visual Studio Trace Files 121 | *.e2e 122 | 123 | # TFS 2012 Local Workspace 124 | $tf/ 125 | 126 | # Guidance Automation Toolkit 127 | *.gpState 128 | 129 | # ReSharper is a .NET coding add-in 130 | _ReSharper*/ 131 | *.[Rr]e[Ss]harper 132 | *.DotSettings.user 133 | 134 | # TeamCity is a build add-in 135 | _TeamCity* 136 | 137 | # DotCover is a Code Coverage Tool 138 | *.dotCover 139 | 140 | # AxoCover is a Code Coverage Tool 141 | .axoCover/* 142 | !.axoCover/settings.json 143 | 144 | # Coverlet is a free, cross platform Code Coverage Tool 145 | coverage*[.json, .xml, .info] 146 | 147 | # Visual Studio code coverage results 148 | *.coverage 149 | *.coveragexml 150 | 151 | # NCrunch 152 | _NCrunch_* 153 | .*crunch*.local.xml 154 | nCrunchTemp_* 155 | 156 | # MightyMoose 157 | *.mm.* 158 | AutoTest.Net/ 159 | 160 | # Web workbench (sass) 161 | .sass-cache/ 162 | 163 | # Installshield output folder 164 | [Ee]xpress/ 165 | 166 | # DocProject is a documentation generator add-in 167 | DocProject/buildhelp/ 168 | DocProject/Help/*.HxT 169 | DocProject/Help/*.HxC 170 | DocProject/Help/*.hhc 171 | DocProject/Help/*.hhk 172 | DocProject/Help/*.hhp 173 | DocProject/Help/Html2 174 | DocProject/Help/html 175 | 176 | # Click-Once directory 177 | publish/ 178 | 179 | # Publish Web Output 180 | *.[Pp]ublish.xml 181 | *.azurePubxml 182 | # Note: Comment the next line if you want to checkin your web deploy settings, 183 | # but database connection strings (with potential passwords) will be unencrypted 184 | *.pubxml 185 | *.publishproj 186 | 187 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 188 | # checkin your Azure Web App publish settings, but sensitive information contained 189 | # in these scripts will be unencrypted 190 | PublishScripts/ 191 | 192 | # NuGet Packages 193 | *.nupkg 194 | # NuGet Symbol Packages 195 | *.snupkg 196 | # The packages folder can be ignored because of Package Restore 197 | **/[Pp]ackages/* 198 | # except build/, which is used as an MSBuild target. 199 | !**/[Pp]ackages/build/ 200 | # Uncomment if necessary however generally it will be regenerated when needed 201 | #!**/[Pp]ackages/repositories.config 202 | # NuGet v3's project.json files produces more ignorable files 203 | *.nuget.props 204 | *.nuget.targets 205 | 206 | # Microsoft Azure Build Output 207 | csx/ 208 | *.build.csdef 209 | 210 | # Microsoft Azure Emulator 211 | ecf/ 212 | rcf/ 213 | 214 | # Windows Store app package directories and files 215 | AppPackages/ 216 | BundleArtifacts/ 217 | Package.StoreAssociation.xml 218 | _pkginfo.txt 219 | *.appx 220 | *.appxbundle 221 | *.appxupload 222 | 223 | # Visual Studio cache files 224 | # files ending in .cache can be ignored 225 | *.[Cc]ache 226 | # but keep track of directories ending in .cache 227 | !?*.[Cc]ache/ 228 | 229 | # Others 230 | ClientBin/ 231 | ~$* 232 | *~ 233 | *.dbmdl 234 | *.dbproj.schemaview 235 | *.jfm 236 | *.pfx 237 | *.publishsettings 238 | orleans.codegen.cs 239 | 240 | # Including strong name files can present a security risk 241 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 242 | #*.snk 243 | 244 | # Since there are multiple workflows, uncomment next line to ignore bower_components 245 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 246 | #bower_components/ 247 | 248 | # RIA/Silverlight projects 249 | Generated_Code/ 250 | 251 | # Backup & report files from converting an old project file 252 | # to a newer Visual Studio version. Backup files are not needed, 253 | # because we have git ;-) 254 | _UpgradeReport_Files/ 255 | Backup*/ 256 | UpgradeLog*.XML 257 | UpgradeLog*.htm 258 | ServiceFabricBackup/ 259 | *.rptproj.bak 260 | 261 | # SQL Server files 262 | *.mdf 263 | *.ldf 264 | *.ndf 265 | 266 | # Business Intelligence projects 267 | *.rdl.data 268 | *.bim.layout 269 | *.bim_*.settings 270 | *.rptproj.rsuser 271 | *- [Bb]ackup.rdl 272 | *- [Bb]ackup ([0-9]).rdl 273 | *- [Bb]ackup ([0-9][0-9]).rdl 274 | 275 | # Microsoft Fakes 276 | FakesAssemblies/ 277 | 278 | # GhostDoc plugin setting file 279 | *.GhostDoc.xml 280 | 281 | # Node.js Tools for Visual Studio 282 | .ntvs_analysis.dat 283 | node_modules/ 284 | 285 | # Visual Studio 6 build log 286 | *.plg 287 | 288 | # Visual Studio 6 workspace options file 289 | *.opt 290 | 291 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 292 | *.vbw 293 | 294 | # Visual Studio LightSwitch build output 295 | **/*.HTMLClient/GeneratedArtifacts 296 | **/*.DesktopClient/GeneratedArtifacts 297 | **/*.DesktopClient/ModelManifest.xml 298 | **/*.Server/GeneratedArtifacts 299 | **/*.Server/ModelManifest.xml 300 | _Pvt_Extensions 301 | 302 | # Paket dependency manager 303 | .paket/paket.exe 304 | paket-files/ 305 | 306 | # FAKE - F# Make 307 | .fake/ 308 | 309 | # CodeRush personal settings 310 | .cr/personal 311 | 312 | # Python Tools for Visual Studio (PTVS) 313 | __pycache__/ 314 | *.pyc 315 | 316 | # Cake - Uncomment if you are using it 317 | # tools/** 318 | # !tools/packages.config 319 | 320 | # Tabs Studio 321 | *.tss 322 | 323 | # Telerik's JustMock configuration file 324 | *.jmconfig 325 | 326 | # BizTalk build output 327 | *.btp.cs 328 | *.btm.cs 329 | *.odx.cs 330 | *.xsd.cs 331 | 332 | # OpenCover UI analysis results 333 | OpenCover/ 334 | 335 | # Azure Stream Analytics local run output 336 | ASALocalRun/ 337 | 338 | # MSBuild Binary and Structured Log 339 | *.binlog 340 | 341 | # NVidia Nsight GPU debugger configuration file 342 | *.nvuser 343 | 344 | # MFractors (Xamarin productivity tool) working folder 345 | .mfractor/ 346 | 347 | # Local History for Visual Studio 348 | .localhistory/ 349 | 350 | # BeatPulse healthcheck temp database 351 | healthchecksdb 352 | 353 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 354 | MigrationBackup/ 355 | 356 | # Ionide (cross platform F# VS Code tools) working folder 357 | .ionide/ -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SysFanControl 2 | Control system fans based on your selected sensor value. It currently only allows temperature and power sensors. 3 | 4 | **Make sure to run as admin.** 5 | 6 | ![Image](/image.png?raw=true) 7 | 8 | SysFanControl relies on [OpenHardwareMonitor's library](https://github.com/openhardwaremonitor/openhardwaremonitor), so if you can't control fans using that, SysFanControl won't work either. 9 | -------------------------------------------------------------------------------- /SysFanControl.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.29123.88 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SysFanControl", "SysFanControl\SysFanControl.csproj", "{9696BEC3-1A4B-4648-BCDA-E9E95F813A57}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenHardwareMonitorLib", "..\openhardwaremonitor\OpenHardwareMonitorLib.csproj", "{B0397530-545A-471D-BB74-027AE456DF1A}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|Any CPU = Debug|Any CPU 13 | Release|Any CPU = Release|Any CPU 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {9696BEC3-1A4B-4648-BCDA-E9E95F813A57}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 17 | {9696BEC3-1A4B-4648-BCDA-E9E95F813A57}.Debug|Any CPU.Build.0 = Debug|Any CPU 18 | {9696BEC3-1A4B-4648-BCDA-E9E95F813A57}.Release|Any CPU.ActiveCfg = Release|Any CPU 19 | {9696BEC3-1A4B-4648-BCDA-E9E95F813A57}.Release|Any CPU.Build.0 = Release|Any CPU 20 | {B0397530-545A-471D-BB74-027AE456DF1A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 21 | {B0397530-545A-471D-BB74-027AE456DF1A}.Debug|Any CPU.Build.0 = Debug|Any CPU 22 | {B0397530-545A-471D-BB74-027AE456DF1A}.Release|Any CPU.ActiveCfg = Release|Any CPU 23 | {B0397530-545A-471D-BB74-027AE456DF1A}.Release|Any CPU.Build.0 = Release|Any CPU 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {6C032C88-7C40-4AF3-8EF5-6123B4827317} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /SysFanControl/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /SysFanControl/App.xaml: -------------------------------------------------------------------------------- 1 |  6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /SysFanControl/App.xaml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Configuration; 4 | using System.Data; 5 | using System.Linq; 6 | using System.Threading.Tasks; 7 | using System.Windows; 8 | 9 | namespace SysFanControl 10 | { 11 | /// 12 | /// Interaction logic for App.xaml 13 | /// 14 | public partial class App : Application 15 | { 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /SysFanControl/BaseNotifyPropertyChanged.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.ComponentModel; 3 | using System.Runtime.CompilerServices; 4 | 5 | namespace SysFanControl 6 | { 7 | public abstract class BaseNotifyPropertyChanged : INotifyPropertyChanged 8 | { 9 | public event PropertyChangedEventHandler PropertyChanged; 10 | 11 | protected bool SetProperty(ref T field, T newValue, [CallerMemberName]string propertyName = null) 12 | { 13 | if (!EqualityComparer.Default.Equals(field, newValue)) 14 | { 15 | field = newValue; 16 | PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); 17 | return true; 18 | } 19 | return false; 20 | } 21 | 22 | protected void PropertyUpdated([CallerMemberName] string propertyName = null) 23 | { 24 | PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /SysFanControl/FodyWeavers.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | -------------------------------------------------------------------------------- /SysFanControl/FodyWeavers.xsd: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | A list of assembly names to exclude from the default action of "embed all Copy Local references", delimited with line breaks 13 | 14 | 15 | 16 | 17 | A list of assembly names to include from the default action of "embed all Copy Local references", delimited with line breaks. 18 | 19 | 20 | 21 | 22 | A list of unmanaged 32 bit assembly names to include, delimited with line breaks. 23 | 24 | 25 | 26 | 27 | A list of unmanaged 64 bit assembly names to include, delimited with line breaks. 28 | 29 | 30 | 31 | 32 | The order of preloaded assemblies, delimited with line breaks. 33 | 34 | 35 | 36 | 37 | 38 | This will copy embedded files to disk before loading them into memory. This is helpful for some scenarios that expected an assembly to be loaded from a physical file. 39 | 40 | 41 | 42 | 43 | Controls if .pdbs for reference assemblies are also embedded. 44 | 45 | 46 | 47 | 48 | Embedded assemblies are compressed by default, and uncompressed when they are loaded. You can turn compression off with this option. 49 | 50 | 51 | 52 | 53 | As part of Costura, embedded assemblies are no longer included as part of the build. This cleanup can be turned off. 54 | 55 | 56 | 57 | 58 | Costura by default will load as part of the module initialization. This flag disables that behavior. Make sure you call CosturaUtility.Initialize() somewhere in your code. 59 | 60 | 61 | 62 | 63 | Costura will by default use assemblies with a name like 'resources.dll' as a satellite resource and prepend the output path. This flag disables that behavior. 64 | 65 | 66 | 67 | 68 | A list of assembly names to exclude from the default action of "embed all Copy Local references", delimited with | 69 | 70 | 71 | 72 | 73 | A list of assembly names to include from the default action of "embed all Copy Local references", delimited with |. 74 | 75 | 76 | 77 | 78 | A list of unmanaged 32 bit assembly names to include, delimited with |. 79 | 80 | 81 | 82 | 83 | A list of unmanaged 64 bit assembly names to include, delimited with |. 84 | 85 | 86 | 87 | 88 | The order of preloaded assemblies, delimited with |. 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed. 97 | 98 | 99 | 100 | 101 | A comma-separated list of error codes that can be safely ignored in assembly verification. 102 | 103 | 104 | 105 | 106 | 'false' to turn off automatic generation of the XML Schema file. 107 | 108 | 109 | 110 | 111 | -------------------------------------------------------------------------------- /SysFanControl/HardwareNotifyPropertyChanged.cs: -------------------------------------------------------------------------------- 1 | namespace SysFanControl.ViewModels 2 | { 3 | public abstract class HardwareNotifyPropertyChanged : BaseNotifyPropertyChanged 4 | { 5 | public abstract void Update(); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /SysFanControl/MainWindow.xaml: -------------------------------------------------------------------------------- 1 |  13 | 14 | 15 | 16 | 17 | 18 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 49 | 50 | 51 | 52 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 83 | 84 | 85 | 86 | 87 | 88 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | -------------------------------------------------------------------------------- /SysFanControl/MainWindow.xaml.cs: -------------------------------------------------------------------------------- 1 | using MahApps.Metro.Controls; 2 | using SysFanControl.ViewModels; 3 | using System; 4 | using System.Windows; 5 | 6 | namespace SysFanControl 7 | { 8 | public partial class MainWindow : MetroWindow 9 | { 10 | private readonly System.Windows.Forms.NotifyIcon notifyIcon; 11 | 12 | public MainWindow() 13 | { 14 | InitializeComponent(); 15 | 16 | var menuStrip = new System.Windows.Forms.ContextMenuStrip(); 17 | var menuItemOpen = new System.Windows.Forms.ToolStripMenuItem 18 | { 19 | Text = "Open" 20 | }; 21 | menuItemOpen.Click += (s, e) => 22 | { 23 | Show(); 24 | WindowState = WindowState.Normal; 25 | }; 26 | menuStrip.Items.Add(menuItemOpen); 27 | var menuItemClose = new System.Windows.Forms.ToolStripMenuItem 28 | { 29 | Text = "Close" 30 | }; 31 | menuItemClose.Click += (s, e) => Close(); 32 | menuStrip.Items.Add(menuItemClose); 33 | 34 | notifyIcon = new System.Windows.Forms.NotifyIcon 35 | { 36 | ContextMenuStrip = menuStrip, 37 | Icon = System.Drawing.Icon.FromHandle(Properties.Resources.speedfan.Handle), 38 | Text = "SysFanControl", 39 | Visible = true 40 | }; 41 | 42 | #if DEBUG 43 | DataContext = new MainWindowViewModel(); 44 | #else 45 | try 46 | { 47 | DataContext = new MainWindowViewModel(); 48 | } 49 | catch (Exception e) 50 | { 51 | MessageBox.Show($"{e.Message}\n{e.StackTrace}", "Error", MessageBoxButton.OK, MessageBoxImage.Error); 52 | Close(); 53 | } 54 | #endif 55 | } 56 | 57 | private void MetroWindow_StateChanged(object sender, EventArgs e) 58 | { 59 | switch (WindowState) 60 | { 61 | case WindowState.Minimized: 62 | notifyIcon.Visible = true; 63 | Hide(); 64 | break; 65 | 66 | case WindowState.Normal: 67 | notifyIcon.Visible = false; 68 | break; 69 | } 70 | } 71 | 72 | private void MetroWindow_Loaded(object sender, RoutedEventArgs e) 73 | { 74 | Hide(); 75 | } 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /SysFanControl/Models/Fan.cs: -------------------------------------------------------------------------------- 1 | using SysFanControl.ViewModels; 2 | using OpenHardwareMonitor.Hardware; 3 | using System; 4 | using System.Linq; 5 | 6 | namespace SysFanControl.Models 7 | { 8 | public class Fan : HardwareNotifyPropertyChanged, IDisposable 9 | { 10 | private readonly ISensor fanSensor, fanControlSensor; 11 | private int speed = 0, percent = 50; 12 | private bool disposed = false; 13 | 14 | public Fan(ISensor fanSensor) 15 | { 16 | if (fanSensor.SensorType != SensorType.Fan) 17 | { 18 | throw new ArgumentException("Argument isn't a fan sensor."); 19 | } 20 | 21 | this.fanSensor = fanSensor; 22 | fanControlSensor = fanSensor.Hardware.Sensors 23 | .Where(s => s.SensorType == SensorType.Control && s.Index == fanSensor.Index) 24 | .First(); 25 | percent = (int)fanControlSensor.Control.SoftwareValue; 26 | } 27 | 28 | ~Fan() 29 | { 30 | Dispose(false); 31 | } 32 | 33 | public int Index { get => fanSensor.Index; } 34 | public int Speed 35 | { 36 | get => speed; 37 | private set => SetProperty(ref speed, value); 38 | } 39 | public int Percent 40 | { 41 | get => percent; 42 | set 43 | { 44 | fanControlSensor.Control.SetSoftware(value); 45 | SetProperty(ref percent, value); 46 | PropertyUpdated(nameof(Speed)); 47 | } 48 | } 49 | public ISensor Sensor { get => fanSensor; } 50 | 51 | public override void Update() 52 | { 53 | fanSensor.Hardware.Update(); 54 | Speed = (int?)fanSensor.Value ?? Speed; 55 | } 56 | 57 | public void SetDefault() 58 | { 59 | fanControlSensor.Control.SetDefault(); 60 | Update(); 61 | } 62 | 63 | public void Dispose() 64 | { 65 | Dispose(true); 66 | GC.SuppressFinalize(this); 67 | } 68 | 69 | protected virtual void Dispose(bool disposing) 70 | { 71 | if (!disposed) 72 | { 73 | SetDefault(); 74 | 75 | disposed = true; 76 | } 77 | } 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /SysFanControl/Models/FanCurve.cs: -------------------------------------------------------------------------------- 1 | using OpenHardwareMonitor.Hardware; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.ComponentModel; 5 | using System.Linq; 6 | 7 | namespace SysFanControl.Models 8 | { 9 | public class FanCurve : Fan 10 | { 11 | private FanCurveSource source; 12 | private readonly object mutex = new object(); 13 | private bool enabled = false, forceUpdate = false; 14 | private decimal previousValue = -999.0M; 15 | public delegate void OnEnabledChanged(FanCurve sender); 16 | private readonly OnEnabledChanged onEnabledChanged; 17 | private DateTime lastUpdateTime = DateTime.Now; 18 | 19 | public FanCurve(ISensor fanSensor, OnEnabledChanged onEnabledChanged) : 20 | base(fanSensor) 21 | { 22 | this.onEnabledChanged = onEnabledChanged; 23 | 24 | var points = new List 25 | { 26 | new FanCurvePoint{ Value = 40.0M, Percent = 50 }, 27 | new FanCurvePoint{ Value = 50.0M, Percent = 75 }, 28 | new FanCurvePoint{ Value = 60.0M, Percent = 100 } 29 | }; 30 | foreach (var point in points) 31 | { 32 | AddPoint(point); 33 | } 34 | Points.ListChanged += (s, e) => 35 | { 36 | lock (mutex) 37 | { 38 | forceUpdate = true; 39 | } 40 | }; 41 | 42 | Hysteresis = 2.0M; 43 | } 44 | 45 | public bool Enabled 46 | { 47 | get => enabled; 48 | set 49 | { 50 | var previousValue = enabled; 51 | SetProperty(ref enabled, value); 52 | 53 | if (!value) 54 | { 55 | SetDefault(); 56 | } 57 | 58 | if (previousValue != value) 59 | { 60 | onEnabledChanged(this); 61 | } 62 | } 63 | } 64 | public BindingList Points { get; } = new BindingList(); 65 | public FanCurveSource Source 66 | { 67 | get => source; 68 | set => SetProperty(ref source, value); 69 | } 70 | public decimal Hysteresis 71 | { 72 | get; set; 73 | } 74 | 75 | public override void Update() 76 | { 77 | base.Update(); 78 | if (Source != null) 79 | { 80 | Source.Update(); 81 | PropertyUpdated(nameof(Source)); 82 | 83 | // Only update the sensor value if the curve isn't enabled. 84 | if (!enabled) 85 | { 86 | return; 87 | } 88 | 89 | if (previousValue == -999.0M) 90 | { 91 | previousValue = (decimal)Source.Value; 92 | } 93 | decimal delta = (decimal)Source.Value - previousValue; 94 | lock (mutex) 95 | { 96 | if (forceUpdate) 97 | { 98 | Percent = CalculateFanPercent(Source.Value); 99 | previousValue = (decimal)Source.Value; 100 | forceUpdate = false; 101 | lastUpdateTime = DateTime.Now; 102 | } 103 | else if (delta > 0.0M) 104 | { 105 | Percent = CalculateFanPercent(Source.Value); 106 | lastUpdateTime = DateTime.Now; 107 | } 108 | else if (delta <= -Hysteresis) 109 | { 110 | Percent = CalculateFanPercent(Source.Value); 111 | previousValue = (decimal)Source.Value; 112 | lastUpdateTime = DateTime.Now; 113 | } 114 | // If we haven't updated fan speed for more than 10 seconds, do an update. 115 | else if ((DateTime.Now - lastUpdateTime).TotalSeconds >= 10.0) 116 | { 117 | Percent = CalculateFanPercent(Source.Value); 118 | previousValue = (decimal)Source.Value; 119 | lastUpdateTime = DateTime.Now; 120 | } 121 | } 122 | } 123 | } 124 | 125 | /// 126 | /// Add a point. 127 | /// 128 | /// 129 | /// The point to add. Should be greater than all the points in . 130 | /// 131 | public void AddPoint(FanCurvePoint point) 132 | { 133 | var previous = Points.Count() > 0 ? Points.Last() : null; 134 | var current = new SmartFanCurvePoint(previous, point); 135 | Points.Add(current); 136 | if (previous != null) 137 | { 138 | previous.NextPoint = current; 139 | } 140 | } 141 | 142 | /// 143 | /// Calculate the speed (in percent) that the fan should be at. 144 | /// 145 | /// Value of the sensor that the fan curve is used for. 146 | /// The fan percent. 147 | private int CalculateFanPercent(float sourceValue) 148 | { 149 | var sourceVal = (decimal)sourceValue; 150 | 151 | if (sourceVal < Points.First().Value) 152 | { 153 | return Points.First().Percent; 154 | } 155 | if (sourceVal > Points.Last().Value) 156 | { 157 | return Points.Last().Percent; 158 | } 159 | 160 | // Find which points sourceValue falls between. 161 | for (int i = 0; i < Points.Count - 1; i++) 162 | { 163 | var current = Points[i]; 164 | var next = Points[i + 1]; 165 | if (sourceVal >= current.Value && (decimal)source.Value <= next.Value) 166 | { 167 | // Interpolate between the points. 168 | var scale = (next.Percent - current.Percent) / (next.Value - current.Value); 169 | return (int)Math.Round(scale * (sourceVal - current.Value) + current.Percent); 170 | } 171 | } 172 | 173 | // Should never get here. 174 | return Percent; 175 | } 176 | } 177 | } 178 | -------------------------------------------------------------------------------- /SysFanControl/Models/FanCurveJSON.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json.Linq; 2 | using OpenHardwareMonitor.Hardware; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | 9 | namespace SysFanControl.Models 10 | { 11 | public static class FanCurveJSON 12 | { 13 | public static JObject Serialise(FanCurve fanCurve) 14 | { 15 | var points = new List(); 16 | foreach (var point in fanCurve.Points) 17 | { 18 | points.Add(new FanCurvePoint { Value = point.Value, Percent = point.Percent }); 19 | } 20 | 21 | var obj = new JObject 22 | { 23 | { "enabled", fanCurve.Enabled }, 24 | { "points", JToken.FromObject(points) }, 25 | { "hysteresis", fanCurve.Hysteresis } 26 | }; 27 | if (fanCurve.Source != null) 28 | { 29 | obj["sensor"] = fanCurve.Source.Sensor.Identifier.ToString(); 30 | } 31 | 32 | return obj; 33 | } 34 | 35 | public static void UpdateFromJSON(JObject json, FanCurve fanCurve, List hardware) 36 | { 37 | if (json.ContainsKey("enabled")) 38 | { 39 | fanCurve.Enabled = json["enabled"].ToObject(); 40 | } 41 | 42 | if (json.ContainsKey("points")) 43 | { 44 | fanCurve.Points.Clear(); 45 | foreach (var point in ((JArray)json["points"]).ToObject>()) 46 | { 47 | fanCurve.AddPoint(point); 48 | } 49 | } 50 | 51 | if (json.ContainsKey("hysteresis")) 52 | { 53 | fanCurve.Hysteresis = json["hysteresis"].ToObject(); 54 | } 55 | 56 | if (json.ContainsKey("sensor")) 57 | { 58 | var sensorId = json["sensor"].ToString(); 59 | 60 | var hardwareResult = hardware.Where(hw => sensorId.Contains(hw.Identifier.ToString())); 61 | if (hardwareResult.Count() > 0) 62 | { 63 | var sensorResult = hardwareResult.First().Sensors.Where(s => s.Identifier.ToString() == sensorId); 64 | if (sensorResult.Count() > 0) 65 | { 66 | fanCurve.Source = new FanCurveSource(sensorResult.First()); 67 | } 68 | } 69 | } 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /SysFanControl/Models/FanCurvePoint.cs: -------------------------------------------------------------------------------- 1 | namespace SysFanControl.Models 2 | { 3 | public class FanCurvePoint : BaseNotifyPropertyChanged 4 | { 5 | private decimal value = 0; 6 | private int percent = 0; 7 | 8 | public decimal Value 9 | { 10 | get => value; 11 | set => SetProperty(ref this.value, value); 12 | } 13 | public int Percent 14 | { 15 | get => percent; 16 | set 17 | { 18 | if (value >= 0 && value <= 100) 19 | { 20 | SetProperty(ref percent, value); 21 | } 22 | } 23 | } 24 | 25 | public static bool operator<(FanCurvePoint lhs, FanCurvePoint rhs) 26 | { 27 | return lhs.Value < rhs.Value && lhs.Percent <= rhs.Percent; 28 | } 29 | public static bool operator>(FanCurvePoint lhs, FanCurvePoint rhs) 30 | { 31 | return lhs.Value > rhs.Value && lhs.Percent >= rhs.Percent; 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /SysFanControl/Models/FanCurveSource.cs: -------------------------------------------------------------------------------- 1 | using OpenHardwareMonitor.Hardware; 2 | using SysFanControl.ViewModels; 3 | using System; 4 | 5 | namespace SysFanControl.Models 6 | { 7 | public class FanCurveSource : HardwareNotifyPropertyChanged 8 | { 9 | private float value = 0.0f; 10 | 11 | public FanCurveSource(ISensor sensor) 12 | { 13 | if (!IsSensorAllowed(sensor)) 14 | { 15 | throw new ArgumentException("Sensor type must be temperature or power."); 16 | } 17 | 18 | Sensor = sensor; 19 | Update(); 20 | } 21 | 22 | public string Name { get => Sensor.Name; } 23 | public float Value 24 | { 25 | get => value; 26 | private set => SetProperty(ref this.value, value); 27 | } 28 | public SensorType Type { get => Sensor.SensorType; } 29 | public ISensor Sensor { get; } 30 | 31 | public override void Update() 32 | { 33 | Sensor.Hardware.Update(); 34 | var newValue = Sensor.Value; 35 | if (newValue.HasValue) 36 | { 37 | Value = newValue.Value; 38 | } 39 | } 40 | 41 | public static bool IsSensorAllowed(ISensor sensor) 42 | { 43 | return sensor.SensorType == SensorType.Temperature || sensor.SensorType == SensorType.Power; 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /SysFanControl/Models/GPU.cs: -------------------------------------------------------------------------------- 1 | using SysFanControl.ViewModels; 2 | using OpenHardwareMonitor.Hardware; 3 | using System; 4 | 5 | namespace SysFanControl.Models 6 | { 7 | public class GPU : HardwareNotifyPropertyChanged 8 | { 9 | private readonly IHardware gpu; 10 | private int temperature = 0; 11 | 12 | public GPU(IHardware gpu) 13 | { 14 | if (gpu.HardwareType != HardwareType.GpuAti && gpu.HardwareType != HardwareType.GpuNvidia) 15 | { 16 | throw new ArgumentException("Argument isn't a GPU."); 17 | } 18 | 19 | this.gpu = gpu; 20 | } 21 | 22 | public int Temperature 23 | { 24 | get => temperature; 25 | private set => SetProperty(ref temperature, value); 26 | } 27 | 28 | public string Name 29 | { 30 | get => gpu.Name; 31 | } 32 | 33 | public override void Update() 34 | { 35 | gpu.Update(); 36 | var newTemperature = gpu.Sensors[0].Value; 37 | if (newTemperature.HasValue) 38 | { 39 | Temperature = (int)newTemperature.Value; 40 | } 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /SysFanControl/Models/SensorEx.cs: -------------------------------------------------------------------------------- 1 | using OpenHardwareMonitor.Hardware; 2 | 3 | namespace SysFanControl.Models 4 | { 5 | public class SensorEx 6 | { 7 | public SensorEx(ISensor sensor) 8 | { 9 | Sensor = sensor; 10 | } 11 | 12 | public ISensor Sensor { get; } 13 | public string Name 14 | { 15 | get => Sensor.Name.ToLower().StartsWith(Sensor.SensorType.ToString().ToLower()) ? 16 | Sensor.Name : $"{Sensor.Name} {Sensor.SensorType.ToString()}"; 17 | } 18 | public float? Value { get => Sensor.Value; } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /SysFanControl/Models/SmartFanCurvePoint.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace SysFanControl.Models 4 | { 5 | /// 6 | /// An extension of that ensures that the current point is between 7 | /// and . 8 | /// 9 | /// 10 | /// Thrown when the current point is not between and . 11 | /// 12 | public class SmartFanCurvePoint : FanCurvePoint 13 | { 14 | private static readonly int decimalPlaces = 1; 15 | private static readonly decimal increment = 0.1M * decimalPlaces; 16 | private FanCurvePoint previousPoint, nextPoint; 17 | 18 | public SmartFanCurvePoint(FanCurvePoint previousPoint, FanCurvePoint point) 19 | { 20 | if (previousPoint != null && previousPoint > point) 21 | { 22 | throw new ArgumentException("Previous point must be less than point."); 23 | } 24 | 25 | Value = point.Value; 26 | Percent = point.Percent; 27 | PreviousPoint = previousPoint; 28 | } 29 | 30 | public new decimal Value 31 | { 32 | get => base.Value; 33 | set 34 | { 35 | // Current value must be greater than previous value. 36 | if (PreviousPoint != null) 37 | { 38 | if (value <= PreviousPoint.Value) 39 | { 40 | base.Value = PreviousPoint.Value + increment; 41 | return; 42 | } 43 | } 44 | // Current value must be less than next value. 45 | if (NextPoint != null) 46 | { 47 | if (value >= NextPoint.Value) 48 | { 49 | base.Value = NextPoint.Value - increment; 50 | return; 51 | } 52 | } 53 | 54 | base.Value = value; 55 | } 56 | } 57 | public new int Percent 58 | { 59 | get => base.Percent; 60 | set 61 | { 62 | // Current percent must be greater than or equal to previous percent. 63 | if (PreviousPoint != null) 64 | { 65 | if (value < PreviousPoint.Percent) 66 | { 67 | base.Percent = PreviousPoint.Percent; 68 | return; 69 | } 70 | } 71 | // Current percent must be less than or equal to next percent. 72 | if (NextPoint != null) 73 | { 74 | if (value > NextPoint.Percent) 75 | { 76 | base.Percent = NextPoint.Percent; 77 | return; 78 | } 79 | } 80 | 81 | base.Percent = value; 82 | } 83 | } 84 | 85 | public FanCurvePoint PreviousPoint 86 | { 87 | get => previousPoint; 88 | set 89 | { 90 | if (!SetPreviousPoint(value)) 91 | { 92 | throw new ArgumentException("Invalid previous point."); 93 | } 94 | } 95 | } 96 | public FanCurvePoint NextPoint 97 | { 98 | get => nextPoint; 99 | set 100 | { 101 | if (!SetNextPoint(value)) 102 | { 103 | throw new ArgumentException("Invalid next point."); 104 | } 105 | } 106 | } 107 | 108 | private bool SetPreviousPoint(FanCurvePoint point) 109 | { 110 | var previousPoint = PreviousPoint ?? point; 111 | if (previousPoint == null) 112 | { 113 | return true; 114 | } 115 | 116 | if (previousPoint > this) 117 | { 118 | return false; 119 | } 120 | 121 | SetProperty(ref this.previousPoint, point, nameof(PreviousPoint)); 122 | return true; 123 | } 124 | private bool SetNextPoint(FanCurvePoint point) 125 | { 126 | var nextPoint = NextPoint ?? point; 127 | if (nextPoint == null) 128 | { 129 | return true; 130 | } 131 | 132 | if (nextPoint < this) 133 | { 134 | return false; 135 | } 136 | 137 | SetProperty(ref this.nextPoint, point, nameof(NextPoint)); 138 | return true; 139 | } 140 | } 141 | } 142 | -------------------------------------------------------------------------------- /SysFanControl/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Resources; 3 | using System.Runtime.CompilerServices; 4 | using System.Runtime.InteropServices; 5 | using System.Windows; 6 | 7 | // General Information about an assembly is controlled through the following 8 | // set of attributes. Change these attribute values to modify the information 9 | // associated with an assembly. 10 | [assembly: AssemblyTitle("GPUFanControl")] 11 | [assembly: AssemblyDescription("")] 12 | [assembly: AssemblyConfiguration("")] 13 | [assembly: AssemblyCompany("")] 14 | [assembly: AssemblyProduct("GPUFanControl")] 15 | [assembly: AssemblyCopyright("Copyright © 2020")] 16 | [assembly: AssemblyTrademark("")] 17 | [assembly: AssemblyCulture("")] 18 | 19 | // Setting ComVisible to false makes the types in this assembly not visible 20 | // to COM components. If you need to access a type in this assembly from 21 | // COM, set the ComVisible attribute to true on that type. 22 | [assembly: ComVisible(false)] 23 | 24 | //In order to begin building localizable applications, set 25 | //CultureYouAreCodingWith in your .csproj file 26 | //inside a . For example, if you are using US english 27 | //in your source files, set the to en-US. Then uncomment 28 | //the NeutralResourceLanguage attribute below. Update the "en-US" in 29 | //the line below to match the UICulture setting in the project file. 30 | 31 | //[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)] 32 | 33 | 34 | [assembly: ThemeInfo( 35 | ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located 36 | //(used if a resource is not found in the page, 37 | // or application resource dictionaries) 38 | ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located 39 | //(used if a resource is not found in the page, 40 | // app, or any theme specific resource dictionaries) 41 | )] 42 | 43 | 44 | // Version information for an assembly consists of the following four values: 45 | // 46 | // Major Version 47 | // Minor Version 48 | // Build Number 49 | // Revision 50 | // 51 | // You can specify all the values or you can default the Build and Revision Numbers 52 | // by using the '*' as shown below: 53 | // [assembly: AssemblyVersion("1.0.*")] 54 | [assembly: AssemblyVersion("1.0.0.0")] 55 | [assembly: AssemblyFileVersion("1.0.0.0")] 56 | -------------------------------------------------------------------------------- /SysFanControl/Properties/Resources.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace SysFanControl.Properties { 12 | using System; 13 | 14 | 15 | /// 16 | /// A strongly-typed resource class, for looking up localized strings, etc. 17 | /// 18 | // This class was auto-generated by the StronglyTypedResourceBuilder 19 | // class via a tool like ResGen or Visual Studio. 20 | // To add or remove a member, edit your .ResX file then rerun ResGen 21 | // with the /str option, or rebuild your VS project. 22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")] 23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 25 | public class Resources { 26 | 27 | private static global::System.Resources.ResourceManager resourceMan; 28 | 29 | private static global::System.Globalization.CultureInfo resourceCulture; 30 | 31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] 32 | internal Resources() { 33 | } 34 | 35 | /// 36 | /// Returns the cached ResourceManager instance used by this class. 37 | /// 38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 39 | public static global::System.Resources.ResourceManager ResourceManager { 40 | get { 41 | if (object.ReferenceEquals(resourceMan, null)) { 42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("SysFanControl.Properties.Resources", typeof(Resources).Assembly); 43 | resourceMan = temp; 44 | } 45 | return resourceMan; 46 | } 47 | } 48 | 49 | /// 50 | /// Overrides the current thread's CurrentUICulture property for all 51 | /// resource lookups using this strongly typed resource class. 52 | /// 53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 54 | public static global::System.Globalization.CultureInfo Culture { 55 | get { 56 | return resourceCulture; 57 | } 58 | set { 59 | resourceCulture = value; 60 | } 61 | } 62 | 63 | /// 64 | /// Looks up a localized resource of type System.Drawing.Icon similar to (Icon). 65 | /// 66 | public static System.Drawing.Icon speedfan { 67 | get { 68 | object obj = ResourceManager.GetObject("speedfan", resourceCulture); 69 | return ((System.Drawing.Icon)(obj)); 70 | } 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /SysFanControl/Properties/Resources.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | 121 | 122 | ..\Resources\speedfan.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a 123 | 124 | -------------------------------------------------------------------------------- /SysFanControl/Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace SysFanControl.Properties 12 | { 13 | 14 | 15 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 16 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] 17 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase 18 | { 19 | 20 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); 21 | 22 | public static Settings Default 23 | { 24 | get 25 | { 26 | return defaultInstance; 27 | } 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /SysFanControl/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /SysFanControl/Resources/speedfan.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/integralfx/SysFanControl/582a5bb46937d45523d7c207fef5ecaa0ac4911e/SysFanControl/Resources/speedfan.ico -------------------------------------------------------------------------------- /SysFanControl/SensorValueConverter.cs: -------------------------------------------------------------------------------- 1 | using OpenHardwareMonitor.Hardware; 2 | using SysFanControl.Models; 3 | using System; 4 | using System.Globalization; 5 | using System.Windows.Data; 6 | 7 | namespace SysFanControl 8 | { 9 | [ValueConversion(typeof(SensorEx), typeof(string))] 10 | public class SensorValueConverter : IValueConverter 11 | { 12 | public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 13 | { 14 | if (value == null) 15 | { 16 | return null; 17 | } 18 | 19 | var source = value as SensorEx; 20 | switch (source.Sensor.SensorType) 21 | { 22 | case SensorType.Temperature: 23 | return $"{source.Sensor.Value}°C"; 24 | case SensorType.Power: 25 | return $"{source.Sensor.Value:0.00}W"; 26 | default: 27 | return source.Sensor.Value.ToString(); 28 | } 29 | } 30 | 31 | public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) 32 | { 33 | return null; 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /SysFanControl/SysFanControl.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | Debug 7 | AnyCPU 8 | {9696BEC3-1A4B-4648-BCDA-E9E95F813A57} 9 | WinExe 10 | SysFanControl 11 | SysFanControl 12 | v4.7.2 13 | 512 14 | {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 15 | 4 16 | true 17 | true 18 | 19 | 20 | 21 | 22 | AnyCPU 23 | true 24 | full 25 | false 26 | bin\Debug\ 27 | DEBUG;TRACE 28 | prompt 29 | 4 30 | 31 | 32 | AnyCPU 33 | pdbonly 34 | true 35 | bin\Release\ 36 | TRACE 37 | prompt 38 | 4 39 | 40 | 41 | Resources\speedfan.ico 42 | 43 | 44 | 45 | ..\packages\ControlzEx.3.0.2.4\lib\net462\ControlzEx.dll 46 | 47 | 48 | ..\packages\Costura.Fody.4.1.0\lib\net40\Costura.dll 49 | 50 | 51 | ..\packages\MahApps.Metro.1.6.5\lib\net47\MahApps.Metro.dll 52 | 53 | 54 | ..\packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll 55 | 56 | 57 | 58 | 59 | 60 | 61 | ..\packages\ControlzEx.3.0.2.4\lib\net462\System.Windows.Interactivity.dll 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 4.0 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | MSBuild:Compile 79 | Designer 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | MSBuild:Compile 93 | Designer 94 | 95 | 96 | App.xaml 97 | Code 98 | 99 | 100 | MainWindow.xaml 101 | Code 102 | 103 | 104 | 105 | 106 | 107 | 108 | Code 109 | 110 | 111 | True 112 | True 113 | Resources.resx 114 | 115 | 116 | True 117 | Settings.settings 118 | True 119 | 120 | 121 | PublicResXFileCodeGenerator 122 | Resources.Designer.cs 123 | 124 | 125 | 126 | SettingsSingleFileGenerator 127 | Settings.Designer.cs 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | {b0397530-545a-471d-bb74-027ae456df1a} 136 | OpenHardwareMonitorLib 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. 150 | 151 | 152 | 153 | 154 | -------------------------------------------------------------------------------- /SysFanControl/ViewModels/MainWindowViewModel.cs: -------------------------------------------------------------------------------- 1 | using SysFanControl.Models; 2 | using OpenHardwareMonitor.Hardware; 3 | using System; 4 | using System.Collections.ObjectModel; 5 | using System.ComponentModel; 6 | using System.Linq; 7 | using System.Windows.Threading; 8 | using System.Collections.Generic; 9 | using Newtonsoft.Json.Linq; 10 | using System.IO; 11 | using System.Windows; 12 | 13 | namespace SysFanControl.ViewModels 14 | { 15 | public class MainWindowViewModel : BaseNotifyPropertyChanged, IDisposable 16 | { 17 | private const string settingsFile = "SysFanControl.json"; 18 | private readonly Computer computer = new Computer 19 | { 20 | MainboardEnabled = true, 21 | CPUEnabled = true, 22 | RAMEnabled = true, 23 | GPUEnabled = true, 24 | FanControllerEnabled = true 25 | }; 26 | private readonly IHardware superIO; 27 | private IHardware selectedHardware; 28 | private ObservableCollection selectedHardwareSensors; 29 | private SensorEx selectedSensor; 30 | private FanCurve selectedFanCurve; 31 | private readonly DispatcherTimer timer; 32 | private bool disposed = false; 33 | private readonly Dictionary> hardwareSensorsMapping = 34 | new Dictionary>(); 35 | private double pollingInterval; 36 | 37 | public string Version { get => "0.5.2"; } 38 | public string Title { get => $"SFC v{Version}"; } 39 | public ObservableCollection Hardware { get; } 40 | public IHardware SelectedHardware 41 | { 42 | get => selectedHardware; 43 | set 44 | { 45 | SetProperty(ref selectedHardware, value); 46 | if (selectedHardware != null) 47 | { 48 | SelectedHardwareSensors = hardwareSensorsMapping[selectedHardware]; 49 | 50 | if (SelectedSensor == null) 51 | { 52 | SelectedSensor = SelectedHardwareSensors.First(); 53 | } 54 | } 55 | } 56 | } 57 | public ObservableCollection SelectedHardwareSensors 58 | { 59 | get => selectedHardwareSensors; 60 | private set => SetProperty(ref selectedHardwareSensors, value); 61 | } 62 | public SensorEx SelectedSensor 63 | { 64 | get => selectedSensor; 65 | set 66 | { 67 | SetProperty(ref selectedSensor, value); 68 | if (SelectedFanCurve != null) 69 | { 70 | SelectedFanCurve.Source = selectedSensor != null ? new FanCurveSource(selectedSensor.Sensor) : null; 71 | } 72 | } 73 | } 74 | public BindingList FanCurves { get; } = new BindingList(); 75 | public FanCurve SelectedFanCurve 76 | { 77 | get => selectedFanCurve != null && selectedFanCurve.Enabled ? selectedFanCurve : null; 78 | set 79 | { 80 | SetProperty(ref selectedFanCurve, value); 81 | // Update the selected hardware and selected sensor with the selected fan curve. 82 | if (SelectedFanCurve != null) 83 | { 84 | // Changing SelectedHardware causes Source.Sensor to change to the first sensor. 85 | var sourceSensor = SelectedFanCurve.Source.Sensor; 86 | SelectedHardware = SelectedFanCurve.Source.Sensor.Hardware; 87 | SelectedSensor = hardwareSensorsMapping[SelectedHardware] 88 | .Where(s => s.Sensor == sourceSensor) 89 | .First(); 90 | } 91 | } 92 | } 93 | public double PollingInterval 94 | { 95 | get => pollingInterval; 96 | set 97 | { 98 | SetProperty(ref pollingInterval, value); 99 | 100 | timer.Stop(); 101 | timer.Interval = TimeSpan.FromSeconds(value); 102 | timer.Start(); 103 | } 104 | } 105 | 106 | /// 107 | /// MainWindowViewModel constructor. 108 | /// 109 | /// 110 | /// Thrown when CPU, GPU, motherboard or SuperIO could not be detected. 111 | /// 112 | public MainWindowViewModel() 113 | { 114 | computer.Open(); 115 | 116 | if (computer.Hardware.Length == 0) 117 | { 118 | throw new HardwareNotDetectedException("No hardware detected. Try running as admin."); 119 | } 120 | 121 | var moboHardware = computer.Hardware.Where(h => h.HardwareType == HardwareType.Mainboard); 122 | if (moboHardware.Count() == 0) 123 | { 124 | throw new HardwareNotDetectedException("No motherboard detected."); 125 | } 126 | 127 | var superIOHardware = moboHardware.First().SubHardware.Where(h => h.HardwareType == HardwareType.SuperIO); 128 | if (superIOHardware.Count() == 0) 129 | { 130 | throw new HardwareNotDetectedException("No SuperIO detected."); 131 | } 132 | 133 | var gpuHardware = computer.Hardware 134 | .Where(h => h.HardwareType == HardwareType.GpuAti || h.HardwareType == HardwareType.GpuNvidia); 135 | if (gpuHardware.Count() == 0) 136 | { 137 | throw new HardwareNotDetectedException("No GPU detected."); 138 | } 139 | 140 | superIO = superIOHardware.First(); 141 | superIO.Update(); 142 | 143 | var superIOFans = superIO.Sensors.Where(s => s.SensorType == SensorType.Fan).ToList(); 144 | foreach (var fanSensor in superIOFans) 145 | { 146 | FanCurves.Add(new FanCurve(fanSensor, OnEnabledChanged)); 147 | } 148 | 149 | Hardware = new ObservableCollection( 150 | // Don't show hardware with 0 allowed sensors. 151 | computer.Hardware.Where(h => 152 | { 153 | if (h.HardwareType == HardwareType.Mainboard) 154 | { 155 | return true; 156 | } 157 | return h.Sensors.Where(FanCurveSource.IsSensorAllowed).Count() > 0; 158 | }) 159 | ); 160 | 161 | // Create the hardware to sensors mapping. 162 | foreach (var hw in Hardware) 163 | { 164 | var sensorCollection = new ObservableCollection(); 165 | var sensors = hw.Sensors.Where(FanCurveSource.IsSensorAllowed); 166 | if (hw.HardwareType == HardwareType.Mainboard) 167 | { 168 | sensors = superIO.Sensors.Where(FanCurveSource.IsSensorAllowed); 169 | } 170 | foreach (var sensor in sensors) 171 | { 172 | sensorCollection.Add(new SensorEx(sensor)); 173 | } 174 | hardwareSensorsMapping.Add(hw, sensorCollection); 175 | } 176 | 177 | SelectedHardware = gpuHardware.First(); 178 | SelectedHardwareSensors = hardwareSensorsMapping[SelectedHardware]; 179 | SelectedSensor = SelectedHardwareSensors.First(); 180 | 181 | LoadSettings(); 182 | 183 | timer = new DispatcherTimer 184 | { 185 | Interval = TimeSpan.FromSeconds(PollingInterval) 186 | }; 187 | timer.Tick += timer_Tick; 188 | timer.Start(); 189 | } 190 | 191 | ~MainWindowViewModel() 192 | { 193 | Dispose(false); 194 | } 195 | 196 | private void SaveSettings() 197 | { 198 | var root = new JObject 199 | { 200 | ["pollingInterval"] = PollingInterval 201 | }; 202 | foreach (var fanCurve in FanCurves) 203 | { 204 | root[fanCurve.Sensor.Identifier.ToString()] = FanCurveJSON.Serialise(fanCurve); 205 | } 206 | 207 | try 208 | { 209 | File.WriteAllText(settingsFile, root.ToString()); 210 | } 211 | catch (Exception e) 212 | { 213 | MessageBox.Show( 214 | $"{e.Message}:\n{e.StackTrace}", 215 | "Error: Failed to save settings", 216 | MessageBoxButton.OK, 217 | MessageBoxImage.Error 218 | ); 219 | } 220 | } 221 | 222 | private void LoadSettings() 223 | { 224 | if (!File.Exists(settingsFile)) 225 | { 226 | return; 227 | } 228 | 229 | try 230 | { 231 | var root = JObject.Parse(File.ReadAllText(settingsFile)); 232 | 233 | if (root.ContainsKey("pollingInterval")) 234 | { 235 | pollingInterval = root["pollingInterval"].ToObject(); 236 | } 237 | else 238 | { 239 | pollingInterval = 2.0; 240 | } 241 | 242 | // Load the fan curves. 243 | var list = root.Properties().Join( 244 | FanCurves, 245 | p => p.Name, 246 | f => f.Sensor.Identifier.ToString(), 247 | (p, f) => new Tuple(p, f) 248 | ); 249 | foreach (var obj in list) 250 | { 251 | FanCurveJSON.UpdateFromJSON((JObject)obj.Item1.Value, obj.Item2, Hardware.ToList()); 252 | } 253 | } 254 | catch (Exception e) 255 | { 256 | MessageBox.Show( 257 | $"{e.Message}:\n{e.StackTrace}", 258 | "Error: Failed to parse settings", 259 | MessageBoxButton.OK, 260 | MessageBoxImage.Error 261 | ); 262 | } 263 | } 264 | 265 | private void OnEnabledChanged(FanCurve sender) 266 | { 267 | // Checked curve, so update the source with the currently selected sensor. 268 | if (sender.Enabled && sender.Source == null) 269 | { 270 | sender.Source = SelectedSensor != null ? new FanCurveSource(SelectedSensor.Sensor) : null; 271 | } 272 | 273 | if (sender == SelectedFanCurve) 274 | { 275 | PropertyUpdated(nameof(SelectedFanCurve)); 276 | } 277 | } 278 | 279 | private void timer_Tick(object sender, EventArgs e) 280 | { 281 | foreach (var fanCurve in FanCurves) 282 | { 283 | fanCurve.Update(); 284 | } 285 | 286 | if (SelectedSensor != null) 287 | { 288 | SelectedSensor.Sensor.Hardware.Update(); 289 | PropertyUpdated(nameof(SelectedSensor)); 290 | } 291 | } 292 | 293 | public void Dispose() 294 | { 295 | Dispose(true); 296 | GC.SuppressFinalize(this); 297 | } 298 | 299 | protected virtual void Dispose(bool disposing) 300 | { 301 | if (!disposed) 302 | { 303 | if (disposing) 304 | { 305 | foreach (var fanCurve in FanCurves) 306 | { 307 | fanCurve.Dispose(); 308 | } 309 | } 310 | 311 | SaveSettings(); 312 | timer.Stop(); 313 | computer.Close(); 314 | 315 | disposed = true; 316 | } 317 | } 318 | 319 | public class HardwareNotDetectedException : Exception 320 | { 321 | public HardwareNotDetectedException(string message) : base(message) 322 | { 323 | 324 | } 325 | } 326 | } 327 | } 328 | -------------------------------------------------------------------------------- /SysFanControl/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /SysFanControl/speedfan.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/integralfx/SysFanControl/582a5bb46937d45523d7c207fef5ecaa0ac4911e/SysFanControl/speedfan.ico -------------------------------------------------------------------------------- /image.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/integralfx/SysFanControl/582a5bb46937d45523d7c207fef5ecaa0ac4911e/image.png --------------------------------------------------------------------------------