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:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user