rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Private Attributes
SensorReader< TSensorType > Class Template Referencefinal

Provides an interface for reading sensors. More...

#include <sensor_reader.h>

Collaboration diagram for SensorReader< TSensorType >:
Collaboration graph
[legend]

Public Types

using sensorValueType = float
 

Public Member Functions

 SensorReader (sensorValueType defaultValue)
 
SensorResult get () const
 
sensorValueType getOrDefault () const
 
 operator sensorValueType () const
 

Private Attributes

const sensorValueType m_defaultValue
 

Detailed Description

template<SensorType TSensorType>
class SensorReader< TSensorType >

Provides an interface for reading sensors.

Example usage:

// Create a sensor reader for type MySensor, and fallback value 10.0 SensorReader<SensorType::MySensor> mySensorReader(10.0f);

<later>

// Returns the sensor value if valid, or 10.0 if invalid. float currentSensorValue = mySensorReader.getOrDefault(); alternatively, because we have implicit conversion: float currentSensorValue = mySensorReader;

Simply calling the get() method returns the full SensorResult, should more complex logic be required in case of an invalid sensor reading.

Definition at line 32 of file sensor_reader.h.

Member Typedef Documentation

◆ sensorValueType

template<SensorType TSensorType>
using SensorReader< TSensorType >::sensorValueType = float

Definition at line 34 of file sensor_reader.h.

Constructor & Destructor Documentation

◆ SensorReader()

template<SensorType TSensorType>
SensorReader< TSensorType >::SensorReader ( sensorValueType  defaultValue)
inlineexplicit

Definition at line 36 of file sensor_reader.h.

37 : m_defaultValue(defaultValue) {}
const sensorValueType m_defaultValue

Member Function Documentation

◆ get()

template<SensorType TSensorType>
SensorResult SensorReader< TSensorType >::get ( ) const
inline

Definition at line 39 of file sensor_reader.h.

39 {
40 return Sensor::get(TSensorType);
41 }
virtual SensorResult get() const =0

Referenced by SensorReader< TSensorType >::getOrDefault().

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

◆ getOrDefault()

template<SensorType TSensorType>
sensorValueType SensorReader< TSensorType >::getOrDefault ( ) const
inline

Definition at line 46 of file sensor_reader.h.

46 {
47 auto result = get();
48
49 if (result.Valid) {
50 return (sensorValueType)result.Value;
51 } else {
52 return m_defaultValue;
53 }
54 }
SensorResult get() const
float sensorValueType

Referenced by SensorReader< TSensorType >::operator sensorValueType().

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

◆ operator sensorValueType()

template<SensorType TSensorType>
SensorReader< TSensorType >::operator sensorValueType ( ) const
inline

Definition at line 57 of file sensor_reader.h.

57 {
58 return getOrDefault();
59 }
sensorValueType getOrDefault() const
Here is the call graph for this function:

Field Documentation

◆ m_defaultValue

template<SensorType TSensorType>
const sensorValueType SensorReader< TSensorType >::m_defaultValue
private

Definition at line 62 of file sensor_reader.h.

Referenced by SensorReader< TSensorType >::getOrDefault().


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