rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
ac_control.cpp
Go to the documentation of this file.
1#include "pch.h"
2
3#include "ac_control.h"
4#include "deadband.h"
6
7namespace {
8 // Deadbands to prevent rapid switching on/off of AC
9 Deadband<200> maxRpmDeadband;
10 Deadband<5> maxCltDeadband;
11 Deadband<5> maxTpsDeadband;
13 MaxLimitWithHysteresis acPressureEnableHysteresis;
14}
15
18
19 engineTooSlow = rpm < 500;
20
21 if (engineTooSlow) {
22 return false;
23 }
24
25 auto maxRpm = engineConfiguration->maxAcRpm;
26 engineTooFast = maxRpm != 0 && maxRpmDeadband.gt(rpm, maxRpm);
27 if (engineTooFast) {
28 return false;
29 }
30
32
33 noClt = !clt;
34 // No AC with failed CLT
35 if (noClt) {
36 return false;
37 }
38
39 // Engine too hot, disable
40 auto maxClt = engineConfiguration->maxAcClt;
41 engineTooHot = (maxClt != 0) && maxCltDeadband.gt(clt.Value, maxClt);
42 if (engineTooHot) {
43 return false;
44 }
45
46 // TPS too high, disable
47 auto maxTps = engineConfiguration->maxAcTps;
48 tpsTooHigh = maxTps != 0 && maxTpsDeadband.gt(Sensor::getOrZero(SensorType::Tps1), maxTps);
49 if (tpsTooHigh) {
50 return false;
51 }
52
54 if (acPressure.Valid) {
55 const auto minAcPressure = static_cast<float>(engineConfiguration->minAcPressure);
56 acPressureTooLow = minPressureDeadband.lt(acPressure.Value, minAcPressure);
57 if (acPressureTooLow) {
58 return false;
59 }
60
61 const auto maxAcPressure = static_cast<float>(engineConfiguration->maxAcPressure);
62 acPressureTooHigh = acPressureEnableHysteresis.checkIfLimitIsExceeded(
63 acPressure.Value,
64 maxAcPressure,
66 );
68 return false;
69 }
70 }
71
72 if (isDisabledByLua) {
73 return false;
74 }
75
76 // All conditions allow AC, simply pass thru switch
77 return acButtonState;
78}
79
81 bool isEnabled = getAcState();
82
83 m_acEnabled = isEnabled;
84
85 if (!isEnabled) {
86 // reset the timer if AC is off
87 m_timeSinceNoAc.reset();
88 }
89
90 float acDelay = engineConfiguration->acDelay;
91 if (acDelay == 0) {
92 // Without delay configured, enable immediately
93 acCompressorState = isEnabled;
94 } else {
95 acCompressorState = isEnabled && m_timeSinceNoAc.hasElapsedSec(acDelay);
96 }
97
99}
100
102 return m_acEnabled;
103}
Timer m_timeSinceNoAc
Definition ac_control.h:21
virtual bool isAcEnabled() const
void onSlowCallback() override
bool getAcState()
RegisteredOutputPin acRelay
Definition efi_gpio.h:90
void setValue(const char *msg, int logicValue, bool isForce=false)
Definition efi_gpio.cpp:604
virtual SensorResult get() const =0
static float getOrZero(SensorType type)
Definition sensor.h:83
EnginePins enginePins
Definition efi_gpio.cpp:24
static constexpr engine_configuration_s * engineConfiguration
static CCM_OPTIONAL FunctionalSensor clt(SensorType::Clt, MS2NT(10))
acPressure("A/C pressure", SensorCategory.SENSOR_INPUTS, FieldType.INT, 816, 1.0, 0.0, 0.0, "kPa")