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"
|
|
|
|
|
2024-03-24 19:06:58 -07:00
|
|
|
PUBLIC_API_WEAK bool fansDisabledByBoardStatus() {
|
2024-03-24 10:28:56 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
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);
|
2024-01-23 08:04:49 -08:00
|
|
|
auto vss = Sensor::get(SensorType::VehicleSpeed);
|
2021-06-11 03:25:12 -07:00
|
|
|
|
2023-09-06 13:59:06 -07:00
|
|
|
#if EFI_SHAFT_POSITION_INPUT
|
2021-11-27 21:40:12 -08:00
|
|
|
cranking = engine->rpmCalculator.isCranking();
|
|
|
|
notRunning = !engine->rpmCalculator.isRunning();
|
2023-09-06 13:59:06 -07:00
|
|
|
#else
|
|
|
|
cranking = false;
|
|
|
|
notRunning = true;
|
|
|
|
#endif
|
2021-06-28 05:52:54 -07:00
|
|
|
|
2024-01-23 08:04:49 -08:00
|
|
|
disabledBySpeed = disableAtSpeed() > 0 && vss.Valid && vss.Value > disableAtSpeed();
|
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
|
2024-04-12 09:50:31 -07:00
|
|
|
tempCode = 31;
|
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)
|
2024-04-12 09:50:31 -07:00
|
|
|
tempCode = 32;
|
2021-11-27 21:40:12 -08:00
|
|
|
return false;
|
2024-01-23 08:04:49 -08:00
|
|
|
} else if (disabledBySpeed) {
|
|
|
|
// Inhibit while driving fast
|
2024-04-12 09:50:31 -07:00
|
|
|
tempCode = 33;
|
2024-01-23 08:04:49 -08:00
|
|
|
return false;
|
2024-03-24 10:28:56 -07:00
|
|
|
} else if (fansDisabledByBoardStatus()) {
|
2024-04-12 09:50:31 -07:00
|
|
|
tempCode = 34;
|
2024-03-24 10:28:56 -07:00
|
|
|
return false;
|
2021-11-27 21:40:12 -08:00
|
|
|
} else if (brokenClt) {
|
2021-06-11 03:25:12 -07:00
|
|
|
// If CLT is broken, turn the fan on
|
2024-04-12 09:50:31 -07:00
|
|
|
tempCode = 35;
|
2021-11-27 21:40:12 -08:00
|
|
|
return true;
|
|
|
|
} else if (enabledForAc) {
|
2024-04-12 09:50:31 -07:00
|
|
|
tempCode = 36;
|
2021-11-27 21:40:12 -08:00
|
|
|
return true;
|
|
|
|
} else if (hot) {
|
2021-06-11 03:25:12 -07:00
|
|
|
// If hot, turn the fan on
|
2024-04-12 09:50:31 -07:00
|
|
|
tempCode = 37;
|
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
|
2024-04-12 09:50:31 -07:00
|
|
|
tempCode = 38;
|
2021-11-27 21:40:12 -08:00
|
|
|
return false;
|
2021-06-11 03:25:12 -07:00
|
|
|
} else {
|
2024-04-12 09:50:31 -07:00
|
|
|
tempCode = 40;
|
2021-06-11 03:25:12 -07:00
|
|
|
// no condition met, maintain previous state
|
2021-11-27 21:40:12 -08:00
|
|
|
return lastState;
|
2021-06-11 03:25:12 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-26 04:12:11 -07:00
|
|
|
void FanController::onSlowCallback() {
|
2021-06-11 03:25:12 -07:00
|
|
|
#if EFI_PROD_CODE
|
|
|
|
if (isRunningBenchTest()) {
|
2024-04-12 09:50:31 -07:00
|
|
|
tempCode = 30;
|
2021-06-11 03:25:12 -07:00
|
|
|
return; // let's not mess with bench testing
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2023-09-26 04:12:11 -07:00
|
|
|
bool acActive = engine->module<AcController>()->isAcEnabled();
|
|
|
|
|
|
|
|
auto& pin = getPin();
|
|
|
|
|
|
|
|
bool result = getState(acActive, pin.getLogicValue());
|
2024-04-12 09:50:31 -07:00
|
|
|
tempAlive = tempAlive + 1;
|
2023-09-26 04:12:11 -07:00
|
|
|
|
|
|
|
pin.setValue(result);
|
2021-06-11 03:25:12 -07:00
|
|
|
}
|