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

#include <frequency_sensor.h>

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

Public Member Functions

 FrequencySensor (SensorType type, efidur_t timeoutPeriod)
 
void initIfValid (brain_pin_e pin, SensorConverter &converter, float filterParameter)
 
void deInit ()
 
void showInfo (const char *sensorName) const override
 
void onEdge (efitick_t nowNt)
 
- Public Member Functions inherited from FunctionalSensor
 FunctionalSensor (SensorType type, efidur_t timeoutPeriod)
 
void showInfo (const char *sensorName) const override
 
- Public Member Functions inherited from FunctionalSensorImpl< SensorConverter >
 FunctionalSensorImpl (SensorType type, efidur_t timeoutPeriod)
 
void postRawValue (float inputValue, efitick_t timestamp) override
 
void setFunction (SensorConverter &func)
 
SensorConvertergetFunction () const
 
float getRaw () const override final
 
- 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 bool isRedundant () const
 
void unregister ()
 
SensorType type () const
 

Data Fields

bool useBiQuad = true
 
int eventCounter = 0
 

Private Attributes

Timer m_edgeTimer
 
brain_pin_e m_pin = Gpio::Unassigned
 
Biquad m_filter
 

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 FunctionalSensorBase
 FunctionalSensorBase (SensorType type, efidur_t timeoutPeriod)
 
- 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 8 of file frequency_sensor.h.

Constructor & Destructor Documentation

◆ FrequencySensor()

FrequencySensor::FrequencySensor ( SensorType  type,
efidur_t  timeoutPeriod 
)
inline

Definition at line 10 of file frequency_sensor.h.

11 : FunctionalSensor(type, timeoutPeriod)
12 { }
Class for sensors that convert from some raw floating point value (ex: voltage, frequency,...
SensorType type() const
Definition sensor.h:162

Member Function Documentation

◆ deInit()

void FrequencySensor::deInit ( )

Definition at line 45 of file frequency_sensor.cpp.

45 {
46 if (!isBrainPinValid(m_pin)) {
47 return;
48 }
49
50#if EFI_PROD_CODE
52#endif
53
55}
@ Unassigned
void efiExtiDisablePin(brain_pin_e brainPin)
bool isBrainPinValid(brain_pin_e brainPin)

Referenced by deinitAuxSpeedSensors(), deinitInputShaftSpeedSensor(), deinitTurbochargerSpeedSensor(), and deInitVehicleSpeedSensor().

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

◆ initIfValid()

void FrequencySensor::initIfValid ( brain_pin_e  pin,
SensorConverter converter,
float  filterParameter 
)

Definition at line 18 of file frequency_sensor.cpp.

18 {
19 if (!isBrainPinValid(pin)) {
20 return;
21 }
22
23 // Filter parameter greater than or equal to 0.5 impossible as it causes filter instability, clamp
24 // far under that value.
25 if (filterParameter > 0.35f) {
26 filterParameter = 0.35f;
27 }
28
29 m_filter.configureLowpass(1, filterParameter);
30
32
33#if EFI_PROD_CODE
34 if (efiExtiEnablePin(getSensorName(), pin, PAL_EVENT_MODE_FALLING_EDGE,
35 freqSensorExtiCallback, reinterpret_cast<void*>(this)) < 0) {
36 return;
37 }
38#endif // EFI_PROD_CODE
39
40 m_pin = pin;
41
42 Register();
43}
void configureLowpass(float samplingFrequency, float cutoffFrequency, float Q=0.54f)
Definition biquad.cpp:48
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 freqSensorExtiCallback(void *arg, efitick_t nowNt)
converter
brain_pin_e pin
Definition stm32_adc.cpp:15

Referenced by initAuxSpeedSensors(), initInputShaftSpeedSensor(), initTurbochargerSpeedSensor(), and initVehicleSpeedSensor().

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

◆ onEdge()

void FrequencySensor::onEdge ( efitick_t  nowNt)

Definition at line 57 of file frequency_sensor.cpp.

57 {
58 // diagnostics
60 float frequency = 1 / m_edgeTimer.getElapsedSecondsAndReset(nowNt);
61
62 if (useBiQuad) {
64 }
65
66 postRawValue(frequency, nowNt);
67}
float filter(float input)
Definition biquad.cpp:74
void postRawValue(float inputValue, efitick_t timestamp) override
static float frequency
Definition init_flex.cpp:21
Here is the call graph for this function:

◆ showInfo()

void FrequencySensor::showInfo ( const char sensorName) const
overridevirtual

Implements Sensor.

Definition at line 54 of file sensor_info_printing.cpp.

54 {
55 efiPrintf("FrequencySensor \"%s\" counter %d", sensorName, eventCounter);
56}

Field Documentation

◆ eventCounter

int FrequencySensor::eventCounter = 0

◆ m_edgeTimer

Timer FrequencySensor::m_edgeTimer
private

Definition at line 26 of file frequency_sensor.h.

Referenced by onEdge().

◆ m_filter

Biquad FrequencySensor::m_filter
private

Definition at line 29 of file frequency_sensor.h.

Referenced by initIfValid(), and onEdge().

◆ m_pin

brain_pin_e FrequencySensor::m_pin = Gpio::Unassigned
private

Definition at line 27 of file frequency_sensor.h.

Referenced by deInit(), and initIfValid().

◆ useBiQuad

bool FrequencySensor::useBiQuad = true

Definition at line 18 of file frequency_sensor.h.

Referenced by initAuxSpeedSensors(), and onEdge().


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