Tray sensor display default color is black and color can be changed now. Fixed CPU load reading for AMD CPUs and added additional misc device for AMD core temperature reading.
authormoel.mich
Fri, 12 Feb 2010 22:46:31 +0000
changeset 4247385d4fc990
parent 41 d92bacc2116e
child 43 5b7398d061b7
Tray sensor display default color is black and color can be changed now. Fixed CPU load reading for AMD CPUs and added additional misc device for AMD core temperature reading.
GUI/MainForm.Designer.cs
GUI/MainForm.cs
GUI/SensorNotifyIcon.cs
GUI/SensorSystemTray.cs
Hardware/CPU/AMD0FCPU.cs
Hardware/CPU/AMD10CPU.cs
Properties/AssemblyInfo.cs
Utilities/Configuration.cs
     1.1 --- a/GUI/MainForm.Designer.cs	Fri Feb 12 08:17:51 2010 +0000
     1.2 +++ b/GUI/MainForm.Designer.cs	Fri Feb 12 22:46:31 2010 +0000
     1.3 @@ -101,12 +101,12 @@
     1.4        this.aboutToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
     1.5        this.timer = new System.Windows.Forms.Timer(this.components);
     1.6        this.splitContainer = new System.Windows.Forms.SplitContainer();
     1.7 -      this.plotPanel = new OpenHardwareMonitor.GUI.PlotPanel();
     1.8        this.notifyContextMenuStrip = new System.Windows.Forms.ContextMenuStrip(this.components);
     1.9        this.restoreToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
    1.10        this.toolStripMenuItem2 = new System.Windows.Forms.ToolStripSeparator();
    1.11        this.exitToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem();
    1.12        this.sensorContextMenuStrip = new System.Windows.Forms.ContextMenuStrip(this.components);
    1.13 +      this.plotPanel = new OpenHardwareMonitor.GUI.PlotPanel();
    1.14        this.columnsContextMenuStrip.SuspendLayout();
    1.15        this.menuStrip.SuspendLayout();
    1.16        this.splitContainer.Panel1.SuspendLayout();
    1.17 @@ -480,16 +480,6 @@
    1.18        this.splitContainer.SplitterWidth = 3;
    1.19        this.splitContainer.TabIndex = 3;
    1.20        // 
    1.21 -      // plotPanel
    1.22 -      // 
    1.23 -      this.plotPanel.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
    1.24 -      this.plotPanel.Dock = System.Windows.Forms.DockStyle.Fill;
    1.25 -      this.plotPanel.Font = new System.Drawing.Font("Segoe UI", 9F);
    1.26 -      this.plotPanel.Location = new System.Drawing.Point(0, 0);
    1.27 -      this.plotPanel.Name = "plotPanel";
    1.28 -      this.plotPanel.Size = new System.Drawing.Size(478, 198);
    1.29 -      this.plotPanel.TabIndex = 0;
    1.30 -      // 
    1.31        // notifyContextMenuStrip
    1.32        // 
    1.33        this.notifyContextMenuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
    1.34 @@ -524,6 +514,16 @@
    1.35        this.sensorContextMenuStrip.Name = "sensorContextMenuStrip";
    1.36        this.sensorContextMenuStrip.Size = new System.Drawing.Size(61, 4);
    1.37        // 
    1.38 +      // plotPanel
    1.39 +      // 
    1.40 +      this.plotPanel.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
    1.41 +      this.plotPanel.Dock = System.Windows.Forms.DockStyle.Fill;
    1.42 +      this.plotPanel.Font = new System.Drawing.Font("Segoe UI", 9F);
    1.43 +      this.plotPanel.Location = new System.Drawing.Point(0, 0);
    1.44 +      this.plotPanel.Name = "plotPanel";
    1.45 +      this.plotPanel.Size = new System.Drawing.Size(478, 198);
    1.46 +      this.plotPanel.TabIndex = 0;
    1.47 +      // 
    1.48        // MainForm
    1.49        // 
    1.50        this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
     2.1 --- a/GUI/MainForm.cs	Fri Feb 12 08:17:51 2010 +0000
     2.2 +++ b/GUI/MainForm.cs	Fri Feb 12 22:46:31 2010 +0000
     2.3 @@ -253,10 +253,9 @@
     2.4          Config.Set("mainForm.Width", Width);
     2.5          Config.Set("mainForm.Height", Height);
     2.6        }
     2.7 -      
     2.8 +           
     2.9        sensorSystemTray.Dispose();
    2.10        notifyIcon.Dispose();
    2.11 -
    2.12        computer.Close();
    2.13      }
    2.14  
    2.15 @@ -315,7 +314,7 @@
    2.16            } else {
    2.17              ToolStripMenuItem item = new ToolStripMenuItem("Add To Tray");
    2.18              item.Click += delegate(object obj, EventArgs args) {
    2.19 -              sensorSystemTray.Add(node.Sensor);
    2.20 +              sensorSystemTray.Add(node.Sensor, true);
    2.21              };
    2.22              sensorContextMenuStrip.Items.Add(item);
    2.23            }
     3.1 --- a/GUI/SensorNotifyIcon.cs	Fri Feb 12 08:17:51 2010 +0000
     3.2 +++ b/GUI/SensorNotifyIcon.cs	Fri Feb 12 22:46:31 2010 +0000
     3.3 @@ -55,18 +55,32 @@
     3.4      private Bitmap bitmap;
     3.5      private Graphics graphics;
     3.6      private int majorVersion;
     3.7 +    private Color color;
     3.8  
     3.9 -    public SensorNotifyIcon(SensorSystemTray sensorSystemTray, ISensor sensor) {
    3.10 +    public SensorNotifyIcon(SensorSystemTray sensorSystemTray, ISensor sensor,
    3.11 +      bool balloonTip) 
    3.12 +    {
    3.13        this.sensor = sensor;
    3.14        this.notifyIcon = new NotifyIcon();
    3.15 -      this.majorVersion = Environment.OSVersion.Version.Major;      
    3.16 +      this.majorVersion = Environment.OSVersion.Version.Major;
    3.17 +      this.color = Config.Get(sensor.Identifier + "/traycolor", Color.Black);
    3.18        
    3.19        ContextMenuStrip contextMenuStrip = new ContextMenuStrip();
    3.20 -      ToolStripMenuItem item = new ToolStripMenuItem("Remove");
    3.21 -      item.Click += delegate(object obj, EventArgs args) {
    3.22 -        sensorSystemTray.Remove(sensor);
    3.23 +      ToolStripMenuItem removeItem = new ToolStripMenuItem("Remove");
    3.24 +      removeItem.Click += delegate(object obj, EventArgs args) {
    3.25 +        sensorSystemTray.Remove(this.sensor);
    3.26        };
    3.27 -      contextMenuStrip.Items.Add(item);
    3.28 +      contextMenuStrip.Items.Add(removeItem);
    3.29 +      ToolStripMenuItem colorItem = new ToolStripMenuItem("Change Color...");
    3.30 +      colorItem.Click += delegate(object obj, EventArgs args) {
    3.31 +        ColorDialog dialog = new ColorDialog();
    3.32 +        dialog.Color = this.color;
    3.33 +        if (dialog.ShowDialog() == DialogResult.OK) {
    3.34 +          this.color = dialog.Color;
    3.35 +          Config.Set(sensor.Identifier + "/traycolor", this.color);
    3.36 +        }
    3.37 +      };
    3.38 +      contextMenuStrip.Items.Add(colorItem);
    3.39        this.notifyIcon.ContextMenuStrip = contextMenuStrip;
    3.40  
    3.41        this.bitmap = new Bitmap(16, 16, PixelFormat.Format32bppArgb);
    3.42 @@ -79,6 +93,11 @@
    3.43        get { return sensor; }
    3.44      }
    3.45  
    3.46 +    public Color Color {
    3.47 +      get { return color; }
    3.48 +      set { color = value; }
    3.49 +    }
    3.50 +
    3.51      public void Dispose() {      
    3.52        Icon icon = notifyIcon.Icon;
    3.53        notifyIcon.Icon = null;
    3.54 @@ -113,7 +132,7 @@
    3.55  
    3.56        graphics.Clear(SystemColors.ButtonFace);
    3.57        TextRenderer.DrawText(graphics, GetString(), SystemFonts.StatusFont,
    3.58 -        new Point(-2, 0), Color.Blue, SystemColors.ButtonFace);
    3.59 +        new Point(-2, 0), color, SystemColors.ButtonFace);
    3.60  
    3.61        BitmapData data = bitmap.LockBits(
    3.62          new Rectangle(0, 0, bitmap.Width, bitmap.Height),
    3.63 @@ -154,9 +173,9 @@
    3.64          green = bytes[i + 1];
    3.65          red = bytes[i + 2];
    3.66  
    3.67 -        bytes[i] = 255;
    3.68 -        bytes[i + 1] = 255;
    3.69 -        bytes[i + 2] = 255;
    3.70 +        bytes[i] = color.B;
    3.71 +        bytes[i + 1] = color.G;
    3.72 +        bytes[i + 2] = color.R;
    3.73          bytes[i + 3] = (byte)(0.3 * red + 0.59 * green + 0.11 * blue);
    3.74        }
    3.75  
    3.76 @@ -184,9 +203,9 @@
    3.77          case SensorType.Fan: format = "{0}\n{1}: {2:F0} RPM"; break;
    3.78        }
    3.79  
    3.80 -      notifyIcon.Text = string.Format(format, 
    3.81 -        sensor.Hardware.Name, sensor.Name, sensor.Value);
    3.82 -      notifyIcon.Visible = true;
    3.83 +      notifyIcon.Text = string.Format(format, sensor.Hardware.Name, sensor.Name,
    3.84 +        sensor.Value);    
    3.85 +      notifyIcon.Visible = true;         
    3.86      }
    3.87    }
    3.88  }
     4.1 --- a/GUI/SensorSystemTray.cs	Fri Feb 12 08:17:51 2010 +0000
     4.2 +++ b/GUI/SensorSystemTray.cs	Fri Feb 12 22:46:31 2010 +0000
     4.3 @@ -37,6 +37,7 @@
     4.4  
     4.5  using System;
     4.6  using System.Collections.Generic;
     4.7 +using System.Drawing;
     4.8  using System.Text;
     4.9  using System.Windows.Forms;
    4.10  using OpenHardwareMonitor.Hardware;
    4.11 @@ -69,14 +70,12 @@
    4.12  
    4.13      private void SensorAdded(ISensor sensor) {
    4.14        if (Config.Get(sensor.Identifier + "/tray", false)) 
    4.15 -        Add(sensor);   
    4.16 +        Add(sensor, false);   
    4.17      }
    4.18  
    4.19      private void SensorRemoved(ISensor sensor) {
    4.20 -      if (Contains(sensor)) {        
    4.21 -        Remove(sensor);
    4.22 -        Config.Set(sensor.Identifier + "/tray", true);
    4.23 -      }
    4.24 +      if (Contains(sensor)) 
    4.25 +        Remove(sensor, false);
    4.26      }
    4.27  
    4.28      public void Dispose() {
    4.29 @@ -96,17 +95,24 @@
    4.30        return false;
    4.31      }
    4.32  
    4.33 -    public void Add(ISensor sensor) {
    4.34 +    public void Add(ISensor sensor, bool balloonTip) {
    4.35        if (Contains(sensor)) {
    4.36          return;
    4.37 -      } else {
    4.38 -        list.Add(new SensorNotifyIcon(this, sensor));
    4.39 +      } else {        
    4.40 +        list.Add(new SensorNotifyIcon(this, sensor, balloonTip));
    4.41          Config.Set(sensor.Identifier + "/tray", true);
    4.42        }
    4.43      }
    4.44  
    4.45      public void Remove(ISensor sensor) {
    4.46 -      Config.Remove(sensor.Identifier + "/tray");
    4.47 +      Remove(sensor, true);
    4.48 +    }
    4.49 +
    4.50 +    private void Remove(ISensor sensor, bool deleteConfig) {
    4.51 +      if (deleteConfig) {
    4.52 +        Config.Remove(sensor.Identifier + "/tray");
    4.53 +        Config.Remove(sensor.Identifier + "/traycolor");
    4.54 +      }
    4.55        SensorNotifyIcon instance = null;
    4.56        foreach (SensorNotifyIcon icon in list)
    4.57          if (icon.Sensor == sensor)
     5.1 --- a/Hardware/CPU/AMD0FCPU.cs	Fri Feb 12 08:17:51 2010 +0000
     5.2 +++ b/Hardware/CPU/AMD0FCPU.cs	Fri Feb 12 22:46:31 2010 +0000
     5.3 @@ -124,20 +124,20 @@
     5.4      }
     5.5  
     5.6      public void Update() {
     5.7 -      if (pciAddress == 0xFFFFFFFF)
     5.8 -        return;
     5.9 +      if (pciAddress != 0xFFFFFFFF) {
    5.10  
    5.11 -      for (uint i = 0; i < coreTemperatures.Length; i++) {
    5.12 -        if (WinRing0.WritePciConfigDwordEx(
    5.13 -          pciAddress, THERMTRIP_STATUS_REGISTER,
    5.14 -          i > 0 ? THERM_SENSE_CORE_SEL_CPU1 : THERM_SENSE_CORE_SEL_CPU0)) {
    5.15 -          uint value;
    5.16 -          if (WinRing0.ReadPciConfigDwordEx(
    5.17 -            pciAddress, THERMTRIP_STATUS_REGISTER, out value)) {
    5.18 -            coreTemperatures[i].Value = ((value >> 16) & 0xFF) + offset;
    5.19 -            ActivateSensor(coreTemperatures[i]);
    5.20 -          } else {
    5.21 -            DeactivateSensor(coreTemperatures[i]);
    5.22 +        for (uint i = 0; i < coreTemperatures.Length; i++) {
    5.23 +          if (WinRing0.WritePciConfigDwordEx(
    5.24 +            pciAddress, THERMTRIP_STATUS_REGISTER,
    5.25 +            i > 0 ? THERM_SENSE_CORE_SEL_CPU1 : THERM_SENSE_CORE_SEL_CPU0)) {
    5.26 +            uint value;
    5.27 +            if (WinRing0.ReadPciConfigDwordEx(
    5.28 +              pciAddress, THERMTRIP_STATUS_REGISTER, out value)) {
    5.29 +              coreTemperatures[i].Value = ((value >> 16) & 0xFF) + offset;
    5.30 +              ActivateSensor(coreTemperatures[i]);
    5.31 +            } else {
    5.32 +              DeactivateSensor(coreTemperatures[i]);
    5.33 +            }
    5.34            }
    5.35          }
    5.36        }
     6.1 --- a/Hardware/CPU/AMD10CPU.cs	Fri Feb 12 08:17:51 2010 +0000
     6.2 +++ b/Hardware/CPU/AMD10CPU.cs	Fri Feb 12 22:46:31 2010 +0000
     6.3 @@ -57,6 +57,7 @@
     6.4  
     6.5      private const ushort PCI_AMD_VENDOR_ID = 0x1022;
     6.6      private const ushort PCI_AMD_10H_MISCELLANEOUS_DEVICE_ID = 0x1203;
     6.7 +    private const ushort PCI_AMD_11H_MISCELLANEOUS_DEVICE_ID = 0x1303;
     6.8      private const uint REPORTED_TEMPERATURE_CONTROL_REGISTER = 0xA4;
     6.9  
    6.10      public AMD10CPU(string name, uint family, uint model, uint stepping, 
    6.11 @@ -90,6 +91,10 @@
    6.12  
    6.13        pciAddress = WinRing0.FindPciDeviceById(PCI_AMD_VENDOR_ID, 
    6.14          PCI_AMD_10H_MISCELLANEOUS_DEVICE_ID, 0);
    6.15 +      if (pciAddress == 0xFFFFFFFF) 
    6.16 +        pciAddress = WinRing0.FindPciDeviceById(PCI_AMD_VENDOR_ID,
    6.17 +          PCI_AMD_11H_MISCELLANEOUS_DEVICE_ID, 0);
    6.18 +
    6.19        Update();                   
    6.20      }
    6.21  
    6.22 @@ -110,16 +115,15 @@
    6.23      }
    6.24  
    6.25      public void Update() {
    6.26 -      if (pciAddress == 0xFFFFFFFF)
    6.27 -        return;
    6.28 -
    6.29 -      uint value;      
    6.30 -      if (WinRing0.ReadPciConfigDwordEx(pciAddress, 
    6.31 -        REPORTED_TEMPERATURE_CONTROL_REGISTER, out value)) {
    6.32 -        coreTemperature.Value = ((value >> 21) & 0x7FF) / 8.0f;
    6.33 -        ActivateSensor(coreTemperature);
    6.34 -      } else {
    6.35 -        DeactivateSensor(coreTemperature);
    6.36 +      if (pciAddress != 0xFFFFFFFF) {
    6.37 +        uint value;
    6.38 +        if (WinRing0.ReadPciConfigDwordEx(pciAddress,
    6.39 +          REPORTED_TEMPERATURE_CONTROL_REGISTER, out value)) {
    6.40 +          coreTemperature.Value = ((value >> 21) & 0x7FF) / 8.0f;
    6.41 +          ActivateSensor(coreTemperature);
    6.42 +        } else {
    6.43 +          DeactivateSensor(coreTemperature);
    6.44 +        }
    6.45        }
    6.46  
    6.47        if (cpuLoad.IsAvailable) {
     7.1 --- a/Properties/AssemblyInfo.cs	Fri Feb 12 08:17:51 2010 +0000
     7.2 +++ b/Properties/AssemblyInfo.cs	Fri Feb 12 22:46:31 2010 +0000
     7.3 @@ -69,5 +69,5 @@
     7.4  // You can specify all the values or you can default the Build and Revision Numbers 
     7.5  // by using the '*' as shown below:
     7.6  // [assembly: AssemblyVersion("1.0.*")]
     7.7 -[assembly: AssemblyVersion("0.1.18.1")]
     7.8 -[assembly: AssemblyFileVersion("0.1.18.1")]
     7.9 +[assembly: AssemblyVersion("0.1.19.0")]
    7.10 +[assembly: AssemblyFileVersion("0.1.19.0")]
     8.1 --- a/Utilities/Configuration.cs	Fri Feb 12 08:17:51 2010 +0000
     8.2 +++ b/Utilities/Configuration.cs	Fri Feb 12 22:46:31 2010 +0000
     8.3 @@ -37,6 +37,7 @@
     8.4  
     8.5  using System;
     8.6  using System.Collections.Generic;
     8.7 +using System.Drawing;
     8.8  using System.IO;
     8.9  
    8.10  namespace OpenHardwareMonitor.Utilities {
    8.11 @@ -133,5 +134,25 @@
    8.12            return value;
    8.13        }
    8.14      }
    8.15 +
    8.16 +    public static void Set(string name, Color color) {
    8.17 +      instance[name] = color.ToArgb().ToString("X8");
    8.18 +    }
    8.19 +
    8.20 +    public static Color Get(string name, Color value) {
    8.21 +      System.Configuration.KeyValueConfigurationElement element =
    8.22 +        instance.config.AppSettings.Settings[name];
    8.23 +      if (element == null)
    8.24 +        return value;
    8.25 +      else {
    8.26 +        int parsedValue;
    8.27 +        if (int.TryParse(element.Value, 
    8.28 +          System.Globalization.NumberStyles.HexNumber, 
    8.29 +          System.Globalization.CultureInfo.InvariantCulture, out parsedValue))
    8.30 +          return Color.FromArgb(parsedValue);
    8.31 +        else
    8.32 +          return value;
    8.33 +      }
    8.34 +    }
    8.35    }
    8.36  }