rusEFI
The most advanced open source ECU
|
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:
Consumers:
tl;dr: Use a SensorConsumer. See sensor_consumer.h
All a consumer does is look up whether a particular sensor is present in the table, and if so, asks it for the current reading. This could synchronously perform sensor acquisition and conversion (not recommended), or use a previously stored value (recommended!). This functionality is implemented in sensor_consumer.h, and sensor.cpp.
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.
Definition in file sensor.h.
Data Structures | |
class | Sensor |
Typedefs | |
using | SensorResult = expected< float > |
Functions | |
SensorType | findSensorTypeByName (const char *name) |
using SensorResult = expected<float> |
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 268 of file sensor.cpp.
Referenced by findSensorByName().