# HG changeset patch # User moel.mich # Date 1266014791 0 # Node ID 47385d4fc9906a0494179fdb267b87039f752e5a # Parent d92bacc2116e8affdf1b55b80801d3232132e390 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. diff -r d92bacc2116e -r 47385d4fc990 GUI/MainForm.Designer.cs --- a/GUI/MainForm.Designer.cs Fri Feb 12 08:17:51 2010 +0000 +++ b/GUI/MainForm.Designer.cs Fri Feb 12 22:46:31 2010 +0000 @@ -101,12 +101,12 @@ this.aboutToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.timer = new System.Windows.Forms.Timer(this.components); this.splitContainer = new System.Windows.Forms.SplitContainer(); - this.plotPanel = new OpenHardwareMonitor.GUI.PlotPanel(); this.notifyContextMenuStrip = new System.Windows.Forms.ContextMenuStrip(this.components); this.restoreToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripMenuItem2 = new System.Windows.Forms.ToolStripSeparator(); this.exitToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem(); this.sensorContextMenuStrip = new System.Windows.Forms.ContextMenuStrip(this.components); + this.plotPanel = new OpenHardwareMonitor.GUI.PlotPanel(); this.columnsContextMenuStrip.SuspendLayout(); this.menuStrip.SuspendLayout(); this.splitContainer.Panel1.SuspendLayout(); @@ -480,16 +480,6 @@ this.splitContainer.SplitterWidth = 3; this.splitContainer.TabIndex = 3; // - // plotPanel - // - this.plotPanel.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D; - this.plotPanel.Dock = System.Windows.Forms.DockStyle.Fill; - this.plotPanel.Font = new System.Drawing.Font("Segoe UI", 9F); - this.plotPanel.Location = new System.Drawing.Point(0, 0); - this.plotPanel.Name = "plotPanel"; - this.plotPanel.Size = new System.Drawing.Size(478, 198); - this.plotPanel.TabIndex = 0; - // // notifyContextMenuStrip // this.notifyContextMenuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { @@ -524,6 +514,16 @@ this.sensorContextMenuStrip.Name = "sensorContextMenuStrip"; this.sensorContextMenuStrip.Size = new System.Drawing.Size(61, 4); // + // plotPanel + // + this.plotPanel.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D; + this.plotPanel.Dock = System.Windows.Forms.DockStyle.Fill; + this.plotPanel.Font = new System.Drawing.Font("Segoe UI", 9F); + this.plotPanel.Location = new System.Drawing.Point(0, 0); + this.plotPanel.Name = "plotPanel"; + this.plotPanel.Size = new System.Drawing.Size(478, 198); + this.plotPanel.TabIndex = 0; + // // MainForm // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); diff -r d92bacc2116e -r 47385d4fc990 GUI/MainForm.cs --- a/GUI/MainForm.cs Fri Feb 12 08:17:51 2010 +0000 +++ b/GUI/MainForm.cs Fri Feb 12 22:46:31 2010 +0000 @@ -253,10 +253,9 @@ Config.Set("mainForm.Width", Width); Config.Set("mainForm.Height", Height); } - + sensorSystemTray.Dispose(); notifyIcon.Dispose(); - computer.Close(); } @@ -315,7 +314,7 @@ } else { ToolStripMenuItem item = new ToolStripMenuItem("Add To Tray"); item.Click += delegate(object obj, EventArgs args) { - sensorSystemTray.Add(node.Sensor); + sensorSystemTray.Add(node.Sensor, true); }; sensorContextMenuStrip.Items.Add(item); } diff -r d92bacc2116e -r 47385d4fc990 GUI/SensorNotifyIcon.cs --- a/GUI/SensorNotifyIcon.cs Fri Feb 12 08:17:51 2010 +0000 +++ b/GUI/SensorNotifyIcon.cs Fri Feb 12 22:46:31 2010 +0000 @@ -55,18 +55,32 @@ private Bitmap bitmap; private Graphics graphics; private int majorVersion; + private Color color; - public SensorNotifyIcon(SensorSystemTray sensorSystemTray, ISensor sensor) { + public SensorNotifyIcon(SensorSystemTray sensorSystemTray, ISensor sensor, + bool balloonTip) + { this.sensor = sensor; this.notifyIcon = new NotifyIcon(); - this.majorVersion = Environment.OSVersion.Version.Major; + this.majorVersion = Environment.OSVersion.Version.Major; + this.color = Config.Get(sensor.Identifier + "/traycolor", Color.Black); ContextMenuStrip contextMenuStrip = new ContextMenuStrip(); - ToolStripMenuItem item = new ToolStripMenuItem("Remove"); - item.Click += delegate(object obj, EventArgs args) { - sensorSystemTray.Remove(sensor); + ToolStripMenuItem removeItem = new ToolStripMenuItem("Remove"); + removeItem.Click += delegate(object obj, EventArgs args) { + sensorSystemTray.Remove(this.sensor); }; - contextMenuStrip.Items.Add(item); + contextMenuStrip.Items.Add(removeItem); + ToolStripMenuItem colorItem = new ToolStripMenuItem("Change Color..."); + colorItem.Click += delegate(object obj, EventArgs args) { + ColorDialog dialog = new ColorDialog(); + dialog.Color = this.color; + if (dialog.ShowDialog() == DialogResult.OK) { + this.color = dialog.Color; + Config.Set(sensor.Identifier + "/traycolor", this.color); + } + }; + contextMenuStrip.Items.Add(colorItem); this.notifyIcon.ContextMenuStrip = contextMenuStrip; this.bitmap = new Bitmap(16, 16, PixelFormat.Format32bppArgb); @@ -79,6 +93,11 @@ get { return sensor; } } + public Color Color { + get { return color; } + set { color = value; } + } + public void Dispose() { Icon icon = notifyIcon.Icon; notifyIcon.Icon = null; @@ -113,7 +132,7 @@ graphics.Clear(SystemColors.ButtonFace); TextRenderer.DrawText(graphics, GetString(), SystemFonts.StatusFont, - new Point(-2, 0), Color.Blue, SystemColors.ButtonFace); + new Point(-2, 0), color, SystemColors.ButtonFace); BitmapData data = bitmap.LockBits( new Rectangle(0, 0, bitmap.Width, bitmap.Height), @@ -154,9 +173,9 @@ green = bytes[i + 1]; red = bytes[i + 2]; - bytes[i] = 255; - bytes[i + 1] = 255; - bytes[i + 2] = 255; + bytes[i] = color.B; + bytes[i + 1] = color.G; + bytes[i + 2] = color.R; bytes[i + 3] = (byte)(0.3 * red + 0.59 * green + 0.11 * blue); } @@ -184,9 +203,9 @@ case SensorType.Fan: format = "{0}\n{1}: {2:F0} RPM"; break; } - notifyIcon.Text = string.Format(format, - sensor.Hardware.Name, sensor.Name, sensor.Value); - notifyIcon.Visible = true; + notifyIcon.Text = string.Format(format, sensor.Hardware.Name, sensor.Name, + sensor.Value); + notifyIcon.Visible = true; } } } diff -r d92bacc2116e -r 47385d4fc990 GUI/SensorSystemTray.cs --- a/GUI/SensorSystemTray.cs Fri Feb 12 08:17:51 2010 +0000 +++ b/GUI/SensorSystemTray.cs Fri Feb 12 22:46:31 2010 +0000 @@ -37,6 +37,7 @@ using System; using System.Collections.Generic; +using System.Drawing; using System.Text; using System.Windows.Forms; using OpenHardwareMonitor.Hardware; @@ -69,14 +70,12 @@ private void SensorAdded(ISensor sensor) { if (Config.Get(sensor.Identifier + "/tray", false)) - Add(sensor); + Add(sensor, false); } private void SensorRemoved(ISensor sensor) { - if (Contains(sensor)) { - Remove(sensor); - Config.Set(sensor.Identifier + "/tray", true); - } + if (Contains(sensor)) + Remove(sensor, false); } public void Dispose() { @@ -96,17 +95,24 @@ return false; } - public void Add(ISensor sensor) { + public void Add(ISensor sensor, bool balloonTip) { if (Contains(sensor)) { return; - } else { - list.Add(new SensorNotifyIcon(this, sensor)); + } else { + list.Add(new SensorNotifyIcon(this, sensor, balloonTip)); Config.Set(sensor.Identifier + "/tray", true); } } public void Remove(ISensor sensor) { - Config.Remove(sensor.Identifier + "/tray"); + Remove(sensor, true); + } + + private void Remove(ISensor sensor, bool deleteConfig) { + if (deleteConfig) { + Config.Remove(sensor.Identifier + "/tray"); + Config.Remove(sensor.Identifier + "/traycolor"); + } SensorNotifyIcon instance = null; foreach (SensorNotifyIcon icon in list) if (icon.Sensor == sensor) diff -r d92bacc2116e -r 47385d4fc990 Hardware/CPU/AMD0FCPU.cs --- a/Hardware/CPU/AMD0FCPU.cs Fri Feb 12 08:17:51 2010 +0000 +++ b/Hardware/CPU/AMD0FCPU.cs Fri Feb 12 22:46:31 2010 +0000 @@ -124,20 +124,20 @@ } public void Update() { - if (pciAddress == 0xFFFFFFFF) - return; + if (pciAddress != 0xFFFFFFFF) { - for (uint i = 0; i < coreTemperatures.Length; i++) { - if (WinRing0.WritePciConfigDwordEx( - pciAddress, THERMTRIP_STATUS_REGISTER, - i > 0 ? THERM_SENSE_CORE_SEL_CPU1 : THERM_SENSE_CORE_SEL_CPU0)) { - uint value; - if (WinRing0.ReadPciConfigDwordEx( - pciAddress, THERMTRIP_STATUS_REGISTER, out value)) { - coreTemperatures[i].Value = ((value >> 16) & 0xFF) + offset; - ActivateSensor(coreTemperatures[i]); - } else { - DeactivateSensor(coreTemperatures[i]); + for (uint i = 0; i < coreTemperatures.Length; i++) { + if (WinRing0.WritePciConfigDwordEx( + pciAddress, THERMTRIP_STATUS_REGISTER, + i > 0 ? THERM_SENSE_CORE_SEL_CPU1 : THERM_SENSE_CORE_SEL_CPU0)) { + uint value; + if (WinRing0.ReadPciConfigDwordEx( + pciAddress, THERMTRIP_STATUS_REGISTER, out value)) { + coreTemperatures[i].Value = ((value >> 16) & 0xFF) + offset; + ActivateSensor(coreTemperatures[i]); + } else { + DeactivateSensor(coreTemperatures[i]); + } } } } diff -r d92bacc2116e -r 47385d4fc990 Hardware/CPU/AMD10CPU.cs --- a/Hardware/CPU/AMD10CPU.cs Fri Feb 12 08:17:51 2010 +0000 +++ b/Hardware/CPU/AMD10CPU.cs Fri Feb 12 22:46:31 2010 +0000 @@ -57,6 +57,7 @@ private const ushort PCI_AMD_VENDOR_ID = 0x1022; private const ushort PCI_AMD_10H_MISCELLANEOUS_DEVICE_ID = 0x1203; + private const ushort PCI_AMD_11H_MISCELLANEOUS_DEVICE_ID = 0x1303; private const uint REPORTED_TEMPERATURE_CONTROL_REGISTER = 0xA4; public AMD10CPU(string name, uint family, uint model, uint stepping, @@ -90,6 +91,10 @@ pciAddress = WinRing0.FindPciDeviceById(PCI_AMD_VENDOR_ID, PCI_AMD_10H_MISCELLANEOUS_DEVICE_ID, 0); + if (pciAddress == 0xFFFFFFFF) + pciAddress = WinRing0.FindPciDeviceById(PCI_AMD_VENDOR_ID, + PCI_AMD_11H_MISCELLANEOUS_DEVICE_ID, 0); + Update(); } @@ -110,16 +115,15 @@ } public void Update() { - if (pciAddress == 0xFFFFFFFF) - return; - - uint value; - if (WinRing0.ReadPciConfigDwordEx(pciAddress, - REPORTED_TEMPERATURE_CONTROL_REGISTER, out value)) { - coreTemperature.Value = ((value >> 21) & 0x7FF) / 8.0f; - ActivateSensor(coreTemperature); - } else { - DeactivateSensor(coreTemperature); + if (pciAddress != 0xFFFFFFFF) { + uint value; + if (WinRing0.ReadPciConfigDwordEx(pciAddress, + REPORTED_TEMPERATURE_CONTROL_REGISTER, out value)) { + coreTemperature.Value = ((value >> 21) & 0x7FF) / 8.0f; + ActivateSensor(coreTemperature); + } else { + DeactivateSensor(coreTemperature); + } } if (cpuLoad.IsAvailable) { diff -r d92bacc2116e -r 47385d4fc990 Properties/AssemblyInfo.cs --- a/Properties/AssemblyInfo.cs Fri Feb 12 08:17:51 2010 +0000 +++ b/Properties/AssemblyInfo.cs Fri Feb 12 22:46:31 2010 +0000 @@ -69,5 +69,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("0.1.18.1")] -[assembly: AssemblyFileVersion("0.1.18.1")] +[assembly: AssemblyVersion("0.1.19.0")] +[assembly: AssemblyFileVersion("0.1.19.0")] diff -r d92bacc2116e -r 47385d4fc990 Utilities/Configuration.cs --- a/Utilities/Configuration.cs Fri Feb 12 08:17:51 2010 +0000 +++ b/Utilities/Configuration.cs Fri Feb 12 22:46:31 2010 +0000 @@ -37,6 +37,7 @@ using System; using System.Collections.Generic; +using System.Drawing; using System.IO; namespace OpenHardwareMonitor.Utilities { @@ -133,5 +134,25 @@ return value; } } + + public static void Set(string name, Color color) { + instance[name] = color.ToArgb().ToString("X8"); + } + + public static Color Get(string name, Color value) { + System.Configuration.KeyValueConfigurationElement element = + instance.config.AppSettings.Settings[name]; + if (element == null) + return value; + else { + int parsedValue; + if (int.TryParse(element.Value, + System.Globalization.NumberStyles.HexNumber, + System.Globalization.CultureInfo.InvariantCulture, out parsedValue)) + return Color.FromArgb(parsedValue); + else + return value; + } + } } }