Fix float to byte conversion. (#547)

The conversion was using a double between the float value to the byte value, which cause some issue with a software value of 100f, which resulted to 254 instead of 255.

Extracted as a function.
This commit is contained in:
Rem0o
2021-09-25 10:40:54 +02:00
committed by GitHub
parent 095cce0394
commit 38162b5824
2 changed files with 11 additions and 3 deletions
@@ -129,6 +129,7 @@ namespace LibreHardwareMonitor.Hardware.Controller.Nzxt
catch (ObjectDisposedException)
{
// Could be unplugged, or the app is stopping...
return;
}
}
}
@@ -87,7 +87,7 @@ namespace LibreHardwareMonitor.Hardware.Motherboard
}
case ControlMode.Software:
{
superIO.SetControl(index, (byte)(cc.SoftwareValue * 2.55));
superIO.SetControl(index, GetSoftwareValueAsByte(cc));
break;
}
default:
@@ -100,7 +100,7 @@ namespace LibreHardwareMonitor.Hardware.Motherboard
control.SoftwareControlValueChanged += cc =>
{
if (cc.ControlMode == ControlMode.Software)
superIO.SetControl(index, (byte)(cc.SoftwareValue * 2.55));
superIO.SetControl(index, GetSoftwareValueAsByte(cc));
};
switch (control.ControlMode)
@@ -117,7 +117,7 @@ namespace LibreHardwareMonitor.Hardware.Motherboard
}
case ControlMode.Software:
{
superIO.SetControl(index, (byte)(control.SoftwareValue * 2.55));
superIO.SetControl(index, GetSoftwareValueAsByte(control));
break;
}
@@ -130,6 +130,13 @@ namespace LibreHardwareMonitor.Hardware.Motherboard
}
}
private static byte GetSoftwareValueAsByte(Control control)
{
const float percentToByteRatio = 2.55f;
float value = control.SoftwareValue * percentToByteRatio;
return (byte)value;
}
private void CreateFanSensors(ISuperIO superIO, ISettings settings, IList<Fan> f)
{
foreach (Fan fan in f)