From 6b86ec9253561182cf444910cfa6ba73d6b55641 Mon Sep 17 00:00:00 2001 From: JoeBroesele <56547187+JoeBroesele@users.noreply.github.com> Date: Mon, 18 Oct 2021 22:11:56 +0200 Subject: [PATCH] Fixes saving the sensor values on program exit and the displayed fan control values for NVIDIA GPUs.. (#575) * Fixes saving the sensor values on program exit. * Fixes the displayed fan control values for NVIDIA GPUs. * Update NvidiaGpu.cs Check cooler id. Co-authored-by: PhyxionNL <7643972+PhyxionNL@users.noreply.github.com> --- .../Hardware/Gpu/NvidiaGpu.cs | 12 ++++++---- LibreHardwareMonitorLib/Hardware/Sensor.cs | 23 ++++++++++--------- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/LibreHardwareMonitorLib/Hardware/Gpu/NvidiaGpu.cs b/LibreHardwareMonitorLib/Hardware/Gpu/NvidiaGpu.cs index 2d6ca3c..ae9d603 100644 --- a/LibreHardwareMonitorLib/Hardware/Gpu/NvidiaGpu.cs +++ b/LibreHardwareMonitorLib/Hardware/Gpu/NvidiaGpu.cs @@ -470,13 +470,15 @@ namespace LibreHardwareMonitor.Hardware.Gpu if (_controls is { Length: > 0 }) { - NvApi.NvFanCoolerControl fanControllers = GetFanCoolersControllers(out status); - if (status == NvApi.NvStatus.OK && fanControllers.Count > 0) + NvApi.NvFanCoolersStatus fanCoolers = GetFanCoolersStatus(out status); + if (status == NvApi.NvStatus.OK && fanCoolers.Count > 0 && fanCoolers.Count == _controls.Length) { - for (int i = 0; i < fanControllers.Count; i++) + for (int i = 0; i < fanCoolers.Count; i++) { - NvApi.NvFanCoolerControlItem item = fanControllers.Items[i]; - _controls[i].Value = item.Level; + NvApi.NvFanCoolersStatusItem item = fanCoolers.Items[i]; + + if (Array.Find(_controls, c => c.Index == item.CoolerId) is { } control) + control.Value = item.CurrentLevel; } } else diff --git a/LibreHardwareMonitorLib/Hardware/Sensor.cs b/LibreHardwareMonitorLib/Hardware/Sensor.cs index 3128e4a..1939492 100644 --- a/LibreHardwareMonitorLib/Hardware/Sensor.cs +++ b/LibreHardwareMonitorLib/Hardware/Sensor.cs @@ -189,19 +189,20 @@ namespace LibreHardwareMonitor.Hardware using MemoryStream memoryStream = new(); using GZipStream gZipStream = new(memoryStream, CompressionMode.Compress); using BufferedStream outputStream = new(gZipStream, 65536); - using BinaryWriter binaryWriter = new(outputStream); - - long t = 0; - - foreach (SensorValue sensorValue in _values) + using (BinaryWriter binaryWriter = new(outputStream)) { - long v = sensorValue.Time.ToBinary(); - binaryWriter.Write(v - t); - t = v; - binaryWriter.Write(sensorValue.Value); - } + long t = 0; - binaryWriter.Flush(); + foreach (SensorValue sensorValue in _values) + { + long v = sensorValue.Time.ToBinary(); + binaryWriter.Write(v - t); + t = v; + binaryWriter.Write(sensorValue.Value); + } + + binaryWriter.Flush(); + } _settings.SetValue(new Identifier(Identifier, "values").ToString(), Convert.ToBase64String(memoryStream.ToArray())); }