random getOrZero clean-up

This commit is contained in:
rusefillc 2022-12-14 19:48:07 -05:00
parent 1e04153867
commit 484f21aeba
5 changed files with 5 additions and 5 deletions

View File

@ -436,7 +436,7 @@ todo: move to shutdown_controller.cpp
const float vBattThresholdOn = 8.0f;
// we fallback into zero instead of VBAT_FALLBACK_VALUE because it's not safe to false-trigger the "ignition on" event,
// and we want to turn on the main relay only when 100% sure.
if ((Sensor::get(SensorType::BatteryVoltage).value_or(0) > vBattThresholdOn) && !isInShutdownMode()) {
if ((Sensor::getOrZero(SensorType::BatteryVoltage) > vBattThresholdOn) && !isInShutdownMode()) {
ignitionOnTimeNt = getTimeNowNt();
efiPrintf("Ignition voltage detected!");
if (stopEngineRequestTimeNt != 0) {

View File

@ -84,7 +84,7 @@ float HpfpQuantity::calcPI(int rpm, float calc_fuel_percent) {
m_pressureTarget_kPa - (engineConfiguration->hpfpTargetDecay *
(FAST_CALLBACK_PERIOD_MS / 1000.)),
interpolate3d(engineConfiguration->hpfpTarget,
engineConfiguration->hpfpTargetLoadBins, Sensor::get(SensorType::Map).value_or(0), // TODO: allow other load axis, like we claim to
engineConfiguration->hpfpTargetLoadBins, Sensor::getOrZero(SensorType::Map), // TODO: allow other load axis, like we claim to
engineConfiguration->hpfpTargetRpmBins, rpm));
auto fuelPressure = Sensor::get(SensorType::FuelPressureHigh);

View File

@ -3,7 +3,7 @@
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::get(SensorType::BatteryVoltage).value_or(0) > 5;
auto hasIgnVoltage = Sensor::getOrZero(SensorType::BatteryVoltage) > 5;
if (hasIgnVoltage) {
m_timeSinceIgnVoltage.reset();

View File

@ -53,7 +53,7 @@ void LimpManager::updateState(int rpm, efitick_t nowNt) {
// User-configured hard RPM limit, either constant or CLT-lookup
// todo: migrate to engineState->desiredRpmLimit to get this variable logged
float revLimit = engineConfiguration->useCltBasedRpmLimit
? interpolate2d(Sensor::get(SensorType::Clt).value_or(0), engineConfiguration->cltRevLimitRpmBins, engineConfiguration->cltRevLimitRpm)
? interpolate2d(Sensor::getOrZero(SensorType::Clt), engineConfiguration->cltRevLimitRpmBins, engineConfiguration->cltRevLimitRpm)
: (float)engineConfiguration->rpmHardLimit;
// Require 50 rpm drop before resuming

View File

@ -82,7 +82,7 @@ bool shouldUpdateCorrection(SensorType sensor) {
// Pause (but don't reset) correction if the AFR is off scale.
// It's probably a transient and poorly tuned transient correction
auto afr = Sensor::get(sensor).value_or(0) * STOICH_RATIO;
auto afr = Sensor::getOrZero(sensor) * STOICH_RATIO;
if (!afr || afr < cfg.minAfr || afr > cfg.maxAfr) {
return false;
}