Fixed an issue in the ram group implementation (sensor values did not get stored to the settings instance).
3 This Source Code Form is subject to the terms of the Mozilla Public
4 License, v. 2.0. If a copy of the MPL was not distributed with this
5 file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 Copyright (C) 2011-2012 Michael Möller <mmoeller@openhardwaremonitor.org>
8 Copyright (C) 2011 Roland Reinl <roland-reinl@gmx.de>
13 using System.Collections.Generic;
14 using OpenHardwareMonitor.Collections;
16 namespace OpenHardwareMonitor.Hardware.HDD {
17 internal class SmartAttribute {
19 private RawValueConversion rawValueConversion;
22 /// Initializes a new instance of the <see cref="SmartAttribute"/> class.
24 /// <param name="identifier">The SMART identifier of the attribute.</param>
25 /// <param name="name">The name of the attribute.</param>
26 public SmartAttribute(byte identifier, string name) :
27 this(identifier, name, null, null, 0) { }
30 /// Initializes a new instance of the <see cref="SmartAttribute"/> class.
32 /// <param name="identifier">The SMART identifier of the attribute.</param>
33 /// <param name="name">The name of the attribute.</param>
34 /// <param name="rawValueConversion">A delegate for converting the raw byte
35 /// array into a value (or null to use the attribute value).</param>
36 public SmartAttribute(byte identifier, string name,
37 RawValueConversion rawValueConversion) :
38 this(identifier, name, rawValueConversion, null, 0) { }
41 /// Initializes a new instance of the <see cref="SmartAttribute"/> class.
43 /// <param name="identifier">The SMART identifier of the attribute.</param>
44 /// <param name="name">The name of the attribute.</param>
45 /// <param name="rawValueConversion">A delegate for converting the raw byte
46 /// array into a value (or null to use the attribute value).</param>
47 /// <param name="sensorType">Type of the sensor or null if no sensor is to
48 /// be created.</param>
49 /// <param name="sensorChannel">If there exists more than one attribute with
50 /// the same sensor channel and type, then a sensor is created only for the
51 /// first attribute.</param>
52 /// <param name="defaultHiddenSensor">True to hide the sensor initially.</param>
53 /// <param name="parameterDescriptions">Description for the parameters of the sensor
54 /// (or null).</param>
55 public SmartAttribute(byte identifier, string name,
56 RawValueConversion rawValueConversion, SensorType? sensorType,
57 int sensorChannel, bool defaultHiddenSensor = false,
58 ParameterDescription[] parameterDescriptions = null)
60 this.Identifier = identifier;
62 this.rawValueConversion = rawValueConversion;
63 this.SensorType = sensorType;
64 this.SensorChannel = sensorChannel;
65 this.DefaultHiddenSensor = defaultHiddenSensor;
66 this.ParameterDescriptions = parameterDescriptions;
70 /// Gets the SMART identifier.
72 public byte Identifier { get; private set; }
74 public string Name { get; private set; }
76 public SensorType? SensorType { get; private set; }
78 public int SensorChannel { get; private set; }
80 public bool DefaultHiddenSensor { get; private set; }
82 public ParameterDescription[] ParameterDescriptions { get; private set; }
84 public bool HasRawValueConversion {
86 return rawValueConversion != null;
90 public float ConvertValue(DriveAttributeValue value,
91 IReadOnlyArray<IParameter> parameters)
93 if (rawValueConversion == null) {
94 return value.AttrValue;
96 return rawValueConversion(value.RawValue, value.AttrValue, parameters);
100 public delegate float RawValueConversion(byte[] rawValue, byte value,
101 IReadOnlyArray<IParameter> parameters);