rusefi/firmware/controllers/ignition_controller.cpp

31 lines
813 B
C++
Raw Normal View History

#include "pch.h"
2024-04-13 09:09:48 -07:00
bool isIgnVoltage() {
return Sensor::getOrZero(SensorType::BatteryVoltage) > 5;
}
void IgnitionController::onSlowCallback() {
// default to 0 if failed sensor to prevent accidental ign-on if battery
// input misconfigured (or the ADC hasn't started yet)
2024-04-13 09:09:48 -07:00
auto hasIgnVoltage = isIgnVoltage();
if (hasIgnVoltage) {
m_timeSinceIgnVoltage.reset();
}
if (hasIgnVoltage == m_lastState) {
// nothing to do, states match
return;
}
// Ignore low voltage transients - we may see this at the start of cranking
2024-04-13 09:09:48 -07:00
// and we don't want to
2024-11-08 12:31:27 -08:00
if (!hasIgnVoltage && secondsSinceIgnVoltage() < 0.2f) {
return;
}
// Store state and notify other modules of the change
m_lastState = hasIgnVoltage;
engine->engineModules.apply_all([&](auto& m) { m.onIgnitionStateChanged(hasIgnVoltage); });
}