rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
Public Member Functions | Private Types | Private Attributes
HellaOilLevelSensor Class Reference

#include <hella_oil_level.h>

Inheritance diagram for HellaOilLevelSensor:
Inheritance graph
[legend]
Collaboration diagram for HellaOilLevelSensor:
Collaboration graph
[legend]

Public Member Functions

 HellaOilLevelSensor (SensorType type)
 
void init (brain_pin_e pin)
 
void deInit ()
 
void onEdge (efitick_t nowNt)
 
- Public Member Functions inherited from StoredValueSensor
SensorResult get () const final override
 
 StoredValueSensor (SensorType type, efidur_t timeoutNt)
 
void invalidate ()
 
void invalidate (UnexpectedCode why)
 
void setValidValue (float value, efitick_t timestamp)
 
void showInfo (const char *sensorName) const override
 
virtual void setTimeout (int timeoutMs)
 
- Public Member Functions inherited from Sensor
bool Register ()
 
const chargetSensorName () const
 
virtual bool hasSensor () const
 
virtual float getRaw () const
 
virtual bool isRedundant () const
 
void unregister ()
 
SensorType type () const
 

Private Types

enum class  NextPulse { None , Temp , Level , Diag }
 

Private Attributes

brain_pin_e m_pin = Gpio::Unassigned
 
Timer m_pulseTimer
 
Timer m_betweenPulseTimer
 
NextPulse m_nextPulse = NextPulse::None
 

Additional Inherited Members

- Static Public Member Functions inherited from Sensor
static void showAllSensorInfo ()
 
static void showInfo (SensorType type)
 
static void resetRegistry ()
 
static const SensorgetSensorOfType (SensorType type)
 
static SensorResult get (SensorType type)
 
static float getOrZero (SensorType type)
 
static float getRaw (SensorType type)
 
static bool isRedundant (SensorType type)
 
static bool hasSensor (SensorType type)
 
static void setMockValue (SensorType type, float value, bool mockRedundant=false)
 
static void setInvalidMockValue (SensorType type)
 
static void resetMockValue (SensorType type)
 
static void resetAllMocks ()
 
static void inhibitTimeouts (bool inhibit)
 
static const chargetSensorName (SensorType type)
 
- Protected Member Functions inherited from Sensor
 Sensor (SensorType type)
 
- Static Protected Attributes inherited from Sensor
static bool s_inhibitSensorTimeouts = false
 

Detailed Description

Definition at line 5 of file hella_oil_level.h.

Member Enumeration Documentation

◆ NextPulse

enum class HellaOilLevelSensor::NextPulse
strongprivate

Constructor & Destructor Documentation

◆ HellaOilLevelSensor()

HellaOilLevelSensor::HellaOilLevelSensor ( SensorType  type)
inline

Definition at line 7 of file hella_oil_level.h.

7: StoredValueSensor(type, MS2NT(2000)) {}
SensorType type() const
Definition sensor.h:162
Base class for sensors that compute a value on one thread, and want to make it available to consumers...

Member Function Documentation

◆ deInit()

void HellaOilLevelSensor::deInit ( )

Definition at line 30 of file hella_oil_level.cpp.

30 {
31 if (!isBrainPinValid(m_pin)) {
32 return;
33 }
34
35#if EFI_PROD_CODE
37#endif
38
40}
@ Unassigned
void efiExtiDisablePin(brain_pin_e brainPin)
bool isBrainPinValid(brain_pin_e brainPin)
Here is the call graph for this function:

◆ init()

void HellaOilLevelSensor::init ( brain_pin_e  pin)

Definition at line 13 of file hella_oil_level.cpp.

13 {
14 if (!isBrainPinValid(pin)) {
15 return;
16 }
17
18#if EFI_PROD_CODE
19 if (efiExtiEnablePin(getSensorName(), pin, PAL_EVENT_MODE_BOTH_EDGES,
20 hellaSensorExtiCallback, reinterpret_cast<void*>(this)) < 0) {
21 return;
22 }
23#endif // EFI_PROD_CODE
24
25 m_pin = pin;
26
27 Register();
28}
bool Register()
Definition sensor.cpp:131
const char * getSensorName() const
Definition sensor.h:130
int efiExtiEnablePin(const char *msg, brain_pin_e brainPin, uint32_t mode, ExtiCallback cb, void *cb_data)
static void hellaSensorExtiCallback(void *arg, efitick_t nowNt)
brain_pin_e pin
Definition stm32_adc.cpp:15
Here is the call graph for this function:

◆ onEdge()

void HellaOilLevelSensor::onEdge ( efitick_t  nowNt)

Definition at line 42 of file hella_oil_level.cpp.

42 {
43 if (efiReadPin(m_pin)) {
44 // Start pulse width timing at the rising edge
45 m_pulseTimer.reset(nowNt);
46
47 float timeBetweenPulses = m_betweenPulseTimer.getElapsedSecondsAndReset(nowNt);
48
49 if (timeBetweenPulses > 0.89 * 0.780 && timeBetweenPulses < 1.11 * 0.780) {
50 // 780ms nominal between Diag and next Temp pulse start, +-10%
51
52 // This was the "long gap" break, next pulse is temperature.
54 } else if (timeBetweenPulses > 0.89 * 0.110 && timeBetweenPulses < 1.11 * 0.110) {
55 // 110ms nominal between each pulse (other than break)
56
57 // Advance the state machine to decode the next pulse in the sequence
58 switch (m_nextPulse) {
59 case NextPulse::Temp:
61 break;
64 break;
65 default:
66 // We don't know how we got here, reset to safe state
68 break;
69 }
70 } else {
71 // The break was too long, ignore it for now.
73 }
74 } else {
75 // Stop timing at the falling edge
76 float lastPulseMs = 1000 * m_pulseTimer.getElapsedSeconds(nowNt);
77
78 if (lastPulseMs > 100 || lastPulseMs < 20) {
79 // Impossibly short or long pulse, something went wrong
81 return;
82 }
83
85 // TODO: decode diag pulse?
86 return;
87 } else if (m_nextPulse == NextPulse::Temp) {
88 // 22ms = Short circuit temp sensor
89 // 23ms = -40C
90 // 87ms = 160C
91 // 88ms = Temp sensor defective
92
93 if (lastPulseMs < 22.8) {
94 // Short circuit
95 // invalidate(UnexpectedCode::Low);
96 } else if (lastPulseMs > 87.2) {
97 // Defective
98 // invalidate(UnexpectedCode::High);
99 } else {
100 float tempC = interpolateClamped(23, -40, 87, 160, lastPulseMs);
101 // setValidValue(tempC, nowNt);
102 }
103 } else if (m_nextPulse == NextPulse::Level) {
104 // 22ms = Unreliable signal
105 // 23ms = level 0mm
106 // 87.86ms = level 150mm
107
108 if (lastPulseMs < 22.8f) {
109 // Unreliable
110 invalidate(UnexpectedCode::Low);
111 } else {
112 float levelMm = interpolateClamped(23, 0, 87.86, 150, lastPulseMs);
113 setValidValue(levelMm, nowNt);
114 }
115 }
116 }
117}
void setValidValue(float value, efitick_t timestamp)
float interpolateClamped(float x1, float y1, float x2, float y2, float x)
bool efiReadPin(brain_pin_e pin)
Definition io_pins.cpp:89
tempC("WBO: Temperature", SensorCategory.SENSOR_INPUTS, FieldType.INT16, 1936, 1.0, 500.0, 1000.0, "C")
Here is the call graph for this function:

Field Documentation

◆ m_betweenPulseTimer

Timer HellaOilLevelSensor::m_betweenPulseTimer
private

Definition at line 21 of file hella_oil_level.h.

Referenced by onEdge().

◆ m_nextPulse

NextPulse HellaOilLevelSensor::m_nextPulse = NextPulse::None
private

Definition at line 24 of file hella_oil_level.h.

Referenced by onEdge().

◆ m_pin

brain_pin_e HellaOilLevelSensor::m_pin = Gpio::Unassigned
private

Definition at line 15 of file hella_oil_level.h.

Referenced by deInit(), init(), and onEdge().

◆ m_pulseTimer

Timer HellaOilLevelSensor::m_pulseTimer
private

Definition at line 18 of file hella_oil_level.h.

Referenced by onEdge().


The documentation for this class was generated from the following files: