only: extracting isIgnVoltage() method

This commit is contained in:
rusefillc 2024-04-13 12:09:48 -04:00
parent f881b178a5
commit 21e22cb7da
3 changed files with 13 additions and 3 deletions

View File

@ -1,12 +1,13 @@
#include "pch.h"
#include "main_relay.h"
#include "ignition_controller.h"
void MainRelayController::onSlowCallback() {
#if EFI_MAIN_RELAY_CONTROL
#if defined(IGN_KEY_DIVIDER)
if (isAdcChannelValid(engineConfiguration->ignKeyAdcChannel)) {
hasIgnitionVoltage = Sensor::getOrZero(SensorType::IgnKeyVoltage) > 5;
hasIgnitionVoltage = isIgnVoltage();
} else
#endif // IGN_KEY_DIVIDER
if (engineConfiguration->ignitionKeyDigitalPin != Gpio::Unassigned) {

View File

@ -1,9 +1,13 @@
#include "pch.h"
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)
auto hasIgnVoltage = Sensor::getOrZero(SensorType::BatteryVoltage) > 5;
auto hasIgnVoltage = isIgnVoltage();
if (hasIgnVoltage) {
m_timeSinceIgnVoltage.reset();
@ -15,7 +19,7 @@ void IgnitionController::onSlowCallback() {
}
// Ignore low voltage transients - we may see this at the start of cranking
// and we don't want to
// and we don't want to
if (!hasIgnVoltage && !m_timeSinceIgnVoltage.hasElapsedSec(0.2f)) {
return;
}

View File

@ -1,3 +1,5 @@
// file ignition_controller.h
#pragma once
#include "engine_module.h"
@ -12,3 +14,6 @@ private:
Timer m_timeSinceIgnVoltage;
bool m_lastState = false;
};
// USB power or vehicle power?
bool isIgnVoltage();