WIP - have working UI for base functions
This commit is contained in:
@@ -0,0 +1,144 @@
|
||||
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
|
||||
// If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
// Copyright (C) LibreHardwareMonitor and Contributors.
|
||||
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
using LibreHardwareMonitor.Hardware;
|
||||
using LibreHardwareMonitor.Windows.WinUI.ViewModels;
|
||||
|
||||
namespace LibreHardwareMonitor.Windows.WinUI.Utilities;
|
||||
|
||||
public static class SensorFormatter
|
||||
{
|
||||
public static string GetFormatString(ISensor sensor)
|
||||
{
|
||||
return sensor.SensorType switch
|
||||
{
|
||||
SensorType.Voltage => "{0:F3} V",
|
||||
SensorType.Current => "{0:F3} A",
|
||||
SensorType.Clock => "{0:F1} MHz",
|
||||
SensorType.Load => "{0:F1} %",
|
||||
SensorType.Temperature => "{0:F1} \u00B0C",
|
||||
SensorType.Fan => "{0:F0} RPM",
|
||||
SensorType.Flow => "{0:F1} L/h",
|
||||
SensorType.Control => "{0:F1} %",
|
||||
SensorType.Level => "{0:F1} %",
|
||||
SensorType.Power => "{0:F1} W",
|
||||
SensorType.Data => "{0:F1} GB",
|
||||
SensorType.SmallData => "{0:F1} MB",
|
||||
SensorType.Factor => "{0:F3}",
|
||||
SensorType.Frequency => "{0:F1} Hz",
|
||||
SensorType.Throughput => "{0:F1} B/s",
|
||||
SensorType.TimeSpan => "{0:g}",
|
||||
SensorType.Timing => "{0:F3} ns",
|
||||
SensorType.Energy => "{0:F0} mWh",
|
||||
SensorType.Noise => "{0:F0} dBA",
|
||||
SensorType.Conductivity => "{0:F1} \u00B5S/cm",
|
||||
SensorType.Humidity => "{0:F0} %",
|
||||
_ => "{0:F1}"
|
||||
};
|
||||
}
|
||||
|
||||
public static string FormatValue(ISensor sensor, float? value, TemperatureUnit temperatureUnit)
|
||||
{
|
||||
if (!value.HasValue)
|
||||
return "-";
|
||||
|
||||
return sensor.SensorType switch
|
||||
{
|
||||
SensorType.Voltage => $"{value:F3} V",
|
||||
SensorType.Current => $"{value:F3} A",
|
||||
SensorType.Clock => $"{value:F1} MHz",
|
||||
SensorType.Load => $"{value:F1} %",
|
||||
SensorType.Temperature when temperatureUnit == TemperatureUnit.Fahrenheit => $"{CelsiusToFahrenheit(value):F1} \u00B0F",
|
||||
SensorType.Temperature => $"{value:F1} \u00B0C",
|
||||
SensorType.Fan => $"{value:F0} RPM",
|
||||
SensorType.Flow => $"{value:F1} L/h",
|
||||
SensorType.Control => $"{value:F1} %",
|
||||
SensorType.Level => $"{value:F1} %",
|
||||
SensorType.Power => $"{value:F1} W",
|
||||
SensorType.Data => $"{value:F1} GB",
|
||||
SensorType.SmallData => $"{value:F1} MB",
|
||||
SensorType.Factor => $"{value:F3}",
|
||||
SensorType.Frequency => $"{value:F1} Hz",
|
||||
SensorType.Throughput => FormatThroughput(sensor, value.Value),
|
||||
SensorType.TimeSpan => string.Format(CultureInfo.CurrentCulture, "{0:g}", TimeSpan.FromSeconds(value.Value)),
|
||||
SensorType.Timing => $"{value:F3} ns",
|
||||
SensorType.Energy => $"{value:F0} mWh",
|
||||
SensorType.Noise => $"{value:F0} dBA",
|
||||
SensorType.Conductivity => $"{value:F1} \u00B5S/cm",
|
||||
SensorType.Humidity => $"{value:F0} %",
|
||||
_ => value.Value.ToString("F1", CultureInfo.CurrentCulture)
|
||||
};
|
||||
}
|
||||
|
||||
public static double? GetPlotValue(ISensor sensor, TemperatureUnit temperatureUnit)
|
||||
{
|
||||
float? value = sensor.Value;
|
||||
if (!value.HasValue)
|
||||
return null;
|
||||
|
||||
if (sensor.SensorType == SensorType.Temperature && temperatureUnit == TemperatureUnit.Fahrenheit)
|
||||
return CelsiusToFahrenheit(value.Value);
|
||||
|
||||
return value.Value;
|
||||
}
|
||||
|
||||
public static string GetToolTip(ISensor sensor, TemperatureUnit temperatureUnit)
|
||||
{
|
||||
StringBuilder builder = new();
|
||||
|
||||
if (sensor is ICriticalSensorLimits criticalSensorLimits)
|
||||
OptionallyAppendRange(builder, sensor, temperatureUnit, criticalSensorLimits.CriticalLowLimit, criticalSensorLimits.CriticalHighLimit, "critical");
|
||||
|
||||
if (sensor is ISensorLimits sensorLimits)
|
||||
OptionallyAppendRange(builder, sensor, temperatureUnit, sensorLimits.LowLimit, sensorLimits.HighLimit, "normal");
|
||||
|
||||
return builder.ToString();
|
||||
}
|
||||
|
||||
private static void OptionallyAppendRange(StringBuilder builder, ISensor sensor, TemperatureUnit temperatureUnit, float? min, float? max, string kind)
|
||||
{
|
||||
if (min.HasValue)
|
||||
{
|
||||
builder.AppendLine(max.HasValue
|
||||
? $"{CultureInfo.CurrentUICulture.TextInfo.ToTitleCase(kind)} range: {FormatValue(sensor, min, temperatureUnit)} to {FormatValue(sensor, max, temperatureUnit)}."
|
||||
: $"Minimal {kind} value: {FormatValue(sensor, min, temperatureUnit)}.");
|
||||
}
|
||||
else if (max.HasValue)
|
||||
{
|
||||
builder.AppendLine($"Maximal {kind} value: {FormatValue(sensor, max, temperatureUnit)}.");
|
||||
}
|
||||
}
|
||||
|
||||
private static string FormatThroughput(ISensor sensor, float value)
|
||||
{
|
||||
if (sensor.Name == "Connection Speed")
|
||||
{
|
||||
return value switch
|
||||
{
|
||||
100000000 => "100Mbps",
|
||||
1000000000 => "1Gbps",
|
||||
_ when value < 1024 => $"{value:F0} bps",
|
||||
_ when value < 1048576 => $"{value / 1024:F1} Kbps",
|
||||
_ when value < 1073741824 => $"{value / 1048576:F1} Mbps",
|
||||
_ => $"{value / 1073741824:F1} Gbps"
|
||||
};
|
||||
}
|
||||
|
||||
const int oneMegabyte = 1048576;
|
||||
return value < oneMegabyte ? $"{value / 1024:F1} KB/s" : $"{value / oneMegabyte:F1} MB/s";
|
||||
}
|
||||
|
||||
private static float? CelsiusToFahrenheit(float? valueInCelsius)
|
||||
{
|
||||
return valueInCelsius * 1.8f + 32;
|
||||
}
|
||||
|
||||
private static float CelsiusToFahrenheit(float valueInCelsius)
|
||||
{
|
||||
return valueInCelsius * 1.8f + 32;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
|
||||
// If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
// Copyright (C) LibreHardwareMonitor and Contributors.
|
||||
|
||||
using LibreHardwareMonitor.Hardware;
|
||||
|
||||
namespace LibreHardwareMonitor.Windows.WinUI.Utilities;
|
||||
|
||||
public static class SensorTypeDisplay
|
||||
{
|
||||
public static string GetText(SensorType sensorType)
|
||||
{
|
||||
return sensorType switch
|
||||
{
|
||||
SensorType.Voltage => "Voltages",
|
||||
SensorType.Current => "Currents",
|
||||
SensorType.Clock => "Clocks",
|
||||
SensorType.Load => "Load",
|
||||
SensorType.Temperature => "Temperatures",
|
||||
SensorType.Fan => "Fans",
|
||||
SensorType.Flow => "Flows",
|
||||
SensorType.Control => "Controls",
|
||||
SensorType.Level => "Levels",
|
||||
SensorType.Power => "Powers",
|
||||
SensorType.Data => "Data",
|
||||
SensorType.SmallData => "Data",
|
||||
SensorType.Factor => "Factors",
|
||||
SensorType.Frequency => "Frequencies",
|
||||
SensorType.Throughput => "Throughput",
|
||||
SensorType.TimeSpan => "Times",
|
||||
SensorType.Timing => "Timings",
|
||||
SensorType.Energy => "Capacities",
|
||||
SensorType.Noise => "Noise Levels",
|
||||
SensorType.Conductivity => "Conductivities",
|
||||
SensorType.Humidity => "Humidity Levels",
|
||||
_ => sensorType.ToString()
|
||||
};
|
||||
}
|
||||
|
||||
public static string GetGlyph(SensorType sensorType)
|
||||
{
|
||||
return sensorType switch
|
||||
{
|
||||
SensorType.Voltage => "\uE945",
|
||||
SensorType.Current => "\uE945",
|
||||
SensorType.Clock => "\uE916",
|
||||
SensorType.Load => "\uE9D9",
|
||||
SensorType.Temperature => "\uE9CA",
|
||||
SensorType.Fan => "\uE9F3",
|
||||
SensorType.Flow => "\uE9D5",
|
||||
SensorType.Control => "\uE713",
|
||||
SensorType.Level => "\uE9D2",
|
||||
SensorType.Power => "\uE7E8",
|
||||
SensorType.Data => "\uE8AB",
|
||||
SensorType.SmallData => "\uE8AB",
|
||||
SensorType.Factor => "\uE9D2",
|
||||
SensorType.Frequency => "\uE916",
|
||||
SensorType.Throughput => "\uE9D5",
|
||||
SensorType.TimeSpan => "\uE121",
|
||||
SensorType.Timing => "\uE121",
|
||||
SensorType.Energy => "\uEBAA",
|
||||
SensorType.Noise => "\uE767",
|
||||
SensorType.Conductivity => "\uE945",
|
||||
SensorType.Humidity => "\uE9CA",
|
||||
_ => "\uE9D9"
|
||||
};
|
||||
}
|
||||
|
||||
public static string GetHardwareGlyph(HardwareType hardwareType)
|
||||
{
|
||||
return hardwareType switch
|
||||
{
|
||||
HardwareType.Motherboard => "\uE950",
|
||||
HardwareType.SuperIO => "\uE950",
|
||||
HardwareType.Cpu => "\uE950",
|
||||
HardwareType.Memory => "\uE8AB",
|
||||
HardwareType.GpuNvidia => "\uE7F4",
|
||||
HardwareType.GpuAmd => "\uE7F4",
|
||||
HardwareType.GpuIntel => "\uE7F4",
|
||||
HardwareType.Storage => "\uEDA2",
|
||||
HardwareType.Network => "\uE968",
|
||||
HardwareType.Cooler => "\uE9F3",
|
||||
HardwareType.EmbeddedController => "\uE950",
|
||||
HardwareType.Psu => "\uE7E8",
|
||||
HardwareType.Battery => "\uEBAA",
|
||||
_ => "\uE950"
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user