1.1 --- a/Hardware/HDD/HDD.cs Thu Oct 07 19:34:36 2010 +0000
1.2 +++ b/Hardware/HDD/HDD.cs Fri Oct 08 12:18:32 2010 +0000
1.3 @@ -19,7 +19,7 @@
1.4 Portions created by the Initial Developer are Copyright (C) 2009-2010
1.5 the Initial Developer. All Rights Reserved.
1.6
1.7 - Contributor(s):
1.8 + Contributor(s): Paul Werelds
1.9
1.10 Alternatively, the contents of this file may be used under the terms of
1.11 either the GNU General Public License Version 2 or later (the "GPL"), or
1.12 @@ -36,6 +36,7 @@
1.13 */
1.14
1.15 using System;
1.16 +using System.Collections.Generic;
1.17 using System.Globalization;
1.18
1.19 namespace OpenHardwareMonitor.Hardware.HDD {
1.20 @@ -46,24 +47,40 @@
1.21 private readonly string name;
1.22 private readonly IntPtr handle;
1.23 private readonly int drive;
1.24 - private readonly int attribute;
1.25 - private readonly Sensor temperature;
1.26 private int count;
1.27 -
1.28
1.29 - public HDD(string name, IntPtr handle, int drive, int attribute,
1.30 - ISettings settings)
1.31 + private readonly SMART.AttributeID temperatureID = 0x00;
1.32 + private readonly SMART.SSDLifeID lifeID = 0x00;
1.33 +
1.34 + private readonly Sensor temperatureSensor;
1.35 + private readonly Sensor lifeSensor;
1.36 +
1.37 + public HDD(string name, IntPtr handle, int drive,
1.38 + SMART.AttributeID temperatureID, ISettings settings)
1.39 {
1.40 this.name = name;
1.41 this.handle = handle;
1.42 this.drive = drive;
1.43 - this.attribute = attribute;
1.44 this.count = 0;
1.45 - this.temperature = new Sensor("HDD", 0, SensorType.Temperature, this,
1.46 - settings);
1.47 + this.temperatureID = temperatureID;
1.48 + this.temperatureSensor = new Sensor("HDD", 0, SensorType.Temperature,
1.49 + this, settings);
1.50 +
1.51 Update();
1.52 }
1.53
1.54 + public HDD(string name, IntPtr handle, int drive, SMART.SSDLifeID lifeID,
1.55 + ISettings settings)
1.56 + {
1.57 + this.name = name;
1.58 + this.handle = handle;
1.59 + this.drive = drive;
1.60 + this.count = 0;
1.61 + this.lifeID = lifeID;
1.62 + this.lifeSensor = new Sensor("HDD", 0, SensorType.Level, this, settings);
1.63 +
1.64 + Update();
1.65 + }
1.66
1.67 public string Name {
1.68 get { return name; }
1.69 @@ -90,7 +107,13 @@
1.70
1.71 public ISensor[] Sensors {
1.72 get {
1.73 - return new ISensor[] { temperature };
1.74 + if (lifeID != SMART.SSDLifeID.None)
1.75 + return new ISensor[] { lifeSensor };
1.76 +
1.77 + if (temperatureID != 0x00)
1.78 + return new ISensor[] { temperatureSensor };
1.79 +
1.80 + return new ISensor[] {};
1.81 }
1.82 }
1.83
1.84 @@ -100,11 +123,30 @@
1.85
1.86 public void Update() {
1.87 if (count == 0) {
1.88 - SMART.DriveAttribute[] attributes = SMART.ReadSmart(handle, drive);
1.89 - if (attributes != null && attribute < attributes.Length)
1.90 - temperature.Value = attributes[attribute].RawValue[0];
1.91 + List<SMART.DriveAttribute> attributes = SMART.ReadSmart(handle, drive);
1.92 + if (temperatureID != 0x00 &&
1.93 + attributes.Exists(attr => (int)attr.ID == (int)temperatureID))
1.94 + {
1.95 + temperatureSensor.Value = attributes
1.96 + .Find(attr => (int)attr.ID == (int)temperatureID)
1.97 + .RawValue[0];
1.98 + }
1.99 +
1.100 + if (lifeID != 0x00 &&
1.101 + attributes.Exists(attr => (int)attr.ID == (int)lifeID))
1.102 + {
1.103 + lifeSensor.Value = attributes
1.104 + .Find(attr => (int)attr.ID == (int)temperatureID)
1.105 + .AttrValue;
1.106 + }
1.107 } else {
1.108 - temperature.Value = temperature.Value;
1.109 + if (temperatureID != 0x00) {
1.110 + temperatureSensor.Value = temperatureSensor.Value;
1.111 + }
1.112 +
1.113 + if (lifeID != 0x00) {
1.114 + lifeSensor.Value = lifeSensor.Value;
1.115 + }
1.116 }
1.117
1.118 count++; count %= UPDATE_DIVIDER;