Replace Storage implementation with CrystalDiskInfo based implementation (#2015)
* Replace Storage implementation with CrystalDiskInfo based implementation. * Formatting. * Code review. * Code review. * Increase space for attribute name in report. * Implement dynamic disk handling for usage sensor. Disable unused warnings. * Further cleanup in NativeMethods.txt and referenced.
This commit is contained in:
@@ -4,48 +4,14 @@
|
||||
// Partial Copyright (C) Michael Möller <mmoeller@openhardwaremonitor.org> and Contributors.
|
||||
// All Rights Reserved.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
using LibreHardwareMonitor.Interop;
|
||||
|
||||
namespace LibreHardwareMonitor.Hardware.Storage;
|
||||
|
||||
public class SmartAttribute
|
||||
public sealed class SmartAttribute
|
||||
{
|
||||
private readonly RawValueConversion _rawValueConversion;
|
||||
|
||||
public delegate float RawValueConversion(byte[] rawValue, byte value, IReadOnlyList<IParameter> parameters);
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="SmartAttribute" /> class.
|
||||
/// Initializes a new instance of the <see cref="SmartAttribute"/> class.
|
||||
/// </summary>
|
||||
/// <param name="id">The SMART id of the attribute.</param>
|
||||
/// <param name="name">The name of the attribute.</param>
|
||||
public SmartAttribute(byte id, string name) : this(id, name, null, null, 0, null)
|
||||
{ }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="SmartAttribute" /> class.
|
||||
/// </summary>
|
||||
/// <param name="id">The SMART id of the attribute.</param>
|
||||
/// <param name="name">The name of the attribute.</param>
|
||||
/// <param name="rawValueConversion">
|
||||
/// A delegate for converting the raw byte
|
||||
/// array into a value (or null to use the attribute value).
|
||||
/// </param>
|
||||
public SmartAttribute(byte id, string name, RawValueConversion rawValueConversion) : this(id, name, rawValueConversion, null, 0, null)
|
||||
{ }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="SmartAttribute" /> class.
|
||||
/// </summary>
|
||||
/// <param name="id">The SMART id of the attribute.</param>
|
||||
/// <param name="name">The name of the attribute.</param>
|
||||
/// <param name="rawValueConversion">
|
||||
/// A delegate for converting the raw byte
|
||||
/// array into a value (or null to use the attribute value).
|
||||
/// </param>
|
||||
/// <param name="smartAttribute">The SMART attribute.</param>
|
||||
/// <param name="sensorType">
|
||||
/// Type of the sensor or null if no sensor is to
|
||||
/// be created.
|
||||
@@ -60,47 +26,25 @@ public class SmartAttribute
|
||||
/// no sensor is created.
|
||||
/// </param>
|
||||
/// <param name="defaultHiddenSensor">True to hide the sensor initially.</param>
|
||||
/// <param name="parameterDescriptions">
|
||||
/// Description for the parameters of the sensor
|
||||
/// (or null).
|
||||
/// </param>
|
||||
public SmartAttribute(byte id, string name, RawValueConversion rawValueConversion, SensorType? sensorType, int sensorChannel, string sensorName, bool defaultHiddenSensor = false, ParameterDescription[] parameterDescriptions = null)
|
||||
public SmartAttribute(DiskInfoToolkit.SmartAttribute smartAttribute, SensorType? sensorType, int sensorChannel, string sensorName, bool defaultHiddenSensor = false)
|
||||
{
|
||||
Id = id;
|
||||
Name = name;
|
||||
_rawValueConversion = rawValueConversion;
|
||||
Attribute = smartAttribute;
|
||||
SensorType = sensorType;
|
||||
SensorChannel = sensorChannel;
|
||||
SensorName = sensorName;
|
||||
DefaultHiddenSensor = defaultHiddenSensor;
|
||||
ParameterDescriptions = parameterDescriptions;
|
||||
SensorName = sensorName ?? Name;
|
||||
IsHiddenByDefault = defaultHiddenSensor;
|
||||
}
|
||||
|
||||
public bool DefaultHiddenSensor { get; }
|
||||
public DiskInfoToolkit.SmartAttribute Attribute { get; internal set; }
|
||||
|
||||
public bool HasRawValueConversion => _rawValueConversion != null;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the SMART identifier.
|
||||
/// </summary>
|
||||
public byte Id { get; }
|
||||
|
||||
public string Name { get; }
|
||||
|
||||
public ParameterDescription[] ParameterDescriptions { get; }
|
||||
|
||||
public int SensorChannel { get; }
|
||||
|
||||
public string SensorName { get; }
|
||||
public byte Id => Attribute.Info.ID;
|
||||
public string Name => Attribute.Info.Name;
|
||||
|
||||
public SensorType? SensorType { get; }
|
||||
public int SensorChannel { get; }
|
||||
public string SensorName { get; }
|
||||
public bool IsHiddenByDefault { get; }
|
||||
|
||||
internal unsafe float ConvertValue(AtaSmart.SMART_ATTRIBUTE value, IReadOnlyList<IParameter> parameters)
|
||||
{
|
||||
if (_rawValueConversion == null)
|
||||
return value.CurrentValue;
|
||||
|
||||
Span<byte> rawValue = new(value.RawValue, 6);
|
||||
return _rawValueConversion(rawValue.ToArray(), value.CurrentValue, parameters);
|
||||
}
|
||||
public float Value => Attribute.Attribute.RawValueULong;
|
||||
public byte Threshold => Attribute.Attribute.Threshold;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user