1.1 --- a/Hardware/HDD/HDD.cs Wed Aug 31 22:48:49 2011 +0000
1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
1.3 @@ -1,136 +0,0 @@
1.4 -/*
1.5 -
1.6 - Version: MPL 1.1/GPL 2.0/LGPL 2.1
1.7 -
1.8 - The contents of this file are subject to the Mozilla Public License Version
1.9 - 1.1 (the "License"); you may not use this file except in compliance with
1.10 - the License. You may obtain a copy of the License at
1.11 -
1.12 - http://www.mozilla.org/MPL/
1.13 -
1.14 - Software distributed under the License is distributed on an "AS IS" basis,
1.15 - WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
1.16 - for the specific language governing rights and limitations under the License.
1.17 -
1.18 - The Original Code is the Open Hardware Monitor code.
1.19 -
1.20 - The Initial Developer of the Original Code is
1.21 - Michael Möller <m.moeller@gmx.ch>.
1.22 - Portions created by the Initial Developer are Copyright (C) 2009-2011
1.23 - the Initial Developer. All Rights Reserved.
1.24 -
1.25 - Contributor(s): Paul Werelds
1.26 -
1.27 - Alternatively, the contents of this file may be used under the terms of
1.28 - either the GNU General Public License Version 2 or later (the "GPL"), or
1.29 - the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
1.30 - in which case the provisions of the GPL or the LGPL are applicable instead
1.31 - of those above. If you wish to allow use of your version of this file only
1.32 - under the terms of either the GPL or the LGPL, and not to allow others to
1.33 - use your version of this file under the terms of the MPL, indicate your
1.34 - decision by deleting the provisions above and replace them with the notice
1.35 - and other provisions required by the GPL or the LGPL. If you do not delete
1.36 - the provisions above, a recipient may use your version of this file under
1.37 - the terms of any one of the MPL, the GPL or the LGPL.
1.38 -
1.39 -*/
1.40 -
1.41 -using System;
1.42 -using System.Collections.Generic;
1.43 -using System.Globalization;
1.44 -
1.45 -namespace OpenHardwareMonitor.Hardware.HDD {
1.46 - internal class HDD : Hardware {
1.47 -
1.48 - private const int UPDATE_DIVIDER = 30; // update only every 30s
1.49 -
1.50 - private readonly IntPtr handle;
1.51 - private readonly int drive;
1.52 - private int count;
1.53 -
1.54 - private readonly SMART.AttributeID temperatureID = SMART.AttributeID.None;
1.55 - private readonly SMART.AttributeID lifeID = SMART.AttributeID.None;
1.56 -
1.57 - private readonly Sensor temperatureSensor;
1.58 - private readonly Sensor lifeSensor;
1.59 -
1.60 - public HDD(string name, IntPtr handle, int drive,
1.61 - SMART.AttributeID temperatureID, SMART.AttributeID lifeID,
1.62 - ISettings settings) : base(name, new Identifier("hdd",
1.63 - drive.ToString(CultureInfo.InvariantCulture)), settings)
1.64 - {
1.65 - this.handle = handle;
1.66 - this.drive = drive;
1.67 - this.count = 0;
1.68 - if (temperatureID != SMART.AttributeID.None) {
1.69 - this.temperatureID = temperatureID;
1.70 - this.temperatureSensor = new Sensor("HDD", 0, SensorType.Temperature,
1.71 - this, settings);
1.72 - }
1.73 -
1.74 - if (lifeID != SMART.AttributeID.None) {
1.75 - this.lifeID = lifeID;
1.76 - this.lifeSensor = new Sensor("Remaining life", 0, SensorType.Level,
1.77 - this, settings);
1.78 - }
1.79 -
1.80 - Update();
1.81 - }
1.82 -
1.83 - public override HardwareType HardwareType {
1.84 - get { return HardwareType.HDD; }
1.85 - }
1.86 -
1.87 - public override ISensor[] Sensors {
1.88 - get {
1.89 - if (lifeID != SMART.AttributeID.None)
1.90 - return new ISensor[] { lifeSensor };
1.91 -
1.92 - if (temperatureID != SMART.AttributeID.None)
1.93 - return new ISensor[] { temperatureSensor };
1.94 -
1.95 - return new ISensor[] {};
1.96 - }
1.97 - }
1.98 -
1.99 - public override void Update() {
1.100 - if (count == 0) {
1.101 - SMART.DriveAttribute[] attributes = SMART.ReadSmart(handle, drive);
1.102 -
1.103 - if (temperatureID != SMART.AttributeID.None &&
1.104 - Array.Exists(attributes, attr => attr.ID == temperatureID))
1.105 - {
1.106 - temperatureSensor.Value = Array
1.107 - .Find(attributes, attr => attr.ID == temperatureID)
1.108 - .RawValue[0];
1.109 - }
1.110 -
1.111 - if (lifeID != SMART.AttributeID.None &&
1.112 - Array.Exists(attributes, attr => attr.ID == lifeID))
1.113 - {
1.114 - lifeSensor.Value = Array
1.115 - .Find(attributes, attr => attr.ID == lifeID)
1.116 - .AttrValue;
1.117 - }
1.118 - } else {
1.119 - if (temperatureID != SMART.AttributeID.None)
1.120 - temperatureSensor.Value = temperatureSensor.Value;
1.121 -
1.122 - if (lifeID != SMART.AttributeID.None)
1.123 - lifeSensor.Value = lifeSensor.Value;
1.124 - }
1.125 -
1.126 - count++; count %= UPDATE_DIVIDER;
1.127 - }
1.128 -
1.129 - public override void Close() {
1.130 - SMART.CloseHandle(handle);
1.131 - base.Close();
1.132 - }
1.133 -
1.134 - public override void Traverse(IVisitor visitor) {
1.135 - foreach (ISensor sensor in Sensors)
1.136 - sensor.Accept(visitor);
1.137 - }
1.138 - }
1.139 -}