rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
fan_control.cpp
Go to the documentation of this file.
1#include "pch.h"
2
3#include "fan_control.h"
4
5#include "bench_test.h"
6
7PUBLIC_API_WEAK bool fansDisabledByBoardStatus() {
8 return false;
9}
10
11PUBLIC_API_WEAK bool fansEnabledByBoardStatus() {
12 return false;
13}
14
15bool FanController::getState(bool acActive, bool lastState) {
18
19#if EFI_SHAFT_POSITION_INPUT
22#else
23 cranking = false;
24 notRunning = true;
25#endif
26
27 disabledBySpeed = disableAtSpeed() > 0 && vss.Valid && vss.Value > disableAtSpeed();
29 brokenClt = !clt;
30 enabledForAc = enableWithAc() && acActive;
31 hot = clt.value_or(0) > getFanOnTemp();
32 cold = clt.value_or(0) < getFanOffTemp();
33
36 return true;
37 } else if (cranking) {
38 // Inhibit while cranking
40 return false;
41 } else if (disabledWhileEngineStopped) {
42 // Inhibit while not running (if so configured)
44 return false;
45 } else if (disabledBySpeed) {
46 // Inhibit while driving fast
48 return false;
49 } else if (fansDisabledByBoardStatus()) {
51 return false;
52 } else if (brokenClt) {
53 // If CLT is broken, turn the fan on
55 return true;
56 } else if (enabledForAc) {
58 return true;
59 } else if (hot) {
61 return true;
62 } else if (cold) {
64 return false;
65 } else {
67 // no condition met, maintain previous state
68 return lastState;
69 }
70}
71
73#if EFI_PROD_CODE
74 if (isRunningBenchTest()) {
76 return; // let's not mess with bench testing
77 }
78#endif
79
80 bool acActive = engine->module<AcController>()->isAcEnabled();
81
82 auto& pin = getPin();
83
84 bool result = getState(acActive, pin.getLogicValue());
85
86 m_state = result;
87
88 pin.setValue(result);
89}
90
bool isRunningBenchTest()
Utility methods related to bench testing.
RpmCalculator rpmCalculator
Definition engine.h:306
constexpr auto & module()
Definition engine.h:200
bool isRunning() const
bool isCranking() const override
virtual SensorResult get() const =0
static EngineAccessor engine
Definition engine.h:413
static constexpr engine_configuration_s * engineConfiguration
PUBLIC_API_WEAK bool fansDisabledByBoardStatus()
PUBLIC_API_WEAK bool fansEnabledByBoardStatus()
bool fansDisabledByBoardStatus()
static CCM_OPTIONAL FunctionalSensor clt(SensorType::Clt, MS2NT(10))
brain_pin_e pin
Definition stm32_adc.cpp:15
virtual OutputPin & getPin()=0
void onSlowCallback() override
virtual bool enableWithAc()=0
virtual bool disableWhenStopped()=0
bool getState(bool acActive, bool lastState)
void setDefaultConfiguration() override
virtual float getFanOffTemp()=0
virtual float getFanOnTemp()=0
virtual int disableAtSpeed()=0