2021-07-25 22:05:17 -07:00
|
|
|
#include "pch.h"
|
|
|
|
|
2021-06-11 03:25:12 -07:00
|
|
|
#include "fan_control.h"
|
|
|
|
|
|
|
|
#include "bench_test.h"
|
|
|
|
|
2021-11-27 21:40:12 -08:00
|
|
|
bool FanController::getState(bool acActive, bool lastState) {
|
2022-07-28 00:04:28 -07:00
|
|
|
auto clt = Sensor::get(SensorType::Clt);
|
2021-06-11 03:25:12 -07:00
|
|
|
|
2021-11-27 21:40:12 -08:00
|
|
|
cranking = engine->rpmCalculator.isCranking();
|
|
|
|
notRunning = !engine->rpmCalculator.isRunning();
|
2021-06-28 05:52:54 -07:00
|
|
|
|
2021-11-27 21:40:12 -08:00
|
|
|
disabledWhileEngineStopped = notRunning && disableWhenStopped();
|
2022-07-28 00:04:28 -07:00
|
|
|
brokenClt = !clt;
|
2021-11-27 21:40:12 -08:00
|
|
|
enabledForAc = enableWithAc() && acActive;
|
2022-07-30 14:08:48 -07:00
|
|
|
hot = clt.value_or(0) > getFanOnTemp();
|
|
|
|
cold = clt.value_or(0) < getFanOffTemp();
|
2021-11-27 21:40:12 -08:00
|
|
|
|
|
|
|
if (cranking) {
|
2021-06-28 05:52:54 -07:00
|
|
|
// Inhibit while cranking
|
2021-11-27 21:40:12 -08:00
|
|
|
return false;
|
|
|
|
} else if (disabledWhileEngineStopped) {
|
2021-06-28 05:52:54 -07:00
|
|
|
// Inhibit while not running (if so configured)
|
2021-11-27 21:40:12 -08:00
|
|
|
return false;
|
|
|
|
} else if (brokenClt) {
|
2021-06-11 03:25:12 -07:00
|
|
|
// If CLT is broken, turn the fan on
|
2021-11-27 21:40:12 -08:00
|
|
|
return true;
|
|
|
|
} else if (enabledForAc) {
|
|
|
|
return true;
|
|
|
|
} else if (hot) {
|
2021-06-11 03:25:12 -07:00
|
|
|
// If hot, turn the fan on
|
2021-11-27 21:40:12 -08:00
|
|
|
return true;
|
|
|
|
} else if (cold) {
|
2021-06-11 03:25:12 -07:00
|
|
|
// If cold, turn the fan off
|
2021-11-27 21:40:12 -08:00
|
|
|
return false;
|
2021-06-11 03:25:12 -07:00
|
|
|
} else {
|
|
|
|
// no condition met, maintain previous state
|
2021-11-27 21:40:12 -08:00
|
|
|
return lastState;
|
2021-06-11 03:25:12 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-27 21:40:12 -08:00
|
|
|
void FanController::update(bool acActive) {
|
|
|
|
auto& pin = getPin();
|
|
|
|
|
|
|
|
bool result = getState(acActive, pin.getLogicValue());
|
|
|
|
|
|
|
|
pin.setValue(result);
|
|
|
|
}
|
|
|
|
|
2021-11-16 01:15:29 -08:00
|
|
|
void updateFans(bool acActive) {
|
2021-06-11 03:25:12 -07:00
|
|
|
#if EFI_PROD_CODE
|
|
|
|
if (isRunningBenchTest()) {
|
|
|
|
return; // let's not mess with bench testing
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2022-04-13 14:55:31 -07:00
|
|
|
engine->fan1.update(acActive);
|
|
|
|
engine->fan2.update(acActive);
|
2021-06-11 03:25:12 -07:00
|
|
|
}
|