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

#include <flex_sensor.h>

Collaboration diagram for FlexSensor:
Collaboration graph
[legend]

Public Member Functions

 FlexSensor (efidur_t timeoutPeriod)
 
void Register (bool withTempSensor)
 
void unregister ()
 
void callback (efitick_t nowNt, bool value)
 
void debug ()
 

Private Attributes

FunctionalSensor flexSensor
 
StoredValueSensor flexFuelTemp
 
FlexConverter converter
 
Biquad flexTempFilter
 
Timer flexFreq
 
Timer flexPulse
 
bool gotRising = false
 
int lowFlexCallbackCounter = 0
 
int flexCallbackCounter = 0
 
float frequency
 
float pulseWidthUs
 
efitick_t latestCallbackTime
 

Detailed Description

Definition at line 37 of file flex_sensor.h.

Constructor & Destructor Documentation

◆ FlexSensor()

FlexSensor::FlexSensor ( efidur_t  timeoutPeriod)
inline

Definition at line 39 of file flex_sensor.h.

42 {
43 // 0.01 means filter bandwidth of ~1hz with ~100hz sensor
46 }
void configureLowpass(float samplingFrequency, float cutoffFrequency, float Q=0.54f)
Definition biquad.cpp:48
FlexConverter converter
Definition flex_sensor.h:55
FunctionalSensor flexSensor
Definition flex_sensor.h:53
StoredValueSensor flexFuelTemp
Definition flex_sensor.h:54
Biquad flexTempFilter
Definition flex_sensor.h:57
void setFunction(ConverterType &func)
@ FuelEthanolPercent
Here is the call graph for this function:

Member Function Documentation

◆ callback()

void FlexSensor::callback ( efitick_t  nowNt,
bool  value 
)

Definition at line 8 of file flex_sensor.cpp.

8 {
9 latestCallbackTime = nowNt;
11 if (value) {
12 if (gotRising) {
13 frequency = 1 / flexFreq.getElapsedSecondsAndReset(nowNt);
15 } else {
16 flexFreq.reset(nowNt);
17 }
18
19 // Start timing pulse width on rising edge
20 flexPulse.reset(nowNt);
21 // got rising edge
22 gotRising = true;
23 } else {
25 if (gotRising) {
26 // End pulse timing on falling edge
27 pulseWidthUs = flexPulse.getElapsedUs(nowNt);
28
29 if (pulseWidthUs < 900) {
30 flexFuelTemp.invalidate(UnexpectedCode::Low);
32 } else if (pulseWidthUs > 5100) {
33 flexFuelTemp.invalidate(UnexpectedCode::High);
35 } else {
36 // -40C = 1000us
37 // 125C = 5000us
38 float tempC = interpolateClamped(1000, -40, 5000, 125, pulseWidthUs);
41 }
42 }
43 }
44#if EFI_PROD_CODE
45 // TODO: confusing output channel name!
47#endif // EFI_PROD_CODE
48}
float filter(float input)
Definition biquad.cpp:74
TunerStudioOutputChannels outputChannels
Definition engine.h:109
float frequency
Definition flex_sensor.h:66
Timer flexFreq
Definition flex_sensor.h:59
Timer flexPulse
Definition flex_sensor.h:59
int lowFlexCallbackCounter
Definition flex_sensor.h:63
bool gotRising
Definition flex_sensor.h:61
efitick_t latestCallbackTime
Definition flex_sensor.h:68
float pulseWidthUs
Definition flex_sensor.h:67
int flexCallbackCounter
Definition flex_sensor.h:64
void postRawValue(float inputValue, efitick_t timestamp) override
void setValidValue(float value, efitick_t timestamp)
float interpolateClamped(float x1, float y1, float x2, float y2, float x)
static EngineAccessor engine
Definition engine.h:413
bool warning(ObdCode code, const char *fmt,...)
@ CUSTOM_FLEX_HIGH
@ CUSTOM_FLEX_LOW
tempC("WBO: Temperature", SensorCategory.SENSOR_INPUTS, FieldType.INT16, 1936, 1.0, 500.0, 1000.0, "C")

Referenced by flexExtiCallback().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ debug()

void FlexSensor::debug ( )

Definition at line 50 of file flex_sensor.cpp.

50 {
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}

Referenced by initFlexSensor().

Here is the caller graph for this function:

◆ Register()

void FlexSensor::Register ( bool  withTempSensor)

Definition at line 58 of file flex_sensor.cpp.

58 {
60
61 if (withTempSensor) {
63 }
64}
bool Register()
Definition sensor.cpp:131

Referenced by initFlexSensor().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ unregister()

void FlexSensor::unregister ( )

Definition at line 66 of file flex_sensor.cpp.

66 {
69}
void unregister()
Definition sensor.cpp:135

Referenced by deInitFlexSensor().

Here is the call graph for this function:
Here is the caller graph for this function:

Field Documentation

◆ converter

FlexConverter FlexSensor::converter
private

Definition at line 55 of file flex_sensor.h.

Referenced by FlexSensor().

◆ flexCallbackCounter

int FlexSensor::flexCallbackCounter = 0
private

Definition at line 64 of file flex_sensor.h.

Referenced by callback(), and debug().

◆ flexFreq

Timer FlexSensor::flexFreq
private

Definition at line 59 of file flex_sensor.h.

Referenced by callback().

◆ flexFuelTemp

StoredValueSensor FlexSensor::flexFuelTemp
private

Definition at line 54 of file flex_sensor.h.

Referenced by callback(), Register(), and unregister().

◆ flexPulse

Timer FlexSensor::flexPulse
private

Definition at line 59 of file flex_sensor.h.

Referenced by callback().

◆ flexSensor

FunctionalSensor FlexSensor::flexSensor
private

Definition at line 53 of file flex_sensor.h.

Referenced by callback(), FlexSensor(), Register(), and unregister().

◆ flexTempFilter

Biquad FlexSensor::flexTempFilter
private

Definition at line 57 of file flex_sensor.h.

Referenced by callback(), and FlexSensor().

◆ frequency

float FlexSensor::frequency
private

Definition at line 66 of file flex_sensor.h.

Referenced by callback(), and debug().

◆ gotRising

bool FlexSensor::gotRising = false
private

Definition at line 61 of file flex_sensor.h.

Referenced by callback().

◆ latestCallbackTime

efitick_t FlexSensor::latestCallbackTime
private

Definition at line 68 of file flex_sensor.h.

Referenced by callback(), and debug().

◆ lowFlexCallbackCounter

int FlexSensor::lowFlexCallbackCounter = 0
private

Definition at line 63 of file flex_sensor.h.

Referenced by callback(), and debug().

◆ pulseWidthUs

float FlexSensor::pulseWidthUs
private

Definition at line 67 of file flex_sensor.h.

Referenced by callback(), and debug().


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