rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
controllers
sensors
converters
resistance_func.cpp
Go to the documentation of this file.
1
/**
2
* @author Matthew Kennedy, (c) 2019
3
*/
4
5
#include "
resistance_func.h
"
6
7
void
ResistanceFunc::configure
(
float
supplyVoltage,
float
pullupResistor,
bool
isPulldown) {
8
m_pullupResistor
= pullupResistor;
9
m_supplyVoltage
= supplyVoltage;
10
m_isPulldown
= isPulldown;
11
}
12
13
SensorResult
ResistanceFunc::convert
(
float
raw)
const
{
14
// If the voltage is very low, the sensor is a dead short.
15
if
(raw < 0.05f) {
16
return
UnexpectedCode::Low;
17
}
18
19
// If the voltage is very high (98% VCC), the sensor is open circuit.
20
if
(raw > (
m_supplyVoltage
* 0.98f)) {
21
return
UnexpectedCode::High;
22
}
23
24
if
(
m_isPulldown
) {
25
// If the sensor is on the high side (fixed resistor is pulldown),
26
// invert the voltage so the math comes out correctly
27
raw =
m_supplyVoltage
- raw;
28
}
29
30
// Voltage is in a sensible range - convert
31
float
resistance =
m_pullupResistor
/ (
m_supplyVoltage
/ raw - 1);
32
33
return
resistance;
34
}
ResistanceFunc::m_supplyVoltage
float m_supplyVoltage
Definition
resistance_func.h:22
ResistanceFunc::m_isPulldown
bool m_isPulldown
Definition
resistance_func.h:24
ResistanceFunc::configure
void configure(float supplyVoltage, float pullupResistor, bool isPulldown)
Definition
resistance_func.cpp:7
ResistanceFunc::m_pullupResistor
float m_pullupResistor
Definition
resistance_func.h:23
ResistanceFunc::convert
SensorResult convert(float inputValue) const override
Definition
resistance_func.cpp:13
resistance_func.h
SensorResult
expected< float > SensorResult
Definition
sensor.h:46
Generated on Sat Sep 27 2025 00:10:06 for rusEFI by
1.9.8