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-16 01:15:29 -08:00
|
|
|
static void fanControl(bool acActive, OutputPin& pin, int8_t fanOnTemp, int8_t fanOffTemp, bool enableWithAc, bool disableWhenStopped) {
|
2021-06-11 03:25:12 -07:00
|
|
|
auto [cltValid, clt] = Sensor::get(SensorType::Clt);
|
|
|
|
|
2021-11-17 00:54:21 -08:00
|
|
|
bool isCranking = engine->rpmCalculator.isCranking();
|
|
|
|
bool isRunning = engine->rpmCalculator.isRunning();
|
2021-06-28 05:52:54 -07:00
|
|
|
|
|
|
|
if (isCranking) {
|
|
|
|
// Inhibit while cranking
|
|
|
|
pin.setValue(false);
|
|
|
|
} else if (disableWhenStopped && !isRunning) {
|
|
|
|
// Inhibit while not running (if so configured)
|
|
|
|
pin.setValue(false);
|
|
|
|
} else if (!cltValid) {
|
2021-06-11 03:25:12 -07:00
|
|
|
// If CLT is broken, turn the fan on
|
|
|
|
pin.setValue(true);
|
2021-06-27 15:51:34 -07:00
|
|
|
} else if (enableWithAc && acActive) {
|
2021-06-11 03:25:12 -07:00
|
|
|
pin.setValue(true);
|
|
|
|
} else if (clt > fanOnTemp) {
|
|
|
|
// If hot, turn the fan on
|
|
|
|
pin.setValue(true);
|
|
|
|
} else if (clt < fanOffTemp) {
|
|
|
|
// If cold, turn the fan off
|
|
|
|
pin.setValue(false);
|
|
|
|
} else {
|
|
|
|
// no condition met, maintain previous state
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
2021-11-17 00:54:21 -08:00
|
|
|
fanControl(acActive, enginePins.fanRelay, engineConfiguration->fanOnTemperature, engineConfiguration->fanOffTemperature, engineConfiguration->enableFan1WithAc, engineConfiguration->disableFan1WhenStopped);
|
|
|
|
fanControl(acActive, enginePins.fanRelay2, engineConfiguration->fan2OnTemperature, engineConfiguration->fan2OffTemperature, engineConfiguration->enableFan2WithAc, engineConfiguration->disableFan2WhenStopped);
|
2021-06-11 03:25:12 -07:00
|
|
|
}
|