GCC Code Coverage Report


Directory: ./
File: firmware/controllers/sensors/converters/resistance_func.cpp
Date: 2025-10-03 00:57:22
Coverage Exec Excl Total
Lines: 100.0% 14 0 14
Functions: 100.0% 2 0 2
Branches: 100.0% 6 0 6
Decisions: 100.0% 6 - 6

Line Branch Decision Exec Source
1 /**
2 * @author Matthew Kennedy, (c) 2019
3 */
4
5 #include "resistance_func.h"
6
7 7 void ResistanceFunc::configure(float supplyVoltage, float pullupResistor, bool isPulldown) {
8 7 m_pullupResistor = pullupResistor;
9 7 m_supplyVoltage = supplyVoltage;
10 7 m_isPulldown = isPulldown;
11 7 }
12
13 18 SensorResult ResistanceFunc::convert(float raw) const {
14 // If the voltage is very low, the sensor is a dead short.
15
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 16 times.
2/2
✓ Decision 'true' taken 2 times.
✓ Decision 'false' taken 16 times.
18 if (raw < 0.05f) {
16 2 return UnexpectedCode::Low;
17 }
18
19 // If the voltage is very high (98% VCC), the sensor is open circuit.
20
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 14 times.
2/2
✓ Decision 'true' taken 2 times.
✓ Decision 'false' taken 14 times.
16 if (raw > (m_supplyVoltage * 0.98f)) {
21 2 return UnexpectedCode::High;
22 }
23
24
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 10 times.
2/2
✓ Decision 'true' taken 4 times.
✓ Decision 'false' taken 10 times.
14 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 4 raw = m_supplyVoltage - raw;
28 }
29
30 // Voltage is in a sensible range - convert
31 14 float resistance = m_pullupResistor / (m_supplyVoltage / raw - 1);
32
33 14 return resistance;
34 }
35