rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
linear_func.cpp
Go to the documentation of this file.
1#include "pch.h"
2
3#include "linear_func.h"
4
5void LinearFunc::configure(float in1, float out1, float in2, float out2, float minOutput, float maxOutput) {
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}
15
16SensorResult LinearFunc::convert(float inputValue) const {
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}
SensorResult convert(float inputValue) const override
float m_minOutput
Definition linear_func.h:25
const float m_divideInput
Definition linear_func.h:29
void configure(float in1, float out1, float in2, float out2, float minOutput, float maxOutput)
float m_maxOutput
Definition linear_func.h:26
expected< float > SensorResult
Definition sensor.h:46