From 485c80b04b0d28ffbe4b8185372aff947511705c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20M=C3=B6ller?= Date: Sat, 27 Mar 2010 19:55:09 +0000 Subject: [PATCH] Fixed Issue 9. --- GUI/SensorNotifyIcon.cs | 7 ++---- Hardware/Computer.cs | 1 - Hardware/LPC/W836XX.cs | 46 ++++++++++++++++++++++++++++++++++---- Properties/AssemblyInfo.cs | 4 ++-- 4 files changed, 46 insertions(+), 12 deletions(-) diff --git a/GUI/SensorNotifyIcon.cs b/GUI/SensorNotifyIcon.cs index 324359a..e298f02 100644 --- a/GUI/SensorNotifyIcon.cs +++ b/GUI/SensorNotifyIcon.cs @@ -129,7 +129,6 @@ namespace OpenHardwareMonitor.GUI { if (icon != null) icon.Dispose(); notifyIcon.Dispose(); - notifyIcon = null; if (brush != null) brush.Dispose(); @@ -137,10 +136,8 @@ namespace OpenHardwareMonitor.GUI { darkBrush.Dispose(); pen.Dispose(); font.Dispose(); - graphics.Dispose(); - graphics = null; - bitmap.Dispose(); - bitmap = null; + graphics.Dispose(); + bitmap.Dispose(); } private string GetString() { diff --git a/Hardware/Computer.cs b/Hardware/Computer.cs index 9be4e43..b42b3a8 100644 --- a/Hardware/Computer.cs +++ b/Hardware/Computer.cs @@ -101,7 +101,6 @@ namespace OpenHardwareMonitor.Hardware { #if !DEBUG } catch (Exception exception) { Utilities.CrashReport.Save(exception); - throw; } #endif }, null, 1000, 1000); diff --git a/Hardware/LPC/W836XX.cs b/Hardware/LPC/W836XX.cs index 1bf5b61..da04f2f 100644 --- a/Hardware/LPC/W836XX.cs +++ b/Hardware/LPC/W836XX.cs @@ -90,7 +90,7 @@ namespace OpenHardwareMonitor.Hardware.LPC { (ushort)(address + ADDRESS_REGISTER_OFFSET), register); return WinRing0.ReadIoPortByte( (ushort)(address + DATA_REGISTER_OFFSET)); - } + } private void WriteByte(byte bank, byte register, byte value) { WinRing0.WriteIoPortByte( @@ -195,6 +195,17 @@ namespace OpenHardwareMonitor.Hardware.LPC { return vendorId == WINBOND_VENDOR_ID; } + private ulong SetBit(ulong target, int bit, int value) { + if ((value & 1) != value) + throw new ArgumentException("Value must be one bit only."); + + if (bit < 0 || bit > 63) + throw new ArgumentException("Bit out of range."); + + ulong mask = (((ulong)1) << bit); + return value > 0 ? target | mask : target & ~mask; + } + public void Update() { foreach (Sensor sensor in voltages) { @@ -244,22 +255,49 @@ namespace OpenHardwareMonitor.Hardware.LPC { } } - long bits = 0; + ulong bits = 0; for (int i = 0; i < FAN_BIT_REG.Length; i++) bits = (bits << 8) | ReadByte(0, FAN_BIT_REG[i]); + ulong newBits = bits; foreach (Sensor sensor in fans) { int count = ReadByte(FAN_TACHO_BANK[sensor.Index], FAN_TACHO_REG[sensor.Index]); + + // assemble fan divisor int divisorBits = (int)( (((bits >> FAN_DIV_BIT2[sensor.Index]) & 1) << 2) | (((bits >> FAN_DIV_BIT1[sensor.Index]) & 1) << 1) | ((bits >> FAN_DIV_BIT0[sensor.Index]) & 1)); int divisor = 1 << divisorBits; + float value = (count < 0xff) ? 1.35e6f / (count * divisor) : 0; sensor.Value = value; if (value > 0) - ActivateSensor(sensor); - } + ActivateSensor(sensor); + + // update fan divisor + if (count > 192 && divisorBits < 7) + divisorBits++; + if (count < 96 && divisorBits > 0) + divisorBits--; + + newBits = SetBit(newBits, FAN_DIV_BIT2[sensor.Index], + (divisorBits >> 2) & 1); + newBits = SetBit(newBits, FAN_DIV_BIT1[sensor.Index], + (divisorBits >> 1) & 1); + newBits = SetBit(newBits, FAN_DIV_BIT0[sensor.Index], + divisorBits & 1); + } + + // write new fan divisors + for (int i = FAN_BIT_REG.Length - 1; i >= 0; i--) { + byte oldByte = (byte)(bits & 0xFF); + byte newByte = (byte)(newBits & 0xFF); + bits = bits >> 8; + newBits = newBits >> 8; + if (oldByte != newByte) + WriteByte(0, FAN_BIT_REG[i], newByte); + } } public string GetReport() { diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs index f93d6a7..e637c06 100644 --- a/Properties/AssemblyInfo.cs +++ b/Properties/AssemblyInfo.cs @@ -69,5 +69,5 @@ using System.Runtime.InteropServices; // 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.27.0")] -[assembly: AssemblyFileVersion("0.1.27.0")] +[assembly: AssemblyVersion("0.1.28.0")] +[assembly: AssemblyFileVersion("0.1.28.0")]