Line | Branch | Decision | Exec | Source |
---|---|---|---|---|
1 | #include "pch.h" | |||
2 | ||||
3 | #include "main_relay.h" | |||
4 | #include "ignition_controller.h" | |||
5 | ||||
6 | 1087 | void MainRelayController::onSlowCallback() { | ||
7 | 1087 | hasIgnitionVoltage = isIgnVoltage(); | ||
8 | ||||
9 |
2/2✓ Branch 0 taken 86 times.
✓ Branch 1 taken 1001 times.
|
2/2✓ Decision 'true' taken 86 times.
✓ Decision 'false' taken 1001 times.
|
1087 | if (hasIgnitionVoltage) { |
10 | 86 | m_lastIgnitionTime.reset(); | ||
11 | } | |||
12 | ||||
13 | #if EFI_MAIN_RELAY_CONTROL | |||
14 |
2/2✓ Branch 0 taken 86 times.
✓ Branch 1 taken 1001 times.
|
2/2✓ Decision 'true' taken 86 times.
✓ Decision 'false' taken 1001 times.
|
1087 | if (hasIgnitionVoltage) { |
15 | 86 | delayedShutoffRequested = false; | ||
16 | } else { | |||
17 | // Query whether any engine modules want to keep the lights on | |||
18 | 31031 | delayedShutoffRequested = engine->engineModules.aggregate([](auto& m, bool prev) { return m.needsDelayedShutoff() | prev; }, false); | ||
19 | } | |||
20 | // TODO: delayed shutoff timeout? | |||
21 | ||||
22 | mainRelayState = hasIgnitionVoltage | delayedShutoffRequested; | |||
23 | #else // not EFI_MAIN_RELAY_CONTROL | |||
24 | mainRelayState = true; | |||
25 | #endif | |||
26 | ||||
27 | enginePins.mainRelay.setValue("mr", mainRelayState); | |||
28 | } | |||
29 | ||||
30 | 1001 | bool MainRelayController::needsDelayedShutoff() { | ||
31 | // Prevent main relay from turning off if we had ignition voltage in the past 1 second | |||
32 | // This avoids accidentally killing the car during a transient, for example | |||
33 | // right when the starter is engaged. | |||
34 | 1001 | return !m_lastIgnitionTime.hasElapsedSec(1); | ||
35 | } | |||
36 |