rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
Data Structures | Typedefs | Functions
sensor.h File Reference

Detailed Description

Base class for sensors. Inherit this class to implement a new type of sensor.

This file defines the basis for all sensor inputs to the ECU, and provides a registry so that consumers may be agnostic to how each sensor may work.

HOW TO ADD A NEW SENSOR TYPE:

  1. Add an entry to the enum in sensor_type.h. Be sure to add it ABOVE the placeholder at the end of the list.
  2. In the init/sensor folder, create/modify logic to create an instance of the new sensor, configure it if necessary, and call its Register() function if it should be enabled. See init_fluid_pressure.cpp for a minimal example.
  3. Consume the new sensor with Sensor::get(SensorType::MyNewSensor)

Providers: Instantiate a subclass of Sensor, and implement the Get() function. Call Register() to install the new sensor in the registry, preparing it for use.

Mocking: The sensor table supports mocking each sensors value. Call Sensor::SetMockValue to set a mock value for a particular sensor, and Sensor::ResetMockValue or Sensor::ResetAllMocks to reset one or all stored mock values.

Composite Sensors: Some sensors may be implemented as composite sensors, ie sensors that depend on other sensors to determine their reading. For example, the throttle pedal may have a pair of potentiometers that provide redundancy for the pedal's position. Each one may be its own sensor, then with one "master" sensors that combines the results of the others, and provides validation of whether the readings agree.

Date
September 12, 2019
Author
Matthew Kennedy, (c) 2019

Definition in file sensor.h.

Data Structures

class  Sensor
 

Typedefs

using SensorResult = expected< float >
 

Functions

SensorType findSensorTypeByName (const char *name)
 

Typedef Documentation

◆ SensorResult

using SensorResult = expected<float>

Definition at line 46 of file sensor.h.

Function Documentation

◆ findSensorTypeByName()

SensorType findSensorTypeByName ( const char name)

this is definitely not the fastest implementation possible but good enough for now? todo: some sort of hashmap in the future?

Definition at line 259 of file sensor.cpp.

259 {
260 using namespace rusefi::stringutil;
261
262 for (size_t i = 0;i < efi::size(s_sensorRegistry); i++) {
263 SensorType type = (SensorType)i;
264 const char *sensorName = getSensorType(type);
265 if (strEqualCaseInsensitive(sensorName, name)) {
266 return type;
267 }
268 }
269
270 return SensorType::Invalid;
271}
const char * getSensorType(SensorType value)
static SensorRegistryEntry s_sensorRegistry[static_cast< size_t >(SensorType::PlaceholderLast)]
Definition sensor.cpp:129
SensorType
Definition sensor_type.h:18

Referenced by findSensorByName(), and initSensorCli().

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

Go to the source code of this file.