GCC Code Coverage Report


Directory: ./
File: firmware/controllers/sensors/flex_sensor.h
Date: 2025-10-03 00:57:22
Coverage Exec Excl Total
Lines: 87.5% 14 0 16
Functions: 100.0% 3 0 3
Branches: 60.0% 3 0 5
Decisions: 50.0% 2 - 4

Line Branch Decision Exec Source
1 /**
2 * @file flex_sensor.h
3 */
4 #include "sensor_type.h"
5 #include "functional_sensor.h"
6 #include "sensor_converter_func.h"
7 #include "biquad.h"
8 #include <rusefi/timer.h>
9
10 class FlexConverter : public SensorConverter {
11 public:
12 4 FlexConverter() {
13 // Update rate is 50-150hz, so this actually filters at 0.5-1.5hz -3db depending on E%, which is ok
14 4 m_filter.configureLowpass(100, 1);
15 4 }
16
17 999 SensorResult convert(float frequency) const override {
18 // Sensor should only report 50-150hz, significantly outside that range indicates a problem
19 // it changes to 200hz+ to indicate methanol "contamination"
20
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 999 times.
1/2
✗ Decision 'true' not taken.
✓ Decision 'false' taken 999 times.
999 if (frequency < 45) {
21 return UnexpectedCode::Low;
22 }
23
24
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 999 times.
1/2
✗ Decision 'true' not taken.
✓ Decision 'false' taken 999 times.
999 if (frequency > 155) {
25 return UnexpectedCode::High;
26 }
27
28 999 float flexPct = clampF(0, frequency - 50, 100);
29
30
1/1
✓ Branch 2 taken 999 times.
999 return m_filter.filter(flexPct);
31 }
32
33 private:
34 mutable Biquad m_filter;
35 };
36
37 class FlexSensor {
38 public:
39 4 FlexSensor(efidur_t timeoutPeriod)
40 4 : flexSensor(SensorType::FuelEthanolPercent, timeoutPeriod)
41 4 , flexFuelTemp(SensorType::FuelTemperature, timeoutPeriod)
42 {
43 // 0.01 means filter bandwidth of ~1hz with ~100hz sensor
44 4 flexTempFilter.configureLowpass(1, 0.01f);
45 4 flexSensor.setFunction(converter);
46 4 }
47 void Register(bool withTempSensor);
48 void unregister();
49 void callback(efitick_t nowNt, bool value);
50 void debug();
51
52 private:
53 FunctionalSensor flexSensor;
54 StoredValueSensor flexFuelTemp;
55 FlexConverter converter;
56
57 Biquad flexTempFilter;
58
59 Timer flexFreq, flexPulse;
60
61 bool gotRising = false;
62
63 int lowFlexCallbackCounter = 0;
64 int flexCallbackCounter = 0;
65
66 float frequency;
67 float pulseWidthUs;
68 efitick_t latestCallbackTime;
69 };
70