Line | Branch | Decision | Exec | Source |
---|---|---|---|---|
1 | /** | |||
2 | * @file flex_sensor.cpp | |||
3 | */ | |||
4 | ||||
5 | #include "pch.h" | |||
6 | #include "flex_sensor.h" | |||
7 | ||||
8 | 2002 | void FlexSensor::callback(efitick_t nowNt, bool value) { | ||
9 | 2002 | latestCallbackTime = nowNt; | ||
10 | 2002 | flexCallbackCounter++; | ||
11 |
2/2✓ Branch 0 taken 1001 times.
✓ Branch 1 taken 1001 times.
|
2/2✓ Decision 'true' taken 1001 times.
✓ Decision 'false' taken 1001 times.
|
2002 | if (value) { |
12 |
2/2✓ Branch 0 taken 999 times.
✓ Branch 1 taken 2 times.
|
2/2✓ Decision 'true' taken 999 times.
✓ Decision 'false' taken 2 times.
|
1001 | if (gotRising) { |
13 | 999 | frequency = 1 / flexFreq.getElapsedSecondsAndReset(nowNt); | ||
14 | 999 | flexSensor.postRawValue(frequency, nowNt); | ||
15 | } else { | |||
16 | 2 | flexFreq.reset(nowNt); | ||
17 | } | |||
18 | ||||
19 | // Start timing pulse width on rising edge | |||
20 | 1001 | flexPulse.reset(nowNt); | ||
21 | // got rising edge | |||
22 | 1001 | gotRising = true; | ||
23 | } else { | |||
24 | 1001 | lowFlexCallbackCounter++; | ||
25 |
2/2✓ Branch 0 taken 1000 times.
✓ Branch 1 taken 1 time.
|
2/2✓ Decision 'true' taken 1000 times.
✓ Decision 'false' taken 1 time.
|
1001 | if (gotRising) { |
26 | // End pulse timing on falling edge | |||
27 | 1000 | pulseWidthUs = flexPulse.getElapsedUs(nowNt); | ||
28 | ||||
29 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1000 times.
|
1/2✗ Decision 'true' not taken.
✓ Decision 'false' taken 1000 times.
|
1000 | if (pulseWidthUs < 900) { |
30 | ✗ | flexFuelTemp.invalidate(UnexpectedCode::Low); | ||
31 | ✗ | warning(ObdCode::CUSTOM_FLEX_LOW, "flex low %f", pulseWidthUs); | ||
32 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1000 times.
|
1/2✗ Decision 'true' not taken.
✓ Decision 'false' taken 1000 times.
|
1000 | } else if (pulseWidthUs > 5100) { |
33 | ✗ | flexFuelTemp.invalidate(UnexpectedCode::High); | ||
34 | ✗ | warning(ObdCode::CUSTOM_FLEX_HIGH, "flex high %f", pulseWidthUs); | ||
35 | } else { | |||
36 | // -40C = 1000us | |||
37 | // 125C = 5000us | |||
38 | 1000 | float tempC = interpolateClamped(1000, -40, 5000, 125, pulseWidthUs); | ||
39 | 1000 | tempC = flexTempFilter.filter(tempC); | ||
40 | 1000 | flexFuelTemp.setValidValue(tempC, nowNt); | ||
41 | } | |||
42 | } | |||
43 | } | |||
44 | #if EFI_PROD_CODE | |||
45 | // TODO: confusing output channel name! | |||
46 | engine->outputChannels.rawFlexFreq = flexCallbackCounter; | |||
47 | #endif // EFI_PROD_CODE | |||
48 | 2002 | } | ||
49 | ||||
50 | ✗ | void FlexSensor::debug() { | ||
51 | ✗ | efiPrintf("flex counter %d", flexCallbackCounter); | ||
52 | ✗ | efiPrintf("lowFlexCallbackCounter counter %d", lowFlexCallbackCounter); | ||
53 | ✗ | efiPrintf("flex freq %f", frequency); | ||
54 | ✗ | efiPrintf("pulseWidthUs %f", pulseWidthUs); | ||
55 | ✗ | efiPrintf("latestCallbackTime %lld", latestCallbackTime); | ||
56 | ✗ | } | ||
57 | ||||
58 | 5 | void FlexSensor::Register(bool withTempSensor) { | ||
59 | 5 | flexSensor.Register(); | ||
60 | ||||
61 |
1/2✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
|
1/2✓ Decision 'true' taken 5 times.
✗ Decision 'false' not taken.
|
5 | if (withTempSensor) { |
62 | 5 | flexFuelTemp.Register(); | ||
63 | } | |||
64 | 5 | } | ||
65 | ||||
66 | ✗ | void FlexSensor::unregister() { | ||
67 | ✗ | flexSensor.unregister(); | ||
68 | ✗ | flexFuelTemp.unregister(); | ||
69 | ✗ | } | ||
70 |