fix: normalize fan speed values by taking min speed into account

This commit is contained in:
Ilya Zlobintsev 2024-01-20 17:43:44 +02:00
parent 7e579f8fc9
commit 945cfd23e6
2 changed files with 9 additions and 6 deletions

View File

@ -63,8 +63,8 @@ impl FanCurve {
.0
.into_iter()
.map(|(temp, ratio)| {
let custom_pwm = (max_pwm * ratio) as u8;
let pwm = cmp::max(min_pwm, custom_pwm);
let custom_pwm = (max_pwm * ratio) - (f32::from(min_pwm) * (1.0 - ratio));
let pwm = cmp::max(min_pwm, custom_pwm as u8);
(temp, pwm)
})
.collect();
@ -203,7 +203,8 @@ mod tests {
}),
};
let pmfw_curve = curve.into_pmfw_curve(current_pmfw_curve).unwrap();
let expected_points = [(40, 20), (50, 35), (60, 50), (70, 75), (80, 100)];
// Normalized values
let expected_points = [(40, 20), (50, 22), (60, 40), (70, 70), (80, 100)];
assert_eq!(&expected_points, pmfw_curve.points.as_ref());
}
}

View File

@ -341,9 +341,11 @@ impl GpuController {
let min_temperature = allowed_ranges.temperature_range.start();
let max_temperature = allowed_ranges.temperature_range.end();
#[allow(clippy::cast_sign_loss, clippy::cast_possible_truncation)]
let custom_pwm = (f64::from(*allowed_ranges.speed_range.end()) * static_speed) as u8;
let static_pwm = cmp::max(*allowed_ranges.speed_range.start(), custom_pwm);
let min_pwm = f64::from(*allowed_ranges.speed_range.start());
let max_pwm = f64::from(*allowed_ranges.speed_range.end());
let custom_pwm = (max_pwm * static_speed) - (min_pwm * (1.0 - static_speed));
#[allow(clippy::cast_possible_truncation, clippy::cast_sign_loss)]
let static_pwm = cmp::max(*allowed_ranges.speed_range.start(), custom_pwm as u8);
let mut points = vec![(*min_temperature, static_pwm)];
for _ in 1..current_curve.points.len() {