ejrh

http://wp.me/p1iPhe-9A - CSV logging and GPU fan control

May 13th, 2011
440
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 8.61 KB | None | 0 0
  1. Index: GUI/MainForm.cs
  2. ===================================================================
  3. --- GUI/MainForm.cs (revision 314)
  4. +++ GUI/MainForm.cs (working copy)
  5. @@ -60,6 +60,7 @@
  6.      private SystemTray systemTray;    
  7.      private StartupManager startupManager = new StartupManager();
  8.      private UpdateVisitor updateVisitor = new UpdateVisitor();
  9. +    private DateTime lastLogTime = System.DateTime.MinValue;
  10.      private SensorGadget gadget;
  11.  
  12.      private UserOption showHiddenSensors;
  13. @@ -343,6 +344,27 @@
  14.  
  15.        if (wmiProvider != null)
  16.          wmiProvider.Update();
  17. +
  18. +      try
  19. +      {
  20. +        int intervalSeconds = settings.GetValue("log.interval", 0);
  21. +        if (intervalSeconds > 0)
  22. +        {
  23. +          DateTime currentTime = System.DateTime.Now;
  24. +          if (currentTime.CompareTo(lastLogTime.AddSeconds(intervalSeconds)) >= 0)
  25. +          {
  26. +            string timeStr = System.DateTime.Now.ToString();
  27. +            LogVisitor logVisitor = new LogVisitor(timeStr);
  28. +            computer.Accept(logVisitor);
  29. +            logVisitor.AppendToFile("sensor.tsv");
  30. +            lastLogTime = currentTime;
  31. +          }
  32. +        }
  33. +      }
  34. +      catch (Exception)
  35. +      {
  36. +        //ignore
  37. +      }
  38.      }
  39.  
  40.      private void SaveConfiguration() {
  41. @@ -494,6 +516,26 @@
  42.                  };
  43.                }
  44.              }
  45. +
  46. +            if (control.ReferenceSensor != null)
  47. +            {
  48. +              MenuItem autoItem = new MenuItem("Auto");
  49. +              controlItem.MenuItems.Add(autoItem);
  50. +              autoItem.Checked = control.ControlMode == ControlMode.Auto;
  51. +              for (int i = 35; i <= 60; i += 1)
  52. +              {
  53. +                MenuItem item = new MenuItem(i + " degrees");
  54. +                autoItem.MenuItems.Add(item);
  55. +                item.Checked = control.ControlMode == ControlMode.Auto &&
  56. +                  Math.Round(control.ReferenceValue) == i;
  57. +                int refValue = i;
  58. +                item.Click += delegate(object obj, EventArgs args)
  59. +                {
  60. +                control.SetAuto(refValue);
  61. +                };
  62. +              }
  63. +            }
  64. +
  65.              treeContextMenu.MenuItems.Add(controlItem);
  66.            }
  67.  
  68. Index: GUI/LogVisitor.cs
  69. ===================================================================
  70. --- GUI/LogVisitor.cs   (revision 0)
  71. +++ GUI/LogVisitor.cs   (revision 0)
  72. @@ -0,0 +1,46 @@
  73. +using System;
  74. +using System.Collections.Generic;
  75. +using OpenHardwareMonitor.Hardware;
  76. +
  77. +namespace OpenHardwareMonitor.GUI
  78. +{
  79. +    public class LogVisitor : IVisitor
  80. +    {
  81. +        private System.Text.StringBuilder buffer;
  82. +        private string timeString;
  83. +        private string parentName;
  84. +
  85. +        public LogVisitor(string timeStr)
  86. +        {
  87. +            buffer = new System.Text.StringBuilder();
  88. +            timeString = timeStr;
  89. +        }
  90. +
  91. +        public void AppendToFile(string filename)
  92. +        {
  93. +            System.IO.File.AppendAllText(filename, buffer.ToString());
  94. +        }
  95. +
  96. +        public void VisitComputer(IComputer computer)
  97. +        {
  98. +            computer.Traverse(this);
  99. +        }
  100. +
  101. +        public void VisitHardware(IHardware hardware)
  102. +        {
  103. +            foreach (IHardware subHardware in hardware.SubHardware)
  104. +                subHardware.Accept(this);
  105. +
  106. +            parentName = hardware.Name;
  107. +            foreach (ISensor sensor in hardware.Sensors)
  108. +                sensor.Accept(this);
  109. +        }
  110. +
  111. +        public void VisitSensor(ISensor sensor)
  112. +        {
  113. +            buffer.Append(timeString + "\t" + parentName + "\t" + sensor.Name + "\t" + sensor.SensorType + "\t" + sensor.Value + "\n");
  114. +        }
  115. +
  116. +        public void VisitParameter(IParameter parameter) { }
  117. +    }
  118. +}
  119. Index: GUI/UpdateVisitor.cs
  120. ===================================================================
  121. --- GUI/UpdateVisitor.cs    (revision 314)
  122. +++ GUI/UpdateVisitor.cs    (working copy)
  123. @@ -49,9 +49,27 @@
  124.        hardware.Update();
  125.        foreach (IHardware subHardware in hardware.SubHardware)
  126.          subHardware.Accept(this);
  127. +
  128. +      foreach (ISensor sensor in hardware.Sensors)
  129. +          sensor.Accept(this);
  130.      }
  131.  
  132. -    public void VisitSensor(ISensor sensor) { }
  133. +    public void VisitSensor(ISensor sensor)
  134. +    {
  135. +      if (sensor.Control != null && sensor.Control.ControlMode == ControlMode.Auto && sensor.Control.ReferenceSensor.Value.HasValue)
  136. +      {
  137. +        float currentVal = sensor.Control.ReferenceSensor.Value.Value;
  138. +        if (currentVal > sensor.Control.ReferenceValue && sensor.Control.SoftwareValue < sensor.Control.MaxSoftwareValue)
  139. +        {
  140. +          sensor.Control.SetSoftware(sensor.Control.SoftwareValue + 1);
  141. +        }
  142. +        else if (currentVal < sensor.Control.ReferenceValue && sensor.Control.SoftwareValue > sensor.Control.MinSoftwareValue)
  143. +        {
  144. +            sensor.Control.SetSoftware(sensor.Control.SoftwareValue - 1);
  145. +        }
  146. +        sensor.Control.SetAuto(sensor.Control.ReferenceValue);
  147. +      }
  148. +    }
  149.  
  150.      public void VisitParameter(IParameter parameter) { }
  151.    }
  152. Index: OpenHardwareMonitor.csproj
  153. ===================================================================
  154. --- OpenHardwareMonitor.csproj  (revision 314)
  155. +++ OpenHardwareMonitor.csproj  (working copy)
  156. @@ -72,6 +72,7 @@
  157.      <Compile Include="GUI\GadgetWindow.cs" />
  158.      <Compile Include="GUI\Gadget.cs" />
  159.      <Compile Include="GUI\HardwareTypeImage.cs" />
  160. +    <Compile Include="GUI\LogVisitor.cs" />
  161.      <Compile Include="GUI\PlotPanel.cs">
  162.        <SubType>UserControl</SubType>
  163.      </Compile>
  164. Index: Hardware/ATI/ATIGPU.cs
  165. ===================================================================
  166. --- Hardware/ATI/ATIGPU.cs  (revision 314)
  167. +++ Hardware/ATI/ATIGPU.cs  (working copy)
  168. @@ -82,7 +82,7 @@
  169.        }
  170.  
  171.        this.fanControl = new Control(controlSensor, settings, afsi.MinPercent,
  172. -        afsi.MaxPercent);
  173. +        afsi.MaxPercent, this.temperature);
  174.        this.fanControl.ControlModeChanged += ControlModeChanged;
  175.        this.fanControl.SoftwareControlValueChanged +=
  176.          SoftwareControlValueChanged;
  177. Index: Hardware/Control.cs
  178. ===================================================================
  179. --- Hardware/Control.cs (revision 314)
  180. +++ Hardware/Control.cs (working copy)
  181. @@ -50,14 +50,17 @@
  182.      private float softwareValue;
  183.      private float minSoftwareValue;
  184.      private float maxSoftwareValue;
  185. +    private ISensor referenceSensor;
  186. +    private float referenceValue;
  187.  
  188.      public Control(ISensor sensor, ISettings settings, float minSoftwareValue,
  189. -      float maxSoftwareValue)
  190. +      float maxSoftwareValue, Sensor referenceSensor)
  191.      {
  192.        this.identifier = new Identifier(sensor.Identifier, "control");
  193.        this.settings = settings;
  194.        this.minSoftwareValue = minSoftwareValue;
  195.        this.maxSoftwareValue = maxSoftwareValue;
  196. +      this.referenceSensor = referenceSensor;
  197.  
  198.        if (!float.TryParse(settings.GetValue(
  199.            new Identifier(identifier, "value").ToString(), "0"),
  200. @@ -100,6 +103,18 @@
  201.        }
  202.      }
  203.  
  204. +    public ISensor ReferenceSensor
  205. +    {
  206. +      get
  207. +      {
  208. +        return referenceSensor;
  209. +      }
  210. +      private set
  211. +      {
  212. +        referenceSensor = value;
  213. +      }
  214. +    }
  215. +
  216.      public float SoftwareValue {
  217.        get {
  218.          return softwareValue;
  219. @@ -116,6 +131,18 @@
  220.        }
  221.      }
  222.  
  223. +    public float ReferenceValue
  224. +    {
  225. +      get
  226. +      {
  227. +        return referenceValue;
  228. +      }
  229. +      private set
  230. +      {
  231. +        referenceValue = value;
  232. +      }
  233. +    }
  234. +
  235.      public void SetDefault() {
  236.        ControlMode = ControlMode.Default;
  237.      }
  238. @@ -137,6 +164,12 @@
  239.        SoftwareValue = value;
  240.      }
  241.  
  242. +    public void SetAuto(float value)
  243. +    {
  244. +        ControlMode = ControlMode.Auto;
  245. +        ReferenceValue = value;
  246. +    }
  247. +
  248.      internal event ControlEventHandler ControlModeChanged;
  249.      internal event ControlEventHandler SoftwareControlValueChanged;
  250.    }
  251. Index: Hardware/IControl.cs
  252. ===================================================================
  253. --- Hardware/IControl.cs    (revision 314)
  254. +++ Hardware/IControl.cs    (working copy)
  255. @@ -39,7 +39,8 @@
  256.  
  257.    public enum ControlMode {
  258.      Default,
  259. -    Software
  260. +    Software,
  261. +    Auto
  262.    }
  263.  
  264.    public interface IControl {
  265. @@ -48,7 +49,10 @@
  266.  
  267.      ControlMode ControlMode { get; }
  268.  
  269. +    ISensor ReferenceSensor { get; }
  270. +
  271.      float SoftwareValue { get; }
  272. +    float ReferenceValue { get; }
  273.  
  274.      void SetDefault();
  275.  
  276. @@ -56,6 +60,7 @@
  277.      float MaxSoftwareValue { get; }
  278.  
  279.      void SetSoftware(float value);
  280. +    void SetAuto(float value);
  281.  
  282.    }
  283.  }
Add Comment
Please, Sign In to add comment