Added sub-hardware support and basic enumeration for mainboards.

This commit is contained in:
Michael Möller 2010-02-27 20:08:13 +00:00
parent f208712a0d
commit 2dcac6acac
12 changed files with 369 additions and 59 deletions

View File

@ -159,8 +159,18 @@ namespace OpenHardwareMonitor.GUI {
} }
} }
private void SubHardwareAdded(IHardware hardware, Node node) {
Node hardwareNode = new HardwareNode(hardware);
node.Nodes.Add(hardwareNode);
foreach (IHardware subHardware in hardware.SubHardware)
SubHardwareAdded(subHardware, hardwareNode);
}
private void HardwareAdded(IHardware hardware) { private void HardwareAdded(IHardware hardware) {
root.Nodes.Add(new HardwareNode(hardware)); Node hardwareNode = new HardwareNode(hardware);
root.Nodes.Add(hardwareNode);
foreach (IHardware subHardware in hardware.SubHardware)
SubHardwareAdded(subHardware, hardwareNode);
} }
private void HardwareRemoved(IHardware hardware) { private void HardwareRemoved(IHardware hardware) {
@ -357,15 +367,25 @@ namespace OpenHardwareMonitor.GUI {
UpdatePlotSelection(null, null); UpdatePlotSelection(null, null);
} }
private void UpdateSensorTypeChecked(object sender, EventArgs e) { private void UpdateSensorTypeVisible(Node node) {
foreach (HardwareNode node in root.Nodes) { HardwareNode hardwareNode = node as HardwareNode;
node.SetVisible(SensorType.Voltage, voltMenuItem.Checked); if (hardwareNode == null)
node.SetVisible(SensorType.Clock, clocksMenuItem.Checked); return;
node.SetVisible(SensorType.Load, loadMenuItem.Checked);
node.SetVisible(SensorType.Temperature, tempMenuItem.Checked); hardwareNode.SetVisible(SensorType.Voltage, voltMenuItem.Checked);
node.SetVisible(SensorType.Fan, fansMenuItem.Checked); hardwareNode.SetVisible(SensorType.Clock, clocksMenuItem.Checked);
node.SetVisible(SensorType.Flow, flowsMenuItem.Checked); hardwareNode.SetVisible(SensorType.Load, loadMenuItem.Checked);
} hardwareNode.SetVisible(SensorType.Temperature, tempMenuItem.Checked);
hardwareNode.SetVisible(SensorType.Fan, fansMenuItem.Checked);
hardwareNode.SetVisible(SensorType.Flow, flowsMenuItem.Checked);
foreach (Node n in node.Nodes)
UpdateSensorTypeVisible(n);
}
private void UpdateSensorTypeChecked(object sender, EventArgs e) {
foreach (HardwareNode node in root.Nodes)
UpdateSensorTypeVisible(node);
} }
private void ToggleSysTray() { private void ToggleSysTray() {

View File

@ -59,13 +59,17 @@ namespace OpenHardwareMonitor.GUI {
hardware.SensorRemoved -= new SensorEventHandler(SensorRemoved); hardware.SensorRemoved -= new SensorEventHandler(SensorRemoved);
foreach (ISensor sensor in hardware.Sensors) foreach (ISensor sensor in hardware.Sensors)
SensorRemoved(sensor); SensorRemoved(sensor);
foreach (IHardware subHardware in hardware.SubHardware)
HardwareRemoved(subHardware);
} }
private void HardwareAdded(IHardware hardware) { private void HardwareAdded(IHardware hardware) {
foreach (ISensor sensor in hardware.Sensors) foreach (ISensor sensor in hardware.Sensors)
SensorAdded(sensor); SensorAdded(sensor);
hardware.SensorAdded += new SensorEventHandler(SensorAdded); hardware.SensorAdded += new SensorEventHandler(SensorAdded);
hardware.SensorRemoved += new SensorEventHandler(SensorRemoved); hardware.SensorRemoved += new SensorEventHandler(SensorRemoved);
foreach (IHardware subHardware in hardware.SubHardware)
HardwareAdded(subHardware);
} }
private void SensorAdded(ISensor sensor) { private void SensorAdded(ISensor sensor) {

View File

@ -61,7 +61,7 @@ namespace OpenHardwareMonitor.Hardware {
groups.Add(group); groups.Add(group);
if (HardwareAdded != null) if (HardwareAdded != null)
foreach (IHardware hardware in group.Hardware) foreach (IHardware hardware in group.Hardware)
HardwareAdded(hardware); HardwareAdded(hardware);
} }
@ -72,7 +72,7 @@ namespace OpenHardwareMonitor.Hardware {
groups.Remove(group); groups.Remove(group);
if (HardwareRemoved != null) if (HardwareRemoved != null)
foreach (IHardware hardware in group.Hardware) foreach (IHardware hardware in group.Hardware)
HardwareRemoved(hardware); HardwareRemoved(hardware);
} }
@ -80,8 +80,7 @@ namespace OpenHardwareMonitor.Hardware {
if (open) if (open)
return; return;
Add(new SMBIOS.SMBIOSGroup()); Add(new Mainboard.MainboardGroup());
Add(new LPC.LPCGroup());
Add(new CPU.CPUGroup()); Add(new CPU.CPUGroup());
Add(new ATI.ATIGroup()); Add(new ATI.ATIGroup());
Add(new Nvidia.NvidiaGroup()); Add(new Nvidia.NvidiaGroup());
@ -93,10 +92,19 @@ namespace OpenHardwareMonitor.Hardware {
open = true; open = true;
} }
private void SubHardwareUpdate(IHardware hardware) {
foreach (IHardware subHardware in hardware.SubHardware) {
subHardware.Update();
SubHardwareUpdate(subHardware);
}
}
public void Update() { public void Update() {
foreach (IGroup group in groups) foreach (IGroup group in groups)
foreach (IHardware hardware in group.Hardware) foreach (IHardware hardware in group.Hardware) {
hardware.Update(); hardware.Update();
SubHardwareUpdate(hardware);
}
} }
public bool HDDEnabled { public bool HDDEnabled {
@ -131,6 +139,38 @@ namespace OpenHardwareMonitor.Hardware {
writer.WriteLine(); writer.WriteLine();
} }
private void ReportHardwareTree(IHardware hardware, TextWriter w,
string space)
{
w.WriteLine("{0}|", space);
w.WriteLine("{0}+-+ {1} ({2})",
space, hardware.Name, hardware.Identifier);
foreach (ISensor sensor in hardware.Sensors) {
w.WriteLine("{0}| +- {1} : {2} : {3} : {4}",
space, sensor.SensorType, sensor.Index, sensor.Name,
string.Format(CultureInfo.InvariantCulture, "{0} : {1} : {2}",
sensor.Value, sensor.Min, sensor.Max));
foreach (IParameter parameter in sensor.Parameters) {
w.WriteLine("{0}| +- {1} : {2} : {3}",
space, parameter.Name, parameter.IsDefault,
string.Format(CultureInfo.InvariantCulture, "{0} : {1}",
parameter.DefaultValue, parameter.Value));
}
}
foreach (IHardware subHardware in hardware.SubHardware)
ReportHardwareTree(subHardware, w, "| ");
}
private void ReportHardware(IHardware hardware, TextWriter w) {
string hardwareReport = hardware.GetReport();
if (hardwareReport != null && hardwareReport != "") {
NewSection(w);
w.Write(hardwareReport);
}
foreach (IHardware subHardware in hardware.SubHardware)
ReportHardware(subHardware, w);
}
public void SaveReport(Version version) { public void SaveReport(Version version) {
using (TextWriter w = using (TextWriter w =
@ -146,23 +186,8 @@ namespace OpenHardwareMonitor.Hardware {
NewSection(w); NewSection(w);
foreach (IGroup group in groups) { foreach (IGroup group in groups) {
foreach (IHardware hardware in group.Hardware) { foreach (IHardware hardware in group.Hardware)
w.WriteLine("|"); ReportHardwareTree(hardware, w, "");
w.WriteLine("+-+ {0} ({1})",
new object[] { hardware.Name, hardware.Identifier });
foreach (ISensor sensor in hardware.Sensors) {
w.WriteLine("| +- {0} : {1} : {2} : {3}",
sensor.SensorType, sensor.Index, sensor.Name,
string.Format(CultureInfo.InvariantCulture, "{0} : {1} : {2}",
sensor.Value, sensor.Min, sensor.Max) );
foreach (IParameter parameter in sensor.Parameters) {
w.WriteLine("| +- {0} : {1} : {2}",
parameter.Name, parameter.IsDefault,
string.Format(CultureInfo.InvariantCulture, "{0} : {1}",
parameter.DefaultValue, parameter.Value) );
}
}
}
} }
w.WriteLine(); w.WriteLine();
@ -174,13 +199,9 @@ namespace OpenHardwareMonitor.Hardware {
} }
IHardware[] hardwareArray = group.Hardware; IHardware[] hardwareArray = group.Hardware;
foreach (IHardware hardware in hardwareArray) { foreach (IHardware hardware in hardwareArray)
string hardwareReport = hardware.GetReport(); ReportHardware(hardware, w);
if (hardwareReport != null && hardwareReport != "") {
NewSection(w);
w.Write(hardwareReport);
}
}
} }
} }
} }
@ -199,7 +220,5 @@ namespace OpenHardwareMonitor.Hardware {
public event HardwareEventHandler HardwareAdded; public event HardwareEventHandler HardwareAdded;
public event HardwareEventHandler HardwareRemoved; public event HardwareEventHandler HardwareRemoved;
} }
} }

View File

@ -77,6 +77,10 @@ namespace OpenHardwareMonitor.Hardware.HDD {
get { return icon; } get { return icon; }
} }
public IHardware[] SubHardware {
get { return new IHardware[0]; }
}
public ISensor[] Sensors { public ISensor[] Sensors {
get { get {
return new ISensor[] { temperature }; return new ISensor[] { temperature };

View File

@ -43,6 +43,10 @@ namespace OpenHardwareMonitor.Hardware {
private List<ISensor> active = new List<ISensor>(); private List<ISensor> active = new List<ISensor>();
public IHardware[] SubHardware {
get { return new IHardware[0]; }
}
public ISensor[] Sensors { public ISensor[] Sensors {
get { return active.ToArray(); } get { return active.ToArray(); }
} }
@ -63,7 +67,9 @@ namespace OpenHardwareMonitor.Hardware {
} }
} }
#pragma warning disable 67
public event SensorEventHandler SensorAdded; public event SensorEventHandler SensorAdded;
public event SensorEventHandler SensorRemoved; public event SensorEventHandler SensorRemoved;
#pragma warning restore 67
} }
} }

View File

@ -54,6 +54,8 @@ namespace OpenHardwareMonitor.Hardware {
void Update(); void Update();
IHardware[] SubHardware { get; }
ISensor[] Sensors { get; } ISensor[] Sensors { get; }
event SensorEventHandler SensorAdded; event SensorEventHandler SensorAdded;

View File

@ -0,0 +1,109 @@
/*
Version: MPL 1.1/GPL 2.0/LGPL 2.1
The contents of this file are subject to the Mozilla Public License Version
1.1 (the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
for the specific language governing rights and limitations under the License.
The Original Code is the Open Hardware Monitor code.
The Initial Developer of the Original Code is
Michael Möller <m.moeller@gmx.ch>.
Portions created by the Initial Developer are Copyright (C) 2009-2010
the Initial Developer. All Rights Reserved.
Contributor(s):
Alternatively, the contents of this file may be used under the terms of
either the GNU General Public License Version 2 or later (the "GPL"), or
the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
in which case the provisions of the GPL or the LGPL are applicable instead
of those above. If you wish to allow use of your version of this file only
under the terms of either the GPL or the LGPL, and not to allow others to
use your version of this file under the terms of the MPL, indicate your
decision by deleting the provisions above and replace them with the notice
and other provisions required by the GPL or the LGPL. If you do not delete
the provisions above, a recipient may use your version of this file under
the terms of any one of the MPL, the GPL or the LGPL.
*/
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Text;
using OpenHardwareMonitor.Hardware.LPC;
namespace OpenHardwareMonitor.Hardware.Mainboard {
public class Mainboard : IHardware {
private SMBIOS smbios;
private string name;
private Image icon;
private LPCGroup lpcGroup;
public Mainboard() {
this.smbios = new SMBIOS();
if (smbios.Board != null && smbios.Board.ProductName != null
&& smbios.Board.ProductName != "") {
if (smbios.Board.Manufacturer == Manufacturer.Unkown)
this.name = smbios.Board.ProductName;
else
this.name = smbios.Board.Manufacturer + " " +
smbios.Board.ProductName;
} else {
this.name = smbios.Board.Manufacturer.ToString();
}
this.icon = Utilities.EmbeddedResources.GetImage("mainboard.png");
this.lpcGroup = new LPCGroup();
}
public string Name {
get { return name; }
}
public string Identifier {
get { return "/mainboard"; }
}
public Image Icon {
get { return icon; }
}
public string GetReport() {
StringBuilder r = new StringBuilder();
r.AppendLine("Mainboard");
r.AppendLine();
r.Append(smbios.GetReport());
return r.ToString();
}
public void Update() { }
public void Close() {
lpcGroup.Close();
}
public IHardware[] SubHardware {
get { return lpcGroup.Hardware; }
}
public ISensor[] Sensors {
get { return new ISensor[0]; }
}
#pragma warning disable 67
public event SensorEventHandler SensorAdded;
public event SensorEventHandler SensorRemoved;
#pragma warning restore 67
}
}

View File

@ -0,0 +1,65 @@
/*
Version: MPL 1.1/GPL 2.0/LGPL 2.1
The contents of this file are subject to the Mozilla Public License Version
1.1 (the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
for the specific language governing rights and limitations under the License.
The Original Code is the Open Hardware Monitor code.
The Initial Developer of the Original Code is
Michael Möller <m.moeller@gmx.ch>.
Portions created by the Initial Developer are Copyright (C) 2009-2010
the Initial Developer. All Rights Reserved.
Contributor(s):
Alternatively, the contents of this file may be used under the terms of
either the GNU General Public License Version 2 or later (the "GPL"), or
the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
in which case the provisions of the GPL or the LGPL are applicable instead
of those above. If you wish to allow use of your version of this file only
under the terms of either the GPL or the LGPL, and not to allow others to
use your version of this file under the terms of the MPL, indicate your
decision by deleting the provisions above and replace them with the notice
and other provisions required by the GPL or the LGPL. If you do not delete
the provisions above, a recipient may use your version of this file under
the terms of any one of the MPL, the GPL or the LGPL.
*/
using System;
using System.Collections.Generic;
namespace OpenHardwareMonitor.Hardware.Mainboard {
public class MainboardGroup : IGroup {
private Mainboard[] mainboards;
public MainboardGroup() {
mainboards = new Mainboard[1];
mainboards[0] = new Mainboard();
}
public void Close() {
foreach (Mainboard mainboard in mainboards)
mainboard.Close();
}
public string GetReport() {
return null;
}
public IHardware[] Hardware {
get { return mainboards; }
}
}
}

View File

@ -0,0 +1,52 @@
/*
Version: MPL 1.1/GPL 2.0/LGPL 2.1
The contents of this file are subject to the Mozilla Public License Version
1.1 (the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
for the specific language governing rights and limitations under the License.
The Original Code is the Open Hardware Monitor code.
The Initial Developer of the Original Code is
Michael Möller <m.moeller@gmx.ch>.
Portions created by the Initial Developer are Copyright (C) 2009-2010
the Initial Developer. All Rights Reserved.
Contributor(s):
Alternatively, the contents of this file may be used under the terms of
either the GNU General Public License Version 2 or later (the "GPL"), or
the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
in which case the provisions of the GPL or the LGPL are applicable instead
of those above. If you wish to allow use of your version of this file only
under the terms of either the GPL or the LGPL, and not to allow others to
use your version of this file under the terms of the MPL, indicate your
decision by deleting the provisions above and replace them with the notice
and other provisions required by the GPL or the LGPL. If you do not delete
the provisions above, a recipient may use your version of this file under
the terms of any one of the MPL, the GPL or the LGPL.
*/
using System;
using System.Collections.Generic;
namespace OpenHardwareMonitor.Hardware.Mainboard {
public enum Manufacturer {
ASUS,
DFI,
EPoX,
Gigabyte,
MSI,
Unkown
}
}

View File

@ -40,17 +40,16 @@ using System.Collections.Generic;
using System.Management; using System.Management;
using System.Text; using System.Text;
namespace OpenHardwareMonitor.Hardware.SMBIOS { namespace OpenHardwareMonitor.Hardware.Mainboard {
public class SMBIOSGroup : IGroup { public class SMBIOS {
private Structure[] table; private Structure[] table;
private BIOSInformation biosInformation = null; private BIOSInformation biosInformation = null;
private BaseBoardInformation baseBoardInformation = null; private BaseBoardInformation baseBoardInformation = null;
public SMBIOSGroup() { public SMBIOS() {
int p = (int)System.Environment.OSVersion.Platform; int p = (int)System.Environment.OSVersion.Platform;
if ((p == 4) || (p == 128)) if ((p == 4) || (p == 128))
return; return;
@ -110,13 +109,8 @@ namespace OpenHardwareMonitor.Hardware.SMBIOS {
table = structureList.ToArray(); table = structureList.ToArray();
} }
public IHardware[] Hardware { get { return new IHardware[0]; } }
public string GetReport() { public string GetReport() {
StringBuilder r = new StringBuilder(); StringBuilder r = new StringBuilder();
r.AppendLine("SMBIOS");
r.AppendLine();
if (biosInformation != null) { if (biosInformation != null) {
r.Append("BIOS Vendor: "); r.AppendLine(biosInformation.Vendor); r.Append("BIOS Vendor: "); r.AppendLine(biosInformation.Vendor);
@ -126,7 +120,7 @@ namespace OpenHardwareMonitor.Hardware.SMBIOS {
if (baseBoardInformation != null) { if (baseBoardInformation != null) {
r.Append("Mainboard Manufacturer: "); r.Append("Mainboard Manufacturer: ");
r.AppendLine(baseBoardInformation.Manufacturer); r.AppendLine(baseBoardInformation.ManufacturerName);
r.Append("Mainboard Name: "); r.Append("Mainboard Name: ");
r.AppendLine(baseBoardInformation.ProductName); r.AppendLine(baseBoardInformation.ProductName);
r.AppendLine(); r.AppendLine();
@ -135,7 +129,13 @@ namespace OpenHardwareMonitor.Hardware.SMBIOS {
return r.ToString(); return r.ToString();
} }
public void Close() { } public BIOSInformation BIOS {
get { return biosInformation; }
}
public BaseBoardInformation Board {
get { return baseBoardInformation; }
}
public class Structure { public class Structure {
private byte type; private byte type;
@ -185,20 +185,39 @@ namespace OpenHardwareMonitor.Hardware.SMBIOS {
public class BaseBoardInformation : Structure { public class BaseBoardInformation : Structure {
private string manufacturer; private string manufacturerName;
private string productName; private string productName;
private Manufacturer manufacturer;
public BaseBoardInformation(byte type, ushort handle, byte[] data, public BaseBoardInformation(byte type, ushort handle, byte[] data,
string[] strings) string[] strings)
: base(type, handle, data, strings) { : base(type, handle, data, strings) {
this.manufacturer = GetString(0x04); this.manufacturerName = GetString(0x04).Trim();
this.productName = GetString(0x05); this.productName = GetString(0x05).Trim();
switch (manufacturerName) {
case "ASUSTeK Computer INC.":
manufacturer = Manufacturer.ASUS; break;
case "DFI":
case "DFI Inc.:":
manufacturer = Manufacturer.DFI; break;
case "EPoX COMPUTER CO., LTD":
manufacturer = Manufacturer.EPoX; break;
case "Gigabyte Technology Co., Ltd.":
manufacturer = Manufacturer.Gigabyte; break;
case "MICRO-STAR INTERNATIONAL CO., LTD":
manufacturer = Manufacturer.MSI; break;
default:
manufacturer = Manufacturer.Unkown; break;
}
} }
public string Manufacturer { get { return manufacturer; } } public string ManufacturerName { get { return manufacturerName; } }
public string ProductName { get { return productName; } } public string ProductName { get { return productName; } }
public Manufacturer Manufacturer { get { return manufacturer; } }
} }
} }
} }

View File

@ -262,6 +262,10 @@ namespace OpenHardwareMonitor.Hardware.TBalancer {
this.portName.TrimStart(new char[]{'/'}).ToLower(); } this.portName.TrimStart(new char[]{'/'}).ToLower(); }
} }
public IHardware[] SubHardware {
get { return new IHardware[0]; }
}
public ISensor[] Sensors { public ISensor[] Sensors {
get { return active.ToArray(); } get { return active.ToArray(); }
} }

View File

@ -78,8 +78,11 @@
<Compile Include="Hardware\LPC\Chip.cs" /> <Compile Include="Hardware\LPC\Chip.cs" />
<Compile Include="Hardware\LPC\F718XX.cs" /> <Compile Include="Hardware\LPC\F718XX.cs" />
<Compile Include="Hardware\LPC\LPCHardware.cs" /> <Compile Include="Hardware\LPC\LPCHardware.cs" />
<Compile Include="Hardware\Mainboard\Mainboard.cs" />
<Compile Include="Hardware\Mainboard\MainboardGroup.cs" />
<Compile Include="Hardware\Mainboard\Manufacturer.cs" />
<Compile Include="Hardware\Parameter.cs" /> <Compile Include="Hardware\Parameter.cs" />
<Compile Include="Hardware\SMBIOS\SMBIOSGroup.cs" /> <Compile Include="Hardware\Mainboard\SMBIOS.cs" />
<Compile Include="Hardware\LPC\W836XX.cs" /> <Compile Include="Hardware\LPC\W836XX.cs" />
<Compile Include="Hardware\Computer.cs" /> <Compile Include="Hardware\Computer.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
@ -172,6 +175,9 @@
</EmbeddedResource> </EmbeddedResource>
<EmbeddedResource Include="Resources\flow.png" /> <EmbeddedResource Include="Resources\flow.png" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Resources\mainboard.png" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ProjectExtensions> <ProjectExtensions>
<VisualStudio AllowExistingFolder="true" /> <VisualStudio AllowExistingFolder="true" />