rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
Public Member Functions | Private Attributes
LinearFunc Class Referencefinal

#include <linear_func.h>

Inheritance diagram for LinearFunc:
Inheritance graph
[legend]
Collaboration diagram for LinearFunc:
Collaboration graph
[legend]

Public Member Functions

 LinearFunc (float divideInput=1.0f)
 
void configure (float in1, float out1, float in2, float out2, float minOutput, float maxOutput)
 
SensorResult convert (float inputValue) const override
 
void showInfo (float testRawValue) const override
 
float getDivideInput () const
 
- Public Member Functions inherited from SensorConverter
 SensorConverter (const SensorConverter &)=delete
 
 SensorConverter ()=default
 

Private Attributes

float m_a = 1
 
float m_b = 0
 
float m_minOutput = 0
 
float m_maxOutput = 0
 
const float m_divideInput
 

Detailed Description

Definition at line 5 of file linear_func.h.

Constructor & Destructor Documentation

◆ LinearFunc()

LinearFunc::LinearFunc ( float  divideInput = 1.0f)
inline

Definition at line 7 of file linear_func.h.

7: m_divideInput(divideInput) {}
const float m_divideInput
Definition linear_func.h:29

Member Function Documentation

◆ configure()

void LinearFunc::configure ( float  in1,
float  out1,
float  in2,
float  out2,
float  minOutput,
float  maxOutput 
)

Definition at line 5 of file linear_func.cpp.

5 {
6 m_minOutput = minOutput;
7 m_maxOutput = maxOutput;
8
9 in1 = in1 / m_divideInput;
10 in2 = in2 / m_divideInput;
11
12 m_a = INTERPOLATION_A(in1, out1, in2, out2);
13 m_b = out1 - m_a * in1;
14}
float m_minOutput
Definition linear_func.h:25
float m_maxOutput
Definition linear_func.h:26

Referenced by initFluidPressure(), initSentLinearSensor(), and initVbatt().

Here is the caller graph for this function:

◆ convert()

SensorResult LinearFunc::convert ( float  inputValue) const
overridevirtual

Implements SensorConverter.

Definition at line 16 of file linear_func.cpp.

16 {
17 float result = m_a * inputValue + m_b;
18
19 // Bounds checks
20 // Flipped error codes in case of m_a < 0 so that they indicate whether the input
21 // voltage is high/low, instead of the output high/low
22 if (result > m_maxOutput) {
23 return m_a > 0 ? UnexpectedCode::High : UnexpectedCode::Low;
24 }
25
26 if (result < m_minOutput) {
27 return m_a > 0 ? UnexpectedCode::Low : UnexpectedCode::High;
28 }
29
30 return result;
31}

Referenced by showInfo().

Here is the caller graph for this function:

◆ getDivideInput()

float LinearFunc::getDivideInput ( ) const
inline

Definition at line 15 of file linear_func.h.

15 {
16 return m_divideInput;
17 }

◆ showInfo()

void LinearFunc::showInfo ( float  testRawValue) const
overridevirtual

Reimplemented from SensorConverter.

Definition at line 87 of file sensor_info_printing.cpp.

87 {
88 efiPrintf(" Linear function slope: %.2f offset: %.2f min: %.1f max: %.1f", m_a, m_b, m_minOutput, m_maxOutput);
89 const auto value = convert(testRawValue);
90 efiPrintf(" raw value %.2f converts to %.2f valid: %s", testRawValue, value.Value, boolToString(value.Valid));
91}
SensorResult convert(float inputValue) const override
const char * boolToString(bool value)
Definition efilib.cpp:19
Here is the call graph for this function:

Field Documentation

◆ m_a

float LinearFunc::m_a = 1
private

Definition at line 22 of file linear_func.h.

Referenced by configure(), convert(), and showInfo().

◆ m_b

float LinearFunc::m_b = 0
private

Definition at line 23 of file linear_func.h.

Referenced by configure(), convert(), and showInfo().

◆ m_divideInput

const float LinearFunc::m_divideInput
private

Definition at line 29 of file linear_func.h.

Referenced by configure(), and getDivideInput().

◆ m_maxOutput

float LinearFunc::m_maxOutput = 0
private

Definition at line 26 of file linear_func.h.

Referenced by configure(), convert(), and showInfo().

◆ m_minOutput

float LinearFunc::m_minOutput = 0
private

Definition at line 25 of file linear_func.h.

Referenced by configure(), convert(), and showInfo().


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