rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes
FuelLevelFunc Class Reference

#include <fuel_level_func.h>

Collaboration diagram for FuelLevelFunc:
Collaboration graph
[legend]

Public Member Functions

 FuelLevelFunc ()
 
SensorResult convert (float inputValue)
 

Private Member Functions

float getFuelLevelAlpha () const
 
float filterFuelValue (float value)
 
void updateFilteredValue (float value)
 

Private Attributes

std::optional< floatm_filteredValue
 
Timer m_fuelLevelTimer
 

Static Private Attributes

static constexpr float MIN_FUEL_LEVEL_UPDATE_PERIOD_SEC
 

Detailed Description

Definition at line 9 of file fuel_level_func.h.

Constructor & Destructor Documentation

◆ FuelLevelFunc()

FuelLevelFunc::FuelLevelFunc ( )
inline

Definition at line 11 of file fuel_level_func.h.

11 : m_filteredValue() {
12 }
std::optional< float > m_filteredValue

Member Function Documentation

◆ convert()

SensorResult FuelLevelFunc::convert ( float  inputValue)

Definition at line 15 of file fuel_level_func.cpp.

15 {
16 if (std::isnan(inputVoltage)) {
17 criticalError("temp error FuelLevelFunc NaN input");
18 m_filteredValue.reset();
19 return UnexpectedCode::Unknown;
20#if EFI_PROD_CODE && HW_HELLEN
21 } else if (isBoardWithPowerManagement() && !hellenEnPinStateChange.hasElapsedMs(200)) {
22 // todo: can we accomplish same reset by AdcSubscription::ResetFilters?
23 m_filteredValue.reset();
24 return UnexpectedCode::Unknown;
25#endif // HW_HELLEN
26 } else if (inputVoltage < engineConfiguration->fuelLevelLowThresholdVoltage) {
27 m_filteredValue.reset();
28 return UnexpectedCode::Low;
29 } else if (engineConfiguration->fuelLevelHighThresholdVoltage < inputVoltage) {
30 m_filteredValue.reset();
31 return UnexpectedCode::High;
32 } else {
33 const float filteredVoltage = filterFuelValue(inputVoltage);
34 const float fuelLevel = interpolate2d(filteredVoltage, config->fuelLevelBins, config->fuelLevelValues);
35 return fuelLevel;
36 }
37}
float filterFuelValue(float value)
static constexpr persistent_config_s * config
static constexpr engine_configuration_s * engineConfiguration
PUBLIC_API_WEAK bool isBoardWithPowerManagement()
Timer hellenEnPinStateChange
scaled_channel< uint16_t, 1000, 1 > fuelLevelBins[FUEL_LEVEL_TABLE_COUNT]
Here is the call graph for this function:

◆ filterFuelValue()

float FuelLevelFunc::filterFuelValue ( float  value)
private

Definition at line 44 of file fuel_level_func.cpp.

44 {
45 if (m_filteredValue.has_value()) {
46 if (m_fuelLevelTimer.hasElapsedSec(maxF(
49 ))) {
50 const float prevFilteredValue = m_filteredValue.value();
51 const float diff = inputVoltage - prevFilteredValue;
52 updateFilteredValue(prevFilteredValue + getFuelLevelAlpha() * diff);
53 }
54 } else {
55 updateFilteredValue(inputVoltage);
56 }
57static bool isFirst = true;
58 if (isFirst) {
59 isFirst = false;
60 efiPrintf("[temp] first %f", m_filteredValue.value());
61 }
62 return m_filteredValue.value();
63}
void updateFilteredValue(float value)
static constexpr float MIN_FUEL_LEVEL_UPDATE_PERIOD_SEC
float getFuelLevelAlpha() const

Referenced by convert().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getFuelLevelAlpha()

float FuelLevelFunc::getFuelLevelAlpha ( ) const
private

Definition at line 39 of file fuel_level_func.cpp.

Referenced by filterFuelValue().

Here is the caller graph for this function:

◆ updateFilteredValue()

void FuelLevelFunc::updateFilteredValue ( float  value)
private

Definition at line 65 of file fuel_level_func.cpp.

65 {
66 m_filteredValue = filteredVoltage;
67 m_fuelLevelTimer.reset();
68}

Referenced by filterFuelValue().

Here is the caller graph for this function:

Field Documentation

◆ m_filteredValue

std::optional<float> FuelLevelFunc::m_filteredValue
private

Definition at line 22 of file fuel_level_func.h.

Referenced by convert(), filterFuelValue(), and updateFilteredValue().

◆ m_fuelLevelTimer

Timer FuelLevelFunc::m_fuelLevelTimer
private

Definition at line 23 of file fuel_level_func.h.

Referenced by filterFuelValue(), and updateFilteredValue().

◆ MIN_FUEL_LEVEL_UPDATE_PERIOD_SEC

constexpr float FuelLevelFunc::MIN_FUEL_LEVEL_UPDATE_PERIOD_SEC
staticconstexprprivate

The documentation for this class was generated from the following files: