Line | Branch | Decision | Exec | Source |
---|---|---|---|---|
1 | /** | |||
2 | * @file init_sensorss.cpp | |||
3 | */ | |||
4 | ||||
5 | #include "pch.h" | |||
6 | ||||
7 | #include "init.h" | |||
8 | #include "cli_registry.h" | |||
9 | #include "io_pins.h" | |||
10 | #include "lua_hooks.h" | |||
11 | ||||
12 | static void initSensorCli(); | |||
13 | ||||
14 | 4 | void initIfValid(const char* msg, adc_channel_e channel) { | ||
15 |
1/2✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
|
1/2✓ Decision 'true' taken 4 times.
✗ Decision 'false' not taken.
|
4 | if (!isAdcChannelValid(channel)) { |
16 | 4 | return; | ||
17 | } | |||
18 | ||||
19 | #if EFI_PROD_CODE && HAL_USE_ADC | |||
20 | /** | |||
21 | TODO: this code is similar to AdcSubscription::SubscribeSensor, what is the plan? shall we extract helper method or else? | |||
22 | */ | |||
23 | ||||
24 | brain_pin_e pin = getAdcChannelBrainPin(msg, channel); | |||
25 | if (pin == Gpio::Invalid) { | |||
26 | // todo: external muxes for internal ADC #3350 | |||
27 | return; | |||
28 | } | |||
29 | efiSetPadMode(msg, pin, PAL_MODE_INPUT_ANALOG); | |||
30 | #endif // EFI_PROD_CODE && HAL_USE_ADC | |||
31 | } | |||
32 | ||||
33 | ✗ | void deInitIfValid(const char* msg, adc_channel_e channel) { | ||
34 | ✗ | if (!isAdcChannelValid(channel)) { | ||
35 | ✗ | return; | ||
36 | } | |||
37 | ||||
38 | #if EFI_PROD_CODE && HAL_USE_ADC | |||
39 | brain_pin_e pin = getAdcChannelBrainPin(msg, channel); | |||
40 | efiSetPadUnused(pin); | |||
41 | #endif // EFI_PROD_CODE && HAL_USE_ADC | |||
42 | } | |||
43 | ||||
44 | 2 | static void initOldAnalogInputs() { | ||
45 |
2/6✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
|
1/2✗ Decision 'true' not taken.
✓ Decision 'false' taken 2 times.
|
2 | if (isAdcChannelValid(engineConfiguration->afr.hwChannel) && engineConfiguration->enableAemXSeries) { |
46 | ✗ | criticalError("Please pick either analog AFR or CAN AFR input not both."); | ||
47 | } | |||
48 | 2 | initIfValid("AFR", engineConfiguration->afr.hwChannel); | ||
49 | 2 | initIfValid("AUXF#1", engineConfiguration->auxFastSensor1_adcChannel); | ||
50 | 2 | } | ||
51 | ||||
52 | ✗ | static void deInitOldAnalogInputs() { | ||
53 | ✗ | deInitIfValid("AFR", activeConfiguration.afr.hwChannel); | ||
54 | ✗ | deInitIfValid("AUXF#1", activeConfiguration.auxFastSensor1_adcChannel); | ||
55 | ✗ | } | ||
56 | ||||
57 | 2 | static void initAuxDigital() { | ||
58 | #if EFI_PROD_CODE | |||
59 | for (size_t i = 0;i<efi::size(engineConfiguration->luaDigitalInputPins);i++) { | |||
60 | efiSetPadMode("Lua Digital", engineConfiguration->luaDigitalInputPins[i], engineConfiguration->luaDigitalInputPinModes[i]); | |||
61 | } | |||
62 | #endif // EFI_PROD_CODE | |||
63 | 2 | } | ||
64 | ||||
65 | 1117 | void pokeAuxDigital() { | ||
66 | #if EFI_PROD_CODE | |||
67 | for (size_t i = 0;i<efi::size(engineConfiguration->luaDigitalInputPins);i++) { | |||
68 | engine->luaDigitalInputState[i].state.update(getAuxDigital(i)); | |||
69 | } | |||
70 | #endif // EFI_PROD_CODE | |||
71 | 1117 | } | ||
72 | ||||
73 | ✗ | static void deInitAuxDigital() { | ||
74 | ✗ | for (size_t i = 0;i<efi::size(activeConfiguration.luaDigitalInputPins);i++) { | ||
75 | ✗ | brain_pin_markUnused(activeConfiguration.luaDigitalInputPins[i]); | ||
76 | } | |||
77 | ✗ | } | ||
78 | ||||
79 | static LuaOverrideSensor overrideRpm(SensorType::DashOverrideRpm, SensorType::Rpm); | |||
80 | static LuaOverrideSensor overrideVehicleSpeed(SensorType::DashOverrideVehicleSpeed, SensorType::VehicleSpeed); | |||
81 | static LuaOverrideSensor overrideClt(SensorType::DashOverrideClt, SensorType::Clt); | |||
82 | static LuaOverrideSensor overrideBatteryVoltage(SensorType::DashOverrideBatteryVoltage, SensorType::BatteryVoltage); | |||
83 | ||||
84 | 4 | void initOverrideSensors() { | ||
85 | 4 | overrideRpm.Register(); | ||
86 | 4 | overrideVehicleSpeed.Register(); | ||
87 | 4 | overrideClt.Register(); | ||
88 | 4 | overrideBatteryVoltage.Register(); | ||
89 | 4 | } | ||
90 | ||||
91 | // todo: closer alignment with 'stopSensors' | |||
92 | 3 | static void sensorStartUpOrReconfiguration(bool isFirstTime) { | ||
93 | 3 | initVbatt(); | ||
94 | 3 | initMap(); | ||
95 | 3 | initTps(); | ||
96 | 3 | initFluidPressure(); | ||
97 | 3 | initThermistors(); | ||
98 | 2 | initVehicleSpeedSensor(); | ||
99 | 2 | initTurbochargerSpeedSensor(); | ||
100 | 2 | initAuxSensors(); | ||
101 | 2 | initAuxSpeedSensors(); | ||
102 | 2 | initInputShaftSpeedSensor(); | ||
103 | #if EFI_TCU | |||
104 | initRangeSensors(); | |||
105 | #endif | |||
106 | 2 | initFlexSensor(isFirstTime); | ||
107 | 2 | } | ||
108 | ||||
109 | ||||
110 | // one-time start-up | |||
111 | // see also 'reconfigureSensors' | |||
112 | 3 | void initNewSensors() { | ||
113 | #if EFI_PROD_CODE && EFI_CAN_SUPPORT | |||
114 | initCanSensors(); | |||
115 | #endif | |||
116 | ||||
117 | 3 | initOverrideSensors(); | ||
118 | ||||
119 | 3 | sensorStartUpOrReconfiguration(true); | ||
120 | // todo: | |||
121 | 2 | initLambda(); | ||
122 | // todo: 'isFirstTime' approach for initEgt vs startEgt | |||
123 | 2 | initEgt(); | ||
124 | 2 | initBaro(); | ||
125 | ||||
126 | 2 | initFuelLevel(); | ||
127 | 2 | initMaf(); | ||
128 | ||||
129 | 2 | initOldAnalogInputs(); | ||
130 | 2 | initAuxDigital(); | ||
131 | ||||
132 | // Init CLI functionality for sensors (mocking) | |||
133 | 2 | initSensorCli(); | ||
134 | ||||
135 | #if defined(HARDWARE_CI) && !defined(HW_PROTEUS) | |||
136 | chThdSleepMilliseconds(100); | |||
137 | ||||
138 | if (Sensor::getOrZero(SensorType::BatteryVoltage) < 8) { | |||
139 | // Fake that we have battery voltage, some tests rely on it | |||
140 | Sensor::setMockValue(SensorType::BatteryVoltage, 10); | |||
141 | } | |||
142 | #endif | |||
143 | ||||
144 | #if EFI_SIMULATOR | |||
145 | // Simulator gets battery voltage so it detects ignition-on | |||
146 | Sensor::setMockValue(SensorType::BatteryVoltage, 14); | |||
147 | #endif // EFI_SIMULATOR | |||
148 | 2 | } | ||
149 | ||||
150 | ✗ | void stopSensors() { | ||
151 | ✗ | deInitAuxDigital(); | ||
152 | ✗ | deInitOldAnalogInputs(); | ||
153 | ||||
154 | ✗ | deinitVbatt(); | ||
155 | ✗ | deinitTps(); | ||
156 | ✗ | deinitFluidPressure(); | ||
157 | ✗ | deinitThermistors(); | ||
158 | ✗ | deInitFlexSensor(); | ||
159 | ✗ | deinitAuxSensors(); | ||
160 | ✗ | deInitVehicleSpeedSensor(); | ||
161 | ✗ | deinitTurbochargerSpeedSensor(); | ||
162 | ✗ | deinitAuxSpeedSensors(); | ||
163 | ✗ | deinitMap(); | ||
164 | ✗ | deinitInputShaftSpeedSensor(); | ||
165 | ✗ | stopEgt(); | ||
166 | ✗ | } | ||
167 | ||||
168 | ✗ | void reconfigureSensors() { | ||
169 | ✗ | sensorStartUpOrReconfiguration(false); | ||
170 | ✗ | startEgt(); | ||
171 | ||||
172 | ✗ | initOldAnalogInputs(); | ||
173 | ✗ | } | ||
174 | ||||
175 | // Mocking/testing helpers | |||
176 | 2 | static void initSensorCli() { | ||
177 | using namespace rusefi::stringutil; | |||
178 | ||||
179 |
1/1✓ Branch 3 taken 2 times.
|
2 | addConsoleActionSS("set_sensor_mock", [](const char* typeName, const char* valueStr) { | |
180 | ✗ | SensorType type = findSensorTypeByName(typeName); | ||
181 | ||||
182 | ✗ | if (type == SensorType::Invalid) { | ||
183 | ✗ | efiPrintf("Invalid sensor type specified: %s", typeName); | ||
184 | ✗ | return; | ||
185 | } | |||
186 | ||||
187 | ✗ | float value = atoff(valueStr); | ||
188 | ||||
189 | ✗ | Sensor::setMockValue(type, value); | ||
190 | }); | |||
191 | ||||
192 | 2 | addConsoleAction("reset_sensor_mocks", Sensor::resetAllMocks); | ||
193 | 2 | addConsoleAction("show_sensors", Sensor::showAllSensorInfo); | ||
194 |
1/1✓ Branch 3 taken 2 times.
|
2 | addConsoleActionI("show_sensor", | |
195 | 2 | [](int idx) { | ||
196 | ✗ | Sensor::showInfo(static_cast<SensorType>(idx)); | ||
197 | ✗ | }); | ||
198 | 2 | } | ||
199 |