rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
nitrous_controller.cpp
Go to the documentation of this file.
1//
2// Created by kifir on 11/25/24.
3//
4
5#include "pch.h"
6
7#if EFI_LAUNCH_CONTROL
9
28
30 float result = 1.0f;
31 if (engineConfiguration->nitrousControlEnabled && isNitrousCondition) {
32 result += engineConfiguration->nitrousFuelAdderPercent / 100.0f;
33 }
34 return result;
35}
36
38 switch (engineConfiguration->nitrousControlArmingMethod) {
39 case DIGITAL_SWITCH_INPUT: {
41 break;
42 }
43 case LUA_GAUGE: {
45 break;
46 }
47 default: { // Unexpected value!!!
48 isNitrousArmed = false;
49 break;
50 }
51 }
52}
53
55 if (engineConfiguration->nitrousMinimumVehicleSpeed != 0) {
56 const expected<float> speed = Sensor::get(SensorType::VehicleSpeed);
57 isNitrousSpeedCondition = speed.Valid && (engineConfiguration->nitrousMinimumVehicleSpeed <= speed.Value);
58 } else {
60 }
61}
62
64 if (engineConfiguration->nitrousMinimumTps != 0) {
65 const expected<float> tps = Sensor::get(SensorType::DriverThrottleIntent);
66 isNitrousTpsCondition = tps.Valid && (engineConfiguration->nitrousMinimumTps <= tps.Value);
67 } else {
69 }
70}
71
73 if (engineConfiguration->nitrousMinimumClt != 0) {
74 const expected<float> clt = Sensor::get(SensorType::Clt);
75 isNitrousCltCondition = clt.Valid && (engineConfiguration->nitrousMinimumClt <= clt.Value);
76 } else {
78 }
79}
80
82 if (engineConfiguration->nitrousMaximumMap != 0) {
83 const expected<float> map = Sensor::get(SensorType::Map);
84 isNitrousMapCondition = map.Valid && (map.Value <= engineConfiguration->nitrousMaximumMap);
85 } else {
87 }
88}
89
91 if (static_cast<float>(engineConfiguration->nitrousMaximumAfr) != 0.0f) {
92 const expected<float> lambda1 = Sensor::get(SensorType::Lambda1);
93 if (lambda1.Valid) {
94 const float afr = lambda1.Value * STOICH_RATIO;
95 isNitrousAfrCondition = (afr <= static_cast<float>(engineConfiguration->nitrousMaximumAfr));
96 } else {
98 }
99 } else {
101 }
102}
103
104namespace {
106}
107
109 const expected<float> rpmSensorReading = Sensor::get(SensorType::Rpm);
110 if (rpmSensorReading.Valid) {
111 const float rpm = rpmSensorReading.Value;
112 if (rpmHysteresis.checkIfLimitIsExceeded(
113 rpm,
114 engineConfiguration->nitrousDeactivationRpm,
115 engineConfiguration->nitrousDeactivationRpmWindow
116 )) {
117 isNitrousRpmCondition = false;
118 } else {
119 isNitrousRpmCondition = (engineConfiguration->nitrousActivationRpm <= rpm);
120 }
121 } else {
122 isNitrousRpmCondition = false;
123 }
124}
125
127 bool result = false;
128#if !EFI_SIMULATOR
129 const switch_input_pin_e triggerPin = engineConfiguration->nitrousControlTriggerPin;
130 const pin_input_mode_e triggerPinMode = engineConfiguration->nitrousControlTriggerPinMode;
131 if (isBrainPinValid(triggerPin)) {
132 result = efiReadPin(triggerPin, triggerPinMode);
133 }
134#endif // !EFI_SIMULATOR
135 return result;
136}
137
139 bool result = false;
140 const SensorResult currentSensorResult = Sensor::get(getLuaGauge());
141 if (currentSensorResult.Valid) {
142 const float currentValue = currentSensorResult.Value;
143 const float armingValue = engineConfiguration->nitrousLuaGaugeArmingValue;
144 switch (engineConfiguration->nitrousLuaGaugeMeaning) {
145 case LUA_GAUGE_LOWER_BOUND: {
146 result = (armingValue <= currentValue);
147 break;
148 }
149 case LUA_GAUGE_UPPER_BOUND: {
150 result = (currentValue <= armingValue);
151 break;
152 }
153 }
154 }
155 return result;
156}
157
160 switch (engineConfiguration->nitrousLuaGauge) {
161 case LUA_GAUGE_1: {
162 break;
163 }
164 case LUA_GAUGE_2: {
165 result = SensorType::LuaGauge2;
166 break;
167 }
168 case LUA_GAUGE_3: {
169 result = SensorType::LuaGauge3;
170 break;
171 }
172 case LUA_GAUGE_4: {
173 result = SensorType::LuaGauge4;
174 break;
175 }
176 case LUA_GAUGE_5: {
177 result = SensorType::LuaGauge5;
178 break;
179 }
180 case LUA_GAUGE_6: {
181 result = SensorType::LuaGauge6;
182 break;
183 }
184 case LUA_GAUGE_7: {
185 result = SensorType::LuaGauge7;
186 break;
187 }
188 case LUA_GAUGE_8: {
189 result = SensorType::LuaGauge8;
190 break;
191 }
192 }
193 return result;
194}
195
196#endif // EFI_LAUNCH_CONTROL
RegisteredOutputPin nitrousRelay
Definition efi_gpio.h:92
bool checkTriggerPinState() const
float getFuelCoefficient() const
void onSlowCallback() override
SensorType getLuaGauge() const
void setValue(const char *msg, int logicValue, bool isForce=false)
Definition efi_gpio.cpp:604
virtual SensorResult get() const =0
EnginePins enginePins
Definition efi_gpio.cpp:24
static constexpr engine_configuration_s * engineConfiguration
static CCM_OPTIONAL FunctionalSensor clt(SensorType::Clt, MS2NT(10))
bool efiReadPin(brain_pin_e pin)
Definition io_pins.cpp:89
bool isBrainPinValid(brain_pin_e brainPin)
pin_input_mode_e
expected< float > SensorResult
Definition sensor.h:46
SensorType
Definition sensor_type.h:18
@ DriverThrottleIntent