From 32055d825ef4da60b52501bfd063f0932d9a0bac Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Sat, 4 Apr 2020 13:30:33 -0600 Subject: [PATCH] Re-enable interpolation of duty cycle --- src/board/system76/darp5/peci.c | 14 ++++++-------- src/board/system76/galp3-c/peci.c | 14 ++++++-------- src/board/system76/lemp9/peci.c | 14 ++++++-------- 3 files changed, 18 insertions(+), 24 deletions(-) diff --git a/src/board/system76/darp5/peci.c b/src/board/system76/darp5/peci.c index 93d8e0d..945a6b2 100644 --- a/src/board/system76/darp5/peci.c +++ b/src/board/system76/darp5/peci.c @@ -57,14 +57,12 @@ uint8_t fan_duty(int16_t temp) { // If in between current temp and previous temp, interpolate if (temp > prev->temp) { - return prev->duty; - - // int16_t dtemp = (cur->temp - prev->temp); - // int16_t dduty = ((int16_t)cur->duty) - ((int16_t)prev->duty); - // return (uint8_t)( - // ((int16_t)prev->duty) + - // ((temp - prev->temp) * dduty) / dtemp - // ); + int16_t dtemp = (cur->temp - prev->temp); + int16_t dduty = ((int16_t)cur->duty) - ((int16_t)prev->duty); + return (uint8_t)( + ((int16_t)prev->duty) + + ((temp - prev->temp) * dduty) / dtemp + ); } } } diff --git a/src/board/system76/galp3-c/peci.c b/src/board/system76/galp3-c/peci.c index 93d8e0d..945a6b2 100644 --- a/src/board/system76/galp3-c/peci.c +++ b/src/board/system76/galp3-c/peci.c @@ -57,14 +57,12 @@ uint8_t fan_duty(int16_t temp) { // If in between current temp and previous temp, interpolate if (temp > prev->temp) { - return prev->duty; - - // int16_t dtemp = (cur->temp - prev->temp); - // int16_t dduty = ((int16_t)cur->duty) - ((int16_t)prev->duty); - // return (uint8_t)( - // ((int16_t)prev->duty) + - // ((temp - prev->temp) * dduty) / dtemp - // ); + int16_t dtemp = (cur->temp - prev->temp); + int16_t dduty = ((int16_t)cur->duty) - ((int16_t)prev->duty); + return (uint8_t)( + ((int16_t)prev->duty) + + ((temp - prev->temp) * dduty) / dtemp + ); } } } diff --git a/src/board/system76/lemp9/peci.c b/src/board/system76/lemp9/peci.c index 93d8e0d..945a6b2 100644 --- a/src/board/system76/lemp9/peci.c +++ b/src/board/system76/lemp9/peci.c @@ -57,14 +57,12 @@ uint8_t fan_duty(int16_t temp) { // If in between current temp and previous temp, interpolate if (temp > prev->temp) { - return prev->duty; - - // int16_t dtemp = (cur->temp - prev->temp); - // int16_t dduty = ((int16_t)cur->duty) - ((int16_t)prev->duty); - // return (uint8_t)( - // ((int16_t)prev->duty) + - // ((temp - prev->temp) * dduty) / dtemp - // ); + int16_t dtemp = (cur->temp - prev->temp); + int16_t dduty = ((int16_t)cur->duty) - ((int16_t)prev->duty); + return (uint8_t)( + ((int16_t)prev->duty) + + ((temp - prev->temp) * dduty) / dtemp + ); } } }