moel@324
|
1 |
/*
|
moel@324
|
2 |
|
moel@344
|
3 |
This Source Code Form is subject to the terms of the Mozilla Public
|
moel@344
|
4 |
License, v. 2.0. If a copy of the MPL was not distributed with this
|
moel@344
|
5 |
file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
moel@324
|
6 |
|
moel@344
|
7 |
Copyright (C) 2011-2012 Michael Möller <mmoeller@openhardwaremonitor.org>
|
moel@344
|
8 |
Copyright (C) 2011 Roland Reinl <roland-reinl@gmx.de>
|
moel@344
|
9 |
|
moel@324
|
10 |
*/
|
moel@324
|
11 |
|
moel@324
|
12 |
using System;
|
moel@324
|
13 |
using System.Collections.Generic;
|
moel@324
|
14 |
|
moel@324
|
15 |
namespace OpenHardwareMonitor.Hardware.HDD {
|
moel@324
|
16 |
internal class SmartAttribute {
|
moel@324
|
17 |
|
moel@324
|
18 |
private RawValueConversion rawValueConversion;
|
moel@324
|
19 |
|
moel@324
|
20 |
/// <summary>
|
moel@324
|
21 |
/// Initializes a new instance of the <see cref="SmartAttribute"/> class.
|
moel@324
|
22 |
/// </summary>
|
moel@324
|
23 |
/// <param name="identifier">The SMART identifier of the attribute.</param>
|
moel@324
|
24 |
/// <param name="name">The name of the attribute.</param>
|
moel@324
|
25 |
public SmartAttribute(byte identifier, string name) :
|
moel@324
|
26 |
this(identifier, name, null, null, 0) { }
|
moel@324
|
27 |
|
moel@324
|
28 |
/// <summary>
|
moel@324
|
29 |
/// Initializes a new instance of the <see cref="SmartAttribute"/> class.
|
moel@324
|
30 |
/// </summary>
|
moel@324
|
31 |
/// <param name="identifier">The SMART identifier of the attribute.</param>
|
moel@324
|
32 |
/// <param name="name">The name of the attribute.</param>
|
moel@324
|
33 |
/// <param name="rawValueConversion">A delegate for converting the raw byte
|
moel@324
|
34 |
/// array into a value (or null to use the attribute value).</param>
|
moel@324
|
35 |
public SmartAttribute(byte identifier, string name,
|
moel@324
|
36 |
RawValueConversion rawValueConversion) :
|
moel@324
|
37 |
this(identifier, name, rawValueConversion, null, 0) { }
|
moel@324
|
38 |
|
moel@324
|
39 |
/// <summary>
|
moel@324
|
40 |
/// Initializes a new instance of the <see cref="SmartAttribute"/> class.
|
moel@324
|
41 |
/// </summary>
|
moel@324
|
42 |
/// <param name="identifier">The SMART identifier of the attribute.</param>
|
moel@324
|
43 |
/// <param name="name">The name of the attribute.</param>
|
moel@324
|
44 |
/// <param name="rawValueConversion">A delegate for converting the raw byte
|
moel@324
|
45 |
/// array into a value (or null to use the attribute value).</param>
|
moel@324
|
46 |
/// <param name="sensorType">Type of the sensor or null if no sensor is to
|
moel@324
|
47 |
/// be created.</param>
|
moel@324
|
48 |
/// <param name="sensorChannel">If there exists more than one attribute with
|
moel@324
|
49 |
/// the same sensor channel and type, then a sensor is created only for the
|
moel@324
|
50 |
/// first attribute.</param>
|
moel@340
|
51 |
/// <param name="defaultHiddenSensor">True to hide the sensor initially.</param>
|
moel@324
|
52 |
public SmartAttribute(byte identifier, string name,
|
moel@324
|
53 |
RawValueConversion rawValueConversion, SensorType? sensorType,
|
moel@340
|
54 |
int sensorChannel, bool defaultHiddenSensor = false)
|
moel@324
|
55 |
{
|
moel@324
|
56 |
this.Identifier = identifier;
|
moel@324
|
57 |
this.Name = name;
|
moel@324
|
58 |
this.rawValueConversion = rawValueConversion;
|
moel@324
|
59 |
this.SensorType = sensorType;
|
moel@324
|
60 |
this.SensorChannel = sensorChannel;
|
moel@340
|
61 |
this.DefaultHiddenSensor = defaultHiddenSensor;
|
moel@324
|
62 |
}
|
moel@324
|
63 |
|
moel@324
|
64 |
/// <summary>
|
moel@324
|
65 |
/// Gets the SMART identifier.
|
moel@324
|
66 |
/// </summary>
|
moel@324
|
67 |
public byte Identifier { get; private set; }
|
moel@324
|
68 |
|
moel@324
|
69 |
public string Name { get; private set; }
|
moel@324
|
70 |
|
moel@324
|
71 |
public SensorType? SensorType { get; private set; }
|
moel@324
|
72 |
|
moel@324
|
73 |
public int SensorChannel { get; private set; }
|
moel@324
|
74 |
|
moel@340
|
75 |
public bool DefaultHiddenSensor { get; private set; }
|
moel@340
|
76 |
|
moel@324
|
77 |
public bool HasRawValueConversion {
|
moel@324
|
78 |
get {
|
moel@324
|
79 |
return rawValueConversion != null;
|
moel@324
|
80 |
}
|
moel@324
|
81 |
}
|
moel@324
|
82 |
|
moel@324
|
83 |
public float ConvertValue(DriveAttributeValue value) {
|
moel@324
|
84 |
if (rawValueConversion == null) {
|
moel@324
|
85 |
return value.AttrValue;
|
moel@324
|
86 |
} else {
|
moel@324
|
87 |
return rawValueConversion(value.RawValue, value.AttrValue);
|
moel@324
|
88 |
}
|
moel@324
|
89 |
}
|
moel@324
|
90 |
|
moel@324
|
91 |
public delegate float RawValueConversion(byte[] rawValue, byte value);
|
moel@324
|
92 |
}
|
moel@324
|
93 |
}
|