rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
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
7void ResistanceFunc::configure(float supplyVoltage, float pullupResistor, bool isPulldown) {
8 m_pullupResistor = pullupResistor;
9 m_supplyVoltage = supplyVoltage;
10 m_isPulldown = isPulldown;
11}
12
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}
void configure(float supplyVoltage, float pullupResistor, bool isPulldown)
SensorResult convert(float inputValue) const override
expected< float > SensorResult
Definition sensor.h:46